2020-07-20 14:14:34 -05:00
|
|
|
extends Enemy
|
2020-07-18 02:27:01 -05:00
|
|
|
|
2020-07-18 17:07:40 -05:00
|
|
|
var Spinning_Bone = preload("res://ai/SpinningBone.tscn")
|
|
|
|
|
|
|
|
onready var ShootDelay : Timer = $ShootDelay
|
|
|
|
onready var ProjectileSpawn: Node2D = $Position2D
|
|
|
|
|
2020-07-18 02:27:01 -05:00
|
|
|
func apply_gravity(delta, modifier = 1):
|
|
|
|
velocity.y += gravity * delta * modifier
|
|
|
|
|
|
|
|
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 dist = global_position.distance_to(Player.position)
|
2020-07-20 15:06:03 -05:00
|
|
|
if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player":
|
|
|
|
velocity = Vector2(0, 0)
|
|
|
|
throw_bone(Vector2.LEFT)
|
|
|
|
elif $RayCast2D2.get_collider() != null && $RayCast2D2.get_collider().has_method("get_type") and $RayCast2D2.get_collider().get_type() == "player":
|
|
|
|
velocity = Vector2(0, 0)
|
|
|
|
throw_bone(Vector2.RIGHT)
|
|
|
|
else:
|
|
|
|
apply_gravity(_delta)
|
|
|
|
velocity.x *= speed
|
|
|
|
velocity = move_and_slide(velocity, UP)
|
|
|
|
|
|
|
|
if dist <= 400:
|
|
|
|
velocity.x = position.direction_to(Globals.player).normalized().x
|
|
|
|
else:
|
2020-07-19 17:58:40 -05:00
|
|
|
velocity = Vector2(0, 0)
|
2020-07-20 15:06:03 -05:00
|
|
|
|
2020-07-18 17:07:40 -05:00
|
|
|
if velocity.x > 0:
|
|
|
|
$Skeleton.flip_h = false
|
|
|
|
elif velocity.x < 0:
|
|
|
|
$Skeleton.flip_h = true
|
2020-07-18 02:27:01 -05:00
|
|
|
|
2020-07-20 15:06:03 -05:00
|
|
|
# Kill
|
2020-07-20 14:30:58 -05:00
|
|
|
if health <= 0:
|
|
|
|
queue_free()
|
|
|
|
|
2020-07-20 15:06:03 -05:00
|
|
|
# Jump
|
2020-07-18 17:07:40 -05:00
|
|
|
if is_on_wall() and is_on_floor():
|
|
|
|
velocity.y = -150
|
2020-07-20 14:14:34 -05:00
|
|
|
|
2020-07-20 15:06:03 -05:00
|
|
|
func throw_bone(direction):
|
|
|
|
if ShootDelay.is_stopped():
|
|
|
|
var temp = Spinning_Bone.instance()
|
|
|
|
get_tree().current_scene.add_child(temp)
|
|
|
|
temp.global_position = ProjectileSpawn.global_position
|
|
|
|
temp.launch_vector(direction)
|
|
|
|
ShootDelay.start()
|
|
|
|
|