Demo
Since it's difficult to demonstrate the Arduino part here, I instead made a version of the game that uses the cursor as input just as a demonstration. (The "a" and "d" keys control the movement of the blue car, the left and right arrow keys control the movement of the red car)
Here's a link to my sketch: https://editor.p5js.org/interfinity/sketches/ga3C05yzX
And here's our demo video:
Overview
For this project, I am in charge of creating the p5 part of the game, whereas Jiqi is in charge of the Arduino and 3D printing enclosures for our game controllers. Our game is a two-player car racing game which involves switching lanes to collect coins and avoid obstacles, whoever collected the more coin wins, if there's a tie, then whoever survived the longer wins.
Process
I made use of the p5play library to detection collision between objects, such as when a car hits an obstacle(which are also cars), or collects a coin. Although I found some of their documentation is incomplete or missing, the library is still quite intuitive and easy to implement, just add these tags to the header section of the HTML file:
<script src="https://p5play.org/v3/planck.min.js"></script>
<script src="https://p5play.org/v3/p5play.js"></script>
Then I can simply start creating "sprites"(game objects) in the setup() function, the "sprite" for the cars and the coins are simply rectangles, with an image on top. Interestingly, in order to create a spinning animation for the coin, I drew 7 frames and used the addAni() function:
coinsL.addAni("spinning", "Assets/Coins/Coin1.webp", 7);
I also drew 3 different "skins" for the cars, which can be changed in the startup menu. During the game, to make the effect that the cars are moving while they stay in the same position, the dashed lines on the road, the coins, the obstacle cars all move down from the top. I used the random() function to generate coins and obstacles cars at random time intervals, while placing some restrictions to ensure they will not be too close to one another. Here are the assets I made and used for the game.

