the-crypt/ai/Hell.gd
2020-07-20 23:24:09 -05:00

48 lines
1.4 KiB
GDScript

extends Enemy
var Hell_Projectile = preload("res://ai/BadFireball.tscn")
onready var ShootDelay : Timer = $ShootDelay
onready var ProjectileSpawn: Node2D = $Position2D
onready var PlayerRaycast: RayCast2D = $PlayerRaycast
func _ready():
health = 0.5
func _physics_process(_delta):
if knockback != Vector2.ZERO:
knockback = lerp(knockback, Vector2.ZERO, 0.5)
move_and_slide(-knockback * knockback_amount)
if knockback.x < 1 and -1 < knockback.x and knockback.y < 1 and -1 < knockback.y:
knockback = Vector2.ZERO
return
var player_position = get_player_position()
var dist = global_position.distance_to(player_position)
PlayerRaycast.cast_to = player_position - global_position
var collider = PlayerRaycast.get_collider()
if collider != null && collider.has_method("get_type") && collider.get_type() == "player":
shoot_fireball(position.direction_to(player_position))
if dist <= 400:
velocity.x = position.direction_to(player_position).normalized().x * speed
else:
velocity = Vector2(0, 0)
apply_gravity(_delta)
velocity = move_and_slide(velocity, UP)
if velocity.x > 0:
$Hell.flip_h = false
elif velocity.x < 0:
$Hell.flip_h = true
if health <= 0:
queue_free()
func shoot_fireball(direction):
if ShootDelay.is_stopped():
var temp = Hell_Projectile.instance()
get_tree().current_scene.add_child(temp)
temp.global_position = ProjectileSpawn.global_position
temp.launch_vector(direction)
ShootDelay.start()