create player snoozing animation
This commit is contained in:
parent
0463707616
commit
9c6af1c034
9 changed files with 47 additions and 6 deletions
Binary file not shown.
|
|
@ -1,11 +1,13 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://cqm5besqgsb7x"]
|
||||
[gd_scene load_steps=13 format=3 uid="uid://cqm5besqgsb7x"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dpsocqnk0e6le" path="res://scenes/player/player.gd" id="1_dovo2"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://6v5nyv2wo47g" path="res://scenes/player/assets/yukotsuki.aseprite" id="2_dovo2"]
|
||||
[ext_resource type="Script" uid="uid://diths5s8vd7lr" path="res://classes/state_machine/state_machine.gd" id="2_lvxji"]
|
||||
[ext_resource type="Script" uid="uid://cl6snimpmxcvu" path="res://scenes/player/states/player_idle.gd" id="3_p47bc"]
|
||||
[ext_resource type="Script" uid="uid://bg5fu1ildsdnq" path="res://scenes/player/states/player_walking.gd" id="4_p47bc"]
|
||||
[ext_resource type="Script" uid="uid://d1ar1gtjoowhw" path="res://scenes/player/states/player_waking.gd" id="5_0owmy"]
|
||||
[ext_resource type="Texture2D" uid="uid://5mm8pi5i0yal" path="res://scenes/player/assets/pointlight_texture.aseprite" id="5_75vfm"]
|
||||
[ext_resource type="Script" uid="uid://cgiphcl4t75v8" path="res://scenes/player/states/player_paused.gd" id="6_qek5x"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_75vfm"]
|
||||
resource_name = "default"
|
||||
|
|
@ -68,6 +70,14 @@ metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
|||
script = ExtResource("4_p47bc")
|
||||
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||
|
||||
[node name="Waking" type="Node" parent="PlayerStateMachine"]
|
||||
script = ExtResource("5_0owmy")
|
||||
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||
|
||||
[node name="Paused" type="Node" parent="PlayerStateMachine"]
|
||||
script = ExtResource("6_qek5x")
|
||||
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||
|
||||
[node name="PointLight2D" type="PointLight2D" parent="."]
|
||||
enabled = false
|
||||
energy = 0.0
|
||||
|
|
@ -83,11 +93,9 @@ libraries = {
|
|||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
position = Vector2(0, -16)
|
||||
sprite_frames = ExtResource("2_dovo2")
|
||||
animation = &"idle"
|
||||
animation = &"snoozing"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -7)
|
||||
shape = SubResource("CapsuleShape2D_gmlin")
|
||||
debug_color = Color(0.28459275, 0.61933166, 0.3529686, 0.41960785)
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ class_name PlayerState extends State
|
|||
|
||||
const IDLE = "Idle"
|
||||
const WALKING = "Walking"
|
||||
const WAKING = "Waking"
|
||||
|
||||
var player: Player
|
||||
|
||||
|
|
|
|||
5
scenes/player/states/player_paused.gd
Normal file
5
scenes/player/states/player_paused.gd
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
extends PlayerState
|
||||
|
||||
|
||||
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
||||
player.sprite.pause()
|
||||
1
scenes/player/states/player_paused.gd.uid
Normal file
1
scenes/player/states/player_paused.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cgiphcl4t75v8
|
||||
7
scenes/player/states/player_waking.gd
Normal file
7
scenes/player/states/player_waking.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
extends PlayerState
|
||||
|
||||
|
||||
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
||||
player.sprite.play("snoozing")
|
||||
await player.sprite.animation_finished
|
||||
finished.emit(IDLE)
|
||||
1
scenes/player/states/player_waking.gd.uid
Normal file
1
scenes/player/states/player_waking.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d1ar1gtjoowhw
|
||||
|
|
@ -13,6 +13,7 @@ func _state_physics_update(_delta: float) -> void:
|
|||
player.velocity = direction * player.max_speed * player.speed_mult
|
||||
|
||||
player.move_and_slide()
|
||||
player.global_position = player.global_position.round()
|
||||
#endregion
|
||||
|
||||
if watch_state([WALKING]): return
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ extends RoomState
|
|||
|
||||
var trans_tween: Tween
|
||||
var player_light_tween: Tween
|
||||
var wake_timer: Timer
|
||||
|
||||
|
||||
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
||||
print("entering room")
|
||||
room.player = _instantiate_player()
|
||||
room.player = _instantiate_player(true)
|
||||
assert(room.player != null, "player is null")
|
||||
room.camera.global_position = room.config.camera_position
|
||||
|
||||
|
|
@ -64,12 +65,23 @@ func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
|||
trans_tween.tween_property(room.canvas_modulate, "color", Color.WHITE, room.config.transition_in_duration).set_trans(room.config.transition_in_type).set_ease(Tween.EASE_OUT)
|
||||
|
||||
await trans_tween.finished
|
||||
|
||||
finished.emit(PLAYING)
|
||||
|
||||
|
||||
func _instantiate_player() -> Player:
|
||||
func _instantiate_player(waking: bool) -> Player:
|
||||
var p: Player = room.player_scene.instantiate()
|
||||
room.add_child(p)
|
||||
if waking:
|
||||
wake_timer = Timer.new()
|
||||
p.add_child(wake_timer)
|
||||
wake_timer.one_shot = true
|
||||
wake_timer.start(room.config.transition_in_duration)
|
||||
|
||||
wake_timer.timeout.connect(_on_wake_timer)
|
||||
|
||||
p.state_machine._transition_to_next_state(PlayerState.PAUSED)
|
||||
|
||||
if room.initial_spawn != Vector2i.ZERO:
|
||||
p.global_position = room.initial_spawn
|
||||
else:
|
||||
|
|
@ -80,3 +92,8 @@ func _instantiate_player() -> Player:
|
|||
p.global_position = room.config.initial_spawn
|
||||
|
||||
return p
|
||||
|
||||
|
||||
func _on_wake_timer() -> void:
|
||||
room.player.state_machine._transition_to_next_state(PlayerState.WAKING)
|
||||
wake_timer.queue_free()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue