End of lesson 24.
This commit is contained in:
parent
d44f69f731
commit
68a1e19ebe
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://b63jt1uexm120
|
||||
|
|
@ -0,0 +1 @@
|
|||
extends Mob
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://dsguwthn2datq
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bo0had2vq4r7h
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue