Compare commits
10 commits
762da40eec
...
041b26c2bd
| Author | SHA1 | Date | |
|---|---|---|---|
| 041b26c2bd | |||
| 5a9d8d221d | |||
| 68cf5ea4df | |||
| cb326a5c94 | |||
| da0b1bcff4 | |||
| 253844755b | |||
| d23a7c4c36 | |||
| d49752c98a | |||
| 0242623476 | |||
| dbced7912b |
19 changed files with 142 additions and 4 deletions
7
resources/room_config.gd
Normal file
7
resources/room_config.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
@tool class_name RoomConfig extends Resource
|
||||
|
||||
|
||||
@export var size: Vector2i = Vector2i.ZERO
|
||||
@export var follow_player: bool = true
|
||||
|
||||
@export var camera_position: Vector2i = Vector2i.ZERO
|
||||
1
resources/room_config.gd.uid
Normal file
1
resources/room_config.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bamoq5wi0lkdy
|
||||
|
|
@ -6,7 +6,7 @@ const DEADZONE = 0.1
|
|||
@export var max_speed: float = 300.0
|
||||
|
||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
@onready var state_machine: StateMachine = $StateMachine
|
||||
@onready var state_machine: StateMachine = $PlayerStateMachine
|
||||
|
||||
var h_press_tick: int = 0 ## last time horizontal axis was pressed
|
||||
var v_press_tick: int = 0 ## last time vertical axis was pressed
|
||||
|
|
|
|||
|
|
@ -16,16 +16,16 @@ motion_mode = 1
|
|||
script = ExtResource("1_dovo2")
|
||||
max_speed = 95.0
|
||||
|
||||
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("initial_state")]
|
||||
[node name="PlayerStateMachine" type="Node" parent="." node_paths=PackedStringArray("initial_state")]
|
||||
script = ExtResource("2_lvxji")
|
||||
initial_state = NodePath("Idle")
|
||||
metadata/_custom_type_script = "uid://diths5s8vd7lr"
|
||||
|
||||
[node name="Idle" type="Node" parent="StateMachine"]
|
||||
[node name="Idle" type="Node" parent="PlayerStateMachine"]
|
||||
script = ExtResource("3_p47bc")
|
||||
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||
|
||||
[node name="Walking" type="Node" parent="StateMachine"]
|
||||
[node name="Walking" type="Node" parent="PlayerStateMachine"]
|
||||
script = ExtResource("4_p47bc")
|
||||
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||
|
||||
|
|
|
|||
12
scenes/room/room.gd
Normal file
12
scenes/room/room.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
class_name Room extends Node2D
|
||||
|
||||
|
||||
@export var room_config: RoomConfig
|
||||
|
||||
@onready var camera: RoomCamera = $RoomCamera
|
||||
@onready var state_machine: StateMachine = $RoomStateMachine
|
||||
|
||||
var player_scene: PackedScene = preload("res://scenes/player/player.tscn")
|
||||
|
||||
var player: Player
|
||||
var initial_spawn: Vector2i = Vector2i(16,16)
|
||||
1
scenes/room/room.gd.uid
Normal file
1
scenes/room/room.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://pcl0om2k32g6
|
||||
32
scenes/room/room.tscn
Normal file
32
scenes/room/room.tscn
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://bxhyxox662buj"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://pcl0om2k32g6" path="res://scenes/room/room.gd" id="1_8xru0"]
|
||||
[ext_resource type="Script" uid="uid://bamoq5wi0lkdy" path="res://resources/room_config.gd" id="2_kxljb"]
|
||||
[ext_resource type="Script" uid="uid://diou146pyb0br" path="res://scenes/room/room_camera.gd" id="3_y1kpu"]
|
||||
[ext_resource type="Script" uid="uid://b7715auuhy7vu" path="res://scenes/room/states/room_starting.gd" id="4_1w8vm"]
|
||||
[ext_resource type="Script" uid="uid://diths5s8vd7lr" path="res://classes/state_machine/state_machine.gd" id="4_vaubn"]
|
||||
[ext_resource type="Script" uid="uid://d2xitfobwbk20" path="res://scenes/room/states/room_playing.gd" id="5_w7vtx"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_y1kpu"]
|
||||
script = ExtResource("2_kxljb")
|
||||
metadata/_custom_type_script = "uid://bamoq5wi0lkdy"
|
||||
|
||||
[node name="Room" type="Node2D"]
|
||||
script = ExtResource("1_8xru0")
|
||||
room_config = SubResource("Resource_y1kpu")
|
||||
|
||||
[node name="RoomStateMachine" type="Node" parent="." node_paths=PackedStringArray("initial_state")]
|
||||
script = ExtResource("4_vaubn")
|
||||
initial_state = NodePath("Starting")
|
||||
metadata/_custom_type_script = "uid://diths5s8vd7lr"
|
||||
|
||||
[node name="Starting" type="Node" parent="RoomStateMachine"]
|
||||
script = ExtResource("4_1w8vm")
|
||||
metadata/_custom_type_script = "uid://hjm43hb4os07"
|
||||
|
||||
[node name="Playing" type="Node" parent="RoomStateMachine"]
|
||||
script = ExtResource("5_w7vtx")
|
||||
metadata/_custom_type_script = "uid://hjm43hb4os07"
|
||||
|
||||
[node name="RoomCamera" type="Camera2D" parent="."]
|
||||
script = ExtResource("3_y1kpu")
|
||||
14
scenes/room/room_camera.gd
Normal file
14
scenes/room/room_camera.gd
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class_name RoomCamera extends Camera2D
|
||||
|
||||
|
||||
var room: Room
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
await owner.ready
|
||||
room = owner as Room
|
||||
assert(room != null, "The RoomCamera type must be used only in the room scene. It needs the owner to be a Room node.")
|
||||
|
||||
|
||||
func follow_player(_delta: float) -> void:
|
||||
global_position = room.player.global_position
|
||||
1
scenes/room/room_camera.gd.uid
Normal file
1
scenes/room/room_camera.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://diou146pyb0br
|
||||
51
scenes/room/room_state.gd
Normal file
51
scenes/room/room_state.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
class_name RoomState extends State
|
||||
|
||||
|
||||
const ENTERING = "Entering"
|
||||
const PLAYING = "Playing"
|
||||
const EXITING = "Exiting"
|
||||
|
||||
var room: Room
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
await owner.ready
|
||||
room = owner as Room
|
||||
assert(room != null, "The RoomState state type must be used only in the room scene. It needs the owner's parent to be a Room node.")
|
||||
|
||||
|
||||
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _exit() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _handle_input(_event: InputEvent) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _state_update(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _state_physics_update(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func match_state(exclude: Array[StringName] = []) -> StringName:
|
||||
if Input.is_action_just_pressed("pause"):
|
||||
if PAUSED in exclude: return ""
|
||||
return PAUSED
|
||||
|
||||
return ""
|
||||
|
||||
|
||||
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, data)
|
||||
return true
|
||||
|
||||
return false
|
||||
1
scenes/room/room_state.gd.uid
Normal file
1
scenes/room/room_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://hjm43hb4os07
|
||||
10
scenes/room/states/room_entering.gd
Normal file
10
scenes/room/states/room_entering.gd
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
extends RoomState
|
||||
|
||||
|
||||
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
||||
room.player = room.player_scene.instantiate()
|
||||
room.add_child(room.player)
|
||||
room.player.global_position = room.initial_spawn
|
||||
|
||||
finished.emit(PLAYING)
|
||||
return
|
||||
1
scenes/room/states/room_entering.gd.uid
Normal file
1
scenes/room/states/room_entering.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b7715auuhy7vu
|
||||
6
scenes/room/states/room_playing.gd
Normal file
6
scenes/room/states/room_playing.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends RoomState
|
||||
|
||||
|
||||
func _state_physics_update(delta: float) -> void:
|
||||
room.camera.follow_player(delta)
|
||||
if match_state([PLAYING]): return
|
||||
1
scenes/room/states/room_playing.gd.uid
Normal file
1
scenes/room/states/room_playing.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d2xitfobwbk20
|
||||
Loading…
Add table
Reference in a new issue