So here’s my complete midterm project — The Pongsidential Debate 2020!
You can probably tell from the name itself that this game is inspired by the classical computer game — The Pong Game, but with a twist of one of the hottest topics nowadays, the 2020 presidential debate. Since it’s almost time for the final election day, and we got such two interesting candidates, I decided nothing would be better to make this themed game now.

The game itself is pretty straightforward. Up to two players can play at the same time with each control one of the presidential candidates. Player one controls Trump using the W and S keys to move the paddle up and down; player two uses Up and Down arrows instead. The ball will bounce between two candidates, and whoever doesn’t catch the ball loses the game. Here are the screens indicating which player wins the game accordingly.


The players can click the screen to restart the game.
While creating the game, I went into several problems, one of which is that I couldn’t make the paddles move using the corresponding keys despite I thought my following code has no problems.

Then, with the help of Professor Scott ❤️, I realized what went wrong. In the beginning, I created a variable “started” to check if the game has started and set it to false. And in my gameOn() function, I placed the paddles when !started = true and didn’t change the “started” variable, so the game never starts.

After Scott pointed this out, I added the else statement to also place the paddles when the game starts. And then, I was able to control the two paddles with different keys.

Here’s my code to my Pongsidential Debate 2020, hope you enjoy the game! ;)
What I wouldn’t have done differently or in the future if I had time
In my original design, the ball is actually set to be the topics debated during the presidential debate and will change content every time a player successfully catches it. Yet I didn’t figure out how to add text on a moving object and update itself each time it bounces, so this design didn’t happen.
Moreover, after playing the game with my friends for a few rounds, I realize the ball actually moves in the same path every time, so the players can just move the paddles to a certain position and never move it again without losing the game. I would like to change the way the ball moves so that every time a player catches the ball, it would bounce in a random direction. In addition, I also would want to increase the speed of the ball as the game continues to increase the difficulty of the game, as of now it only moves at the same speed which can make the game too hard for any of the players to lose.
Reference:
A beginner-level tutorial of how to code a single player pong game in p5.js: https://medium.com/@kellylougheed/javascript-pong-with-p5-js-3ae1b859418c