make enemies use the event bus

This commit is contained in:
2022-09-01 11:26:34 -04:00
parent ea83bf8660
commit cb81734279
3 changed files with 29 additions and 2 deletions

View File

@@ -22,6 +22,8 @@ func _ready() -> void:
if direction == 1:
$AnimatedSprite.flip_h = true
Event.connect("level_loaded", self, "_on_level_loaded")
func _physics_process(delta: float) -> void:
if $LeftWallChecker.is_colliding():
@@ -29,17 +31,18 @@ func _physics_process(delta: float) -> void:
elif $RightWallChecker.is_colliding():
wall_checker_collided($RightWallChecker)
var velocity: Vector2 = Vector2(0, 0)
if not follow_path:
var target_position = position
target_position.x *= 2 * direction
position = position.move_toward(target_position, round(speed * delta))
var velocity = get_velocity_towards_target(delta)
velocity = get_velocity_towards_target(delta)
var collision = move_and_collide(velocity, true, true, true)
if collision and collision.collider.name != "Player":
var _collision = move_and_collide(velocity)
else:
var velocity = get_velocity_towards_target(delta)
velocity = get_velocity_towards_target(delta)
var collision = move_and_collide(velocity, true, true, true)
if collision and collision.collider.name != "Player":
@@ -60,6 +63,8 @@ func _physics_process(delta: float) -> void:
elif start_position.x + target.x < position.x:
$AnimatedSprite.flip_h = false
Event.emit_signal("object_updated", self.get_name(), "Flying", global_position, velocity)
func get_velocity_towards_target(delta: float) -> Vector2:
var velocity = Vector2(0, 0)
@@ -80,3 +85,7 @@ func wall_checker_collided(wall_checker: RayCast2D) -> void:
emit_signal("player_touched")
direction *= -1
$AnimatedSprite.flip_h = not $AnimatedSprite.flip_h
func _on_level_loaded() -> void:
Event.emit_signal("object_created", self.get_name(), "Flying", global_position, Vector2(0, 0))