Finalized Concept for the Project
For my final project, I will create Goal Rush, which is a football reaction game where the player acts as a goalkeeper in a penalty shootout. The goal is to save as many penalty shots as possible by reacting to random signals. The project uses a physical setup with three buttons and corresponding LEDs to simulate the direction of the ball (left, center, or right). Each button press simulates the goalkeeper’s dive to save the ball.
The buttons, LEDs, and game logic are connected to and managed by an Arduino. The Arduino communicates with a p5.js program, which mirrors the physical gameplay with a digital goalpost, goalkeeper, and ball animations. The LEDs light up to signal where the ball is “shot,” and the player must press the corresponding button to save the goal. The correct press sends a signal to p5.js, making the goalkeeper dive in the corresponding direction. If the player reacts too late or presses the wrong button, the ball goes into the net, and a missed goal is recorded.
Arduino Program Design
- Buttons:
- Button 1 (Left):
- Connected to digital pin 2.
- Represents the goalkeeper diving to the left.
- Button 2 (Center):
- Connected to digital pin 3.
- Represents the goalkeeper staying in the center.
- Button 3 (Right):
- Connected to digital pin 4.
- Represents the goalkeeper diving to the right.
- Button 1 (Left):
What It Does:
Each button, when pressed, sends a signal to the Arduino. The program identifies which button was pressed and determines if it corresponds to the lit LED.
- LEDs:
- LED 1 (Left):
- Connected to digital pin 5.
- Lights up to indicate the ball is being “shot” to the left.
- LED 2 (Center):
- Connected to digital pin 6.
- Lights up to indicate the ball is being “shot” to the center.
- LED 3 (Right):
- Connected to digital pin 7.
- Lights up to indicate the ball is being “shot” to the right.
- LED 1 (Left):
What It Does:
The LEDs are controlled by the Arduino to light up randomly, signaling where the ball is heading. This gives the player a cue for which button to press.
- Wires:
- Signal Wires: Connect each button and LED to their respective digital pins on the Arduino to transmit input and output signals.
- Power Wires: Connect all components to the Arduino’s 5V and GND pins to ensure proper power supply.
Arduino Program Workflow:
- Random LED activation:
- The Arduino randomly selects one of the LEDs (left, center, or right) to light up, signaling the ball’s direction.
- A small delay allows the player time to react.
- Button Monitoring:
- The Arduino continuously checks the state of the buttons using digitalRead.
- If a button is pressed, the Arduino determines whether it matches the lit LED:
- Match: Sends a success signal (-1, 0, 1 based on the button pressed) to p5.js.
- Mismatch or No Press: Sends a failure signal to p5.js.
- Serial Communication:
- Sends the button state (-1, 0, or 1) and save/miss result to p5.js, where the digital game is updated accordingly.
p5.js Program Design
- Digital Goalpost:
- Displays three zones (left, center, right) where the ball can be shot.
- Digital Goalkeeper:
- Moves left, center, or right based on data received from Arduino (-1 for left, 0 for center, 1 for right).
- Ball Animation:
- A ball is animated to travel toward one of the three zones, matching the lit LED in the physical setup.
- Scoreboard:
- Tracks successful saves and missed goals.
- Game Timer:
- Limits the game duration and increases difficulty by speeding up the ball animations over time.
p5.js Program Workflow:
- Input from Arduino:
- Receives data from Arduino indicating which button was pressed and whether it was correct.
- Updates the goalkeeper’s position (left, center, or right) based on the button data.
- Random Shot Generation:
- Randomly determines the ball’s trajectory (left, center, or right), mirroring the Arduino’s LED activation.
- Collision Detection:
- Checks whether the goalkeeper’s position matches the ball’s trajectory when the ball reaches the goal:
- Match: Displays a save animation and increases the score.
- Mismatch: Displays a missed goal animation.
- Checks whether the goalkeeper’s position matches the ball’s trajectory when the ball reaches the goal:
- Visual Outputs:
- Updates the digital display to show the ball’s movement, the goalkeeper’s dives, and the game’s score and timer.