Engineers: Shriya Rajesh, Amrutha Challa
Project Idea: In this project, we created Whack-a-Mole using the Nexys A7 FPGA board. Moles will appear at random on the screen in a 4 x 4 grid. To hit the mole, players must first select the desired square using the switches. The player will then press one of the buttons to hit the mole. If this is done within an appropriate amount of time, they get the point; if not, the game will move to the next mole and the player will not get the point. The game ends when a total of 25 moles have been shown on screen. If 20+ moles were hit, the player wins; otherwise, they lose.
We were motivated to create a functional game that uses hardware inputs, timing logic, and VGA output to deliver a responsive gameplay experience.
Whack-a-Mole-style games rely on using the clock for timers, using random selection that is compatible with an FPGA board, and debouncing buttons so users can quickly select a square.
- A state machine to plan out each aspect of the game.
- VGA display to show the graphics of a start screen, a game over screen, a grid for the holes, and a rectangle for the mole.
- Using switches and buttons to select and click on a square and debouncing logic so that each button press only adds one point to the score.
- Using the clock for timing logic to ensure the mole switches to a new location if the user has not selected a square within 5 seconds.
- An algorithm to randomly select which square the mole will move to next.
- Need to handle moving objects for the confetti if the player wins the game.
- Counters and registers are needed to maintain the score and track whether the game is over if there has been 25 moles.
- Reset the grid
- Wait for player to click start
- Randomly pick the next square
- Waits for debouncing to ensure each hit is one point
- Mole appears in that square
- Stays for maximum of 5s (time subject to change)
- Stay in state until player hits mole or time runs out
- Mole disappears
- Display score in the SSD
- Increment number of displayed moles
- Appropriately increment score (+0 if not hit, +1 if hit)
- Depending on number of moles, return to Wait or Finished (game ends after 25 moles)
- Display win/lose screen
- Wait for players to reset the game
Grid Mapping:
- The 4×4 grid consists of holes, each of which corresponds to a switch that is used to select a square.
Random Square Selection:
- Used a Linear Feedback Shift Register (LFSR) for an algorithm which “randomly” generates numbers from 1-16, which determines the mole’s next square.
Timers:
- Use the clock to determine how many cycles are necessary to reach the delay time before the mole times out and moves to another square.
Mole Hit Detection:
- When the user presses a button, the selected square is compared with the mole’s square to determine whether the mole was hit.
VGA Graphics:
- A rectangle represents the mole and the grid represents the holes.
- The start screen waits for a button to be pressed before showing the game.
- The end screen is either red or is a black background with colorful confetti depending on whether the player was successful in hitting at least 20 moles.
We tested the program by going through different test cases to ensure that our program was working as expected, including the edge cases.
Test Cases:
- Each switch highlights its corresponding square.
- Scoring exactly 20 moles and hitting more than 20 moles would each lead to the win screen being displayed.
- If less than 20 moles are hit, the game will display the game over screen.
- The mole will timeout if a square is not selected within 5 seconds.
- The score is displayed accurately if moles are not selected in time or if the wrong square is selected instead.
- Each time the button is pressed to hit the mole, the score either stays the same or increments exactly once regardless of how long the button is pressed.
- The score should reset properly if the user selects the play again option after completing the game.
Start Screen:
- The VGA display shows a black screen with a yellow rectangle and the user must press a button on the FPGA board to start the game.
Game Screen:
- There is a purple background with a grid of black squares on it to represent the holes the mole will appear in. The mole is a pink rectangle and the user needs to use the FPGA board’s switches to select the correct square and press the button to hit the mole. The VGA display shows patterns on the black grid for a more engaging visual appearance for users.
End Screen:
- The end screen is black with colorful confetti falling if the user has scored at least 20 points. If the user has lost the game, the screen will be red. The user will see this screen until they press the button on the FPGA board to play again, at which point the user will be shown the game screen.
Randomization
- Learned about the LFSR algorithm to determine how it worked with an initial number to provide 0-15 as outputs and then added 1 so that the numbers would correspond with 1-16 to map to the holes.
Debouncing
- Needed to determine how to stop the score from increasing multiple times when the mole was only hit once so we added a condition that the score would only increase once until the square was deselected so that the player would have only be able to hit the mole once each time it appeared.
Timers
- Timers had to be calculated with the clock frequency because telling a program to wait for an amount of time only works for simulations, not when working with an FPGA board. So, we needed to wait until the correct amount of clock cycles had occurred to wait for the necessary amount of time.
Graphics
- We wanted to emulate a retro style aesthetic for the game, with bright colors, patterns, and interesting shapes. When trying to create different shapes programmatically, however, we ran into numerous issues; for instance, when we tried to use the Pythagorean Theorem to constrain a circle sprite, it instead created a rippling dotted pattern throughout the screen. We ended up using this as a background and decided to stick with square moles that changed position depending on the center of each grid square.
Some future work we can do to improve our project is to add graphics to have engaging sprites, such as for our mole, for a hammer, or for the holes so that users would be able easily recognize the game.
- The mole sprite will be changed from a rectangle to an image of a mole.
- Instead of selecting a square by highlighting it, we can add an animated hammer sprite.
- We could have circles for the holes instead of squares in our grid.
- We could also increase the game complexity by creating a larger grid and using a combination of multiple switches to represent each square, instead of one switch per square.
- We could add sound effects for when a mole is hit or missed.
- We could introduce multiple moles at once, in addition to “fake” moles that would yield a penalty if hit.
- We could add more dynamic animations for start, game end, and winning screens.
We created a functional game of Whack-A-Mole using the Nexys A7 FPGA board and a VGA display. We used random generation, debouncing techniques, timers based on the clock frequency, animated graphics, and an SSD display to engineer our project. We planned our project out with a state machine to determine the transition conditions and the RTL statements that would go inside each state. By combining these technical concepts with hardware and a VGA display, we were able to successfully program Whack-A-Mole.
Presentation: https://docs.google.com/presentation/d/1E_JE7IEzu9fe2jUclHFPAlwqkdURtb2zFrs4JL4D9Z8
Game: https://youtu.be/67w-ylWgHjo