Skip to content

Conversation

@wnbaum
Copy link
Contributor

@wnbaum wnbaum commented Jun 19, 2024

I thought it would be fun to take a stab at implementing a very basic version of the pong game to see what other blocks/improvements we would need to implement.

I added scoring, and resetting the ball on score. For resetting the ball, interestingly enough, setting the position of a RigidBody does not work like a normal Node2D, you have to query the physics server. So I added a block for "Set Physics Position", which honestly isn't very clear for a beginner.

One thing I did find in making this is that we should think about making the variables more streamlined. Typing the variable name out every time is annoying without being able to copy blocks, and we should have a block for "Change variable by", so I don't have to use the "get variable" block every time.

I also found a small bug in StatementBlock where TYPE_NIL is technically equivalent to false, so it was being considered null.

@wnbaum wnbaum requested a review from manuq June 19, 2024 23:03
Copy link
Contributor

@manuq manuq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did Pong! So cool! I left a comment about the implementation but we can iterate after merging. Feel free to merge, my only request is to explain the changes in the commit message body.

param_input.name = "ParameterInput%d" % start # Unique path
param_input.placeholder = param_name
if param_type:
if param_type != null:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


var b = BLOCKS["statement_block"].instantiate()
b.block_format = "Set Physics Position {position: VECTOR2}"
b.statement = "PhysicsServer2D.body_set_state(get_rid(),PhysicsServer2D.BODY_STATE_TRANSFORM,Transform2D.IDENTITY.translated({position}))"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this is not needed in Moddable Pong.

I think because what we do for respawning the ball is (from memory):

  • Duplicate the node
  • Queue free the old one
  • Set a random position to the new one, and finally call add_child

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think setting the position this way is fine too, since we don't have node instantiation yet. This seemed like the simplest way.

Also, we should add random blocks in the future! I remember using them very often in Scratch, and they introduced me to the world of procedural generation :)

var parent_class: String
if found_simple_class_script:
parent_class = found_simple_class_script.get_base_class()
parent_class = str(found_simple_class_script.get_instance_base_type())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change? What is this doing and why is it needed? Ideally in each commit message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was explained in #59.

size = Vector2(128, 1080)

[node name="GoalArea" type="Area2D"]
collision_mask = 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@wnbaum wnbaum force-pushed the functional-pong branch from 63a8892 to 84a4184 Compare June 20, 2024 17:40
@wnbaum
Copy link
Contributor Author

wnbaum commented Jun 20, 2024

Rebased to incorporate sound effects in the pong scene.

Should we move it into an examples folder in the addon?

Note: It seems like the pong_game scene is already the main project scene, so we don't need to modify that.

Copy link
Member

@dbnicholson dbnicholson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it being in an examples directory in the plugin so that someone who installs the plugin can play with a fully formed game and see how the plugin is intended to be used.

Could you also add something to the commit message like @manuq requested? You can probably just copy in the text you put in the PR.

@wnbaum
Copy link
Contributor Author

wnbaum commented Jun 20, 2024

Sure, will do!

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.
wnbaum added 2 commits June 20, 2024 15:42
The BlockCode scripts were out of date anyways, and the pong game is a better example.
Copy link
Member

@dbnicholson dbnicholson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. I was thinking maybe we should leave test_game as a complete playground, but I don't think there's a ton of benefit.

@dbnicholson dbnicholson merged commit dcf2afa into main Jun 20, 2024
@dbnicholson dbnicholson deleted the functional-pong branch June 20, 2024 20:23
@dbnicholson dbnicholson mentioned this pull request Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants