Showing posts with label Processing. Show all posts
Showing posts with label Processing. 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.

Monday, August 19, 2013

Project 4: Snake Version 0.3.1 - now with a little less crashing.

Version 0.3.1 of the snake game fixes a problem where pressing the 't' key to give yourself points before the game starts caused the game to crash. All the cheat keys (and the control swap key) now only work while the game is playing.

All the other features introduced in version 0.3.0 remain unchanged.

You can download it here:

  • The Windows Versions (32-bit, and 64-bit)
  • The Mac OS X Version
  • The Linux Versions (32-bit and 64-bit)
  • Friday, August 16, 2013

    Project 4: Snake Version 0.3.0 (Almost Undetectably New!)

    The Snake game has still been holding my attention, so I've put together the newest update. This new version however is primarily changes to the design and organization of the game.

    Does this mean you won't be able to tell the difference from version 0.2.0? Not entirely. The new structure has made it easier for me to switch things in and out and make things a little easier.



    The biggest change is that now the controls are modelled after those implemented in Nibbles. This means that when you're heading in any direction you can now only turn to the side rather than back on yourself. However if you liked the original controls, all you have to do is press 'k' to switch between the two controls.

    Furthermore if you want to make things easier or harder on yourself there are some cheats available:

    • Press 't' to add a point to your score, this moves the target and is just like you hit the target on your own.
    • Press 'y' to add a level. This levels you up, speeding up the game.
    • Press 'u' to turn off collisions, so you can go on forever without worrying about running into yourself. Press 'u' again to turn them back on again.
    That's pretty much the update for this time. Lots of changes that mean more to me than you, but it should make it a lot easier to do the things I'm thinking for the future. Speaking of which Version 0.4.0 will be along in a little while and should bring a GUI and different kinds of worlds to play.

    But for now you can download Version 0.3.0 below:

    Edit: See the Patched Version 0.3.1
    • The Windows Versions (32-bit, and 64-bit)
    • The Mac OS X Version Edit: There seems to be a problem with the Mac OS X app. I will investigate as soon as I can.
    • The Linux Versions (32-bit and 64-bit)


    Tuesday, July 16, 2013

    Project 4: A Further Surprise Snake Update (Version 0.2.0)

    So it seems I still have a lot of procrastinating to do. I've managed to turn out another version of Snake. (This time version 0.2.0).


    This version introduces:

    * Awful Sound Effects - it's weird old beeps, that kinda appealed to me
    * Mute - press 'M' to turn off the awful sound effects (this doesn't preserve between games yet)
    * Scaling Snake Colour - now as the snake grows it fades to grey towards the end of it's tail. This makes it easier to see which way you're going (especially when coming back from pause).

    Please play and let me know in the comments if you run into any problems or bugs or any thoughts at all really.

    You can get the game from these links:


    Thanks as always!

    Thursday, July 11, 2013

    Project 4: A Surprise Update on the Snake (Version 0.1.0)

    Again, my skills in procrastination have allowed me to get things done. This time, now that I don't have it as an active project, I managed to put out a revision of the Snake game.

    This version introduces a couple of new features:
    • Pausing! Now you can press 'p' to stop the game whenever you want. To resume the game just press any of the arrow keys and start going again. 
    • Bouncing Scores! I'm sure I'm the only person who cares, but now when you hit a target the score bounces up and down a little bit. It's not amazing animation, but it's something.
    • Proper key handling. This doesn't change the game at all, but I was able to apply a lot of the things I've learned about Processing.org and realized that the tutorial I'd followed way back in the beginning had a strange way of handling key presses (relying on the main loop of the program). Now I've updated it to use proper event handling. 

    You can download the update:
    If you'd care to beta test this for me I'd really appreciate it. Leave me your thoughts in the comment section.


    Monday, July 01, 2013

    Project 4: Snake: Update and Wrap-up

    It may have taken me nearly a year to do a few afternoon's worth of programming, but the first version of my Snake game is finally done. (Spoilers: You can play it using the links at the bottom of the article.)


    This was quite a bit of fun to put together. One of the nice things about programming a game (especially one this simple) is that the results are immediately visible. It's also nice to have small targets to hit that are fairly easily achieved.

    The game plays pretty much like any instance of snake you may have run across in the past. I did choose to have the edges of the world wrap because I was entertained by the math, but I also enjoy that it does cause you to think a little extra since the snake is not always apparent as adjacent to you. Right now the game speeds up for levels 1 - 10, but the game doesn't end until you reach level 33.

    For the record though you can technically win the game, however I'm not sure how possible that is in reality. I've found the responsiveness with my Mac Book Pro to be insufficient at the higher levels, but with a different key board it may be easier. It's also somewhat difficult because there's no boarder around the snake and so it's very difficult to see where the snake is at any given point in time.



    I'm pleased with the level and score markers that pop up. It would be nice to have them fade in or out, or for the scores to bounce a little. I decided to stop where I got to and if I'm able to put those in as extras in a later version. Additionally in later versions I'd like to add some game modes and manage difficulty better than I am right now.

    I'd really appreciate some help testing out this version of the game. If you have a little time I'd like to know:

    • if/how it works on different platforms (links are below)
    • if there are any bugs
    • is it fun? What could make it more fun?
    Comments in the comment section would be appreciated.

    For now it needs to be downloaded, it's not really worth making it embeddable.
    Control the snake with your arrow keys. You can quit with the 'q' key and win with the 'w' key. From the game over screen you can start playing again by hitting the space bar.

    These should all run with the included files. Processing has an automatic generator and I've found that the Windows and Mac versions seem to work for me. I haven't had time to test it on Linux yet.

    Thanks for your support. I'll do another version but for now it's on to other things!


    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...