Skip to content

Commit

Permalink
Trigger wave_end event on creeps reaching portal
Browse files Browse the repository at this point in the history
  • Loading branch information
Praytic committed Apr 3, 2023
1 parent 9fcd3da commit 708c6a9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Scenes/Creeps/Creep.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extends Unit
# TODO: implement armor

signal moved(delta)
signal reached_portal(damage_to_portal)


# NOTE: order is important to be able to compare
Expand Down Expand Up @@ -99,6 +100,10 @@ func adjust_height(height: float, speed: float):
Vector2(_visual.position.x, _visual.position.y - height),
duration).set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_OUT)

func reach_portal():
var damage_to_portal = get_damage_to_portal()
reached_portal.emit(damage_to_portal)
queue_free()

#########################
### Private ###
Expand Down Expand Up @@ -222,3 +227,7 @@ func get_display_name() -> String:
func set_path(path: Path2D):
_path = path
position = path.get_curve().get_point_position(0) + path.position

func get_damage_to_portal():
# TODO: Implement formula
return 1
1 change: 1 addition & 0 deletions Scenes/Creeps/CreepSpawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func generate_creep_for_wave(wave: Wave, creep_size) -> Creep:
creep.set_category(wave.get_race())
creep.set_base_health(wave.get_base_hp())
creep.death.connect(Callable(wave, "_on_Creep_death"))
creep.reached_portal.connect(Callable(wave, "_on_Creep_reached_portal").bind(creep))
return creep


Expand Down
5 changes: 5 additions & 0 deletions Scenes/Creeps/Wave.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ func _process(_delta):
#########################

func _on_Creep_death(event):
print_debug("Creep [%s] has died." % event.get_target())
_creeps.erase(event.get_target())

func _on_Creep_reached_portal(damage, creep: Creep):
print_debug("Creep [%s] reached portal. Damage to portal: %s" % [creep, damage])
_creeps.erase(creep)


#########################
### Setters / Getters ###
Expand Down
2 changes: 1 addition & 1 deletion Scenes/GameScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func _on_HUD_stop_wave():

func _on_CreepExit_body_entered(body):
if body is Creep:
body.queue_free()
body.reach_portal()


func _on_CreepSpawner_wave_ended(_wave_index: int):
Expand Down

0 comments on commit 708c6a9

Please sign in to comment.