ft: made sprite behaviour consistent across entities
This commit is contained in:
@@ -28,7 +28,7 @@ func _ready() -> void:
|
||||
var screen_size = get_viewport_rect().size
|
||||
GameManager.init_screen_size(screen_size.x, screen_size.y)
|
||||
|
||||
attack_area.monitoring = false # no collision until attacking TODO: Thing about being attacked
|
||||
attack_area.monitoring = false # no collision until attacking TODO: Think about being attacked
|
||||
attack_timer.wait_time = attack_duration
|
||||
attack_cooldown_timer.wait_time = attack_cooldown_duration
|
||||
|
||||
@@ -36,7 +36,6 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(delta):
|
||||
# TODO: Connects this to some respawn screen
|
||||
if isAlive:
|
||||
velocity = Vector2.ZERO
|
||||
if Input.is_action_pressed("move_right"):
|
||||
|
||||
@@ -15,8 +15,7 @@ var can_attack: bool = true
|
||||
|
||||
func _ready() -> void:
|
||||
health = maxHealth
|
||||
sprite.play("Healthy") # TODO: sprite play logic (esp wrt state switching)
|
||||
wrapper.play_sprite("Healthy")
|
||||
play_sprite(idle_sprite)
|
||||
if starting_pos:
|
||||
collision.set_position(starting_pos)
|
||||
|
||||
@@ -61,8 +60,8 @@ func die() -> void:
|
||||
super.die()
|
||||
|
||||
func become_injured() -> void:
|
||||
sprite.play("Hurt")
|
||||
wrapper.play_sprite("Hurt")
|
||||
idle_sprite = "Hurt"
|
||||
play_sprite(idle_sprite)
|
||||
|
||||
func _on_sight_body_entered(body: Node2D) -> void:
|
||||
if fsm.map(fsm.state) != fsm.States.HUNTING and body.is_in_group("prey") or (health < maxHealth and body.is_in_group("player")):
|
||||
|
||||
@@ -5,8 +5,7 @@ var target: Node2D
|
||||
func enter(previous_state_path: String, data := {}) -> void:
|
||||
if data.has("target"):
|
||||
target = data["target"]
|
||||
owner.sprite.play("Hunting")
|
||||
owner.wrapper.play_sprite("Hunting")
|
||||
owner.play_sprite("Hunting")
|
||||
else:
|
||||
# default behaviour; do nothing
|
||||
finished.emit(owner.fsm.States.IDLE, {})
|
||||
|
||||
@@ -2,15 +2,14 @@ extends AbstractPrey
|
||||
|
||||
@onready var wrapper: WrappingManager = $WrappingManager
|
||||
@onready var collision: CharacterBody2D = $Collision
|
||||
@onready var sprite: AnimatedSprite2D = $"Collision/Sprite"
|
||||
@onready var sprite: AnimatedSprite2D = $Collision/Sprite
|
||||
@onready var fsm: StateMachine = $StateMachine
|
||||
var starting_pos
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
health = maxHealth
|
||||
sprite.play("Healthy")
|
||||
wrapper.play_sprite("Healthy")
|
||||
play_sprite(idle_sprite)
|
||||
if starting_pos:
|
||||
collision.set_position(starting_pos)
|
||||
|
||||
@@ -32,14 +31,13 @@ func handle_damage(dmg: int, src: Node) -> void:
|
||||
fsm.transition_to_next_state(fsm.States.FLEEING, {"threat": src})
|
||||
|
||||
func die() -> void:
|
||||
sprite.play("Dying")
|
||||
wrapper.play_sprite("Dying")
|
||||
play_sprite("Dying")
|
||||
GameManager.foodManager._spawn_food(collision.position)
|
||||
super.die()
|
||||
|
||||
func become_injured() -> void:
|
||||
sprite.play("Injured")
|
||||
wrapper.play_sprite("Injured")
|
||||
idle_sprite = "Injured"
|
||||
play_sprite(idle_sprite)
|
||||
|
||||
func _on_sight_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("predator") or (health < maxHealth and body.is_in_group("player")):
|
||||
|
||||
@@ -6,6 +6,7 @@ var threshold: float = 100
|
||||
func enter(previous_state_path: String, data := {}) -> void:
|
||||
if data.has("threat"):
|
||||
threat = data["threat"]
|
||||
owner.play_sprite("Fleeing")
|
||||
else:
|
||||
# default behaviour; do nothing
|
||||
finished.emit(owner.fsm.States.IDLE, {})
|
||||
|
||||
@@ -5,6 +5,7 @@ var dir = Vector3(1, 1, 0)
|
||||
|
||||
func enter(previous_state_path: String, data := {}) -> void:
|
||||
timer.start((float)(randi() % 5)/5)
|
||||
owner.play_sprite(owner.idle_sprite)
|
||||
|
||||
func physics_update(_delta: float) -> void:
|
||||
owner.move(_delta * Vector3(randfn(0, 1), randfn(0, 1), 0), 1)
|
||||
|
||||
@@ -6,6 +6,7 @@ var dir: Vector3 = Vector3(0,0,0);
|
||||
func enter(previous_state_path: String, data := {}) -> void:
|
||||
timer.start((float)(randi() % 10)/5)
|
||||
dir = calc_dir(randi() % 360)
|
||||
owner.play_sprite(owner.idle_sprite)
|
||||
|
||||
func physics_update(_delta: float) -> void:
|
||||
owner.move(dir)
|
||||
|
||||
Reference in New Issue
Block a user