Skip to content

Commit 4527106

Browse files
committed
Basic functional pong game
Added scoring, and resetting the ball on score. Added a block for "Set Physics Position" which queries physics server, since "Set Position" does not work on RigidBody2D. Fixed small bug in StatementBlock where TYPE_NIL is technically equivalent to false, so it was being considered null.
1 parent 850d0ab commit 4527106

File tree

5 files changed

+778
-110
lines changed

5 files changed

+778
-110
lines changed

addons/block_code/ui/blocks/statement_block/statement_block.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static func format_string(parent_block: Block, attach_to: Node, string: String,
116116
var param_input: ParameterInput = preload("res://addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn").instantiate()
117117
param_input.name = "ParameterInput%d" % start # Unique path
118118
param_input.placeholder = param_name
119-
if param_type:
119+
if param_type != null:
120120
param_input.variant_type = param_type
121121
elif option:
122122
param_input.option = true

addons/block_code/ui/picker/categories/category_factory.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ static func get_built_in_categories(_class_name: String) -> Array[BlockCategory]
363363
b.signal_name = "body_%s" % [verb]
364364
block_list.append(b)
365365

366+
var b = BLOCKS["statement_block"].instantiate()
367+
b.block_format = "Set Physics Position {position: VECTOR2}"
368+
b.statement = "PhysicsServer2D.body_set_state(get_rid(),PhysicsServer2D.BODY_STATE_TRANSFORM,Transform2D.IDENTITY.translated({position}))"
369+
block_list.append(b)
370+
366371
props = ["mass", "linear_velocity", "angular_velocity"]
367372

368373
"Area2D":

pong_game/goal_area.tscn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[gd_scene load_steps=2 format=3 uid="uid://vc7u0ljq02eh"]
1+
[gd_scene load_steps=2 format=3 uid="uid://fhoapg3anjsu"]
22

33
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8q7gx"]
44
size = Vector2(128, 1080)
55

66
[node name="GoalArea" type="Area2D"]
7+
collision_mask = 3
78

89
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
910
shape = SubResource("RectangleShape2D_8q7gx")

pong_game/pong_game.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ static func get_custom_blocks() -> Array[BlockCategory]:
1414
var score_list: Array[Block] = []
1515
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
1616
b.block_type = Types.BlockType.EXECUTE
17-
b.block_format = "Change player 1 score by {score: INT}"
17+
b.block_format = "Set player 1 score to {score: INT}"
1818
b.statement = 'get_tree().call_group("hud", "set_player_score", "right", {score})'
1919
score_list.append(b)
2020

2121
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
2222
b.block_type = Types.BlockType.EXECUTE
23-
b.block_format = "Change player 2 score by {score: INT}"
23+
b.block_format = "Set player 2 score to {score: INT}"
2424
b.statement = 'get_tree().call_group("hud", "set_player_score", "left", {score})'
2525
score_list.append(b)
2626

0 commit comments

Comments
 (0)