CyberTower/scripts/Tower.gd
2024-02-17 00:55:13 +08:00

38 lines
676 B
GDScript

class_name Tower
extends Area2D
signal tower_broken
@export var sprite: Sprite2D
@export var max_health = 100
@export var max_energy = 20
var health: float
var energy: float
func move_to_center():
var screen_size = get_viewport_rect().size
position = Vector2(screen_size.x / 2, screen_size.y / 2)
func take_damage(amount: float):
health -= amount
if health <= 0:
tower_broken.emit()
get_tree().paused = true
func _ready():
move_to_center()
health = max_health
energy = max_energy
func _process(_delta):
sprite.regeneration_progress = health / max_health
func _on_someone_entered(body):
if body is Enemy:
take_damage(body.damage)
body.queue_free()