Skip to content

Commit

Permalink
Fix last issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SaturnHafen committed Feb 1, 2024
1 parent 632b4da commit c068faa
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 33 deletions.
4 changes: 2 additions & 2 deletions prototypes/game-robot-programming/code0.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ func get_code():
func get_stmts():
var areas = self.get_parent().get_overlapping_areas()

areas.sort_custom(func (a: Area2D, b: Area2D): return a.position.y < b.position.y)
areas.sort_custom(func (a: Area2D, b: Area2D): return a.global_position.y < b.global_position.y)

areas = areas.filter(func(x: Area2D): return x.position.y > self.get_parent().position.y)
areas = areas.filter(func(x: Area2D): return x.global_position.y > self.get_parent().global_position.y)

return areas

Expand Down
4 changes: 2 additions & 2 deletions prototypes/game-robot-programming/code10.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ func get_code():
func get_stmts():
var areas = self.get_parent().get_overlapping_areas()

areas.sort_custom(func (a: Area2D, b: Area2D): return a.position.y < b.position.y)
areas = areas.filter(func(x: Area2D): return x.position.y > self.get_parent().position.y)
areas.sort_custom(func (a: Area2D, b: Area2D): return a.global_position.y < b.global_position.y)
areas = areas.filter(func(x: Area2D): return x.global_position.y > self.get_parent().global_position.y)

return areas

Expand Down
4 changes: 2 additions & 2 deletions prototypes/game-robot-programming/code2.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ func get_code():
func get_stmts():
var areas = self.get_parent().get_overlapping_areas()

areas.sort_custom(func (a: Area2D, b: Area2D): return a.position.y < b.position.y)
areas.sort_custom(func (a: Area2D, b: Area2D): return a.global_position.y < b.global_position.y)

areas = areas.filter(func(x: Area2D): return x.position.y > self.get_parent().position.y)
areas = areas.filter(func(x: Area2D): return x.global_position.y > self.get_parent().global_position.y)

return areas

Expand Down
4 changes: 2 additions & 2 deletions prototypes/game-robot-programming/code4.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ func get_code():
func get_stmts():
var areas = self.get_parent().get_overlapping_areas()

areas.sort_custom(func (a: Area2D, b: Area2D): return a.position.y < b.position.y)
areas.sort_custom(func (a: Area2D, b: Area2D): return a.global_position.y < b.global_position.y)

areas = areas.filter(func(x: Area2D): return x.position.y > self.get_parent().position.y)
areas = areas.filter(func(x: Area2D): return x.global_position.y > self.get_parent().global_position.y)

return areas

