Added aliens and glow on the numbers
This commit is contained in:
34
Alien.gd
Normal file
34
Alien.gd
Normal file
@@ -0,0 +1,34 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
class_name Alien
|
||||
|
||||
signal alien_died(value : int)
|
||||
|
||||
@export var hits : int = 5
|
||||
@export var points : int = 500
|
||||
|
||||
func _ready() -> void:
|
||||
$Sprite2D.play("default")
|
||||
move_random()
|
||||
|
||||
func move_random() -> void:
|
||||
velocity = Vector2(randf() - 0.5, randf() - 0.5).normalized() * 30
|
||||
get_tree().create_timer(randf() * 3).timeout.connect(move_random)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if position.y < 28:
|
||||
position.y += delta * 30
|
||||
else:
|
||||
move_and_slide()
|
||||
|
||||
func hit() -> void:
|
||||
hits -= 1
|
||||
if hits <= 0:
|
||||
alien_died.emit(points)
|
||||
get_parent().call_deferred("remove_child", self)
|
||||
call_deferred("queue_free")
|
||||
else:
|
||||
$AlienSound.play()
|
||||
var tween = get_tree().create_tween()
|
||||
$Sprite2D.modulate = Color(1, 1, 1, 0)
|
||||
tween.tween_property($Sprite2D, "modulate", Color(1, 1, 1, 1), 0.3)
|
||||
Reference in New Issue
Block a user