Skip to content

Commit 583b8ac

Browse files
committed
boxes_on_platfor_count
1 parent 7e2623e commit 583b8ac

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

Code/GameManager.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ func _initialize_platforms():
1717
"platform": platform,
1818
"occupied": false
1919
})
20+
21+
func get_occupied_platforms_count():
22+
var occupied_count = 0
23+
for platform_dict in all_platforms:
24+
if platform_dict["occupied"] == true:
25+
occupied_count += 1
26+
return occupied_count
2027

2128
func _initialize_boxes():
2229
# Ensure boxes are initialized after they are added to the scene

Code/characters/player_robot.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var result_received = false
2323

2424
func _ready():
2525
targetPos = self.position
26+
var root_node = get_tree().root
27+
print(root_node.name)
2628
var file = FileAccess.open("res://commands.txt", FileAccess.READ)
2729
if file:
2830
while !file.eof_reached():
@@ -62,6 +64,8 @@ func _process(_delta):
6264
_on_check_if_can_move()
6365
'platform_count':
6466
_on_get_platforms_count()
67+
'bop':
68+
_on_get_boxes_on_platfor_count()
6569
animation_tree.set("parameters/Walk/blend_position", facing)
6670
else:
6771
state_machine.travel("End") # Idle state if no commands are left
@@ -148,3 +152,9 @@ func _on_get_platforms_count():
148152
print("Number of platforms: ", platform_count)
149153
return platform_count
150154

155+
func _on_get_boxes_on_platfor_count():
156+
var gm = get_tree().get_nodes_in_group("game_manager")[0]
157+
var occupied_platforms = gm.get_occupied_platforms_count()
158+
print("Number of boxes on platfroms: ", occupied_platforms)
159+
return occupied_platforms
160+

Code/commands.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
platform_count
2+
bop
23
l
34
l
45
l
@@ -16,3 +17,4 @@ p
1617
cm
1718
d
1819
p
20+
bop

Code/levels/level_0.tscn

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,20 @@ position = Vector2(56, 72)
359359
collision_layer = 15
360360
collision_mask = 15
361361

362+
[node name="Box2" parent="." instance=ExtResource("6_crsa5")]
363+
position = Vector2(104, 103)
364+
collision_layer = 15
365+
collision_mask = 15
366+
362367
[node name="EndZone" parent="." groups=["platforms"] instance=ExtResource("7_xxre3")]
363368
z_index = 0
364369
position = Vector2(56, 104)
365370

366-
[node name="GameManager" parent="." instance=ExtResource("8_nfk0q")]
371+
[node name="EndZone2" parent="." groups=["platforms"] instance=ExtResource("7_xxre3")]
372+
z_index = 0
373+
position = Vector2(120, 135)
374+
375+
[node name="GameManager" parent="." groups=["game_manager"] instance=ExtResource("8_nfk0q")]
367376

368377
[node name="InteractionManager" parent="." groups=["interaction_manager"] instance=ExtResource("9_h8w3f")]
369378
position = Vector2(60, 63)

Code/levels/level_1.tscn

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=13 format=3 uid="uid://ds60hc12tavm3"]
1+
[gd_scene load_steps=14 format=3 uid="uid://ds60hc12tavm3"]
22

33
[ext_resource type="Texture2D" uid="uid://os7624ctmhq3" path="res://art/robot_atlas.png" id="1_mkdx5"]
44
[ext_resource type="Texture2D" uid="uid://dwsmec5b5rj0y" path="res://art/tiles/water.png" id="2_vwt3w"]
@@ -8,6 +8,7 @@
88
[ext_resource type="PackedScene" uid="uid://vb8lfikq5dc7" path="res://box.tscn" id="6_jjywg"]
99
[ext_resource type="PackedScene" uid="uid://deb7q6h0om8hc" path="res://End.tscn" id="7_you6s"]
1010
[ext_resource type="PackedScene" uid="uid://c7m1f03wf08sa" path="res://interaction/InteractionManager.tscn" id="8_5uy7b"]
11+
[ext_resource type="PackedScene" uid="uid://5q5c8pt7mew2" path="res://GameManager.tscn" id="9_0kenn"]
1112

1213
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_0ydj6"]
1314
texture = ExtResource("1_mkdx5")
@@ -331,7 +332,7 @@ sources/0 = SubResource("TileSetAtlasSource_0ydj6")
331332
sources/2 = SubResource("TileSetAtlasSource_y6uth")
332333
sources/5 = SubResource("TileSetAtlasSource_p6k03")
333334

334-
[node name="level_1" type="Node2D"]
335+
[node name="level_1" type="Node2D" groups=["level"]]
335336

336337
[node name="TileMap" type="TileMap" parent="."]
337338
tile_set = SubResource("TileSet_leduy")
@@ -367,3 +368,5 @@ z_index = 1
367368
position = Vector2(72, 88)
368369

369370
[node name="InteractionManager" parent="." groups=["interaction_manager"] instance=ExtResource("8_5uy7b")]
371+
372+
[node name="GameManager" parent="." groups=["game_manager"] instance=ExtResource("9_0kenn")]

0 commit comments

Comments
 (0)