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!
-Ball sometimes passes through the paddle when hit at the corners of the screen
-Menu graphics glitching slightly when selecting options
Added in simple AI for playing single player and now the first player to 5 points wins!
Original version with only a 2 player endless mode and controls screen.
function ai(p) if (p.x > ball.x) p.x -=1 elseif (p.x + p.width < ball.x) p.x +=1 end
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).
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.
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.
[Please log in to post a comment]