Compare commits
2 commits
02ea306ff1
...
b557833edb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b557833edb | ||
| bbff19c6ce |
3 changed files with 173 additions and 1 deletions
144
Scripts/PlayerManager.gd
Normal file
144
Scripts/PlayerManager.gd
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
class_name PlayerManager
|
||||||
|
|
||||||
|
|
||||||
|
#TODO Get rid of tower_blueprint
|
||||||
|
@onready var tower_blueprint = preload("res://Towers/tower.tscn")
|
||||||
|
|
||||||
|
@onready var selected_tower : Tower = null
|
||||||
|
|
||||||
|
@onready var cam : Camera3D = $"../Camera3D"
|
||||||
|
@onready var the_cube : TheCube = %TheCube
|
||||||
|
|
||||||
|
var tower_count : int = 0:
|
||||||
|
set(value):
|
||||||
|
tower_count = value
|
||||||
|
EventBus.tower_count_changed.emit(tower_count)
|
||||||
|
|
||||||
|
|
||||||
|
var team_in_action : Array[Tower]:
|
||||||
|
set(value):
|
||||||
|
team_in_action = value
|
||||||
|
EventBus.team_in_action_changed.emit(team_in_action)
|
||||||
|
|
||||||
|
|
||||||
|
var team_in_rest : Array[Tower]
|
||||||
|
var target_tower : Tower
|
||||||
|
|
||||||
|
var selected_collider : CollisionObject3D
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
EventBus.tower_selected.connect(_on_EventBus_tower_selected)
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
handle_player_controls()
|
||||||
|
if Input.is_action_just_pressed("build"):
|
||||||
|
if not selected_collider:
|
||||||
|
return
|
||||||
|
|
||||||
|
if selected_collider.collision_layer == 1:
|
||||||
|
build_tower()
|
||||||
|
if selected_collider is TheCube:
|
||||||
|
EventBus.open_shop.emit()
|
||||||
|
else:
|
||||||
|
EventBus.close_shop.emit()
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("rest"):
|
||||||
|
EventBus.close_shop.emit()
|
||||||
|
if target_tower:
|
||||||
|
send_to_rest()
|
||||||
|
|
||||||
|
func handle_player_controls() -> void:
|
||||||
|
var space_state : PhysicsDirectSpaceState3D = get_world_3d().direct_space_state
|
||||||
|
var mouse_pos : Vector2 = get_viewport().get_mouse_position()
|
||||||
|
|
||||||
|
var origin : Vector3 = cam.project_ray_origin(mouse_pos)
|
||||||
|
var end : Vector3 = origin + cam.project_ray_normal(mouse_pos) * 100
|
||||||
|
var ray : PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.create(origin, end)
|
||||||
|
ray.collide_with_bodies = true
|
||||||
|
|
||||||
|
var ray_result : Dictionary = space_state.intersect_ray(ray)
|
||||||
|
|
||||||
|
if ray_result.is_empty():
|
||||||
|
visible = false
|
||||||
|
selected_collider = null
|
||||||
|
return
|
||||||
|
|
||||||
|
var collider : CollisionObject3D = ray_result.get("collider")
|
||||||
|
selected_collider = collider
|
||||||
|
|
||||||
|
visible = true
|
||||||
|
global_position = collider.global_position
|
||||||
|
global_position += Vector3(0.0,0.2,0.0)
|
||||||
|
|
||||||
|
if selected_collider is Tower:
|
||||||
|
target_tower = collider
|
||||||
|
else:
|
||||||
|
target_tower = null
|
||||||
|
|
||||||
|
# Refactoriser ce code
|
||||||
|
func build_tower() -> void:
|
||||||
|
if !visible:
|
||||||
|
return
|
||||||
|
|
||||||
|
var temp_tower : Tower = tower_blueprint.instantiate()
|
||||||
|
|
||||||
|
|
||||||
|
#Move existing tower
|
||||||
|
for tower : Tower in team_in_action:
|
||||||
|
if tower.tower_name == temp_tower.tower_name:
|
||||||
|
move_tower()
|
||||||
|
return
|
||||||
|
|
||||||
|
#Send to action a resting tower
|
||||||
|
for tower : Tower in team_in_rest:
|
||||||
|
if tower.tower_name == temp_tower.tower_name:
|
||||||
|
move_tower()
|
||||||
|
send_to_action()
|
||||||
|
return
|
||||||
|
|
||||||
|
#Build Tower
|
||||||
|
if temp_tower.price < the_cube.money:
|
||||||
|
#Can't build
|
||||||
|
print("Too costly")
|
||||||
|
return
|
||||||
|
else :
|
||||||
|
#Can build
|
||||||
|
EventBus.money_spent.emit(temp_tower.price)
|
||||||
|
tower_count += 1
|
||||||
|
$"../Towers".add_child(temp_tower)
|
||||||
|
EventBus.tower_builded.emit(temp_tower)
|
||||||
|
selected_tower = temp_tower
|
||||||
|
send_to_action()
|
||||||
|
move_tower()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func move_tower():
|
||||||
|
selected_tower.global_position = global_position
|
||||||
|
|
||||||
|
|
||||||
|
func send_to_rest():
|
||||||
|
team_in_action.erase(selected_tower)
|
||||||
|
team_in_rest.append(selected_tower)
|
||||||
|
selected_tower.is_rest = true
|
||||||
|
EventBus.team_in_action_changed.emit(team_in_action)
|
||||||
|
|
||||||
|
|
||||||
|
func send_to_action():
|
||||||
|
team_in_rest.erase(selected_tower)
|
||||||
|
team_in_action.append(selected_tower)
|
||||||
|
selected_tower.is_rest = false
|
||||||
|
EventBus.team_in_action_changed.emit(team_in_action)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_EventBus_tower_selected(tower : PackedScene):
|
||||||
|
# TODO: Remove tower_blueprint
|
||||||
|
print("pouette")
|
||||||
|
# tower_blueprint = tower
|
||||||
|
|
||||||
|
# TODO: Utile ?
|
||||||
|
func _on_cube_icon_pressed() -> void:
|
||||||
|
pass
|
||||||
|
#open_shop()
|
||||||
1
Scripts/PlayerManager.gd.uid
Normal file
1
Scripts/PlayerManager.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://caf3yamufmhd4
|
||||||
|
|
@ -1,12 +1,25 @@
|
||||||
[gd_scene load_steps=7 format=3 uid="uid://djyye2otjju2d"]
|
[gd_scene load_steps=12 format=3 uid="uid://djyye2otjju2d"]
|
||||||
|
|
||||||
[ext_resource type="Theme" uid="uid://bbp4qcbwkeg7x" path="res://default_theme.tres" id="1_xxfb2"]
|
[ext_resource type="Theme" uid="uid://bbp4qcbwkeg7x" path="res://default_theme.tres" id="1_xxfb2"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bqpeu50pgsdfk" path="res://UI/tower_button.tscn" id="2_qus6b"]
|
[ext_resource type="PackedScene" uid="uid://bqpeu50pgsdfk" path="res://UI/tower_button.tscn" id="2_qus6b"]
|
||||||
[ext_resource type="Script" uid="uid://jg5ny0u7buos" path="res://game_menu.gd" id="2_wr0q8"]
|
[ext_resource type="Script" uid="uid://jg5ny0u7buos" path="res://game_menu.gd" id="2_wr0q8"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cs24awnya7o5p" path="res://Assets/VFX/start_menu_vignette.png" id="3_3rcmp"]
|
||||||
[ext_resource type="Texture2D" uid="uid://uptdcefxlv4c" path="res://Assets/Icones/ppdf_bio_image_placeholder_2.png" id="3_wr0q8"]
|
[ext_resource type="Texture2D" uid="uid://uptdcefxlv4c" path="res://Assets/Icones/ppdf_bio_image_placeholder_2.png" id="3_wr0q8"]
|
||||||
[ext_resource type="Script" uid="uid://tn3qdhcyaxsg" path="res://UI/upgrade_button.gd" id="4_3rcmp"]
|
[ext_resource type="Script" uid="uid://tn3qdhcyaxsg" path="res://UI/upgrade_button.gd" id="4_3rcmp"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dksohsrys0yy7" path="res://Assets/Icones/baby-face.svg" id="5_pbvm6"]
|
[ext_resource type="Texture2D" uid="uid://dksohsrys0yy7" path="res://Assets/Icones/baby-face.svg" id="5_pbvm6"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_pbvm6"]
|
||||||
|
bg_color = Color(0.933333, 0.933333, 0.933333, 1)
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yd342"]
|
||||||
|
bg_color = Color(0.2, 0.2, 0.2, 0.588235)
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tklej"]
|
||||||
|
bg_color = Color(0.2, 0.2, 0.2, 0.588235)
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_scae6"]
|
||||||
|
bg_color = Color(0.2, 0.2, 0.2, 0.588235)
|
||||||
|
|
||||||
[node name="GameMenu" type="Control"]
|
[node name="GameMenu" type="Control"]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
|
|
@ -24,6 +37,17 @@ anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxFlat_pbvm6")
|
||||||
|
|
||||||
|
[node name="TextureRect" type="TextureRect" parent="Background"]
|
||||||
|
modulate = Color(1, 1, 1, 0.305882)
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
texture = ExtResource("3_3rcmp")
|
||||||
|
|
||||||
[node name="MenuHeader" type="HBoxContainer" parent="."]
|
[node name="MenuHeader" type="HBoxContainer" parent="."]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
|
|
@ -100,6 +124,7 @@ offset_left = 313.0
|
||||||
offset_top = 86.0
|
offset_top = 86.0
|
||||||
offset_right = 1113.0
|
offset_right = 1113.0
|
||||||
offset_bottom = 598.0
|
offset_bottom = 598.0
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxFlat_yd342")
|
||||||
|
|
||||||
[node name="MarginContainer2" type="MarginContainer" parent="CharacterSheet/TowerStats"]
|
[node name="MarginContainer2" type="MarginContainer" parent="CharacterSheet/TowerStats"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
|
|
@ -217,6 +242,7 @@ offset_right = -19.0
|
||||||
offset_bottom = -28.0
|
offset_bottom = -28.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxFlat_tklej")
|
||||||
|
|
||||||
[node name="MarginContainer2" type="MarginContainer" parent="CharacterSheet/TowerUpgrades"]
|
[node name="MarginContainer2" type="MarginContainer" parent="CharacterSheet/TowerUpgrades"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
|
|
@ -286,6 +312,7 @@ offset_right = 153.0
|
||||||
offset_bottom = -28.0
|
offset_bottom = -28.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxFlat_scae6")
|
||||||
|
|
||||||
[node name="MarginContainer" type="MarginContainer" parent="CharacterSheet/TowerSkills"]
|
[node name="MarginContainer" type="MarginContainer" parent="CharacterSheet/TowerSkills"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue