Compare commits
4 commits
e161eb1117
...
47aa35a4c7
| Author | SHA1 | Date | |
|---|---|---|---|
| 47aa35a4c7 | |||
| ef7df7ea89 | |||
| a939ea4837 | |||
| 9dc5be7351 |
7 changed files with 37 additions and 12 deletions
|
|
@ -45,10 +45,10 @@ func match_state(exclude: Array[StringName] = []) -> StringName:
|
||||||
return ""
|
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)
|
var next_state: StringName = match_state(exclude)
|
||||||
if next_state != "":
|
if next_state != "":
|
||||||
finished.emit(next_state)
|
finished.emit(next_state, data)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -12,7 +12,7 @@ dest_files=["res://.godot/imported/yukotsuki.aseprite-2775b59c70c8f83084c0d15003
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
||||||
layer/exclude_layers_pattern=""
|
layer/exclude_layers_pattern="ref"
|
||||||
layer/only_visible_layers=false
|
layer/only_visible_layers=false
|
||||||
sheet/sheet_type="packed"
|
sheet/sheet_type="packed"
|
||||||
sheet/sheet_columns=12
|
sheet/sheet_columns=12
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,31 @@ const DEADZONE = 0.1
|
||||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||||
@onready var state_machine: StateMachine = $StateMachine
|
@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:
|
func get_movement_vector() -> Vector2:
|
||||||
var x_mov: float = Input.get_action_strength('move_right') - Input.get_action_strength('move_left')
|
var x_strength: 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')
|
var y_strength: float = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
|
||||||
return Vector2(x_mov, y_mov)
|
|
||||||
|
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))
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
position = Vector2(0, -16)
|
position = Vector2(0, -16)
|
||||||
sprite_frames = ExtResource("2_dovo2")
|
sprite_frames = ExtResource("2_dovo2")
|
||||||
|
animation = &"idle"
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2(0, -7)
|
position = Vector2(0, -7)
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,10 @@ var next_state: StringName
|
||||||
|
|
||||||
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
||||||
print('entering idle')
|
print('entering idle')
|
||||||
|
|
||||||
player.velocity = Vector2.ZERO
|
player.velocity = Vector2.ZERO
|
||||||
player.move_and_slide()
|
player.move_and_slide()
|
||||||
|
|
||||||
# TODO: animations
|
player.sprite.play("idle")
|
||||||
|
|
||||||
print('entered')
|
print('entered')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,15 @@ func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _state_physics_update(_delta: float) -> void:
|
func _state_physics_update(_delta: float) -> void:
|
||||||
var movement_vector: Vector2 = player.get_movement_vector()
|
var direction: Vector2 = player.get_movement_vector()
|
||||||
var direction: Vector2 = movement_vector.normalized()
|
direction = direction.normalized()
|
||||||
player.velocity = direction * player.max_speed
|
player.velocity = direction * player.max_speed
|
||||||
|
|
||||||
player.move_and_slide()
|
player.move_and_slide()
|
||||||
|
|
||||||
if watch_state([WALKING]): return
|
if watch_state([WALKING]): return
|
||||||
|
|
||||||
# TODO: animations
|
if direction.y > 0:
|
||||||
#player.sprite.play(player.anim_dir)
|
player.sprite.play("walk_down")
|
||||||
|
if direction.y < 0:
|
||||||
|
player.sprite.play("walk_up")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue