alai/godot/characters/enemies/blockface/Blockface.gd

35 lines
1.0 KiB
GDScript3
Raw Normal View History

2022-07-21 00:05:08 -04:00
extends KinematicBody2D
onready var start_position = position
var velocity = Vector2()
export var speed = 50.0
export var fall_speed = 75.0
var return_to_start: bool = false
2022-09-01 11:26:34 -04:00
func _ready() -> void:
Event.connect("level_loaded", self, "_on_level_loaded")
2022-07-21 00:05:08 -04:00
func _physics_process(delta: float) -> void:
if return_to_start:
position = position.move_toward(start_position, speed * delta)
2022-09-01 11:26:34 -04:00
Event.emit_signal("object_updated", self.get_name(), "Rising", global_position, velocity)
2022-07-21 00:05:08 -04:00
else:
var collision = move_and_collide(Vector2(0, (position.y + fall_speed) * delta))
if collision:
return_to_start = true
$AnimatedSprite.play("normal")
if collision.collider.name == "Player":
2022-09-01 21:59:21 -04:00
Event.emit_signal("player_touched", 3)
2022-09-01 11:26:34 -04:00
Event.emit_signal("object_updated", self.get_name(), "Falling", global_position, velocity)
2022-07-21 00:05:08 -04:00
if position.y <= start_position.y:
return_to_start = false
$AnimatedSprite.play("angry")
2022-09-01 11:26:34 -04:00
func _on_level_loaded() -> void:
Event.emit_signal("object_created", self.get_name(), "Falling", global_position, Vector2(0, 0))