Cleaned up skeleton script

This commit is contained in:
Logan 2020-07-20 15:06:03 -05:00
parent 6e2bc0c01d
commit 11f5d50964

View file

@ -10,60 +10,46 @@ func apply_gravity(delta, modifier = 1):
func _physics_process(_delta): func _physics_process(_delta):
var dist = global_position.distance_to(Globals.player) var dist = global_position.distance_to(Globals.player)
if Globals.player != null: if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player":
if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player": velocity = Vector2(0, 0)
velocity = Vector2(0, 0) throw_bone(Vector2.LEFT)
if ShootDelay.is_stopped(): elif $RayCast2D2.get_collider() != null && $RayCast2D2.get_collider().has_method("get_type") and $RayCast2D2.get_collider().get_type() == "player":
var temp = Spinning_Bone.instance() velocity = Vector2(0, 0)
get_tree().current_scene.add_child(temp) throw_bone(Vector2.RIGHT)
temp.global_position = ProjectileSpawn.global_position elif $RayCast2D3.get_collider() != null && $RayCast2D3.get_collider().has_method("get_type") and $RayCast2D3.get_collider().get_type() == "player":
temp.launch_left() velocity = Vector2(0, 0)
ShootDelay.start() throw_bone(Vector2.UP + Vector2.LEFT)
elif $RayCast2D2.get_collider() != null && $RayCast2D2.get_collider().has_method("get_type") and $RayCast2D2.get_collider().get_type() == "player": elif $RayCast2D4.get_collider() != null && $RayCast2D4.get_collider().has_method("get_type") and $RayCast2D4.get_collider().get_type() == "player":
velocity = Vector2(0, 0) velocity = Vector2(0, 0)
if ShootDelay.is_stopped(): throw_bone(Vector2.UP + Vector2.RIGHT)
var temp = Spinning_Bone.instance() else:
get_tree().current_scene.add_child(temp) apply_gravity(_delta)
temp.global_position = ProjectileSpawn.global_position velocity.x *= speed
temp.launch_right() velocity = move_and_slide(velocity, UP)
ShootDelay.start()
elif $RayCast2D3.get_collider() != null && $RayCast2D3.get_collider().has_method("get_type") and $RayCast2D3.get_collider().get_type() == "player": if dist <= 400:
velocity = Vector2(0, 0) velocity.x = position.direction_to(Globals.player).normalized().x
if ShootDelay.is_stopped(): else:
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()
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:
velocity = Vector2(0, 0) velocity = Vector2(0, 0)
if velocity.x > 0: if velocity.x > 0:
$Skeleton.flip_h = false $Skeleton.flip_h = false
elif velocity.x < 0: elif velocity.x < 0:
$Skeleton.flip_h = true $Skeleton.flip_h = true
# Kill
if health <= 0: if health <= 0:
queue_free() queue_free()
# Jump
if is_on_wall() and is_on_floor(): if is_on_wall() and is_on_floor():
velocity.y = -150 velocity.y = -150
func on_impact(collision): func throw_bone(direction):
if collision.collider.has_method("get_type"): if ShootDelay.is_stopped():
collision.collider.set_health(collision.collider.get_health() - 1) var temp = Spinning_Bone.instance()
if health == 0: get_tree().current_scene.add_child(temp)
queue_free() temp.global_position = ProjectileSpawn.global_position
temp.launch_vector(direction)
ShootDelay.start()