diff --git a/scenes/game.tscn b/scenes/game.tscn index 9cb03ff..0f753e0 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -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://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="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"] [node name="Game" type="Node" node_paths=PackedStringArray("map")] script = ExtResource("1_uwrxv") -map = NodePath("Map") +map = NodePath("MapContainer") [node name="Command Processor" type="Timer" parent="."] wait_time = 3.0 autostart = true 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="."] layout_mode = 3 diff --git a/scenes/game/maps/entities/mob.tscn b/scenes/game/maps/entities/mob.tscn index 2786071..e8ab632 100644 --- a/scenes/game/maps/entities/mob.tscn +++ b/scenes/game/maps/entities/mob.tscn @@ -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="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://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"] @@ -122,6 +123,7 @@ animations = [{ }] [node name="Mob" type="Node2D"] +script = ExtResource("1_mu6cs") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] position = Vector2(8, 8) diff --git a/scenes/game/maps/entities/player.tscn b/scenes/game/maps/entities/player.tscn new file mode 100644 index 0000000..92d2726 --- /dev/null +++ b/scenes/game/maps/entities/player.tscn @@ -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") diff --git a/scripts/game/commands/CommandDispatcher.gd b/scripts/game/commands/CommandDispatcher.gd index eba3eb8..41b1c34 100644 --- a/scripts/game/commands/CommandDispatcher.gd +++ b/scripts/game/commands/CommandDispatcher.gd @@ -1,11 +1,16 @@ extends Node +# Command Processor Signals signal PROCESS_COMMAND(command) signal WAIT_FOR_COMMAND signal PAUSE_PROCESSOR +# Game Signals signal PLAYER_MOVE(direction) +# Message Console Signals signal DISPLAY_MESSAGE(message) signal DISPLAY_COMMAND_PROMPT signal DISPLAY_CLEAR + +signal LOAD_MAP(currentMap, newMap, spawnpoint, facing) diff --git a/scripts/game/game_screen.gd b/scripts/game/game_screen.gd index 123b2c5..cf4ebb1 100644 --- a/scripts/game/game_screen.gd +++ b/scripts/game/game_screen.gd @@ -5,8 +5,7 @@ class_name GameScreen @export var map:Node func _ready(): - map.add_child(load(GameManager.currentMapPath).instantiate()) - CommandDispatcher.WAIT_FOR_COMMAND.emit() + CommandDispatcher.LOAD_MAP.emit(null, GameManager.defaultMapPath, null, Map.Direction.North) func _on_pass_button_pressed(): diff --git a/scripts/game/maps/MapContainer.gd b/scripts/game/maps/MapContainer.gd new file mode 100644 index 0000000..95874ca --- /dev/null +++ b/scripts/game/maps/MapContainer.gd @@ -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() diff --git a/scripts/game/maps/MapContainer.gd.uid b/scripts/game/maps/MapContainer.gd.uid new file mode 100644 index 0000000..404e56a --- /dev/null +++ b/scripts/game/maps/MapContainer.gd.uid @@ -0,0 +1 @@ +uid://b63jt1uexm120 diff --git a/scripts/game/maps/entities/Player.gd b/scripts/game/maps/entities/Player.gd new file mode 100644 index 0000000..442531e --- /dev/null +++ b/scripts/game/maps/entities/Player.gd @@ -0,0 +1 @@ +extends Mob diff --git a/scripts/game/maps/entities/Player.gd.uid b/scripts/game/maps/entities/Player.gd.uid new file mode 100644 index 0000000..53f7cfb --- /dev/null +++ b/scripts/game/maps/entities/Player.gd.uid @@ -0,0 +1 @@ +uid://dsguwthn2datq diff --git a/scripts/game/maps/entities/mob.gd b/scripts/game/maps/entities/mob.gd new file mode 100644 index 0000000..b2532c2 --- /dev/null +++ b/scripts/game/maps/entities/mob.gd @@ -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 diff --git a/scripts/game/maps/entities/mob.gd.uid b/scripts/game/maps/entities/mob.gd.uid new file mode 100644 index 0000000..8c8645c --- /dev/null +++ b/scripts/game/maps/entities/mob.gd.uid @@ -0,0 +1 @@ +uid://bo0had2vq4r7h diff --git a/scripts/game/maps/map.gd b/scripts/game/maps/map.gd index d688516..fd740f3 100644 --- a/scripts/game/maps/map.gd +++ b/scripts/game/maps/map.gd @@ -3,3 +3,17 @@ extends TileMap class_name Map 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) diff --git a/scripts/game/maps/map2d.gd b/scripts/game/maps/map2d.gd index b7dd7e9..d68cad9 100644 --- a/scripts/game/maps/map2d.gd +++ b/scripts/game/maps/map2d.gd @@ -12,15 +12,9 @@ func getTerrainDataForTile(layer, data, x, y): else: return null -# Called when the node enters the scene tree for the first time. -#func _ready() -> void: -# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 39, 17)) -# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 0, 0)) -# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 11, 11)) -# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 6, 9)) -# 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 +func spawnPlayerAtPosition(position, facing): + player = load("res://scenes/game/maps/entities/player.tscn").instantiate() + + super.spawnPlayerAtPosition(position, facing) + + return player