For this assignment, I used a state machine to build a two player game based on speed and out-pressing your opponent.
In this game, the LEDs blink outwardly, at different levels, getting faster and faster each round. Your goal is to collect points by pressing the button before your partner.
If your press the button at level 1, you get 5 points, at level 2 you get 10, and at level three you get 15 points.
Once you press your button, the next round begins and the game speeds up.
Whoever has the most points at the end of 20 rounds, wins!
The game was based on this state machine:
(its a bit messy, sorry)
So basically, initially it is in the GAME_BEG state until one player presses a button. It then cycles through the NONE, ONE, TWO, and THREE states getting faster at the end of each cycle, unless someone presses their button in which case it returns to the NONE state, starts a new round, and adds points to their score. When the rounds reach 20, it goes to GAME_OVER until someone presses a button, then it goes back to GAME_BEG and resets the speed and score.
NONE, ONE, TWO, and THREE:
The inspiration of this game came from this gif actually:
Earlier in the semester I got my 5 LED setup to sort of mimic this movement and I just turned that movement into a game.
There was a lot to think about with this game, especially with scoring. I found that sometimes, I would implement too many parts of the game without checking for functionality and I would have to go back and undo a lot to see what broke my game. One thing I didn’t think about and spend WAY too much time on was resetting the speed and rounds at the GAME_BEG state. I didn’t do that at first and the game would start and immediately enter GAME_OVER because the rounds weren’t reset. Once that was fixed, most everything else went smoothly.