Showing posts with label Pong. Show all posts
Showing posts with label Pong. Show all posts

Sunday, November 03, 2019

Project 19 - Pong - Phase 1

Project 19 - Pong

I am implementing Pong. Yes, that Pong. I’m implementing it both for fun, but also because it’s going to be necessary for a project for work in the fairly new future.


I figured since I was implementing Pong, I might as well make a project out of it. As a bonus since my implementation is basically finished, I get a free finished project out of the deal.

I decided, as is my wont, to work in Processing.org. This is pretty much my go to platform whenever I need to prototype something or do a thing with quick interactions. I’m also educating myself about P5.js which is proving to be fun as well.

My original take was to work with vectors, which has exposed me to all of the linear algebra I didn’t learn or have forgotten. This will also be helpful for my Bubble Puzzler work (which apparently I haven't updated here, to my surprise). I then remember that my Phase 2 for this project is to have a working version of Pong on the Atari ST, and so I’d be better off handling things like coordinates and motion as simple variables. You can find the source in on GitHub.


// player positions on the screen
int p1Y;
int p2Y;
int p1X;
int p2X;

// paddle display information
int paddleW = 10;
int paddleH = 75;

// player scores
int p1Score = 0;
int p2Score = 0;

// ball position on the screen and motion
int ballX;
int ballY;
int ballMoveX;
int ballMoveY;

int ballSize = 10;

Within the program my code is fairly basic, I’m relying on processing’s control of the framerate, and basically assign the ball a speed between 2 and -2 on the y axis and 2 and -2 on the x axis. This feels like a fairly workable implementation of speed, although increasing it as the game goes on would be an option (I suspect an actually competitive game would go on for quite a while).

The ball bounces off the top wall and off the paddles. If the ball hits a paddle near the edge (about 1/8th of its total length) then it bounces in the y direction as well as the x.


void bouncePaddle(int paddleX, int paddleY) {
    // bounces the ball off the paddle 
   if (((ballX + ballSize >= paddleX) && (ballX <= paddleX + paddleW)) && 
              ((ballY + ballSize >= paddleY) && (ballY <= paddleY + paddleH))) 
        {
     ballMoveX *= -1;
     
     // reflects the ball back on the y axis if it hits near the edge of the paddle
     // mostly for fun, not sure it was in pong, but I enjoy it in most clones
     if ((ballY + ballSize < (paddleY + (paddleH / 8))) || 
         (ballY + ballSize > (paddleY + 7 * (paddleH / 8)))) {
       ballMoveY *= -1;
     }
     
   }
   
}


This produces enough interesting effects that I’m calling this phase of the project done.

That being said, in the short term, I suppose I need some more inputs because solitaire pong seems not-too much fun. Beyond that I think that’s probably it for the Processing.org implementation. My next priority is to prepare to produce the Atari ST version of the game. I would also like to produce a version of Breakout because that seems fun and possibly also add in a few interesting visual effects.

I should be done the AtariST version by early January because I need my students to start on their projects by then.

The Video Games I Played - February 2024

This is the second new monthly games post . I'm not feeling very settled in what anything means. The book posts have some basic stats...