ft: prey player detection
This commit is contained in:
@@ -3,7 +3,9 @@ extends AbstractPrey2D
|
||||
@onready var sprite = get_node("AnimatedSprite2D")
|
||||
@onready var fsm = $StateMachine
|
||||
|
||||
# Mirroed sprites for periodic boundary
|
||||
var desired_rotation: float = self.rotation
|
||||
|
||||
# Mirrored sprites for periodic boundary
|
||||
var mirrorSprite1: Node2D
|
||||
var mirrorSprite2: Node2D
|
||||
var mirrorSprite3: Node2D
|
||||
@@ -29,11 +31,14 @@ func _process(delta: float) -> void:
|
||||
_handle_wrapping()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
pass
|
||||
# rotate smoothly
|
||||
if self.rotation != self.desired_rotation: # FIXME: causes the mirror sprites to flip out
|
||||
self.rotation = lerp_angle(self.rotation, self.desired_rotation, 4 * delta)
|
||||
|
||||
func move(motion: Vector3) -> void:
|
||||
move_and_collide(Vector2(motion.x, motion.y)) # Moves along the given vector
|
||||
|
||||
self.desired_rotation = atan2(motion.y, motion.x)
|
||||
|
||||
# Apply boundary to new position
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
|
||||
@@ -55,6 +60,11 @@ func become_injured() -> void:
|
||||
mirrorSprite2.play("Injured")
|
||||
mirrorSprite3.play("Injured")
|
||||
|
||||
func _on_sight_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("predators") or body.is_in_group("player"):
|
||||
fsm.transition_to_next_state(fsm.States.FLEEING, {"threat": body})
|
||||
|
||||
|
||||
# Mirroring table:
|
||||
# |---|---|---|---|
|
||||
# | 4 | 3 | 4 | 3 |
|
||||
@@ -142,9 +152,3 @@ func _handle_wrapping():
|
||||
# Top
|
||||
#mirrorSprite3.position = Vector2(sprite.position.x, sprite.position.y - GameManager.screen_size.y)
|
||||
mirrorSprite3.position = Vector2(0, - GameManager.screen_size.y)
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
Reference in New Issue
Block a user