Blobby/src/Actors/Enemies/Beings/SimpleEnemy.gd

40 lines
843 B
GDScript

extends Player
export var score := 100
func _ready() -> void:
set_physics_process(false)
velocity.x = -30
# TODO adapt to groups
func _on_StompDetector_body_entered(body: Node) -> void:
if body.global_position.y > get_node("StompDetector").global_position.y:
return
get_node("EnemyBody").disabled = true
die()
func _physics_process(delta: float) -> void:
velocity.y += _gravity * delta
if is_on_wall() or is_at_ledge():
velocity.x *= -1.0
velocity.y = move_and_slide(velocity, FLOOR_NORMAL).y
func is_at_ledge():
for raycast in $LedgeDetectorRays.get_children():
if !raycast.is_colliding():
return true
return false
func die() -> void:
queue_free()
GlobalState.score += score
func _on_EnemySkin_area_entered(area:Area2D) -> void:
if area.is_in_group("harmful"):
get_node("EnemyBody").disabled = true
die()