added asteroid health and damage

each hit takes 1 hard-coded damage right now. no effects, and all size asteroids are the same score of 1.
This commit is contained in:
Red3Tango 2023-12-11 14:44:37 -07:00
parent 62a8db361a
commit 4571943fe1
6 changed files with 15 additions and 2 deletions

View File

@ -4,4 +4,5 @@ class_name AsteroidResource
@export var speed_min_max := Vector2.ZERO
@export var rotate_min_max := Vector2.ZERO
@export var health: int = 0
@export var visual: Texture2D

View File

@ -4,6 +4,7 @@ class_name Asteroid
var asteroid_type: AsteroidResource
var start_force: Vector2 = Vector2.ZERO
var start_spin: float = 0.0
var health: int = 0
@onready var ttl: Timer = $TTL
@onready var sprite_2d: Sprite2D = $Sprite2D
@ -14,6 +15,14 @@ func _ready() -> void:
shape.radius = (asteroid_type.visual.get_width() / 2.0) - 2
linear_velocity = start_force
angular_velocity = deg_to_rad(start_spin)
health = 1 if asteroid_type.health == 0 else asteroid_type.health
func take_damage() -> void:
health -= 1
if health <= 0:
queue_free()
Relay.gain_point.emit()
func _on_screen_entered() -> void:

View File

@ -7,4 +7,5 @@
script = ExtResource("1_f4kaj")
speed_min_max = Vector2(20, 40)
rotate_min_max = Vector2(0, 0)
health = 3
visual = ExtResource("2_wotvc")

View File

@ -7,4 +7,5 @@
script = ExtResource("1_utums")
speed_min_max = Vector2(40, 60)
rotate_min_max = Vector2(0, 0)
health = 2
visual = ExtResource("2_4ipe5")

View File

@ -7,4 +7,5 @@
script = ExtResource("1_vyivm")
speed_min_max = Vector2(50, 100)
rotate_min_max = Vector2(0, 0)
health = 1
visual = ExtResource("2_g5m6w")

View File

@ -14,6 +14,6 @@ func _on_ttl_timeout() -> void:
func _on_body_entered(body: Node2D) -> void:
body.queue_free()
Relay.gain_point.emit()
if body is Asteroid:
body.take_damage()
self.queue_free()