Compare commits
2 commits
bd6ced2a16
...
9c6af1c034
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c6af1c034 | |||
| 0463707616 |
10 changed files with 55 additions and 10 deletions
Binary file not shown.
|
|
@ -10,7 +10,7 @@ const DEADZONE = 0.1
|
||||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||||
@onready var state_machine: StateMachine = $PlayerStateMachine
|
@onready var state_machine: StateMachine = $PlayerStateMachine
|
||||||
@onready var point_light: PointLight2D = $PointLight2D
|
@onready var point_light: PointLight2D = $PointLight2D
|
||||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
@onready var point_light_animation: AnimationPlayer = $PointLight2D/AnimationPlayer
|
||||||
|
|
||||||
var h_press_tick: int = 0 ## last time horizontal axis was pressed
|
var h_press_tick: int = 0 ## last time horizontal axis was pressed
|
||||||
var v_press_tick: int = 0 ## last time vertical axis was pressed
|
var v_press_tick: int = 0 ## last time vertical axis was pressed
|
||||||
|
|
@ -84,7 +84,7 @@ func _on_loop_toggled(enabled: bool, loop_size: Rect2i) -> void:
|
||||||
func enable_point_light(enabled: bool, energy: float = 0) -> void:
|
func enable_point_light(enabled: bool, energy: float = 0) -> void:
|
||||||
point_light.enabled = enabled
|
point_light.enabled = enabled
|
||||||
point_light.energy = energy
|
point_light.energy = energy
|
||||||
if enabled: animation_player.play("default")
|
if enabled: point_light_animation.play("default")
|
||||||
else: animation_player.pause()
|
else: point_light_animation.play("RESET")
|
||||||
|
|
||||||
point_light_toggled.emit(enabled, energy)
|
point_light_toggled.emit(enabled, energy)
|
||||||
|
|
|
||||||
|
|
@ -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="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="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://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://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://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="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"]
|
[sub_resource type="Animation" id="Animation_75vfm"]
|
||||||
resource_name = "default"
|
resource_name = "default"
|
||||||
|
|
@ -35,7 +37,7 @@ tracks/0/keys = {
|
||||||
"times": PackedFloat32Array(0),
|
"times": PackedFloat32Array(0),
|
||||||
"transitions": PackedFloat32Array(1),
|
"transitions": PackedFloat32Array(1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [0.0]
|
"values": [-15.0]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_qek5x"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_qek5x"]
|
||||||
|
|
@ -68,12 +70,22 @@ metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||||
script = ExtResource("4_p47bc")
|
script = ExtResource("4_p47bc")
|
||||||
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
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="."]
|
[node name="PointLight2D" type="PointLight2D" parent="."]
|
||||||
enabled = false
|
enabled = false
|
||||||
energy = 0.0
|
energy = 0.0
|
||||||
texture = ExtResource("5_75vfm")
|
texture = ExtResource("5_75vfm")
|
||||||
|
offset = Vector2(0, -15)
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="PointLight2D"]
|
||||||
|
root_node = NodePath("../..")
|
||||||
libraries = {
|
libraries = {
|
||||||
&"": SubResource("AnimationLibrary_qek5x")
|
&"": SubResource("AnimationLibrary_qek5x")
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +93,7 @@ libraries = {
|
||||||
[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"
|
animation = &"snoozing"
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2(0, -7)
|
position = Vector2(0, -7)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ class_name PlayerState extends State
|
||||||
|
|
||||||
const IDLE = "Idle"
|
const IDLE = "Idle"
|
||||||
const WALKING = "Walking"
|
const WALKING = "Walking"
|
||||||
|
const WAKING = "Waking"
|
||||||
|
|
||||||
var player: Player
|
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.velocity = direction * player.max_speed * player.speed_mult
|
||||||
|
|
||||||
player.move_and_slide()
|
player.move_and_slide()
|
||||||
|
player.global_position = player.global_position.round()
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
if watch_state([WALKING]): return
|
if watch_state([WALKING]): return
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,12 @@ extends RoomState
|
||||||
|
|
||||||
var trans_tween: Tween
|
var trans_tween: Tween
|
||||||
var player_light_tween: Tween
|
var player_light_tween: Tween
|
||||||
|
var wake_timer: Timer
|
||||||
|
|
||||||
|
|
||||||
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
||||||
print("entering room")
|
print("entering room")
|
||||||
room.player = _instantiate_player()
|
room.player = _instantiate_player(true)
|
||||||
assert(room.player != null, "player is null")
|
assert(room.player != null, "player is null")
|
||||||
room.camera.global_position = room.config.camera_position
|
room.camera.global_position = room.config.camera_position
|
||||||
|
|
||||||
|
|
@ -47,7 +48,7 @@ func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
||||||
else:
|
else:
|
||||||
player_light_tween.tween_property(room.player.point_light, "energy", 0, room.config.transition_in_duration).set_trans(room.config.transition_in_type).set_ease(Tween.EASE_OUT)
|
player_light_tween.tween_property(room.player.point_light, "energy", 0, room.config.transition_in_duration).set_trans(room.config.transition_in_type).set_ease(Tween.EASE_OUT)
|
||||||
player_light_tween.tween_callback(func() -> void:
|
player_light_tween.tween_callback(func() -> void:
|
||||||
room.player.point_light.enabled = false
|
room.player.enable_point_light(false)
|
||||||
player_light_tween = null
|
player_light_tween = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -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)
|
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
|
await trans_tween.finished
|
||||||
|
|
||||||
finished.emit(PLAYING)
|
finished.emit(PLAYING)
|
||||||
|
|
||||||
|
|
||||||
func _instantiate_player() -> Player:
|
func _instantiate_player(waking: bool) -> Player:
|
||||||
var p: Player = room.player_scene.instantiate()
|
var p: Player = room.player_scene.instantiate()
|
||||||
room.add_child(p)
|
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:
|
if room.initial_spawn != Vector2i.ZERO:
|
||||||
p.global_position = room.initial_spawn
|
p.global_position = room.initial_spawn
|
||||||
else:
|
else:
|
||||||
|
|
@ -80,3 +92,8 @@ func _instantiate_player() -> Player:
|
||||||
p.global_position = room.config.initial_spawn
|
p.global_position = room.config.initial_spawn
|
||||||
|
|
||||||
return p
|
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