Expand Down
45 changes: 23 additions & 22 deletions prototypes/game-robot-programming/game-robot-programming.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ expression = SubResource("Resource_vtyea")
deferred = false
enabled = true
[sub_resource type="RectangleShape2D" id="RectangleShape2D_7imq0"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_y274l"]
resource_local_to_scene = true
size = Vector2(200, 500)
Expand Down Expand Up @@ -636,6 +636,7 @@ rotation = 3.14159
scale = Vector2(0.6, 0.6)
collision_mask = 0
script = ExtResource("3_oymdl")
orientation = 2
[node name="HP" type="Node2D" parent="Enemy"]
position = Vector2(0, -48)
Expand Down Expand Up @@ -1212,24 +1213,24 @@ text = "Reset
metadata/pronto_connections = [SubResource("Resource_rqgae")]
[node name="enemy-code-code" type="Node2D" parent="."]
position = Vector2(2200, 20)
position = Vector2(2200, 200)
[node name="Area2D3" type="Area2D" parent="enemy-code-code"]
[node name="Area2D2" type="Area2D" parent="enemy-code-code"]
script = ExtResource("2_n7j77")
[node name="Polygon2D" type="Polygon2D" parent="enemy-code-code/Area2D3"]
[node name="Polygon2D" type="Polygon2D" parent="enemy-code-code/Area2D2"]
color = Color(0.47451, 0.52549, 0.882353, 1)
polygon = PackedVector2Array(100, 10, 100, -10, -100, -10, -100, 10)
[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy-code-code/Area2D3"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy-code-code/Area2D2"]
position = Vector2(0, 250)
shape = SubResource("RectangleShape2D_7imq0")
shape = SubResource("RectangleShape2D_y274l")
[node name="Code" type="Node2D" parent="enemy-code-code/Area2D3"]
[node name="Code" type="Node2D" parent="enemy-code-code/Area2D2"]
position = Vector2(-5, -198)
script = ExtResource("7_h438j")
[node name="Button" type="Button" parent="enemy-code-code/Area2D3"]
[node name="Button" type="Button" parent="enemy-code-code/Area2D2"]
offset_left = 82.0
offset_top = -17.0
offset_right = 100.0
Expand All @@ -1239,7 +1240,7 @@ text = "+
script = ExtResource("6_y2un6")
metadata/pronto_connections = [SubResource("Resource_l2spb")]
[node name="Button2" type="Button" parent="enemy-code-code/Area2D3"]
[node name="Button2" type="Button" parent="enemy-code-code/Area2D2"]
offset_left = 65.0
offset_top = -17.0
offset_right = 79.0
Expand All @@ -1248,36 +1249,36 @@ text = "-"
script = ExtResource("7_ulk6s")
metadata/pronto_connections = [SubResource("Resource_asa6e")]
[node name="Label" type="Label" parent="enemy-code-code/Area2D3"]
[node name="Label" type="Label" parent="enemy-code-code/Area2D2"]
offset_left = -53.0
offset_top = -10.0
offset_right = 47.0
offset_bottom = 13.0
text = "Repeat while"
[node name="Area2D2" type="Area2D" parent="enemy-code-code"]
position = Vector2(0, 20)
[node name="Area2D3" type="Area2D" parent="enemy-code-code"]
position = Vector2(10, 20)
script = ExtResource("2_n7j77")
[node name="Polygon2D" type="Polygon2D" parent="enemy-code-code/Area2D2"]
[node name="Polygon2D" type="Polygon2D" parent="enemy-code-code/Area2D3"]
color = Color(1, 0.164706, 0.34902, 1)
polygon = PackedVector2Array(100, 10, 100, -10, -100, -10, -100, 10, 100, 10)
[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy-code-code/Area2D2"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy-code-code/Area2D3"]
shape = SubResource("RectangleShape2D_qq34o")
[node name="Code" type="Node2D" parent="enemy-code-code/Area2D2"]
[node name="Code" type="Node2D" parent="enemy-code-code/Area2D3"]
script = ExtResource("16_w751w")
[node name="Label" type="Label" parent="enemy-code-code/Area2D2"]
[node name="Label" type="Label" parent="enemy-code-code/Area2D3"]
offset_left = -83.0
offset_top = -11.0
offset_right = 94.0
offset_bottom = 12.0
text = "true"
[node name="Area2D4" type="Area2D" parent="enemy-code-code"]
position = Vector2(0, 40)
position = Vector2(10, 40)
script = ExtResource("2_n7j77")
[node name="Polygon2D" type="Polygon2D" parent="enemy-code-code/Area2D4"]
Expand All @@ -1298,7 +1299,7 @@ offset_bottom = 12.0
text = "Drive Forward"
[node name="Area2D5" type="Area2D" parent="enemy-code-code"]
position = Vector2(0, 60)
position = Vector2(10, 60)
script = ExtResource("2_n7j77")
[node name="Polygon2D" type="Polygon2D" parent="enemy-code-code/Area2D5"]
Expand All @@ -1319,7 +1320,7 @@ offset_bottom = 12.0
text = "Fire Laser Left"
[node name="Area2D6" type="Area2D" parent="enemy-code-code"]
position = Vector2(0, 100)
position = Vector2(10, 100)
script = ExtResource("2_n7j77")
[node name="Polygon2D" type="Polygon2D" parent="enemy-code-code/Area2D6"]
Expand Down Expand Up @@ -1359,7 +1360,7 @@ offset_bottom = 12.0
text = "Do if"
[node name="Area2D7" type="Area2D" parent="enemy-code-code"]
position = Vector2(0, 120)
position = Vector2(20, 120)
script = ExtResource("2_n7j77")
[node name="Polygon2D" type="Polygon2D" parent="enemy-code-code/Area2D7"]
Expand All @@ -1380,7 +1381,7 @@ offset_bottom = 12.0
text = "Wall directly ahead"
[node name="Area2D8" type="Area2D" parent="enemy-code-code"]
position = Vector2(0, 140)
position = Vector2(20, 140)
script = ExtResource("2_n7j77")
[node name="Polygon2D" type="Polygon2D" parent="enemy-code-code/Area2D8"]
Expand Down Expand Up @@ -1414,8 +1415,8 @@ text = "Rotate left"
[connection signal="input_event" from="VBoxContainer/EnemyInVision/SpawnerBehavior/Area2D" to="VBoxContainer/EnemyInVision/SpawnerBehavior/Area2D" method="_on_input_event"]
[connection signal="input_event" from="VBoxContainer/Laser/SpawnerBehavior/Area2D" to="VBoxContainer/Laser/SpawnerBehavior/Area2D" method="_on_input_event"]
[connection signal="input_event" from="VBoxContainer/Punch/SpawnerBehavior/Area2D" to="VBoxContainer/Punch/SpawnerBehavior/Area2D" method="_on_input_event"]
[connection signal="input_event" from="enemy-code-code/Area2D3" to="enemy-code-code/Area2D3" method="_on_input_event"]
[connection signal="input_event" from="enemy-code-code/Area2D2" to="enemy-code-code/Area2D2" method="_on_input_event"]
[connection signal="input_event" from="enemy-code-code/Area2D3" to="enemy-code-code/Area2D3" method="_on_input_event"]
[connection signal="input_event" from="enemy-code-code/Area2D4" to="enemy-code-code/Area2D4" method="_on_input_event"]
[connection signal="input_event" from="enemy-code-code/Area2D5" to="enemy-code-code/Area2D5" method="_on_input_event"]
[connection signal="input_event" from="enemy-code-code/Area2D6" to="enemy-code-code/Area2D6" method="_on_input_event"]
Expand Down
12 changes: 9 additions & 3 deletions prototypes/game-robot-programming/run.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends Button
func execute_area(area_to_run: Area2D, robot):
var areas = area_to_run.get_node("Code").get_stmts()
var executed = []
print(robot, area_to_run, areas)

for area in areas:
await area_to_run.get_tree().create_timer(0.2).timeout
Expand Down Expand Up @@ -33,10 +34,12 @@ func execute_area(area_to_run: Area2D, robot):

elif stmt == "rotate-left":
print("rotate left")
executed.append(area)
robot.rotation_degrees -= 90
robot.orientation = (robot.orientation + 1) % 4
elif stmt == "rotate-right":
print("rotate right")
executed.append(area)
robot.rotation_degrees += 90
robot.orientation = ((robot.orientation - 1) + 4) % 4
elif stmt == "while":
Expand All @@ -53,7 +56,6 @@ func execute_area(area_to_run: Area2D, robot):

while condition.get_node("Code").check(robot):
print("Condition passed!")

await execute_area(area, robot)

executed.append_array(area.get_node("Code").get_stmts())
Expand All @@ -68,14 +70,17 @@ func execute_area(area_to_run: Area2D, robot):
if not condition.get_node("Code").is_condition():
print("No conditions inside container")
continue

if condition.get_node("Code").check(robot):
print("if is true")
execute_area(area, robot)

print(executed)
executed.append_array(area.get_node("Code").get_stmts())
print(executed)

elif stmt == "laser":
print("laser")
executed.append(area)

robot.get_node("Laser/LaserShape").visible = true

Expand All @@ -90,6 +95,7 @@ func execute_area(area_to_run: Area2D, robot):

elif stmt == "punch":
print("punch")
executed.append(area)

var bodies = robot.get_node("FrontFree").get_overlapping_bodies()
for body in bodies:
Expand Down
Binary file modified prototypes/game-robot-programming/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c068faa

Please sign in to comment.