CyberTower/scripts/Tower.gd

38 lines
676 B
GDScript3
Raw Permalink Normal View History

2024-02-16 16:55:13 +00:00
class_name Tower
2024-02-16 10:10:00 +00:00
extends Area2D
2024-02-16 12:35:30 +00:00
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():
2024-02-16 10:10:00 +00:00
var screen_size = get_viewport_rect().size
position = Vector2(screen_size.x / 2, screen_size.y / 2)
2024-02-16 12:35:30 +00:00
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()