Fixed debugger errors in many files and optimized some scenes/code
This commit is contained in:
61
Enemies/Ghost Enemy.gd
Normal file
61
Enemies/Ghost Enemy.gd
Normal file
@@ -0,0 +1,61 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
export var fireball: PackedScene
|
||||
|
||||
var player: KinematicBody2D = null
|
||||
var move: Vector2 = Vector2.ZERO
|
||||
const SPEED: int = 50
|
||||
var counter: int = 0
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
var health: int = 4
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
visible = false
|
||||
return
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
if player and position.distance_to(player.position) > 1:
|
||||
velocity = position.direction_to(player.position).normalized() * SPEED
|
||||
|
||||
velocity = move_and_slide(velocity)
|
||||
return
|
||||
|
||||
|
||||
func _on_Area2D_body_entered(body: Node) -> void:
|
||||
if body.is_in_group('player'):
|
||||
player = body
|
||||
if counter == 0:
|
||||
self.visible = true
|
||||
$AnimatedSprite.play('appear')
|
||||
counter = 1
|
||||
return
|
||||
|
||||
|
||||
func _on_AnimatedSprite_animation_finished() -> void:
|
||||
$AnimatedSprite.play('idle')
|
||||
return
|
||||
|
||||
|
||||
func _on_Hitbox_area_entered(area: Area2D) -> void:
|
||||
if area.is_in_group('player_weapon_1'):
|
||||
health -= 1
|
||||
elif area.is_in_group('player_weapon_2'):
|
||||
health -= 2
|
||||
if health <= 0:
|
||||
$AnimatedSprite.play('vanish')
|
||||
yield($AnimatedSprite, 'animation_finished')
|
||||
call_deferred('queue_free')
|
||||
return
|
||||
|
||||
|
||||
func _on_Projectile_Timer_timeout() -> void:
|
||||
if player:
|
||||
var projectile: Node = fireball.instance()
|
||||
projectile.init($AnimatedSprite.global_position, player.position)
|
||||
get_tree().get_current_scene().get_node('Projectiles').add_child(projectile)
|
||||
$AnimatedSprite.play('shriek')
|
||||
return
|
Reference in New Issue
Block a user