End of lesson 31
This commit is contained in:
parent
f4e4de59f5
commit
ffbbfd455e
|
|
@ -35,6 +35,7 @@ window/stretch/scale_mode="integer"
|
||||||
|
|
||||||
2d_physics/layer_1="Map"
|
2d_physics/layer_1="Map"
|
||||||
2d_physics/layer_2="Player"
|
2d_physics/layer_2="Player"
|
||||||
|
2d_physics/layer_3="NPCs"
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,131 @@
|
||||||
|
[gd_scene load_steps=20 format=3 uid="uid://bjlob58yvst7u"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://d3e5mg0gk8u7r" path="res://scenes/game/maps/entities/mob.tscn" id="1_nvsti"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://byx166hd5b3as" path="res://gfx/game/maps/entities/player/Idle/Untitled-0_0.png" id="2_vclwd"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://gm5dhmls0klm" path="res://gfx/game/maps/entities/player/WalkLeft/Untitled-3_0.png" id="3_muq5y"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cio1xyswbao5j" path="res://gfx/game/maps/entities/player/WalkRight/Untitled-3_0.png" id="4_mqjq0"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://svg30tifp74r" path="res://gfx/game/maps/entities/player/WalkUp/Untitled-2_0.png" id="5_sh7wu"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://puqpn3m0ejv1" path="res://gfx/game/maps/entities/player/WalkDown/Untitled-2_0.png" id="6_7u5it"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bel7ltrdmhvx3" path="res://gfx/game/maps/entities/player/WalkDown/Untitled-2_1.png" id="7_ii2o2"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bvallk0cswtnq" path="res://gfx/game/maps/entities/player/WalkDown/Untitled-2_2.png" id="8_cndau"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b4ptv7ts0nlhu" path="res://gfx/game/maps/entities/player/WalkDown/Untitled-2_3.png" id="9_l7rxc"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://ddw1m0c2pby4c" path="res://gfx/game/maps/entities/player/WalkLeft/Untitled-3_1.png" id="10_nr0px"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://brsuvqye8vfji" path="res://gfx/game/maps/entities/player/WalkLeft/Untitled-3_2.png" id="11_kyfvt"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cnnbbvgvnprqv" path="res://gfx/game/maps/entities/player/WalkLeft/Untitled-3_3.png" id="12_isd5t"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://by38ifhhoq0iv" path="res://gfx/game/maps/entities/player/WalkRight/Untitled-3_1.png" id="13_it0yr"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cooxpasywe0a6" path="res://gfx/game/maps/entities/player/WalkRight/Untitled-3_2.png" id="14_mw6f8"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://byqc5gd0r2ija" path="res://gfx/game/maps/entities/player/WalkRight/Untitled-3_3.png" id="15_55gq8"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://vu0jihe8b75u" path="res://gfx/game/maps/entities/player/WalkUp/Untitled-2_1.png" id="16_c8g65"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cpw3bdg07t8s7" path="res://gfx/game/maps/entities/player/WalkUp/Untitled-2_2.png" id="17_8tifw"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b2068kd1mmpsh" path="res://gfx/game/maps/entities/player/WalkUp/Untitled-2_3.png" id="18_jpsqg"]
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_vu83q"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("2_vclwd")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Idle Down",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("3_muq5y")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Idle Left",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("4_mqjq0")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Idle Right",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("5_sh7wu")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Idle Up",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("6_7u5it")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("7_ii2o2")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("8_cndau")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("9_l7rxc")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Walk Down",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("3_muq5y")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("10_nr0px")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("11_kyfvt")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("12_isd5t")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Walk Left",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("4_mqjq0")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("13_it0yr")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("14_mw6f8")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("15_55gq8")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Walk Right",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("5_sh7wu")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("16_c8g65")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("17_8tifw")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("18_jpsqg")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Walk Up",
|
||||||
|
"speed": 5.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[node name="Guard" instance=ExtResource("1_nvsti")]
|
||||||
|
health = 120
|
||||||
|
|
||||||
|
[node name="AnimatedSprite2D" parent="." index="0"]
|
||||||
|
modulate = Color(0.591513, 0.809975, 1, 1)
|
||||||
|
sprite_frames = SubResource("SpriteFrames_vu83q")
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=21 format=3 uid="uid://d3e5mg0gk8u7r"]
|
[gd_scene load_steps=22 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="Script" uid="uid://bo0had2vq4r7h" path="res://scripts/game/maps/entities/mob.gd" id="1_mu6cs"]
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
[ext_resource type="Texture2D" uid="uid://b2068kd1mmpsh" path="res://gfx/game/maps/entities/player/WalkUp/Untitled-2_3.png" id="17_7e337"]
|
[ext_resource type="Texture2D" uid="uid://b2068kd1mmpsh" path="res://gfx/game/maps/entities/player/WalkUp/Untitled-2_3.png" id="17_7e337"]
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id="SpriteFrames_5m0ve"]
|
[sub_resource type="SpriteFrames" id="SpriteFrames_5m0ve"]
|
||||||
|
resource_local_to_scene = true
|
||||||
animations = [{
|
animations = [{
|
||||||
"frames": [{
|
"frames": [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
|
|
@ -125,6 +126,9 @@ animations = [{
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mu6cs"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mu6cs"]
|
||||||
size = Vector2(4, 4)
|
size = Vector2(4, 4)
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_tvinw"]
|
||||||
|
size = Vector2(16, 16)
|
||||||
|
|
||||||
[node name="Mob" type="Node2D" node_paths=PackedStringArray("animator", "collisionRay_1", "collisionRay_2")]
|
[node name="Mob" type="Node2D" node_paths=PackedStringArray("animator", "collisionRay_1", "collisionRay_2")]
|
||||||
script = ExtResource("1_mu6cs")
|
script = ExtResource("1_mu6cs")
|
||||||
animator = NodePath("AnimatedSprite2D")
|
animator = NodePath("AnimatedSprite2D")
|
||||||
|
|
@ -134,20 +138,29 @@ collisionRay_2 = NodePath("CollisionRayCast_2")
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
position = Vector2(8, 8)
|
position = Vector2(8, 8)
|
||||||
sprite_frames = SubResource("SpriteFrames_5m0ve")
|
sprite_frames = SubResource("SpriteFrames_5m0ve")
|
||||||
animation = &"Walk Up"
|
animation = &"Idle Down"
|
||||||
frame = 3
|
|
||||||
frame_progress = 0.497982
|
|
||||||
|
|
||||||
[node name="CollisionRayCast_1" type="RayCast2D" parent="."]
|
[node name="CollisionRayCast_1" type="RayCast2D" parent="."]
|
||||||
position = Vector2(8, 8)
|
position = Vector2(8, 8)
|
||||||
target_position = Vector2(0, 16)
|
target_position = Vector2(0, 16)
|
||||||
|
collision_mask = 5
|
||||||
|
|
||||||
[node name="CollisionRayCast_2" type="RayCast2D" parent="."]
|
[node name="CollisionRayCast_2" type="RayCast2D" parent="."]
|
||||||
position = Vector2(8, 8)
|
position = Vector2(8, 8)
|
||||||
target_position = Vector2(0, 16)
|
target_position = Vector2(0, 16)
|
||||||
|
collision_mask = 5
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="."]
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||||
position = Vector2(8, 8)
|
position = Vector2(8, 8)
|
||||||
shape = SubResource("RectangleShape2D_mu6cs")
|
shape = SubResource("RectangleShape2D_mu6cs")
|
||||||
|
|
||||||
|
[node name="RigidBody2D" type="RigidBody2D" parent="."]
|
||||||
|
collision_layer = 6
|
||||||
|
collision_mask = 6
|
||||||
|
freeze = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
|
||||||
|
position = Vector2(8, 8)
|
||||||
|
shape = SubResource("RectangleShape2D_tvinw")
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,8 +1,9 @@
|
||||||
[gd_scene load_steps=4 format=3 uid="uid://cspwqlbaoldqe"]
|
[gd_scene load_steps=5 format=3 uid="uid://cspwqlbaoldqe"]
|
||||||
|
|
||||||
[ext_resource type="TileSet" uid="uid://c21smbsro4gdq" path="res://tilesets/default.tres" id="1_wjcuv"]
|
[ext_resource type="TileSet" uid="uid://c21smbsro4gdq" path="res://tilesets/default.tres" id="1_wjcuv"]
|
||||||
[ext_resource type="Script" uid="uid://bbrwrbwsxt32g" path="res://scripts/game/maps/WorldMap.gd" id="2_yhw3p"]
|
[ext_resource type="Script" uid="uid://bbrwrbwsxt32g" path="res://scripts/game/maps/WorldMap.gd" id="2_yhw3p"]
|
||||||
[ext_resource type="PackedScene" uid="uid://jdrco447avx6" path="res://scenes/game/maps/entities/change_map_trigger.tscn" id="3_1qy6k"]
|
[ext_resource type="PackedScene" uid="uid://jdrco447avx6" path="res://scenes/game/maps/entities/change_map_trigger.tscn" id="3_1qy6k"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://d3e5mg0gk8u7r" path="res://scenes/game/maps/entities/mob.tscn" id="4_suym0"]
|
||||||
|
|
||||||
[node name="World Map" type="TileMap"]
|
[node name="World Map" type="TileMap"]
|
||||||
tile_set = ExtResource("1_wjcuv")
|
tile_set = ExtResource("1_wjcuv")
|
||||||
|
|
@ -18,3 +19,6 @@ stepIncrement = 0.5
|
||||||
position = Vector2(592, 240)
|
position = Vector2(592, 240)
|
||||||
map = "uid://dq38dmxq6tmtb"
|
map = "uid://dq38dmxq6tmtb"
|
||||||
spawnpoint = Vector2i(0, 15)
|
spawnpoint = Vector2i(0, 15)
|
||||||
|
|
||||||
|
[node name="Mob" parent="Entities" instance=ExtResource("4_suym0")]
|
||||||
|
position = Vector2(576, 208)
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,20 @@ extends Map2d
|
||||||
|
|
||||||
class_name WorldMap
|
class_name WorldMap
|
||||||
|
|
||||||
func playerCanMoveTo(position:Vector2) -> bool:
|
func playerCanMoveTo(newPosition:Vector2) -> bool:
|
||||||
var tilesize = tile_set.tile_size.x
|
|
||||||
var cast_cell_1
|
var cast_cell_1
|
||||||
var cast_cell_2
|
var cast_cell_2
|
||||||
|
|
||||||
player.updateRaycasts(position)
|
player.updateRaycasts(newPosition)
|
||||||
|
|
||||||
cast_cell_1 = local_to_map(position + player.collisionRay_1.position)
|
cast_cell_1 = local_to_map(newPosition + player.collisionRay_1.position)
|
||||||
cast_cell_2 = local_to_map(position + player.collisionRay_2.position)
|
cast_cell_2 = local_to_map(newPosition + player.collisionRay_2.position)
|
||||||
|
|
||||||
if (getTerrainDataForTile(0, TerrainDataTypes.TerrainType, cast_cell_1.x, cast_cell_1.y) != "Water" and
|
if (getTerrainDataForTile(0, TerrainDataTypes.TerrainType, cast_cell_1.x, cast_cell_1.y) != "Water" and
|
||||||
getTerrainDataForTile(0, TerrainDataTypes.TerrainType, cast_cell_2.x, cast_cell_2.y) != "Water"):
|
getTerrainDataForTile(0, TerrainDataTypes.TerrainType, cast_cell_2.x, cast_cell_2.y) != "Water"):
|
||||||
|
|
||||||
|
if (player.wouldCollideAt(newPosition)):
|
||||||
|
return false
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
CommandDispatcher.DISPLAY_MESSAGE.emit("Your path is blocked.")
|
CommandDispatcher.DISPLAY_MESSAGE.emit("Your path is blocked.")
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,11 @@ extends Mob
|
||||||
class_name Player
|
class_name Player
|
||||||
|
|
||||||
@export var camera:Camera2D
|
@export var camera:Camera2D
|
||||||
|
|
||||||
|
|
||||||
|
func wouldCollideAt(destination):
|
||||||
|
if (super.wouldCollideAt(destination)):
|
||||||
|
#CommandDispatcher.DISPLAY_MESSAGE.emit("Your path is blocked.")
|
||||||
|
return true
|
||||||
|
else:
|
||||||
|
return false
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ extends Node2D
|
||||||
|
|
||||||
class_name Mob
|
class_name Mob
|
||||||
|
|
||||||
|
@export var health:int = 100
|
||||||
|
|
||||||
@export var animator:AnimatedSprite2D
|
@export var animator:AnimatedSprite2D
|
||||||
|
|
||||||
@export var collisionRay_1:RayCast2D
|
@export var collisionRay_1:RayCast2D
|
||||||
|
|
@ -77,6 +79,4 @@ func wouldCollideAt(destination):
|
||||||
updateRaycasts(destination)
|
updateRaycasts(destination)
|
||||||
|
|
||||||
if collisionRay_1.is_colliding() || collisionRay_2.is_colliding():
|
if collisionRay_1.is_colliding() || collisionRay_2.is_colliding():
|
||||||
CommandDispatcher.DISPLAY_MESSAGE.emit("Your path is blocked.")
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue