signal bus and entity invoking them
This commit is contained in:
parent
88c56f8aed
commit
93e7d28de4
4 changed files with 37 additions and 0 deletions
30
base/scripts/autoload/game_signal_bus.gd
Normal file
30
base/scripts/autoload/game_signal_bus.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends Node
|
||||
|
||||
#region Entity
|
||||
|
||||
## Invoked when entity is damaged or healed
|
||||
signal entity_hp_changed(context : Entity.HPChangedContext)
|
||||
|
||||
## Invoked when entity is spawned
|
||||
signal entity_spawned(entity : Entity)
|
||||
|
||||
## Invoked when entity is killed
|
||||
signal entity_killed(entity : Entity.KilledContext)
|
||||
|
||||
#endregion
|
||||
|
||||
#region Player interactions
|
||||
|
||||
## Invoked when interactable detects mouse pointer over it
|
||||
signal interactable_hover_begin(interactable : InteractiveObject)
|
||||
|
||||
## Invoked when interactable detects mouse pointer exit
|
||||
signal interactable_hover_end(interactable : InteractiveObject)
|
||||
|
||||
## Invoked when interactable is interacted
|
||||
signal interactable_used(interactable : InteractiveObject)
|
||||
|
||||
## Invoked by and ammo change
|
||||
signal ammo_updated(current_ammo : int, max_ammo : int)
|
||||
|
||||
#endregion
|
1
base/scripts/autoload/game_signal_bus.gd.uid
Normal file
1
base/scripts/autoload/game_signal_bus.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://5r53k5fk8ouy
|
|
@ -8,6 +8,8 @@ class_name Entity
|
|||
## Current amount of health points of an entity. Cannot be below 0 or [code]max_hp[/code]
|
||||
var hp : float = max_hp
|
||||
|
||||
func _ready() -> void:
|
||||
GameSignalBus.entity_spawned.emit(self)
|
||||
|
||||
## Emitted when damage is taken
|
||||
signal damage_taken(context : DamageTakenContext)
|
||||
|
@ -31,6 +33,7 @@ func deal_damage(amount : float, source : Entity):
|
|||
delta_context.target = self
|
||||
delta_context.delta = -amount
|
||||
hp_changed.emit(delta_context)
|
||||
GameSignalBus.entity_hp_changed.emit(delta_context)
|
||||
|
||||
hp -= amount
|
||||
if hp <= 0:
|
||||
|
@ -51,6 +54,7 @@ func heal(amount : float, source : Entity):
|
|||
delta_context.target = self
|
||||
delta_context.delta = amount
|
||||
hp_changed.emit(delta_context)
|
||||
GameSignalBus.entity_hp_changed.emit(delta_context)
|
||||
|
||||
hp += amount
|
||||
if hp > max_hp:
|
||||
|
@ -63,6 +67,7 @@ func kill(source : Entity):
|
|||
context.source = source
|
||||
context.target = self
|
||||
killed.emit(context)
|
||||
GameSignalBus.entity_killed.emit(context)
|
||||
|
||||
deconstruct()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue