2020-07-18 02:27:01 -05:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
2020-07-18 17:07:40 -05:00
|
|
|
var Spinning_Bone = preload("res://ai/SpinningBone.tscn")
|
|
|
|
var speed = 60
|
|
|
|
var gravity =500
|
2020-07-19 18:50:32 -05:00
|
|
|
var health = 1
|
2020-07-18 02:27:01 -05:00
|
|
|
const UP = Vector2(0, -1)
|
|
|
|
|
2020-07-18 17:07:40 -05:00
|
|
|
|
|
|
|
onready var ShootDelay : Timer = $ShootDelay
|
|
|
|
onready var ProjectileSpawn: Node2D = $Position2D
|
|
|
|
|
2020-07-18 02:27:01 -05:00
|
|
|
var velocity = Vector2()
|
|
|
|
|
|
|
|
func apply_gravity(delta, modifier = 1):
|
|
|
|
velocity.y += gravity * delta * modifier
|
|
|
|
|
|
|
|
func _physics_process(_delta):
|
2020-07-19 17:58:40 -05:00
|
|
|
var dist = global_position.distance_to(Globals.player)
|
2020-07-18 02:27:01 -05:00
|
|
|
if Globals.player != null:
|
2020-07-18 17:07:40 -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)
|
|
|
|
if ShootDelay.is_stopped():
|
|
|
|
var temp = Spinning_Bone.instance()
|
|
|
|
get_tree().current_scene.add_child(temp)
|
|
|
|
temp.global_position = ProjectileSpawn.global_position
|
|
|
|
temp.launch_left()
|
|
|
|
ShootDelay.start()
|
|
|
|
elif $RayCast2D2.get_collider() != null && $RayCast2D2.get_collider().has_method("get_type") and $RayCast2D2.get_collider().get_type() == "player":
|
|
|
|
velocity = Vector2(0, 0)
|
|
|
|
if ShootDelay.is_stopped():
|
|
|
|
var temp = Spinning_Bone.instance()
|
|
|
|
get_tree().current_scene.add_child(temp)
|
|
|
|
temp.global_position = ProjectileSpawn.global_position
|
|
|
|
temp.launch_right()
|
|
|
|
ShootDelay.start()
|
|
|
|
elif $RayCast2D3.get_collider() != null && $RayCast2D3.get_collider().has_method("get_type") and $RayCast2D3.get_collider().get_type() == "player":
|
|
|
|
velocity = Vector2(0, 0)
|
|
|
|
if ShootDelay.is_stopped():
|
|
|
|
var temp = Spinning_Bone.instance()
|
|
|
|
get_tree().current_scene.add_child(temp)
|
|
|
|
temp.global_position = ProjectileSpawn.global_position
|
|
|
|
temp.launch_upleft()
|
|
|
|
ShootDelay.start()
|
|
|
|
elif $RayCast2D4.get_collider() != null && $RayCast2D4.get_collider().has_method("get_type") and $RayCast2D4.get_collider().get_type() == "player":
|
|
|
|
velocity = Vector2(0, 0)
|
|
|
|
if ShootDelay.is_stopped():
|
|
|
|
var temp = Spinning_Bone.instance()
|
|
|
|
get_tree().current_scene.add_child(temp)
|
|
|
|
temp.global_position = ProjectileSpawn.global_position
|
|
|
|
temp.launch_upright()
|
|
|
|
ShootDelay.start()
|
2020-07-19 17:58:40 -05:00
|
|
|
if dist <= 400:
|
2020-07-18 17:07:40 -05:00
|
|
|
velocity.x = position.direction_to(Globals.player).normalized().x
|
2020-07-19 17:58:40 -05:00
|
|
|
else:
|
|
|
|
velocity = Vector2(0, 0)
|
2020-07-18 17:07:40 -05:00
|
|
|
apply_gravity(_delta)
|
|
|
|
velocity.x *= speed
|
|
|
|
velocity = move_and_slide(velocity, UP)
|
|
|
|
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-18 17:07:40 -05:00
|
|
|
if is_on_wall() and is_on_floor():
|
|
|
|
velocity.y = -150
|
|
|
|
func on_impact(collision):
|
|
|
|
if collision.collider.has_method("get_type"):
|
|
|
|
collision.collider.set_health(collision.collider.get_health() - 1)
|
|
|
|
queue_free()
|
|
|
|
if health == 0:
|
|
|
|
queue_free()
|