ft: wrapping manager overhaul
This commit is contained in:
@@ -1,33 +1,26 @@
|
||||
extends AbstractPrey2D
|
||||
extends AbstractPrey
|
||||
|
||||
@onready var wrapper: WrappingManager = $WrappingManager
|
||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
@onready var collision: CharacterBody2D = $Collision
|
||||
@onready var sprite: AnimatedSprite2D = $"Collision/Sprite"
|
||||
@onready var fsm: StateMachine = $StateMachine
|
||||
|
||||
@export var speed = 0.5
|
||||
var desired_rotation: float = self.rotation
|
||||
var starting_pos
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
health = maxHealth
|
||||
sprite.play("Healthy")
|
||||
if starting_pos:
|
||||
collision.set_position(starting_pos)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
# smoothly rotate
|
||||
if self.rotation != self.desired_rotation:
|
||||
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func set_position(pos: Vector2) -> void:
|
||||
if collision:
|
||||
collision.set_position(pos)
|
||||
else:
|
||||
starting_pos = pos
|
||||
|
||||
func move(motion: Vector3, mod: float = 1.0) -> void:
|
||||
move_and_collide(Vector2(motion.x, motion.y).normalized() * self.speed * mod) # Moves along the given vector
|
||||
self.desired_rotation = atan2(motion.y, motion.x)
|
||||
|
||||
# Apply boundary to new position
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
collision.move(motion, mod)
|
||||
|
||||
func handle_damage(dmg: int, src: Node) -> void:
|
||||
health = max(0, health-dmg)
|
||||
@@ -40,7 +33,7 @@ func handle_damage(dmg: int, src: Node) -> void:
|
||||
func die() -> void:
|
||||
sprite.play("Dying")
|
||||
wrapper.play_sprite("Dying")
|
||||
GameManager.foodManager._spawn_food(position)
|
||||
GameManager.foodManager._spawn_food(collision.position)
|
||||
super.die()
|
||||
|
||||
func become_injured() -> void:
|
||||
|
||||
Reference in New Issue
Block a user