a game about throwing hammers made for the github game off
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## A enemy! Kill it!
extends Hittable
class_name Enemy

signal died

## Maximum health
@export var max_health: int = 1

## Current health
@onready var health := max_health:
  set(value):
    health = clamp(value, 0, max_health)
    if health == 0:
      died.emit() # ~~voodoo magic makes this signal connect to die()~~
      die() # the voodoo magic broke ;-;

func hit(damage: int) -> void:
  health -= damage

func die() -> void:
  Utils.instance_scene_on_main(preload("res://fx/enemy_death.tscn"), global_position)
  queue_free()