End of lesson 24.

This commit is contained in:
Penelope 2025-04-07 21:12:10 -03:00
parent d44f69f731
commit 68a1e19ebe
13 changed files with 127 additions and 18 deletions

View File

@ -1,21 +1,26 @@
[gd_scene load_steps=6 format=3 uid="uid://c0b5w48jk67qd"] [gd_scene load_steps=7 format=3 uid="uid://c0b5w48jk67qd"]
[ext_resource type="Script" uid="uid://c0uvlwmkm3r8o" path="res://scripts/game/game_screen.gd" id="1_uwrxv"] [ext_resource type="Script" uid="uid://c0uvlwmkm3r8o" path="res://scripts/game/game_screen.gd" id="1_uwrxv"]
[ext_resource type="Script" uid="uid://dcqqr8b42tn0x" path="res://scripts/game/CommandProcessor.gd" id="2_lbhrr"] [ext_resource type="Script" uid="uid://dcqqr8b42tn0x" path="res://scripts/game/CommandProcessor.gd" id="2_lbhrr"]
[ext_resource type="Texture2D" uid="uid://ccxs3ctob15es" path="res://gfx/ui/main_frame.png" id="2_lnu2h"] [ext_resource type="Texture2D" uid="uid://ccxs3ctob15es" path="res://gfx/ui/main_frame.png" id="2_lnu2h"]
[ext_resource type="FontFile" uid="uid://1u28cjgctsn7" path="res://fonts/alagard_by_pix3m-d6awiwp.ttf" id="3_lbhrr"] [ext_resource type="FontFile" uid="uid://1u28cjgctsn7" path="res://fonts/alagard_by_pix3m-d6awiwp.ttf" id="3_lbhrr"]
[ext_resource type="Script" uid="uid://b63jt1uexm120" path="res://scripts/game/maps/MapContainer.gd" id="3_p57ef"]
[ext_resource type="Script" uid="uid://dv3fd112uj8o1" path="res://scripts/ui/Message Console.gd" id="5_iywne"] [ext_resource type="Script" uid="uid://dv3fd112uj8o1" path="res://scripts/ui/Message Console.gd" id="5_iywne"]
[node name="Game" type="Node" node_paths=PackedStringArray("map")] [node name="Game" type="Node" node_paths=PackedStringArray("map")]
script = ExtResource("1_uwrxv") script = ExtResource("1_uwrxv")
map = NodePath("Map") map = NodePath("MapContainer")
[node name="Command Processor" type="Timer" parent="."] [node name="Command Processor" type="Timer" parent="."]
wait_time = 3.0 wait_time = 3.0
autostart = true autostart = true
script = ExtResource("2_lbhrr") script = ExtResource("2_lbhrr")
[node name="Map" type="Node" parent="."] [node name="MapContainer" type="Node" parent="." node_paths=PackedStringArray("entities")]
script = ExtResource("3_p57ef")
entities = NodePath("Entities")
[node name="Entities" type="Node" parent="MapContainer"]
[node name="UI" type="Control" parent="."] [node name="UI" type="Control" parent="."]
layout_mode = 3 layout_mode = 3

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=19 format=3 uid="uid://d3e5mg0gk8u7r"] [gd_scene load_steps=20 format=3 uid="uid://d3e5mg0gk8u7r"]
[ext_resource type="Texture2D" uid="uid://byx166hd5b3as" path="res://gfx/game/maps/entities/player/Idle/Untitled-0_0.png" id="1_li2a0"] [ext_resource type="Texture2D" uid="uid://byx166hd5b3as" path="res://gfx/game/maps/entities/player/Idle/Untitled-0_0.png" id="1_li2a0"]
[ext_resource type="Script" uid="uid://bo0had2vq4r7h" path="res://scripts/game/maps/entities/mob.gd" id="1_mu6cs"]
[ext_resource type="Texture2D" uid="uid://gm5dhmls0klm" path="res://gfx/game/maps/entities/player/WalkLeft/Untitled-3_0.png" id="2_mu6cs"] [ext_resource type="Texture2D" uid="uid://gm5dhmls0klm" path="res://gfx/game/maps/entities/player/WalkLeft/Untitled-3_0.png" id="2_mu6cs"]
[ext_resource type="Texture2D" uid="uid://cio1xyswbao5j" path="res://gfx/game/maps/entities/player/WalkRight/Untitled-3_0.png" id="3_tvinw"] [ext_resource type="Texture2D" uid="uid://cio1xyswbao5j" path="res://gfx/game/maps/entities/player/WalkRight/Untitled-3_0.png" id="3_tvinw"]
[ext_resource type="Texture2D" uid="uid://svg30tifp74r" path="res://gfx/game/maps/entities/player/WalkUp/Untitled-2_0.png" id="4_cdxgq"] [ext_resource type="Texture2D" uid="uid://svg30tifp74r" path="res://gfx/game/maps/entities/player/WalkUp/Untitled-2_0.png" id="4_cdxgq"]
@ -122,6 +123,7 @@ animations = [{
}] }]
[node name="Mob" type="Node2D"] [node name="Mob" type="Node2D"]
script = ExtResource("1_mu6cs")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(8, 8) position = Vector2(8, 8)

