Concept:
Finding the concept for this project was rather difficult– I initially thought about creating a rhythm game that would use the WASD keys and the arrow keys similar to a 2D Beat Saber where the direction you cut mattered as much as your timing. I was inspired by Mandy’s project from Fall 2024 where she made a two player dance game where you have to input a specific pattern of keys in combination with your partner. I thought her project had a lot of charm to it; however, I imagine syncing the rhythm to the onscreen inputs would prove challenging so I scrapped that idea early on.
Then I revisited the project I made for week 3 where we had to use loops. Back then I just wanted to follow Professor Aya’s advice (when she visited on Monday of week 3) and use object-oriented programming to add manually controlled collision physics to the project I made for week 2. That’s how I accidentally made Pong but this week I considered seriously turning it into a fully-functioning project.
I realized that my code was going to be very messy and a long scroll from top to bottom if I kept it all in one .js file, so I looked up how to split up the files. After I created new js files I realized that setup() and draw() could only be run in the main sketch.js file so I had to find a way to work around that for the gameLogic js file which is just an imported week 3 js file. I basically made new functions and named them initiateGame() and initiateMenu() and called them in the main sketch.js setup() function; I also had to add two lines of code into the html file to have the project access these new js files.
<script src="menu.js"></script> <script src="gameLogic.js"></script>
Updating the “PING” Game
Besides the obvious requirements to add a menu screen and a restart button, there were plenty of personal touches I wanted to add to what I made two weeks ago.
The first of which was to implement a more visually appealing score tracking system. Last time I had the game continuously repeat so I made a very minimalistic but number-based scoring system to fit with the rest of the minimalist aesthetic. Since I was adding a set number of rounds now, I wanted to use a more interesting way of representing each point. There would be a rectangle in the middle that would either flick upwards or downwards slightly based on which side took the point (kind of like a lightswitch in a way).
The next idea was to have the ability for an options menu to change the in-game volume mixer and maybe even keybinds.
Since there was also the need to reset the game without restarting the whole sketch now, I made sure to add an ESC function where you can back out to the menu from the game and also subsequently reset the scores and start a new game the next time the user clicks the button to enter the game.
//RESET SCORE function resetGame(){ //resets the score roundNumber = 0; topScore = 0; topCounter = []; bottomScore = 0; bottomCounter = []; } ... function menuMousePressed(){ twoPlayerButton.handleClick(mouseX, mouseY); resetGame(); }
I also made each button with its own class while passing functions as parameters to call when clicked. I have only test one button so far– the twoPlayerButton that leads you into the normal mode – but it works great and I’ve “scaffolded” an area for more buttons to be added the same way.
allMenuButtons.push( twoPlayerButton = new button( tempButton, //image width/2 + 120, //xPos height/2, //yPos tempButton.width, //sets to uploaded file dimensions tempButton.height, switchToGame //which function to call if clicked? ) );
User Interface Planning
To plan out the UI, I quickly made a Canva file that matched the dimensions of my project and made a quick sketch of what I wanted the menu to look like. I’m going for a rather
This is also how I came up with a better name for the game: Pong2
It’s not quite Pong 2, but since the paddles are no longer restricted to one dimension along each edge and now have true 2D movement, I wanted to call it something representative of that.
For the font choice I chose Gotham for its geometric feel. Since p5js didn’t have access to Gotham, I downloaded an otf file online and placed it in my sketch folder.
For the final version of the sketch, I want to add a faint bouncing ball in the background to make the menu screen feel more dynamic and alive too.
A detail I was quite proud about was setting up a hover checker that would turn my cursor into a hand if I was hovering over something that was clickable.
for (let btn of allMenuButtons) { btn.display(); //displays the button if (btn.isHovered(mouseX, mouseY)) { hovering = true; //check if hovering any buttons } } if (hovering) { cursor(HAND); } else { cursor(ARROW); }
Identify the Most Frightening Aspect:
The most frightening part of this project is most certainly the one player mode I want to make where you can play against an AI. Theoretically it’s just some simple math to have it sort of predict the ball’s trajectory but I imagine it would consume a considerable amount of effort to figure out how that would work.
I might drop this aspect altogether if it’s too challenging to make before the deadline but I really would like to make it work.
Sounds appealing, just make sure to hit the requirement of creating a new interaction and not just reimplementing an existing game.