Refactor + clean
This commit is contained in:
parent
adc1b9034c
commit
6f815d9cae
15 changed files with 69 additions and 118 deletions
|
|
@ -79,3 +79,7 @@ signal energy_has_changed(tower : Tower)
|
|||
#Emitter : WaveManager.gd
|
||||
#Subscriber : gui.gd
|
||||
signal allowedTowerHasChange(allowedTowers : Array[Tower.TYPES])
|
||||
|
||||
#Emitter : WaveManager.gd
|
||||
#Subscriber : gui.gd
|
||||
signal waveHasChange(waveNumber : int)
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
extends Node
|
||||
|
||||
var health : int = 100
|
||||
var money : int = 300
|
||||
|
||||
var wave : int = 0
|
||||
|
||||
var enemies_alive : int = 0
|
||||
|
||||
func reset() -> void:
|
||||
health = 100
|
||||
money = 300
|
||||
wave = 0
|
||||
enemies_alive = 0
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://crqs1b44v67nr
|
||||
|
|
@ -1,42 +1,14 @@
|
|||
[gd_resource type="Resource" script_class="Level" load_steps=15 format=3 uid="uid://ob41fnhkjr3o"]
|
||||
[gd_resource type="Resource" script_class="Level" load_steps=11 format=3 uid="uid://ob41fnhkjr3o"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cuhq6u67cbbqm" path="res://Scripts/Level.gd" id="1_ftl6b"]
|
||||
[ext_resource type="Script" uid="uid://chu8s12rtdeqx" path="res://Scripts/Wave.gd" id="2_457yt"]
|
||||
[ext_resource type="Script" uid="uid://blxx3vs2wnfet" path="res://Scripts/Troop.gd" id="3_ub8wd"]
|
||||
[ext_resource type="PackedScene" uid="uid://dknt1oiyei5e5" path="res://enemies/enemy-a.tscn" id="4_ujs1b"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_5q243"]
|
||||
script = ExtResource("3_ub8wd")
|
||||
enemy = ExtResource("4_ujs1b")
|
||||
number_to_spawn = 1
|
||||
spawn_delay = 0.0
|
||||
metadata/_custom_type_script = "uid://blxx3vs2wnfet"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ps5n4"]
|
||||
script = ExtResource("3_ub8wd")
|
||||
enemy = ExtResource("4_ujs1b")
|
||||
number_to_spawn = 1
|
||||
spawn_delay = 3.0
|
||||
metadata/_custom_type_script = "uid://blxx3vs2wnfet"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_qfjse"]
|
||||
script = ExtResource("3_ub8wd")
|
||||
enemy = ExtResource("4_ujs1b")
|
||||
number_to_spawn = 1
|
||||
spawn_delay = 3.0
|
||||
metadata/_custom_type_script = "uid://blxx3vs2wnfet"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_m6gub"]
|
||||
script = ExtResource("2_457yt")
|
||||
troops = Array[ExtResource("3_ub8wd")]([SubResource("Resource_5q243"), SubResource("Resource_ps5n4"), SubResource("Resource_qfjse")])
|
||||
wait_time_before_launch_wave = 4.0
|
||||
wait_for_enemy_kills = true
|
||||
metadata/_custom_type_script = "uid://chu8s12rtdeqx"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_1mxdl"]
|
||||
script = ExtResource("3_ub8wd")
|
||||
enemy = ExtResource("4_ujs1b")
|
||||
number_to_spawn = 1
|
||||
number_to_spawn = 3
|
||||
spawn_delay = 0.0
|
||||
metadata/_custom_type_script = "uid://blxx3vs2wnfet"
|
||||
|
||||
|
|
@ -44,40 +16,38 @@ metadata/_custom_type_script = "uid://blxx3vs2wnfet"
|
|||
script = ExtResource("3_ub8wd")
|
||||
enemy = ExtResource("4_ujs1b")
|
||||
number_to_spawn = 1
|
||||
spawn_delay = 3.0
|
||||
spawn_delay = 10.0
|
||||
metadata/_custom_type_script = "uid://blxx3vs2wnfet"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_457yt"]
|
||||
script = ExtResource("2_457yt")
|
||||
troops = Array[ExtResource("3_ub8wd")]([SubResource("Resource_1mxdl"), SubResource("Resource_87wss")])
|
||||
wait_time_before_launch_wave = 5.0
|
||||
wait_for_enemy_kills = true
|
||||
metadata/_custom_type_script = "uid://chu8s12rtdeqx"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ftl6b"]
|
||||
[sub_resource type="Resource" id="Resource_ps5n4"]
|
||||
script = ExtResource("3_ub8wd")
|
||||
enemy = ExtResource("4_ujs1b")
|
||||
number_to_spawn = 1
|
||||
spawn_delay = 1.0
|
||||
spawn_delay = 0.0
|
||||
metadata/_custom_type_script = "uid://blxx3vs2wnfet"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ub8wd"]
|
||||
[sub_resource type="Resource" id="Resource_qfjse"]
|
||||
script = ExtResource("3_ub8wd")
|
||||
enemy = ExtResource("4_ujs1b")
|
||||
number_to_spawn = 1
|
||||
spawn_delay = 1.0
|
||||
spawn_delay = 10.0
|
||||
metadata/_custom_type_script = "uid://blxx3vs2wnfet"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ujs1b"]
|
||||
[sub_resource type="Resource" id="Resource_m6gub"]
|
||||
script = ExtResource("2_457yt")
|
||||
troops = Array[ExtResource("3_ub8wd")]([SubResource("Resource_ftl6b"), SubResource("Resource_ub8wd")])
|
||||
wait_time_before_launch_wave = 3.0
|
||||
troops = Array[ExtResource("3_ub8wd")]([SubResource("Resource_ps5n4"), SubResource("Resource_qfjse")])
|
||||
wait_for_enemy_kills = true
|
||||
metadata/_custom_type_script = "uid://chu8s12rtdeqx"
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_ftl6b")
|
||||
waves = Array[ExtResource("2_457yt")]([SubResource("Resource_m6gub"), SubResource("Resource_457yt"), SubResource("Resource_ujs1b")])
|
||||
waves = Array[ExtResource("2_457yt")]([SubResource("Resource_457yt"), SubResource("Resource_m6gub")])
|
||||
auto_start = false
|
||||
allowedTowers = Array[int]([1, 2])
|
||||
metadata/_custom_type_script = "uid://cuhq6u67cbbqm"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
[sub_resource type="Resource" id="Resource_cm6sg"]
|
||||
script = ExtResource("2_2ji0m")
|
||||
troops = Array[ExtResource("3_y8rub")]([])
|
||||
wait_time_before_launch_wave = 3.0
|
||||
wait_for_enemy_kills = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ps5n4"]
|
||||
|
|
@ -44,7 +43,6 @@ spawn_delay = 1.0
|
|||
[sub_resource type="Resource" id="Resource_c4t4w"]
|
||||
script = ExtResource("2_2ji0m")
|
||||
troops = Array[ExtResource("3_y8rub")]([SubResource("Resource_ps5n4"), SubResource("Resource_qeljc"), SubResource("Resource_1p7sg"), SubResource("Resource_y8rub"), SubResource("Resource_w0brl")])
|
||||
wait_time_before_launch_wave = 3.8
|
||||
wait_for_enemy_kills = true
|
||||
metadata/_custom_type_script = "uid://chu8s12rtdeqx"
|
||||
|
||||
|
|
@ -61,7 +59,6 @@ spawn_delay = 1.0
|
|||
[sub_resource type="Resource" id="Resource_s83h5"]
|
||||
script = ExtResource("2_2ji0m")
|
||||
troops = Array[ExtResource("3_y8rub")]([SubResource("Resource_2ji0m"), SubResource("Resource_nj0jn")])
|
||||
wait_time_before_launch_wave = 3.6
|
||||
wait_for_enemy_kills = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_833nr"]
|
||||
|
|
@ -72,7 +69,6 @@ spawn_delay = 1.0
|
|||
[sub_resource type="Resource" id="Resource_xgtww"]
|
||||
script = ExtResource("2_2ji0m")
|
||||
troops = Array[ExtResource("3_y8rub")]([SubResource("Resource_833nr")])
|
||||
wait_time_before_launch_wave = 7.0
|
||||
wait_for_enemy_kills = true
|
||||
|
||||
[resource]
|
||||
|
|
|
|||
|
|
@ -220,9 +220,6 @@ curve = SubResource("Curve3D_aqk2v")
|
|||
script = ExtResource("5_036b0")
|
||||
level = ExtResource("8_44brb")
|
||||
|
||||
[node name="WaveTimer" type="Timer" parent="WaveManager"]
|
||||
one_shot = true
|
||||
|
||||
[node name="TroopTimer" type="Timer" parent="WaveManager"]
|
||||
one_shot = true
|
||||
|
||||
|
|
|
|||
|
|
@ -2,5 +2,4 @@ extends Resource
|
|||
class_name Wave
|
||||
|
||||
@export var troops : Array[Troop]
|
||||
@export var wait_time_before_launch_wave : float = 3
|
||||
@export var wait_for_enemy_kills : bool = true
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
extends Path3D
|
||||
class_name WaveManager
|
||||
|
||||
const PACK_DELAY : float = .15
|
||||
|
||||
@export var level : Level
|
||||
var current_wave : Wave
|
||||
var current_troop : Troop
|
||||
|
||||
var enemies_to_spawn : int = 0
|
||||
var wave : int = 0
|
||||
var enemies_alive : int = 0
|
||||
var wave_on_going : bool = false
|
||||
|
||||
@onready var waveTimer := $WaveTimer
|
||||
|
||||
@onready var troopTimer := $TroopTimer
|
||||
|
||||
|
||||
|
|
@ -19,7 +23,7 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if GameManager.wave > 0 || level.auto_start:
|
||||
if wave > 0 || level.auto_start:
|
||||
spawn_manager()
|
||||
|
||||
|
||||
|
|
@ -29,19 +33,43 @@ func spawn_next_wave() -> void:
|
|||
return
|
||||
|
||||
current_wave = level.waves.pop_front()
|
||||
GameManager.wave += 1
|
||||
waveTimer.start(current_wave.wait_time_before_launch_wave)
|
||||
wave += 1
|
||||
EventBus.waveHasChange.emit(wave)
|
||||
|
||||
|
||||
func spawn_troop() -> void:
|
||||
for n in current_troop.number_to_spawn:
|
||||
add_child(current_troop.enemy.instantiate())
|
||||
GameManager.enemies_alive += 1
|
||||
spawnEnemy(n * PACK_DELAY)
|
||||
|
||||
|
||||
func spawnEnemy(delay : float) -> void:
|
||||
var enemy := createEnemy()
|
||||
|
||||
if delay > 0:
|
||||
var enemyTimer := createTimer(delay)
|
||||
enemyTimer.timeout.connect(
|
||||
func():
|
||||
add_child(enemy)
|
||||
enemyTimer.queue_free()
|
||||
)
|
||||
add_child(enemyTimer)
|
||||
else:
|
||||
add_child(enemy)
|
||||
|
||||
enemies_alive += 1
|
||||
|
||||
|
||||
func createEnemy() -> PathFollow3D :
|
||||
var fp3D : PathFollow3D = current_troop.enemy.instantiate()
|
||||
var enemy : Enemy = fp3D.find_children("*", "Enemy")[0]
|
||||
enemy.died.connect(func(): enemies_alive -= 1)
|
||||
|
||||
return fp3D
|
||||
|
||||
|
||||
func spawn_manager() -> void:
|
||||
#Send next troop
|
||||
if !waveTimer.is_stopped() || !troopTimer.is_stopped():
|
||||
if !troopTimer.is_stopped():
|
||||
return
|
||||
|
||||
if !current_wave:
|
||||
|
|
@ -56,7 +84,7 @@ func spawn_manager() -> void:
|
|||
troopTimer.start(current_troop.spawn_delay)
|
||||
|
||||
wave_on_going = true
|
||||
if GameManager.enemies_alive == 0 && current_wave.troops.is_empty():
|
||||
if enemies_alive == 0 && current_wave.troops.is_empty():
|
||||
wave_on_going = false
|
||||
spawn_next_wave()
|
||||
elif !current_wave.wait_for_enemy_kills:
|
||||
|
|
@ -65,3 +93,12 @@ func spawn_manager() -> void:
|
|||
|
||||
func clearLevel() -> void:
|
||||
queue_free()
|
||||
|
||||
|
||||
func createTimer(delay : float, oneShot = true, autoStart = true) -> Timer :
|
||||
var timer := Timer.new()
|
||||
timer.wait_time = delay
|
||||
timer.one_shot = oneShot
|
||||
timer.autostart = autoStart
|
||||
|
||||
return timer
|
||||
|
|
|
|||
|
|
@ -18,14 +18,10 @@ var health : int = max_health :
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
call_deferred("display_money_on_first_call")
|
||||
EventBus.money_received.connect(_on_EventBus_money_received)
|
||||
EventBus.money_spent.connect(_on_EventBus_money_spent)
|
||||
EventBus.player_has_won.connect(_on_EventBus_player_has_won)
|
||||
|
||||
#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)
|
||||
EventBus.money_changed.emit.call_deferred(money)
|
||||
|
||||
|
||||
func take_damage(damage : int) -> void:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ extends StaticBody3D
|
|||
class_name Tower
|
||||
|
||||
# DANGER NONE Should always be first
|
||||
enum TYPES { NONE, PIERRE, ALINE, MAXENCE, VICTORIA, EVAN, ALEX }
|
||||
enum TYPES { NONE, PIERRE, ALINE, MAXENCE, VICTORIA, EVAN, ALEX, GERALDINE }
|
||||
|
||||
var bullet : PackedScene = preload("res://Bullets/bullet.tscn")
|
||||
@export var tower_name : String = "Pierre"
|
||||
|
|
@ -37,10 +37,7 @@ 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
|
||||
is_exhausted = energy < energy_cost
|
||||
EventBus.energy_has_changed.emit(self)
|
||||
|
||||
var current_targets : Array = []
|
||||
|
|
@ -85,10 +82,6 @@ func apply_upgrade(upgrade : TowerUpgrade):
|
|||
else:
|
||||
printerr("Upgrade already bought")
|
||||
|
||||
func _init() -> void:
|
||||
EventBus.energy_has_changed.emit(self)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
EventBus.tower_upgraded.connect(_on_EventBus_tower_upgraded)
|
||||
energy_bar.set_up(energy, max_energy)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ var value:
|
|||
get:
|
||||
return getTypedValue(text)
|
||||
|
||||
func _init() -> void:
|
||||
func _ready() -> void:
|
||||
text_changed.connect(valueUpdated)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ enum DIRECTION { UP, DOWN, TOP, LEFT, VERTICAL, HORIZONTAL}
|
|||
@onready var waitForKill := $VBoxContainer2/ButtonContainer4/WaitForKill
|
||||
@onready var levelSelect := $VBoxContainer2/HBoxContainer/LevelSelect
|
||||
@onready var waveTabContainer := $VBoxContainer2/ScrollContainer/WaveContainer
|
||||
@onready var waveTimerInput := $VBoxContainer2/ButtonContainer3/WaveTimer
|
||||
@onready var towerSelector := $VBoxContainer2/ButtonContainer5/TowerSelector
|
||||
var level : Level
|
||||
var currentWave : int = -1
|
||||
|
|
@ -223,12 +222,7 @@ func selectLevel(levelName : String) -> void :
|
|||
level = load(LEVEL_NAME_PATH_PATERN.format([["name", levelName]]))
|
||||
|
||||
|
||||
func changeWaveCooldown(duration : float) -> void:
|
||||
level.waves[currentWave].wait_time_before_launch_wave = duration
|
||||
|
||||
|
||||
func tabFocusHaschanged(idx : int) -> void:
|
||||
waveTimerInput.setValue(level.waves[idx].wait_time_before_launch_wave)
|
||||
currentWave = idx
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://dh24t8804isms"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://dh24t8804isms"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://27y0jliv6ckx" path="res://addons/LevelEditor/WaveMaker.gd" id="1_usfft"]
|
||||
[ext_resource type="Script" uid="uid://b47p2u458hsn0" path="res://addons/LevelEditor/UI/CustomOptionButton.gd" id="2_xjxpq"]
|
||||
[ext_resource type="Script" uid="uid://bpv75ucqoy446" path="res://addons/LevelEditor/UI/CustomLineEdit.gd" id="3_qw7ts"]
|
||||
|
||||
[node name="Menu" type="HBoxContainer"]
|
||||
offset_right = 885.0
|
||||
|
|
@ -98,25 +97,6 @@ layout_mode = 2
|
|||
layout_mode = 2
|
||||
text = "Attendre la mort des enemies pour lancer la vague suivante"
|
||||
|
||||
[node name="ButtonContainer3" type="HBoxContainer" parent="VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="WaveTimer" type="LineEdit" parent="VBoxContainer2/ButtonContainer3"]
|
||||
custom_minimum_size = Vector2(55, 55)
|
||||
layout_mode = 2
|
||||
script = ExtResource("3_qw7ts")
|
||||
inputType = 2
|
||||
step = 0.2
|
||||
metadata/_custom_type_script = "uid://bpv75ucqoy446"
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer2/ButtonContainer3"]
|
||||
custom_minimum_size = Vector2(10, 0)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer2/ButtonContainer3"]
|
||||
layout_mode = 2
|
||||
text = "Timer avant lancement de la vague"
|
||||
|
||||
[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer2"]
|
||||
custom_minimum_size = Vector2(0, 30)
|
||||
layout_mode = 2
|
||||
|
|
@ -163,7 +143,6 @@ drag_to_rearrange_enabled = true
|
|||
[connection signal="toggled" from="VBoxContainer2/ButtonContainer2/AutoLaunchLevel" to="." method="_on_auto_launch_wave_toggled"]
|
||||
[connection signal="pressed" from="VBoxContainer2/ButtonContainer2/RemoveWave" to="." method="removeWave"]
|
||||
[connection signal="toggled" from="VBoxContainer2/ButtonContainer4/WaitForKill" to="." method="_on_wait_for_kill_toggled"]
|
||||
[connection signal="valueHasChanged" from="VBoxContainer2/ButtonContainer3/WaveTimer" to="." method="changeWaveCooldown"]
|
||||
[connection signal="multi_selected" from="VBoxContainer2/ButtonContainer5/TowerSelector" to="." method="onSelectedTowerChange"]
|
||||
[connection signal="active_tab_rearranged" from="VBoxContainer2/ScrollContainer/WaveContainer" to="." method="changeWaveOrder"]
|
||||
[connection signal="tab_changed" from="VBoxContainer2/ScrollContainer/WaveContainer" to="." method="tabFocusHaschanged"]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
extends CharacterBody3D
|
||||
class_name Enemy
|
||||
|
||||
signal died
|
||||
|
||||
@onready var death_vfx_packed : PackedScene = preload("res://VFX/death_particles.tscn")
|
||||
@onready var sad_vfx_packed : PackedScene = preload("res://VFX/sad_particles.tscn")
|
||||
|
||||
|
|
@ -35,7 +37,7 @@ func _ready() -> void:
|
|||
func _physics_process(delta: float) -> void:
|
||||
if !is_alive:
|
||||
return
|
||||
|
||||
|
||||
if not movement_stop:
|
||||
Path.set_progress(Path.get_progress() + speed * delta)
|
||||
if attack_target:
|
||||
|
|
@ -54,13 +56,13 @@ func attack():
|
|||
|
||||
func death() -> void:
|
||||
is_alive = false
|
||||
GameManager.enemies_alive -= 1
|
||||
died.emit()
|
||||
EventBus.money_received.emit(money)
|
||||
$Sprite3D.visible = false
|
||||
var death_vfx : CPUParticles3D = death_vfx_packed.instantiate()
|
||||
get_tree().current_scene.add_child(death_vfx)
|
||||
death_vfx.global_position = global_position
|
||||
|
||||
|
||||
Path.queue_free()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ config/icon="res://icon.svg"
|
|||
|
||||
[autoload]
|
||||
|
||||
GameManager="*res://Globals/GameManager.gd"
|
||||
EventBus="*res://Globals/EventBus.gd"
|
||||
Transition="*res://Globals/transition.tscn"
|
||||
SignalLens="*res://addons/signal_lens/autoload/signal_lens_autoload.gd"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue