A fast "pong" coding for the pong anniversary

Channel:
Subscribers:
135
Published on ● Video Link: https://www.youtube.com/watch?v=Tx0e_xer-J8



Duration: 8:29
58 views
3


on November 29th we celebrate the release of Pong day, so here you are my 10cents contribute: a simple basic pong game wrote from scratch while recording my desktop (rendered to you in fast motion).

Some details not so clear in the video.
- yb,xb are the "ball" x and y in a Cartesian system where the origin (zero) is in the upper left corner, and y grows downward.
- dx,dy are "delta-x" and "delta-y" , the amount of shift the xb and yb will get in the next cycle
- yp and ye are the vertical start position of your bar and the enemy's one.

The AI is simple but (probably) unbeatable: the enemy yp is incremented or decremented according to the enemy's bar centre respect the ball position: if the ball is upper then the bar centre, then we move the bar upward (so we decrement ye). And viceversa.

Feel free to change, upgrade, destroy this code, it's just a start. For example, try to make less smart the AI (for example, you can decide to move the enemy bar only if the ball is on the right half of the screen, giving in this way a malus to it).

Comment with your works if you want, but above all enjoy coding.
Cheers