Skip to content

Commit

Permalink
pieces now spawn one at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
rosskarchner committed Aug 14, 2024
1 parent 836cebb commit 552d30d
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 50 deletions.
26 changes: 26 additions & 0 deletions scenes/GameScene/game.gd
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()

58 changes: 11 additions & 47 deletions scenes/GameScene/game.tscn
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="."]
12 changes: 9 additions & 3 deletions scenes/GameScene/segment.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
@tool
extends Node2D
class_name Segment

var draggable = false
signal dropped

var draggable = true
var is_inside_dropable = false
var offset: Vector2
var dragStartPosition: Vector2
Expand Down Expand Up @@ -87,16 +90,19 @@ func _on_click_area_mouse_exited() -> void:
func _on_click_area_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if Engine.is_editor_hint():
return
if event.is_action_pressed("click"):
if event.is_action_pressed("click") and draggable:
dragging = true
offset = get_global_mouse_position() - global_position
dragStartPosition =global_position
Dragging.is_dragging = true
elif event.is_action_released("click"):
elif event.is_action_released("click") and draggable:
dragging = false
Dragging.is_dragging = false
if drop_target:
drop_target.monitorable = false
global_position = drop_target.global_position
dropped.emit()
$ClickArea.queue_free()
drop_target = null
else:
global_position = dragStartPosition
Expand Down
55 changes: 55 additions & 0 deletions scenes/Levels/level_1.tscn
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)])
23 changes: 23 additions & 0 deletions scenes/gamepiece_spawner.gd
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)

0 comments on commit 552d30d

Please sign in to comment.