Compare commits

..

4 commits

Author SHA1 Message Date
47aa35a4c7 allow data dict in watch state helper 2025-11-22 15:54:21 -03:00
ef7df7ea89 change movement to 4 directional 2025-11-22 15:53:59 -03:00
a939ea4837 up and down animations 2025-11-22 15:06:44 -03:00
9dc5be7351 begin work on player animations 2025-11-22 12:54:07 -03:00
7 changed files with 37 additions and 12 deletions

View file

@ -45,10 +45,10 @@ func match_state(exclude: Array[StringName] = []) -> StringName:
return ""
func watch_state(exclude: Array[StringName] = []) -> bool:
func watch_state(exclude: Array[StringName] = [], data: Dictionary[StringName, Variant] = {}) -> bool:
var next_state: StringName = match_state(exclude)
if next_state != "":
finished.emit(next_state)
finished.emit(next_state, data)
return true
return false

View file

@ -12,7 +12,7 @@ dest_files=["res://.godot/imported/yukotsuki.aseprite-2775b59c70c8f83084c0d15003
[params]
layer/exclude_layers_pattern=""
layer/exclude_layers_pattern="ref"
layer/only_visible_layers=false
sheet/sheet_type="packed"
sheet/sheet_columns=12

View file

@ -8,8 +8,31 @@ const DEADZONE = 0.1
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var state_machine: StateMachine = $StateMachine
var h_press_tick: int = 0 ## last time horizontal axis was pressed
var v_press_tick: int = 0 ## last time vertical axis was pressed
func _input(event: InputEvent) -> void:
if event.is_action_pressed("move_left") or event.is_action_pressed("move_right"):
h_press_tick = Time.get_ticks_msec()
if event.is_action_pressed("move_up") or event.is_action_pressed("move_down"):
v_press_tick = Time.get_ticks_msec()
func get_movement_vector() -> Vector2:
var x_mov: float = Input.get_action_strength('move_right') - Input.get_action_strength('move_left')
var y_mov: float = Input.get_action_strength('move_down') - Input.get_action_strength('move_up')
return Vector2(x_mov, y_mov)
var x_strength: float = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
var y_strength: float = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
if abs(x_strength) < DEADZONE and abs(y_strength) < DEADZONE:
return Vector2.ZERO
if abs(x_strength) < DEADZONE:
return Vector2(0, signf(y_strength))
if abs(y_strength) < DEADZONE:
return Vector2(signf(x_strength), 0)
# use most recent axis press
if h_press_tick > v_press_tick:
return Vector2(signf(x_strength), 0)
else:
return Vector2(0, signf(y_strength))

View file

@ -31,6 +31,7 @@ metadata/_custom_type_script = "uid://bebe1y51hwns8"
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(0, -16)
sprite_frames = ExtResource("2_dovo2")
animation = &"idle"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -7)

View file

@ -6,11 +6,10 @@ var next_state: StringName
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
print('entering idle')
player.velocity = Vector2.ZERO
player.move_and_slide()
# TODO: animations
player.sprite.play("idle")
print('entered')

View file

@ -10,13 +10,15 @@ func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
func _state_physics_update(_delta: float) -> void:
var movement_vector: Vector2 = player.get_movement_vector()
var direction: Vector2 = movement_vector.normalized()
var direction: Vector2 = player.get_movement_vector()
direction = direction.normalized()
player.velocity = direction * player.max_speed
player.move_and_slide()
if watch_state([WALKING]): return
# TODO: animations
#player.sprite.play(player.anim_dir)
if direction.y > 0:
player.sprite.play("walk_down")
if direction.y < 0:
player.sprite.play("walk_up")