View File

@ -0,0 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://bpsrg5d3gncnd"]
[ext_resource type="PackedScene" uid="uid://d3e5mg0gk8u7r" path="res://scenes/game/maps/entities/mob.tscn" id="1_7y2qh"]
[ext_resource type="Script" uid="uid://dsguwthn2datq" path="res://scripts/game/maps/entities/Player.gd" id="2_us7jc"]
[node name="Player" instance=ExtResource("1_7y2qh")]
script = ExtResource("2_us7jc")

View File

@ -1,11 +1,16 @@
extends Node extends Node
# Command Processor Signals
signal PROCESS_COMMAND(command) signal PROCESS_COMMAND(command)
signal WAIT_FOR_COMMAND signal WAIT_FOR_COMMAND
signal PAUSE_PROCESSOR signal PAUSE_PROCESSOR
# Game Signals
signal PLAYER_MOVE(direction) signal PLAYER_MOVE(direction)
# Message Console Signals
signal DISPLAY_MESSAGE(message) signal DISPLAY_MESSAGE(message)
signal DISPLAY_COMMAND_PROMPT signal DISPLAY_COMMAND_PROMPT
signal DISPLAY_CLEAR signal DISPLAY_CLEAR
signal LOAD_MAP(currentMap, newMap, spawnpoint, facing)

View File

@ -5,8 +5,7 @@ class_name GameScreen
@export var map:Node @export var map:Node
func _ready(): func _ready():
map.add_child(load(GameManager.currentMapPath).instantiate()) CommandDispatcher.LOAD_MAP.emit(null, GameManager.defaultMapPath, null, Map.Direction.North)
CommandDispatcher.WAIT_FOR_COMMAND.emit()
func _on_pass_button_pressed(): func _on_pass_button_pressed():

View File

@ -0,0 +1,23 @@
extends Node
@export var entities:Node
var map:Map
func _ready():
CommandDispatcher.LOAD_MAP.connect(loadMap)
func loadMap(currentMapPath, newMapPath, spawnpoint, facing):
var newMap:Map = load(newMapPath).instantiate()
CommandDispatcher.PAUSE_PROCESSOR.emit()
if (currentMapPath != null):
currentMapPath.queue_free()
add_child(newMap)
entities.add_child(newMap.spawnPlayerAtPosition(spawnpoint, facing))
CommandDispatcher.WAIT_FOR_COMMAND.emit()

View File

@ -0,0 +1 @@
uid://b63jt1uexm120

View File

@ -0,0 +1 @@
extends Mob

View File

@ -0,0 +1 @@
uid://dsguwthn2datq

View File

@ -0,0 +1,56 @@
extends Node2D
class_name Mob
@export var animator:AnimatedSprite2D
@export var collisionRay_1:RayCast2D
@export var collisionRay_2:RayCast2D
func updateRaycasts(destination):
var direction = destination - position
if (direction.x != 0):
collisionRay_1.position = Vector2(8, 1)
collisionRay_2.position = Vector2(8, 15)
if (direction.y != 0):
collisionRay_1.position = Vector2(1, 8)
collisionRay_2.position = Vector2(15, 8)
if (direction.x < 0):
collisionRay_1.position.x -= 1
collisionRay_2.position.x -= 1
if (direction.y < 0):
collisionRay_1.position.y -= 1
collisionRay_2.position.y -= 1
collisionRay_1.target_position = Vector2(direction)
collisionRay_1.force_raycast_update()
collisionRay_2.target_position = Vector2(direction)
collisionRay_2.force_raycast_update()
func updateAnimation(direction):
var sequence
match(direction):
Map.Direction.East:
sequence = "Walk Right"
Map.Direction.West:
sequence = "Walk Left"
Map.Direction.North:
sequence = "Walk Up"
Map.Direction.South:
sequence = "Walk Down"
if (animator.animation != sequence):
animator.animation = sequence
animator.frame = 0
else:
if (animator.frame == animator.sprite_frames.get_frame_count(animator.animation) - 1):
animator.frame = 0
else:
animator.frame += 1

View File

@ -0,0 +1 @@
uid://bo0had2vq4r7h

View File

@ -3,3 +3,17 @@ extends TileMap
class_name Map class_name Map
enum Direction { North, East, South, West } enum Direction { North, East, South, West }
@export var defaultPlayerStartPosition:Vector2i
var player
func spawnPlayerAtPosition(position, facing):
var spawnposition
if (position == null):
spawnposition = defaultPlayerStartPosition
else:
spawnposition = position
player.position = Vector2(spawnposition.x * 16, spawnposition.y * 16)

View File

@ -12,15 +12,9 @@ func getTerrainDataForTile(layer, data, x, y):
else: else:
return null return null
# Called when the node enters the scene tree for the first time. func spawnPlayerAtPosition(position, facing):
#func _ready() -> void: player = load("res://scenes/game/maps/entities/player.tscn").instantiate()
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 39, 17))
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 0, 0)) super.spawnPlayerAtPosition(position, facing)
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 11, 11))
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 6, 9)) return player
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 22, 22))
#
#
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass