Log In  

Decided to remake an old classic, Pong! I know this has been done a million times before but I thought I'd give it a shot and maybe learn a thing or two.

Move left and right and smack the ball to the other side to score!

Known Bugs:
-Ball sometimes passes through the paddle when hit at the corners of the screen
-Menu graphics glitching slightly when selecting options

Player 1:
Arrow Keys

Player 2

Version 1.1:
Added in simple AI for playing single player and now the first player to 5 points wins!

Cart #30857 | 2016-10-13 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Version 1.0:
Original version with only a 2 player endless mode and controls screen.

Cart #30325 | 2016-10-08 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

P#30327 2016-10-08 17:30 ( Edited 2016-10-17 19:13)

Good, but DEFINITELY want to consider making an option for a 1-player game. Not everyone has as many friends as some do. :)

P#30335 2016-10-08 18:15 ( Edited 2016-10-11 02:09)

Haha okay I'll see if I can add that in the future ;) I've just been playing using 2 hands whilst testing but it's really difficult -___-

P#30585 2016-10-10 17:47 ( Edited 2016-10-10 21:47)
function ai(p)
  if (p.x > ball.x) p.x -=1
  elseif (p.x + p.width < ball.x) p.x +=1

Something like that should work. The elseif considers the width of the paddle, so that it doesn't keep trying to slam the right side wall. I didn't really look how you have it set up, but I assume you have some kind of width property, and if not, just put in the number value. Then, in your menu, add an option for 1 or 2 players. If 1 player is selected, enable the ai obviously, and disable the second player controls (to prevent cheating). Should be relatively straightforward.

Bonus points if you also make it so the AI has a chance to bounce off walls similar to how players can (with the function I wrote, the AI would never bounce off a wall, since the furthest it would ever move would be exactly to the wall and then stopping, so you'd just have to make it use your acceleration/deceleration routines instead of my incrementing and decrementing the x coordinate).

P#30621 2016-10-11 00:09 ( Edited 2016-10-11 04:10)

Thanks for the reply Scathe! Yeah I see what you mean, I thought programming the AI for this would be way harder than just accelerating towards the balls x co-ord but I think this should do nicely!

I'll have a go at implementing it now...

P#30661 2016-10-11 11:54 ( Edited 2016-10-11 15:54)

PC, I noticed your ball does not have deflection with English. That is, if the ball hits the far left of your paddle, then the ball will be reflected with a much stronger tilt to the left.

Same on the opposite. If the ball hits a paddle, either player's or opponent's paddle. If the ball hits the right edge, then the ball will have an increased acceleration to the right.

Let's see if we can pick up PONG on the Youtube.


Now watch the player on the right as they do a high deflect.

P#31056 2016-10-16 15:44 ( Edited 2016-10-16 19:47)

dw817, I originally wanted to get the ball to be able to bounce off of the ends of the paddles but decided against it for the sake of simplicity ¯_(ツ)_/¯

You can, however, move the paddle fast in a certain direction to add some of the paddles velocity to the ball and send it flying off in any given direction.

P#31066 2016-10-16 16:33 ( Edited 2016-10-16 20:33)

Hey good job! Did my suggestion end up helping?

P#31087 2016-10-16 22:24 ( Edited 2016-10-17 02:24)

Yes definitely Scathe, thank you!

P#31120 2016-10-17 15:13 ( Edited 2016-10-17 19:13)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-02-22 23:58:03 | 0.013s | Q:24