Add functionality to move to next level via door

This commit is contained in:
James Skemp 2023-11-27 18:03:13 -06:00
parent d95a50dc2b
commit fbd8a20f18
6 changed files with 93 additions and 61 deletions

View File

@ -7,35 +7,6 @@
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kpuwb"]
size = Vector2(25, 19)
[sub_resource type="Animation" id="Animation_eh8sk"]
resource_name = "walk"
length = 0.6
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:texture")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("2_fx066")]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:frame")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [0, 5]
}
[sub_resource type="Animation" id="Animation_odm27"]
length = 0.001
tracks/0/type = "value"
@ -92,6 +63,35 @@ tracks/1/keys = {
"values": [0, 5]
}
[sub_resource type="Animation" id="Animation_eh8sk"]
resource_name = "walk"
length = 0.6
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:texture")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("2_fx066")]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:frame")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [0, 5]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_i8afe"]
_data = {
"RESET": SubResource("Animation_odm27"),

View File

@ -16,3 +16,5 @@ func next_level():
current_level += 1
if current_level <= num_levels:
get_tree().change_scene_to_file(game_scene)
else:
get_tree().change_scene_to_file(title_screen)

19
items/door.tscn Normal file
View File

@ -0,0 +1,19 @@
[gd_scene load_steps=3 format=3 uid="uid://cq0stxc6m8gly"]
[ext_resource type="Texture2D" uid="uid://vvobipbxsvhd" path="res://assets/environment/props.png" id="1_uowq2"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_x47sx"]
[node name="Door" type="Area2D"]
collision_layer = 8
collision_mask = 2
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_uowq2")
offset = Vector2(0, -8)
region_enabled = true
region_rect = Rect2(13, 62, 24, 37)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(-1, -5)
shape = SubResource("RectangleShape2D_x47sx")

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@ extends Node2D
signal score_changed(score: int)
var door_scene = load("res://items/door.tscn")
var item_scene = load("res://items/item.tscn")
var score: int = 0:
set = set_score
@ -26,10 +27,16 @@ func spawn_items():
for cell in item_cells:
var data = $Items.get_cell_tile_data(0, cell)
var type = data.get_custom_data("type")
var item = item_scene.instantiate()
add_child(item)
item.init(type, $Items.map_to_local(cell))
item.picked_up.connect(self._on_item_picked_up)
if type == "door":
var door = door_scene.instantiate()
add_child(door)
door.position = $Items.map_to_local(cell)
door.body_entered.connect(_on_door_entered)
else:
var item = item_scene.instantiate()
add_child(item)
item.init(type, $Items.map_to_local(cell))
item.picked_up.connect(self._on_item_picked_up)
func _on_item_picked_up():
@ -43,3 +50,7 @@ func set_score(value: int):
func _on_player_died():
GameState.restart()
func _on_door_entered(body):
GameState.next_level()

View File

@ -5,33 +5,6 @@
[ext_resource type="Texture2D" uid="uid://d0rqiaxuha1p6" path="res://assets/environment/middle.png" id="2_tfyow"]
[ext_resource type="FontFile" uid="uid://cxp0s6ifyv2ue" path="res://assets/Kenney Thick.ttf" id="3_glnlm"]
[sub_resource type="Animation" id="Animation_ytxpk"]
resource_name = "intro"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Title:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(216, -200), Vector2(216, 282)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Message:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0.6),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
[sub_resource type="Animation" id="Animation_0aske"]
length = 0.001
tracks/0/type = "value"
@ -59,6 +32,33 @@ tracks/1/keys = {
"values": [true]
}
[sub_resource type="Animation" id="Animation_ytxpk"]
resource_name = "intro"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Title:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(216, -200), Vector2(216, 282)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Message:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0.6),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_7l1v6"]
_data = {
"RESET": SubResource("Animation_0aske"),