79 lines
1.9 KiB
GDScript
79 lines
1.9 KiB
GDScript
extends StaticBody2D
|
|
|
|
signal death
|
|
|
|
export var glowing_blue_fireball: PackedScene
|
|
|
|
var player: KinematicBody2D = null
|
|
var health: int = 12
|
|
var center: Vector2
|
|
var center_x: float
|
|
var shoot_y: int
|
|
|
|
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
|
|
|
|
|
|
func _ready() -> void:
|
|
center = $Sprite.global_position
|
|
center_x = center.x
|
|
shoot_y = int(center.y) + 1
|
|
rng.randomize()
|
|
return
|
|
|
|
|
|
func _on_shoot_timeout() -> void:
|
|
if player:
|
|
var shoot_directions: Array = [
|
|
Vector2(center_x + rng.randf_range(-1, 1), shoot_y),
|
|
Vector2(center_x + rng.randf_range(-1, 1), shoot_y),
|
|
Vector2(center_x + rng.randf_range(-1, 1), shoot_y),
|
|
Vector2(center_x + rng.randf_range(-1, 1), shoot_y),
|
|
Vector2(center_x + rng.randf_range(-1, 1), shoot_y)]
|
|
|
|
for itr in shoot_directions:
|
|
var projectile: Node = glowing_blue_fireball.instance()
|
|
projectile.init(center, itr)
|
|
get_tree().get_current_scene().get_node('Projectiles').add_child(projectile)
|
|
|
|
$'Flash Timer'.start()
|
|
$Flash.set_visible(true)
|
|
return
|
|
|
|
|
|
func _on_flash_timer_timeout() -> void:
|
|
$Flash.set_visible(false)
|
|
return
|
|
|
|
|
|
func _on_hit_timeout() -> void:
|
|
$Sprite.self_modulate = Color(1, 1, 1)
|
|
return
|
|
|
|
|
|
func _on_hitbox_area_entered(area: Area2D) -> void:
|
|
if area.is_in_group('player_weapon_1'):
|
|
health -= 1
|
|
$Sprite.self_modulate = Color(1, 0, 0)
|
|
$Hit.start()
|
|
elif area.is_in_group('player_weapon_2'):
|
|
health -= 2
|
|
$Sprite.self_modulate = Color(1, 0, 0)
|
|
$Hit.start()
|
|
|
|
if health <= 0:
|
|
emit_signal('death')
|
|
call_deferred('queue_free')
|
|
return
|
|
|
|
|
|
func _on_player_detector_body_entered(body: Node) -> void:
|
|
if body.is_in_group('player'):
|
|
player = body
|
|
return
|
|
|
|
|
|
func _on_player_detector_body_exited(body: Node) -> void:
|
|
if body.is_in_group('player'):
|
|
player = null
|
|
return
|