2020-07-20 23:24:09 -05:00
|
|
|
extends Enemy
|
2020-07-19 17:19:31 -05:00
|
|
|
|
2020-07-21 23:27:14 -05:00
|
|
|
var Hell_Projectile = preload("res://ai/Scenes/DemonFireball.tscn")
|
2020-07-19 17:19:31 -05:00
|
|
|
|
|
|
|
onready var ShootDelay : Timer = $ShootDelay
|
|
|
|
onready var ProjectileSpawn: Node2D = $Position2D
|
2020-07-20 23:24:09 -05:00
|
|
|
onready var PlayerRaycast: RayCast2D = $PlayerRaycast
|
2020-07-19 17:19:31 -05:00
|
|
|
|
2020-07-20 23:24:09 -05:00
|
|
|
func _ready():
|
2020-07-23 12:16:10 -05:00
|
|
|
health = 2
|
2020-07-21 15:00:32 -05:00
|
|
|
knockback_amount = 700
|
2020-07-19 17:19:31 -05:00
|
|
|
|
|
|
|
func _physics_process(_delta):
|
2020-07-20 23:24:09 -05:00
|
|
|
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()
|
2020-07-23 02:13:08 -05:00
|
|
|
|
2020-07-20 23:24:09 -05:00
|
|
|
|
2020-07-23 23:04:24 -05:00
|
|
|
if dist <= 250:
|
2020-07-20 23:24:09 -05:00
|
|
|
velocity.x = position.direction_to(player_position).normalized().x * speed
|
2020-07-23 15:32:05 -05:00
|
|
|
if collider != null && collider.has_method("get_type") && collider.get_type() == "player":
|
|
|
|
shoot_fireball(position.direction_to(player_position))
|
2020-07-20 23:24:09 -05:00
|
|
|
else:
|
|
|
|
velocity = Vector2(0, 0)
|
2020-07-20 16:28:05 -05:00
|
|
|
|
2020-07-19 17:19:31 -05:00
|
|
|
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
|
2020-07-20 23:24:09 -05:00
|
|
|
if health <= 0:
|
|
|
|
queue_free()
|
2020-07-21 01:07:58 -05:00
|
|
|
|
2020-07-21 23:55:01 -05:00
|
|
|
if is_on_wall() and is_on_floor():
|
|
|
|
velocity.y = -90
|
|
|
|
|
2020-07-21 01:07:58 -05:00
|
|
|
func do_knockback(normal):
|
|
|
|
if $Hell.flip_h == true:
|
|
|
|
knockback = Vector2(-4, -4)
|
|
|
|
else:
|
|
|
|
knockback = Vector2(4, 0)
|
2020-07-20 23:24:09 -05:00
|
|
|
|
|
|
|
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()
|