the-crypt/ai/Script/Skeleton Enemy.gd

72 lines
2 KiB
GDScript3
Raw Normal View History

2020-07-20 14:14:34 -05:00
extends Enemy
2020-07-18 02:27:01 -05:00
2020-07-23 12:16:10 -05:00
export var max_range: int = 200
export var stationary: bool = false
2020-07-22 14:05:31 -05:00
var Spinning_Bone = preload("res://ai/Scenes/SpinningBone.tscn")
2020-07-18 17:07:40 -05:00
onready var ShootDelay : Timer = $ShootDelay
onready var ProjectileSpawn: Node2D = $Position2D
2020-07-23 12:16:10 -05:00
func _ready():
health = 1.5
$RayCast2D.cast_to.x = -1 * max_range
$RayCast2D2.cast_to.y = 1 * max_ranged
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-21 01:07:58 -05:00
var dist = global_position.distance_to(Player.position)
var gravity = 4350
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
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)
2020-07-23 12:16:10 -05:00
if dist <= max_range and not stationary:
velocity.x = position.direction_to(Player.position).normalized().x
2020-07-20 15:06:03 -05:00
else:
2020-07-21 01:07:58 -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-21 01:07:58 -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 = -90
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()
2020-07-21 01:07:58 -05:00
func do_knockback(normal):
if $Skeleton.flip_h == true:
knockback = Vector2(-4, -4)
else:
knockback = Vector2(4, 0)
2020-07-20 15:06:03 -05:00