Starting working on GUI : Cube Icon + integrity bar + money counter + money buy tower
This commit is contained in:
parent
fd72147865
commit
29a7d9b884
25 changed files with 401 additions and 48 deletions
1
Assets/Icones/cube.svg
Normal file
1
Assets/Icones/cube.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg style="height: 512px; width: 512px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M0 0h512v512H0z" fill="#ffffff" fill-opacity="1"></path><g class="" style="" transform="translate(0,0)"><path d="M256 24.585 51.47 118.989 256 213.394l204.53-94.405zM38.998 133.054v258.353L247 487.415V229.063zm434.004 0L265 229.062v258.353l208.002-96.008z" fill="#333333" fill-opacity="1"></path></g></svg>
|
||||||
|
After Width: | Height: | Size: 414 B |
37
Assets/Icones/cube.svg.import
Normal file
37
Assets/Icones/cube.svg.import
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://nh6qxoglb4g3"
|
||||||
|
path="res://.godot/imported/cube.svg-c0871abfea5e01c560421978cffeb532.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Assets/Icones/cube.svg"
|
||||||
|
dest_files=["res://.godot/imported/cube.svg-c0871abfea5e01c560421978cffeb532.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
|
svg/scale=1.0
|
||||||
|
editor/scale_with_editor_scale=false
|
||||||
|
editor/convert_colors_with_editor_theme=false
|
||||||
|
|
@ -23,6 +23,8 @@ billboard = 2
|
||||||
texture = ExtResource("2_r5o86")
|
texture = ExtResource("2_r5o86")
|
||||||
|
|
||||||
[node name="Impact" type="Area3D" parent="."]
|
[node name="Impact" type="Area3D" parent="."]
|
||||||
|
collision_layer = 4
|
||||||
|
collision_mask = 4
|
||||||
|
|
||||||
[node name="CollisionShape3D2" type="CollisionShape3D" parent="Impact"]
|
[node name="CollisionShape3D2" type="CollisionShape3D" parent="Impact"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0714111, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0714111, 0)
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,14 @@ extends Node
|
||||||
|
|
||||||
#Emitter : TowerButton.gd
|
#Emitter : TowerButton.gd
|
||||||
#Subscriber : World.gd
|
#Subscriber : World.gd
|
||||||
signal tower_selected(tower : PackedScene)
|
signal tower_selected(tower : PackedScene, tower_button : TowerButton)
|
||||||
|
|
||||||
|
|
||||||
|
#Emitter : cube.gd
|
||||||
|
#Subscriber : progress_bar_cube_integrity.gd
|
||||||
|
signal cube_integrity_changed(_value : int, _max_value : int)
|
||||||
|
|
||||||
|
|
||||||
|
#Emitter : cube.gd
|
||||||
|
#Subscriber : label_money.gd
|
||||||
|
signal money_changed(_value : int)
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,32 @@
|
||||||
extends StaticBody3D
|
extends StaticBody3D
|
||||||
class_name TheCube
|
class_name TheCube
|
||||||
|
|
||||||
@export var max_life : int = 50
|
@export var max_health : int = 50
|
||||||
var health : int = max_life :
|
|
||||||
|
var health : int = max_health :
|
||||||
set(value):
|
set(value):
|
||||||
health = value
|
health = value
|
||||||
|
EventBus.cube_integrity_changed.emit(health, max_health)
|
||||||
if health <= 0:
|
if health <= 0:
|
||||||
death()
|
death()
|
||||||
|
|
||||||
|
|
||||||
|
@export var money : int = 100 :
|
||||||
|
set(value):
|
||||||
|
money = value
|
||||||
|
EventBus.money_changed.emit(money)
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
call_deferred("display_money_on_first_call")
|
||||||
|
|
||||||
|
#Because I can't connect properly on first frame and send money info
|
||||||
|
func display_money_on_first_call() -> void:
|
||||||
|
EventBus.money_changed.emit(money)
|
||||||
|
|
||||||
|
|
||||||
func take_damage(damage : int) -> void:
|
func take_damage(damage : int) -> void:
|
||||||
health -= damage
|
health -= damage
|
||||||
print(health)
|
|
||||||
|
|
||||||
|
|
||||||
func death():
|
func death():
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
albedo_color = Color(0.051971, 0.051971, 0.051971, 1)
|
albedo_color = Color(0.051971, 0.051971, 0.051971, 1)
|
||||||
|
|
||||||
[node name="TheCube" type="StaticBody3D"]
|
[node name="TheCube" type="StaticBody3D"]
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 8
|
||||||
script = ExtResource("1_wrmut")
|
script = ExtResource("1_wrmut")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,48 @@ class_name Tower
|
||||||
var bullet : PackedScene = preload("res://Bullets/arrow.tscn")
|
var bullet : PackedScene = preload("res://Bullets/arrow.tscn")
|
||||||
@export var tower_name : String = "Pierre"
|
@export var tower_name : String = "Pierre"
|
||||||
@export var bullet_damage : int = 1
|
@export var bullet_damage : int = 1
|
||||||
@export var energy : float = 100.0 #Next thing to do
|
@export var price : int = 100
|
||||||
|
|
||||||
|
@export_group("Energy")
|
||||||
|
@export var max_energy : float = 100.0 #Next thing to do
|
||||||
|
@export var energy_regen : float = 10.0
|
||||||
|
@export var energy_cost : float = 50.0
|
||||||
|
@onready var energy_bar : EnergyBar3D = $EnergyBar3D
|
||||||
|
|
||||||
|
var tower_button : TowerButton = null
|
||||||
|
|
||||||
|
var energy : float = max_energy:
|
||||||
|
set(value):
|
||||||
|
energy = clampf(value, 0.0, max_energy)
|
||||||
|
energy_bar.update(value)
|
||||||
|
if energy < energy_cost:
|
||||||
|
is_exhausted = true
|
||||||
|
else:
|
||||||
|
is_exhausted = false
|
||||||
|
|
||||||
var current_targets : Array = []
|
var current_targets : Array = []
|
||||||
var current : CharacterBody3D
|
var current : CharacterBody3D
|
||||||
var can_shoot : bool = true
|
var can_shoot : bool = true
|
||||||
|
var is_exhausted : bool = false
|
||||||
|
|
||||||
|
var is_rest : bool = false:
|
||||||
|
set(value):
|
||||||
|
is_rest = value
|
||||||
|
if value:
|
||||||
|
resting()
|
||||||
|
else:
|
||||||
|
in_action()
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
energy_bar.set_up(energy, max_energy)
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
if is_rest:
|
||||||
|
return
|
||||||
|
|
||||||
if is_instance_valid(current):
|
if is_instance_valid(current):
|
||||||
if can_shoot:
|
if can_shoot && not is_exhausted:
|
||||||
shoot()
|
shoot()
|
||||||
can_shoot = false
|
can_shoot = false
|
||||||
$Cooldown.start()
|
$Cooldown.start()
|
||||||
|
|
@ -22,6 +55,8 @@ func _process(delta: float) -> void:
|
||||||
|
|
||||||
|
|
||||||
func shoot() -> void:
|
func shoot() -> void:
|
||||||
|
energy -= energy_cost
|
||||||
|
|
||||||
var temp_bullet : Bullet = bullet.instantiate()
|
var temp_bullet : Bullet = bullet.instantiate()
|
||||||
temp_bullet.target = current
|
temp_bullet.target = current
|
||||||
temp_bullet.bullet_damage = bullet_damage
|
temp_bullet.bullet_damage = bullet_damage
|
||||||
|
|
@ -29,6 +64,17 @@ func shoot() -> void:
|
||||||
temp_bullet.global_position = $Aim.global_position
|
temp_bullet.global_position = $Aim.global_position
|
||||||
|
|
||||||
|
|
||||||
|
func resting() -> void:
|
||||||
|
energy += energy_regen
|
||||||
|
visible = false
|
||||||
|
$EnergyCooldown.start()
|
||||||
|
|
||||||
|
|
||||||
|
func in_action() -> void:
|
||||||
|
visible = true
|
||||||
|
$EnergyCooldown.stop()
|
||||||
|
|
||||||
|
|
||||||
func choose_target(_current_targets : Array) -> void:
|
func choose_target(_current_targets : Array) -> void:
|
||||||
var temp_array : Array = _current_targets
|
var temp_array : Array = _current_targets
|
||||||
var current_target : CharacterBody3D = null
|
var current_target : CharacterBody3D = null
|
||||||
|
|
@ -41,6 +87,7 @@ func choose_target(_current_targets : Array) -> void:
|
||||||
|
|
||||||
current = current_target
|
current = current_target
|
||||||
|
|
||||||
|
|
||||||
func _on_range_body_entered(body: Node3D) -> void:
|
func _on_range_body_entered(body: Node3D) -> void:
|
||||||
if body is Enemy:
|
if body is Enemy:
|
||||||
current_targets.append(body)
|
current_targets.append(body)
|
||||||
|
|
@ -55,3 +102,7 @@ func _on_range_body_exited(body: Node3D) -> void:
|
||||||
|
|
||||||
func _on_cooldown_timeout() -> void:
|
func _on_cooldown_timeout() -> void:
|
||||||
can_shoot = true
|
can_shoot = true
|
||||||
|
|
||||||
|
|
||||||
|
func _on_energy_cooldown_timeout() -> void:
|
||||||
|
resting()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://trg7ag3dqr2l"]
|
[gd_scene load_steps=6 format=3 uid="uid://trg7ag3dqr2l"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://8kpvuurr5h5n" path="res://Towers/tower.gd" id="1_egfuc"]
|
[ext_resource type="Script" uid="uid://8kpvuurr5h5n" path="res://Towers/tower.gd" id="1_egfuc"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bn6ikwol6x8r0" path="res://Assets/Characters/Male1.png" id="2_egfuc"]
|
[ext_resource type="Texture2D" uid="uid://bn6ikwol6x8r0" path="res://Assets/Characters/Male1.png" id="2_egfuc"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bm303ot1ck82l" path="res://UI/energy_bar_3d.tscn" id="3_pajr1"]
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_egfuc"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_egfuc"]
|
||||||
size = Vector3(1, 0.1, 1)
|
size = Vector3(1, 0.1, 1)
|
||||||
|
|
@ -20,6 +21,8 @@ shape = SubResource("BoxShape3D_egfuc")
|
||||||
|
|
||||||
[node name="Range" type="Area3D" parent="."]
|
[node name="Range" type="Area3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.923584, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.923584, 0)
|
||||||
|
collision_layer = 4
|
||||||
|
collision_mask = 4
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Range"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Range"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.475708, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.475708, 0)
|
||||||
|
|
@ -33,6 +36,9 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.02026, 0)
|
||||||
[node name="Cooldown" type="Timer" parent="."]
|
[node name="Cooldown" type="Timer" parent="."]
|
||||||
wait_time = 1.5
|
wait_time = 1.5
|
||||||
|
|
||||||
|
[node name="EnergyCooldown" type="Timer" parent="."]
|
||||||
|
wait_time = 0.5
|
||||||
|
|
||||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
[node name="Sprite3D" type="Sprite3D" parent="."]
|
||||||
transform = Transform3D(3.5, 0, 0, 0, 3.5, 0, 0, 0, 3.5, 0, 0.515442, 0)
|
transform = Transform3D(3.5, 0, 0, 0, 3.5, 0, 0, 0, 3.5, 0, 0.515442, 0)
|
||||||
billboard = 2
|
billboard = 2
|
||||||
|
|
@ -41,6 +47,10 @@ hframes = 8
|
||||||
vframes = 12
|
vframes = 12
|
||||||
frame = 75
|
frame = 75
|
||||||
|
|
||||||
|
[node name="EnergyBar3D" parent="." instance=ExtResource("3_pajr1")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.44473, 0)
|
||||||
|
|
||||||
[connection signal="body_entered" from="Range" to="." method="_on_range_body_entered"]
|
[connection signal="body_entered" from="Range" to="." method="_on_range_body_entered"]
|
||||||
[connection signal="body_exited" from="Range" to="." method="_on_range_body_exited"]
|
[connection signal="body_exited" from="Range" to="." method="_on_range_body_exited"]
|
||||||
[connection signal="timeout" from="Cooldown" to="." method="_on_cooldown_timeout"]
|
[connection signal="timeout" from="Cooldown" to="." method="_on_cooldown_timeout"]
|
||||||
|
[connection signal="timeout" from="EnergyCooldown" to="." method="_on_energy_cooldown_timeout"]
|
||||||
|
|
|
||||||
9
UI/cube_integrity.gd
Normal file
9
UI/cube_integrity.gd
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
extends ProgressBar
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
EventBus.cube_integrity_changed.connect(_on_EventBus_cube_integrity_changed)
|
||||||
|
value = 100
|
||||||
|
|
||||||
|
|
||||||
|
func _on_EventBus_cube_integrity_changed(_value, _max_value) -> void:
|
||||||
|
set_value(float(_value)/float(_max_value) * 100.0)
|
||||||
1
UI/cube_integrity.gd.uid
Normal file
1
UI/cube_integrity.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dmcgoepvytnn
|
||||||
9
UI/energy_bar_2d.gd
Normal file
9
UI/energy_bar_2d.gd
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
extends ProgressBar
|
||||||
|
|
||||||
|
func setup_bar(amount : int, max_amount : int) -> void:
|
||||||
|
max_value = max_amount
|
||||||
|
value = amount
|
||||||
|
|
||||||
|
|
||||||
|
func update_bar(amount : int) -> void:
|
||||||
|
value = amount
|
||||||
1
UI/energy_bar_2d.gd.uid
Normal file
1
UI/energy_bar_2d.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://ckd6msqvmhtos
|
||||||
29
UI/energy_bar_2d.tscn
Normal file
29
UI/energy_bar_2d.tscn
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
[gd_scene load_steps=4 format=3 uid="uid://xlhufcqxk113"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://ckd6msqvmhtos" path="res://UI/energy_bar_2d.gd" id="1_4beyc"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qpj2g"]
|
||||||
|
bg_color = Color(0.341176, 0.0823529, 0.0941176, 0)
|
||||||
|
border_width_left = 2
|
||||||
|
border_width_top = 2
|
||||||
|
border_width_right = 2
|
||||||
|
border_width_bottom = 2
|
||||||
|
expand_margin_left = 4.0
|
||||||
|
expand_margin_top = 4.0
|
||||||
|
expand_margin_right = 4.0
|
||||||
|
expand_margin_bottom = 4.0
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xcn5x"]
|
||||||
|
bg_color = Color(0.921569, 0.890196, 0.415686, 1)
|
||||||
|
|
||||||
|
[node name="HealthBar2D" type="ProgressBar"]
|
||||||
|
custom_minimum_size = Vector2(100, 10)
|
||||||
|
offset_left = 4.0
|
||||||
|
offset_top = 4.0
|
||||||
|
offset_right = 104.0
|
||||||
|
offset_bottom = 14.0
|
||||||
|
theme_override_styles/background = SubResource("StyleBoxFlat_qpj2g")
|
||||||
|
theme_override_styles/fill = SubResource("StyleBoxFlat_xcn5x")
|
||||||
|
value = 50.0
|
||||||
|
show_percentage = false
|
||||||
|
script = ExtResource("1_4beyc")
|
||||||
15
UI/energy_bar_3d.gd
Normal file
15
UI/energy_bar_3d.gd
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
extends Sprite3D
|
||||||
|
class_name EnergyBar3D
|
||||||
|
|
||||||
|
@onready var bar : ProgressBar = $SubViewport/EnergyBar2D
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
texture = $SubViewport.get_texture()
|
||||||
|
|
||||||
|
|
||||||
|
func set_up(value : int, max_amount : int) -> void:
|
||||||
|
bar.setup_bar(value, max_amount)
|
||||||
|
|
||||||
|
|
||||||
|
func update(value : int) -> void:
|
||||||
|
bar.update_bar(value)
|
||||||
1
UI/energy_bar_3d.gd.uid
Normal file
1
UI/energy_bar_3d.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://d0hr28ug7324
|
||||||
16
UI/energy_bar_3d.tscn
Normal file
16
UI/energy_bar_3d.tscn
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
[gd_scene load_steps=4 format=3 uid="uid://bm303ot1ck82l"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bd7ed8dvc7m0v" path="res://icon.svg" id="1_d48o1"]
|
||||||
|
[ext_resource type="Script" uid="uid://d0hr28ug7324" path="res://UI/energy_bar_3d.gd" id="2_d48o1"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://xlhufcqxk113" path="res://UI/energy_bar_2d.tscn" id="3_8lue3"]
|
||||||
|
|
||||||
|
[node name="EnergyBar3D" type="Sprite3D"]
|
||||||
|
billboard = 2
|
||||||
|
texture = ExtResource("1_d48o1")
|
||||||
|
script = ExtResource("2_d48o1")
|
||||||
|
|
||||||
|
[node name="SubViewport" type="SubViewport" parent="."]
|
||||||
|
size = Vector2i(108, 18)
|
||||||
|
size_2d_override_stretch = true
|
||||||
|
|
||||||
|
[node name="EnergyBar2D" parent="SubViewport" instance=ExtResource("3_8lue3")]
|
||||||
76
UI/gui.tscn
Normal file
76
UI/gui.tscn
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
[gd_scene load_steps=6 format=3 uid="uid://p6a6rb7sgeqd"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://d2x8oy4os7ysn" path="res://UI/label_money.gd" id="1_cwd3r"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://nh6qxoglb4g3" path="res://Assets/Icones/cube.svg" id="1_epgl5"]
|
||||||
|
[ext_resource type="Script" uid="uid://dmcgoepvytnn" path="res://UI/cube_integrity.gd" id="2_sj6ny"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_nxmp4"]
|
||||||
|
bg_color = Color(0.180392, 0.180392, 0.180392, 0)
|
||||||
|
border_color = Color(0.099986, 0.099986, 0.0999859, 1)
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_epgl5"]
|
||||||
|
bg_color = Color(0.727498, 0.222072, 0.249347, 1)
|
||||||
|
|
||||||
|
[node name="GUI" type="Control"]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
|
[node name="VBox" type="VBoxContainer" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 12
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_top = -32.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 0
|
||||||
|
|
||||||
|
[node name="HBox" type="HBoxContainer" parent="VBox"]
|
||||||
|
layout_mode = 2
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="LabelMoney" type="Label" parent="VBox/HBox"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 1
|
||||||
|
text = "Money :"
|
||||||
|
vertical_alignment = 2
|
||||||
|
script = ExtResource("1_cwd3r")
|
||||||
|
|
||||||
|
[node name="Margin" type="MarginContainer" parent="VBox/HBox"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="CubeIcon" type="TextureButton" parent="VBox/HBox"]
|
||||||
|
custom_minimum_size = Vector2(50, 50)
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 4
|
||||||
|
texture_normal = ExtResource("1_epgl5")
|
||||||
|
texture_pressed = ExtResource("1_epgl5")
|
||||||
|
texture_hover = ExtResource("1_epgl5")
|
||||||
|
texture_disabled = ExtResource("1_epgl5")
|
||||||
|
texture_focused = ExtResource("1_epgl5")
|
||||||
|
ignore_texture_size = true
|
||||||
|
stretch_mode = 0
|
||||||
|
|
||||||
|
[node name="Margin2" type="MarginContainer" parent="VBox/HBox"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="LabelTeam" type="Label" parent="VBox/HBox"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 1
|
||||||
|
text = "actif/total"
|
||||||
|
vertical_alignment = 2
|
||||||
|
|
||||||
|
[node name="CubeIntegrity" type="ProgressBar" parent="VBox"]
|
||||||
|
custom_minimum_size = Vector2(0, 5)
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_styles/background = SubResource("StyleBoxFlat_nxmp4")
|
||||||
|
theme_override_styles/fill = SubResource("StyleBoxFlat_epgl5")
|
||||||
|
value = 50.0
|
||||||
|
show_percentage = false
|
||||||
|
script = ExtResource("2_sj6ny")
|
||||||
9
UI/label_money.gd
Normal file
9
UI/label_money.gd
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
extends Label
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
EventBus.money_changed.connect(_on_EventBus_money_changed)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_EventBus_money_changed(_value) -> void:
|
||||||
|
print("money to change : ", _value)
|
||||||
|
set_text("Money = " + str(_value))
|
||||||
1
UI/label_money.gd.uid
Normal file
1
UI/label_money.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://d2x8oy4os7ysn
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
[gd_scene load_steps=3 format=3 uid="uid://he31g7f3ru1c"]
|
[gd_scene load_steps=3 format=3 uid="uid://he31g7f3ru1c"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://bqpeu50pgsdfk" path="res://UI/tower_button.tscn" id="1_txsyf"]
|
[ext_resource type="PackedScene" uid="uid://bqpeu50pgsdfk" path="res://UI/tower_button.tscn" id="1_txsyf"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dp846r4jscm5p" path="res://Towers/tower-b.tscn" id="2_oxe32"]
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_oxe32"]
|
||||||
|
bg_color = Color(0.921569, 0.890196, 0.415686, 1)
|
||||||
|
|
||||||
[node name="ShopPanel" type="Panel"]
|
[node name="ShopPanel" type="Panel"]
|
||||||
custom_minimum_size = Vector2(300, 0)
|
custom_minimum_size = Vector2(300, 0)
|
||||||
|
|
@ -23,11 +25,18 @@ grow_vertical = 2
|
||||||
[node name="PierreButton" parent="VBoxContainer" instance=ExtResource("1_txsyf")]
|
[node name="PierreButton" parent="VBoxContainer" instance=ExtResource("1_txsyf")]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="AlineButton" parent="VBoxContainer" instance=ExtResource("1_txsyf")]
|
[node name="EnergyBar" type="ProgressBar" parent="VBoxContainer/PierreButton"]
|
||||||
layout_mode = 2
|
custom_minimum_size = Vector2(0, 5)
|
||||||
text = "Aline
|
layout_mode = 1
|
||||||
350 Trucs"
|
anchors_preset = 12
|
||||||
tower = ExtResource("2_oxe32")
|
anchor_top = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_top = -4.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 0
|
||||||
|
theme_override_styles/fill = SubResource("StyleBoxFlat_oxe32")
|
||||||
|
show_percentage = false
|
||||||
|
|
||||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
|
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
@ -38,5 +47,3 @@ custom_minimum_size = Vector2(0, 50)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Cancel
|
text = "Cancel
|
||||||
"
|
"
|
||||||
|
|
||||||
[editable path="VBoxContainer/AlineButton"]
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
extends Button
|
extends Button
|
||||||
|
class_name TowerButton
|
||||||
|
|
||||||
@export var tower : PackedScene
|
@export var tower : PackedScene
|
||||||
|
var tower_in_game : Tower
|
||||||
|
|
||||||
func _on_pressed() -> void:
|
func _on_pressed() -> void:
|
||||||
EventBus.tower_selected.emit(tower)
|
EventBus.tower_selected.emit(tower, self)
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
if tower_in_game:
|
||||||
|
$EnergyBar.value = tower_in_game.energy/tower_in_game.max_energy * 100.0
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ radius = 1.0
|
||||||
[node name="PathFollow3D" type="PathFollow3D"]
|
[node name="PathFollow3D" type="PathFollow3D"]
|
||||||
|
|
||||||
[node name="EnemyA" type="CharacterBody3D" parent="."]
|
[node name="EnemyA" type="CharacterBody3D" parent="."]
|
||||||
|
collision_layer = 4
|
||||||
|
collision_mask = 4
|
||||||
script = ExtResource("1_l7e03")
|
script = ExtResource("1_l7e03")
|
||||||
speed = 1
|
speed = 1
|
||||||
|
|
||||||
|
|
@ -30,6 +32,8 @@ vframes = 12
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6, 0)
|
||||||
|
|
||||||
[node name="AttackRange" type="Area3D" parent="EnemyA"]
|
[node name="AttackRange" type="Area3D" parent="EnemyA"]
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 8
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="EnemyA/AttackRange"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="EnemyA/AttackRange"]
|
||||||
shape = SubResource("SphereShape3D_cmo2f")
|
shape = SubResource("SphereShape3D_cmo2f")
|
||||||
|
|
|
||||||
|
|
@ -51,3 +51,4 @@ rest={
|
||||||
3d_physics/layer_1="floor"
|
3d_physics/layer_1="floor"
|
||||||
3d_physics/layer_2="tower"
|
3d_physics/layer_2="tower"
|
||||||
3d_physics/layer_3="baddy"
|
3d_physics/layer_3="baddy"
|
||||||
|
3d_physics/layer_4="cube"
|
||||||
|
|
|
||||||
84
world.gd
84
world.gd
|
|
@ -1,9 +1,11 @@
|
||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
@onready var tower_blueprint = preload("res://Towers/tower.tscn")
|
@onready var tower_blueprint = preload("res://Towers/tower.tscn")
|
||||||
|
@onready var selected_tower_button : TowerButton = $CanvasLayer/UI/ShopPanel/VBoxContainer/PierreButton
|
||||||
|
|
||||||
@onready var cam : Camera3D = $Camera3D
|
@onready var cam : Camera3D = $Camera3D
|
||||||
@onready var selector : Node3D = $Selector
|
@onready var selector : Node3D = $Selector
|
||||||
|
@onready var the_cube : TheCube = %TheCube
|
||||||
|
|
||||||
|
|
||||||
var team_in_action : Array[Tower]
|
var team_in_action : Array[Tower]
|
||||||
|
|
@ -11,6 +13,8 @@ var team_in_rest : Array[Tower]
|
||||||
var target_tower : Tower
|
var target_tower : Tower
|
||||||
var in_build_menu : bool = false
|
var in_build_menu : bool = false
|
||||||
|
|
||||||
|
var selected_collider : CollisionObject3D
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
$Spawner.spawn_next_wave()
|
$Spawner.spawn_next_wave()
|
||||||
$CanvasLayer/UI/ShopPanel.visible = in_build_menu
|
$CanvasLayer/UI/ShopPanel.visible = in_build_menu
|
||||||
|
|
@ -20,9 +24,20 @@ func _ready() -> void:
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
handle_player_controls()
|
handle_player_controls()
|
||||||
if Input.is_action_just_pressed("build"):
|
if Input.is_action_just_pressed("build"):
|
||||||
build_tower(tower_blueprint)
|
if not selected_collider:
|
||||||
if Input.is_action_just_pressed("rest") && target_tower:
|
return
|
||||||
send_to_rest(target_tower)
|
|
||||||
|
if selected_collider.collision_layer == 1:
|
||||||
|
build_tower(tower_blueprint)
|
||||||
|
if selected_collider is TheCube:
|
||||||
|
open_shop()
|
||||||
|
else:
|
||||||
|
close_shop()
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("rest"):
|
||||||
|
close_shop()
|
||||||
|
if target_tower:
|
||||||
|
send_to_rest(target_tower)
|
||||||
|
|
||||||
|
|
||||||
func handle_player_controls() -> void:
|
func handle_player_controls() -> void:
|
||||||
|
|
@ -38,38 +53,57 @@ func handle_player_controls() -> void:
|
||||||
|
|
||||||
if ray_result.is_empty():
|
if ray_result.is_empty():
|
||||||
selector.visible = false
|
selector.visible = false
|
||||||
|
selected_collider = null
|
||||||
return
|
return
|
||||||
|
|
||||||
selector.visible = true
|
|
||||||
var collider : CollisionObject3D = ray_result.get("collider")
|
var collider : CollisionObject3D = ray_result.get("collider")
|
||||||
|
selected_collider = collider
|
||||||
|
|
||||||
|
selector.visible = true
|
||||||
selector.global_position = collider.global_position
|
selector.global_position = collider.global_position
|
||||||
selector.global_position += Vector3(0.0,0.2,0.0)
|
selector.global_position += Vector3(0.0,0.2,0.0)
|
||||||
|
|
||||||
if collider is Tower:
|
if selected_collider is Tower:
|
||||||
target_tower = collider
|
target_tower = collider
|
||||||
else:
|
else:
|
||||||
target_tower = null
|
target_tower = null
|
||||||
|
|
||||||
|
# Refactoriser ce code
|
||||||
func build_tower(scene : PackedScene) -> void:
|
func build_tower(scene : PackedScene) -> void:
|
||||||
if !selector.visible:
|
if !selector.visible:
|
||||||
return
|
return
|
||||||
|
|
||||||
var temp_tower : Tower = scene.instantiate()
|
var temp_tower : Tower = scene.instantiate()
|
||||||
|
|
||||||
|
|
||||||
|
#Move existing tower
|
||||||
for tower : Tower in team_in_action:
|
for tower : Tower in team_in_action:
|
||||||
if tower.tower_name == temp_tower.tower_name:
|
if tower.tower_name == temp_tower.tower_name:
|
||||||
move_tower(tower)
|
move_tower(tower)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
#Send to action a resting tower
|
||||||
for tower : Tower in team_in_rest:
|
for tower : Tower in team_in_rest:
|
||||||
if tower.tower_name == temp_tower.tower_name:
|
if tower.tower_name == temp_tower.tower_name:
|
||||||
move_tower(tower)
|
move_tower(tower)
|
||||||
send_to_action(tower)
|
send_to_action(tower)
|
||||||
return
|
return
|
||||||
|
|
||||||
add_child(temp_tower)
|
#Build Tower
|
||||||
team_in_action.append(temp_tower)
|
if temp_tower.price < the_cube.money:
|
||||||
temp_tower.global_position = selector.global_position
|
#Can't build
|
||||||
|
print("Too costly")
|
||||||
|
return
|
||||||
|
else :
|
||||||
|
#Can build
|
||||||
|
the_cube.money -= temp_tower.price
|
||||||
|
temp_tower.tower_button = selected_tower_button
|
||||||
|
add_child(temp_tower)
|
||||||
|
selected_tower_button.tower_in_game = temp_tower
|
||||||
|
|
||||||
|
send_to_action(temp_tower)
|
||||||
|
move_tower(temp_tower)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func move_tower(tower : Tower):
|
func move_tower(tower : Tower):
|
||||||
|
|
@ -79,19 +113,33 @@ func move_tower(tower : Tower):
|
||||||
func send_to_rest(tower : Tower):
|
func send_to_rest(tower : Tower):
|
||||||
team_in_action.erase(tower)
|
team_in_action.erase(tower)
|
||||||
team_in_rest.append(tower)
|
team_in_rest.append(tower)
|
||||||
tower.visible = false
|
tower.is_rest = true
|
||||||
|
|
||||||
|
|
||||||
func send_to_action(tower : Tower):
|
func send_to_action(tower : Tower):
|
||||||
team_in_rest.erase(tower)
|
team_in_rest.erase(tower)
|
||||||
team_in_action.append(tower)
|
team_in_action.append(tower)
|
||||||
tower.visible = true
|
tower.is_rest = false
|
||||||
|
|
||||||
|
func open_shop():
|
||||||
func _on_EventBus_tower_selected(tower : PackedScene):
|
if in_build_menu:
|
||||||
tower_blueprint = tower
|
close_shop()
|
||||||
|
return
|
||||||
|
|
||||||
func _on_recrutement_button_pressed() -> void:
|
in_build_menu = true
|
||||||
in_build_menu = !in_build_menu
|
|
||||||
$CanvasLayer/UI/ShopPanel.visible = in_build_menu
|
$CanvasLayer/UI/ShopPanel.visible = in_build_menu
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func close_shop():
|
||||||
|
in_build_menu = false
|
||||||
|
$CanvasLayer/UI/ShopPanel.visible = in_build_menu
|
||||||
|
|
||||||
|
|
||||||
|
func _on_EventBus_tower_selected(tower : PackedScene, tower_button : TowerButton):
|
||||||
|
tower_blueprint = tower
|
||||||
|
selected_tower_button = tower_button
|
||||||
|
|
||||||
|
|
||||||
|
func _on_cube_icon_pressed() -> void:
|
||||||
|
open_shop()
|
||||||
|
|
|
||||||
19
world.tscn
19
world.tscn
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=13 format=3 uid="uid://ky0uewndeuwv"]
|
[gd_scene load_steps=14 format=3 uid="uid://ky0uewndeuwv"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://qqid42jkpkmv" path="res://world.gd" id="1_fj7yv"]
|
[ext_resource type="Script" uid="uid://qqid42jkpkmv" path="res://world.gd" id="1_fj7yv"]
|
||||||
[ext_resource type="PackedScene" uid="uid://d1f6m15niwgt" path="res://Tiles/tile.tscn" id="3_aqk2v"]
|
[ext_resource type="PackedScene" uid="uid://d1f6m15niwgt" path="res://Tiles/tile.tscn" id="3_aqk2v"]
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
[ext_resource type="Resource" uid="uid://dkbuy7fetnihs" path="res://Waves/wave_1.tres" id="7_ioo17"]
|
[ext_resource type="Resource" uid="uid://dkbuy7fetnihs" path="res://Waves/wave_1.tres" id="7_ioo17"]
|
||||||
[ext_resource type="Resource" uid="uid://dvw6vm3vbpmdl" path="res://Waves/wave_2.tres" id="8_wse8f"]
|
[ext_resource type="Resource" uid="uid://dvw6vm3vbpmdl" path="res://Waves/wave_2.tres" id="8_wse8f"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dbx8ow3v45k4k" path="res://UI/ui.tscn" id="9_ioo17"]
|
[ext_resource type="PackedScene" uid="uid://dbx8ow3v45k4k" path="res://UI/ui.tscn" id="9_ioo17"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://p6a6rb7sgeqd" path="res://UI/gui.tscn" id="11_ic0uy"]
|
||||||
|
|
||||||
[sub_resource type="Curve3D" id="Curve3D_aqk2v"]
|
[sub_resource type="Curve3D" id="Curve3D_aqk2v"]
|
||||||
_data = {
|
_data = {
|
||||||
|
|
@ -140,6 +141,7 @@ transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 9.5, 0
|
||||||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 9.5, 0, 0.5)
|
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 9.5, 0, 0.5)
|
||||||
|
|
||||||
[node name="TheCube" parent="Map" instance=ExtResource("5_wse8f")]
|
[node name="TheCube" parent="Map" instance=ExtResource("5_wse8f")]
|
||||||
|
unique_name_in_owner = true
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10.1496, 0.657819, 0.497613)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10.1496, 0.657819, 0.497613)
|
||||||
|
|
||||||
[node name="Spawner" type="Path3D" parent="."]
|
[node name="Spawner" type="Path3D" parent="."]
|
||||||
|
|
@ -161,20 +163,11 @@ light_color = Color(0.823308, 0.863845, 0.742102, 1)
|
||||||
|
|
||||||
[node name="UI" parent="CanvasLayer" instance=ExtResource("9_ioo17")]
|
[node name="UI" parent="CanvasLayer" instance=ExtResource("9_ioo17")]
|
||||||
|
|
||||||
[node name="RecrutementButton" type="Button" parent="CanvasLayer/UI"]
|
[node name="GUI" parent="CanvasLayer/UI" instance=ExtResource("11_ic0uy")]
|
||||||
custom_minimum_size = Vector2(200, 50)
|
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 2
|
|
||||||
anchor_top = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
offset_left = 29.0
|
|
||||||
offset_top = -77.0
|
|
||||||
offset_right = 229.0
|
|
||||||
offset_bottom = -27.0
|
|
||||||
grow_vertical = 0
|
|
||||||
text = "Recrutement"
|
|
||||||
|
|
||||||
[connection signal="timeout" from="Spawner/SpawnTimer" to="Spawner" method="_on_spawn_timer_timeout"]
|
[connection signal="timeout" from="Spawner/SpawnTimer" to="Spawner" method="_on_spawn_timer_timeout"]
|
||||||
[connection signal="pressed" from="CanvasLayer/UI/RecrutementButton" to="." method="_on_recrutement_button_pressed"]
|
[connection signal="pressed" from="CanvasLayer/UI/GUI/VBox/HBox/CubeIcon" to="." method="_on_cube_icon_pressed"]
|
||||||
|
|
||||||
[editable path="CanvasLayer/UI"]
|
[editable path="CanvasLayer/UI"]
|
||||||
|
[editable path="CanvasLayer/UI/GUI"]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue