generated from Maaack/Godot-Game-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
836cebb
commit 552d30d
Showing
5 changed files
with
124 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
extends Node2D | ||
|
||
@export var levels:Array[PackedScene] | ||
|
||
var current_level = 0 | ||
var current_level_instance = null | ||
|
||
@onready var piece_spawner = $GamepieceSpawner | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready() -> void: | ||
load_current_level() | ||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
func _process(delta: float) -> void: | ||
pass | ||
|
||
|
||
func load_current_level(): | ||
if not current_level_instance: | ||
current_level_instance = levels[current_level].instantiate() | ||
add_child(current_level_instance) | ||
piece_spawner.add_segments_to_queue(current_level_instance.get_node("PossibleSolution").get_children()) | ||
piece_spawner.reveal_next_piece() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,17 @@ | ||
[gd_scene load_steps=7 format=4 uid="uid://drwnwutwrrpb0"] | ||
[gd_scene load_steps=4 format=3 uid="uid://drwnwutwrrpb0"] | ||
|
||
[ext_resource type="PackedScene" uid="uid://cy1uuyuh3e44f" path="res://scenes/GameScene/load.tscn" id="2_6vgst"] | ||
[ext_resource type="PackedScene" uid="uid://73fcyu51g72" path="res://scenes/power_source.tscn" id="2_efwgb"] | ||
[ext_resource type="PackedScene" uid="uid://cfrdeamt1c5dy" path="res://scenes/GameScene/segment.tscn" id="4_cmlyv"] | ||
[ext_resource type="PackedScene" uid="uid://cp11itxbkl8u2" path="res://scenes/drop_area.tscn" id="6_dvwn4"] | ||
|
||
[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_0044b"] | ||
resource_name = "Map" | ||
scenes/1/scene = ExtResource("6_dvwn4") | ||
scenes/2/scene = ExtResource("2_efwgb") | ||
scenes/3/scene = ExtResource("2_6vgst") | ||
|
||
[sub_resource type="TileSet" id="TileSet_28ise"] | ||
tile_shape = 3 | ||
tile_size = Vector2i(94, 94) | ||
sources/0 = SubResource("TileSetScenesCollectionSource_0044b") | ||
[ext_resource type="PackedScene" uid="uid://j34kskfwf7ku" path="res://scenes/Levels/level_1.tscn" id="1_cw4a4"] | ||
[ext_resource type="Script" path="res://scenes/GameScene/game.gd" id="1_y3mbf"] | ||
[ext_resource type="Script" path="res://scenes/gamepiece_spawner.gd" id="3_8wmyh"] | ||
|
||
[node name="Game" type="Node2D"] | ||
position = Vector2(254, 124) | ||
script = ExtResource("1_y3mbf") | ||
levels = Array[PackedScene]([ExtResource("1_cw4a4")]) | ||
|
||
[node name="TileMapLayerHex" type="TileMapLayer" parent="."] | ||
position = Vector2(-26, -18) | ||
tile_map_data = PackedByteArray("AAD//wMAAAAAAAAAAQAAAAMAAAAAAAAAAQAAAAIAAAAAAAAAAQD//wIAAAAAAAAAAQD//wEAAAAAAAAAAQD+/wEAAAAAAAAAAQD+/wIAAAAAAAAAAgABAAIAAAAAAAAAAwD+/wMAAAAAAAAAAQD//wQAAAAAAAAAAQAAAAQAAAAAAAAAAQABAAQAAAAAAAAAAQABAAMAAAAAAAAAAQAAAAEAAAAAAAAAAQA=") | ||
tile_set = SubResource("TileSet_28ise") | ||
|
||
[node name="Segment" parent="." instance=ExtResource("4_cmlyv")] | ||
position = Vector2(-133, -53) | ||
connection_pairs = Array[Vector2i]([Vector2i(2, -2)]) | ||
|
||
[node name="Segment2" parent="." instance=ExtResource("4_cmlyv")] | ||
position = Vector2(-82, 20) | ||
connection_pairs = Array[Vector2i]([Vector2i(5, 2)]) | ||
|
||
[node name="Segment3" parent="." instance=ExtResource("4_cmlyv")] | ||
position = Vector2(63, -54) | ||
connection_pairs = Array[Vector2i]([Vector2i(5, 3)]) | ||
|
||
[node name="Segment4" parent="." instance=ExtResource("4_cmlyv")] | ||
position = Vector2(-179, 27) | ||
connection_pairs = Array[Vector2i]([Vector2i(0, 1)]) | ||
|
||
[node name="Segment5" parent="." instance=ExtResource("4_cmlyv")] | ||
position = Vector2(114, 20) | ||
connection_pairs = Array[Vector2i]([Vector2i(4, 2)]) | ||
|
||
[node name="Segment6" parent="." instance=ExtResource("4_cmlyv")] | ||
position = Vector2(-34, -55) | ||
connection_pairs = Array[Vector2i]([Vector2i(5, 3)]) | ||
[node name="GamepieceSpawner" type="Node2D" parent="."] | ||
top_level = true | ||
position = Vector2(54, 30) | ||
script = ExtResource("3_8wmyh") | ||
|
||
[node name="Segment7" parent="." instance=ExtResource("4_cmlyv")] | ||
position = Vector2(17, 19) | ||
connection_pairs = Array[Vector2i]([Vector2i(1, 0)]) | ||
[node name="LevelContainer" type="Node2D" parent="."] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
[gd_scene load_steps=7 format=4 uid="uid://j34kskfwf7ku"] | ||
|
||
[ext_resource type="PackedScene" uid="uid://cp11itxbkl8u2" path="res://scenes/drop_area.tscn" id="1_g2nlb"] | ||
[ext_resource type="PackedScene" uid="uid://73fcyu51g72" path="res://scenes/power_source.tscn" id="2_spqev"] | ||
[ext_resource type="PackedScene" uid="uid://cy1uuyuh3e44f" path="res://scenes/GameScene/load.tscn" id="3_gak4n"] | ||
[ext_resource type="PackedScene" uid="uid://cfrdeamt1c5dy" path="res://scenes/GameScene/segment.tscn" id="4_c6ir0"] | ||
|
||
[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_ie45y"] | ||
resource_name = "Map" | ||
scenes/1/scene = ExtResource("1_g2nlb") | ||
scenes/2/scene = ExtResource("2_spqev") | ||
scenes/3/scene = ExtResource("3_gak4n") | ||
|
||
[sub_resource type="TileSet" id="TileSet_f5i1a"] | ||
tile_shape = 3 | ||
tile_size = Vector2i(94, 94) | ||
sources/0 = SubResource("TileSetScenesCollectionSource_ie45y") | ||
|
||
[node name="Level1" type="Node2D"] | ||
|
||
[node name="Tiles" type="TileMapLayer" parent="."] | ||
position = Vector2(-26, -18) | ||
tile_map_data = PackedByteArray("AAD//wMAAAAAAAAAAQAAAAMAAAAAAAAAAQAAAAIAAAAAAAAAAQD//wIAAAAAAAAAAQD//wEAAAAAAAAAAQD+/wEAAAAAAAAAAQD+/wIAAAAAAAAAAgABAAIAAAAAAAAAAwD+/wMAAAAAAAAAAQD//wQAAAAAAAAAAQAAAAQAAAAAAAAAAQABAAQAAAAAAAAAAQABAAMAAAAAAAAAAQAAAAEAAAAAAAAAAQA=") | ||
tile_set = SubResource("TileSet_f5i1a") | ||
|
||
[node name="PossibleSolution" type="Node2D" parent="."] | ||
visible = false | ||
|
||
[node name="Segment" parent="PossibleSolution" instance=ExtResource("4_c6ir0")] | ||
position = Vector2(-133, -53) | ||
connection_pairs = Array[Vector2i]([Vector2i(2, -2)]) | ||
|
||
[node name="Segment2" parent="PossibleSolution" instance=ExtResource("4_c6ir0")] | ||
position = Vector2(-82, 20) | ||
connection_pairs = Array[Vector2i]([Vector2i(5, 2)]) | ||
|
||
[node name="Segment3" parent="PossibleSolution" instance=ExtResource("4_c6ir0")] | ||
position = Vector2(63, -54) | ||
connection_pairs = Array[Vector2i]([Vector2i(5, 3)]) | ||
|
||
[node name="Segment4" parent="PossibleSolution" instance=ExtResource("4_c6ir0")] | ||
position = Vector2(-179, 27) | ||
connection_pairs = Array[Vector2i]([Vector2i(0, 1)]) | ||
|
||
[node name="Segment5" parent="PossibleSolution" instance=ExtResource("4_c6ir0")] | ||
position = Vector2(114, 20) | ||
connection_pairs = Array[Vector2i]([Vector2i(4, 2)]) | ||
|
||
[node name="Segment6" parent="PossibleSolution" instance=ExtResource("4_c6ir0")] | ||
position = Vector2(-34, -55) | ||
connection_pairs = Array[Vector2i]([Vector2i(5, 3)]) | ||
|
||
[node name="Segment7" parent="PossibleSolution" instance=ExtResource("4_c6ir0")] | ||
position = Vector2(17, 19) | ||
connection_pairs = Array[Vector2i]([Vector2i(1, 0)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
extends Node2D | ||
class_name GamepieceSpawner | ||
|
||
|
||
@onready var queue = Node2D.new() | ||
|
||
|
||
func _ready() -> void: | ||
queue.hide() | ||
add_child(queue) | ||
|
||
|
||
func add_segments_to_queue(pieces:Array[Node]) -> void: | ||
pieces.shuffle() | ||
for piece in pieces: | ||
piece.position=Vector2.ZERO | ||
piece.dropped.connect(reveal_next_piece) | ||
piece.reparent(queue) | ||
|
||
func reveal_next_piece() -> void: | ||
var next_piece = queue.get_child(0) | ||
if next_piece: | ||
next_piece.reparent(self) |