Peashooters

This commit is contained in:
Rendo 2025-08-09 21:35:02 +05:00
commit 68cfe89f1d
47 changed files with 1571 additions and 279 deletions

View file

@ -8,8 +8,9 @@ class_name Entity
## Optional spawn layer for grid interactions
@export var layer : StringName = ""
## Current amount of health points of an entity. Cannot be below 0 or [code]max_hp[/code]
var hp : float = max_hp
@onready var hp : float = max_hp
##
var disabled : bool = false
signal damaged
## Emitted when damage is taken
@ -20,6 +21,21 @@ signal healed(context : HealedContext)
signal hp_changed(context : HPChangedContext)
## Emitted when kill is requested
signal killed(context : KilledContext)
##
signal toggled(disabled : bool)
##
func disable():
if disabled: return
disabled = true
toggled.emit(disabled)
##
func enable():
if disabled == false: return
disabled = false
toggled.emit(disabled)
## Properly deal damage to entity
func deal_damage(amount : float, source : Entity):
@ -42,7 +58,6 @@ func deal_damage(amount : float, source : Entity):
hp = 0
kill(source)
## Properly heal entity
func heal(amount : float, source : Entity):
var context = HealedContext.new()
@ -61,7 +76,6 @@ func heal(amount : float, source : Entity):
if hp > max_hp:
hp = max_hp
## Invoked when an entity is killed by damage.
func kill(source : Entity):
var context = KilledContext.new()
@ -72,9 +86,6 @@ func kill(source : Entity):
LevelEventBus.entity_killed.emit(context)
if not layer.is_empty():
LevelEventBus.layer_entity_killed.emit(context)
deconstruct()
## Method used to properly deconstruct entity
func deconstruct():