0% found this document useful (0 votes)
90 views

FPGA Asteroid Game

This document describes an asteroids game created on an FPGA using push buttons and a 7-segment display. The game uses finite state machines to control the position of the ship (controlled by buttons) and randomly generated asteroids. If an asteroid reaches the ship's position, "BAnG" is displayed before restarting. The author details the hardware components used and provides steps to replicate the design, including creating FSMs for positions and display decoding, and integrating them to create the full game. Potential extensions are discussed, like increasing difficulty over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

FPGA Asteroid Game

This document describes an asteroids game created on an FPGA using push buttons and a 7-segment display. The game uses finite state machines to control the position of the ship (controlled by buttons) and randomly generated asteroids. If an asteroid reaches the ship's position, "BAnG" is displayed before restarting. The author details the hardware components used and provides steps to replicate the design, including creating FSMs for positions and display decoding, and integrating them to create the full game. Potential extensions are discussed, like increasing difficulty over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

instructables

FPGA Asteroid Game

by BrandonH155

For our CPE 133 Final Project, we decided to create used to move your ship out of the way of the asteroid.
an asteroids game on our FPGA using two push Upon failure to do so, the display reads ‘BAnG’ for a
button switches and the 7-segment display. The moment and then quickly restarts the game so the
game works so that an asteroid spawns in one of user may try again. What follows is a brief description
three randomly selected rows, and comes hurtling of how the project was made so that any user may
toward the ship on the other side of the 7-segment replicate or improve our design.
display. The upper button and lower button can be

FPGA Asteroid Game: Page 1


Step 1: Overview

The project largely consists of Finite State Machines FSMs were created for the ship’s position, the rock’s
(FSMs), which use logic to transfer the FPGA position, and for the 7-segment decoder. The purpose
between states which store and display different of the ship’s FSM is so that the ship can move to the
values of ship and rock positions. The two major correct position when the player presses an up or
modules are the game FSMs for the rock and ship, down button. The FSM is needed because it needs to
and the binary to 7-segment display decoder FSM, remember which position it was last in in order to
which are integrated together using a very simple move to the correct position.
structural model in VHDL.

The purpose of the rock’s FSM is to move the rock to The FSM for the 7-segment display decoder was
the correct position based on which row it is in and used to not only display the ship and the rock but also
the last position in that row. In addition, it keeps track to display “BAnG” when the ship position and the rock
of the position for the module that will display it and position are the same.
pseudo-randomly picks a new row to appear on next.

FPGA Asteroid Game: Page 2


Step 2: Materials

The materials used in the project were:

Basys3 Development Board from Digilent, Inc.


Vivado Design Suite
sseg_dec.vhd (This file was provided to us on Polylearn and was written by Bryan Mealy)
Clk_div.vhd (This file was provided to us on Polylearn and was written by Bryan Mealy)
Three Finite State Machines (FSMs)

Step 3: Making the Game

The game module was created by using behavioral 0←1←2←3


modeling to describe the states of the ship and rock
for their own respective FSMs. The advantage of this 4←5←6←7
is that it is far easier to model the circuit behaviorally
by describing what it does rather than figuring out all 11 ← 10 ← 9 ← 8
of the components needed to design the hardware.
The clock used for the rock’s next state logic controls
The rock states were done using a pseudo random the speed of the game; we found through trial and
number generator for the first position of the rock. To error that 9999999 is a good value for its max count.
accomplish this, we gave the generator its own clock
which was extremely fast relative to the speed of the The ship’s logic works by initializing into the center
game. On each rising edge, a three bit number is position (position 4) on the far left side. If the upper
incremented, and all of its values correspond to one button or lower button are pressed, the ship will move
of three start states for the ship. Therefore, three up and down into position 0 and 11 corresponding to
values correspond to position 3 (the top right), three the button that has been pressed.
correspond to position 7 (the center), and two
correspond to position 11 (the bottom right). In order to have the ship movement feel good for the
user, we did not make its movement asynchronous.
Once the random generation has occurred and the We used a clock for its state changes, and we used a
asteroid has been given an initial state, it flows max count of 5555555.
horizontally toward the ship with no interruption.

FPGA Asteroid Game: Page 3


FPGA Asteroid Game: Page 4
http://www.instructables.com/ORIG/FK3/2CM3/JAWTTQ5V/FK32CM3JAWTTQ5V.txt
… Download (https://cdn.instructables.com/ORIG/FK3/2CM3/JAWTTQ5V/FK32CM3JAWTTQ5V.txt)

(https://cdn.instructables.com/ORIG/FK3/2CM3/JAWTTQ5V/FK32CM3JAWTTQ5V.txt)
Download (https://cdn.instructables.com/ORIG/FGX/4LGA/JAWTTQ8O/FGX4LGAJAWTTQ8O.txt)
http://www.instructables.com/ORIG/FGX/4LGA/JAWTTQ8O/FGX4LGAJAWTTQ8O.txt

(https://cdn.instructables.com/ORIG/FGX/4LGA/JAWTTQ8O/FGX4LGAJAWTTQ8O.txt)

Step 4: Displaying the Result

The binary to 7-segment decoder takes in the 4-bit If it does not return true, the decoder will display the
position variables for the ship and the asteroid and ship and the rock by switching between them at a
displays the appropriate image (either the ship and very high clock frequency and fooling the eye into
rock or the message “BAnG”). seeing them as if they are being displayed at the
same time.
It accomplishes this by first checking if the two are
equal and then displaying the message “BAnG” if the
check returns true.

Download (https://cdn.instructables.com/ORIG/FOU/VBZS/JAWTTQG0/FOUVBZSJAWTTQG0.txt)
http://www.instructables.com/ORIG/FOU/VBZS/JAWTTQG0/FOUVBZSJAWTTQG0.txt

(https://cdn.instructables.com/ORIG/FOU/VBZS/JAWTTQG0/FOUVBZSJAWTTQG0.txt)

Step 5: Putting It All Together

We encompassed the ship’s and rock’s FSM in one large FSM that we wired to the display FSM. The inputs to the
game are the up button and the down button on the BASYS3 board and the system clock. The outputs are the
segment and anode vectors seven segment-display.

These inputs and outputs will be seen in the constraints file where they are port mapped.

FPGA Asteroid Game: Page 5


Download (https://cdn.instructables.com/ORIG/FES/NYOM/JAWTTQJ2/FESNYOMJAWTTQJ2.txt)
http://www.instructables.com/ORIG/FES/NYOM/JAWTTQJ2/FESNYOMJAWTTQJ2.txt

(https://cdn.instructables.com/ORIG/FES/NYOM/JAWTTQJ2/FESNYOMJAWTTQJ2.txt)

Step 6: Future Modifications

In the future, adding more ship movement again. This would increase the difficulty of the game
functionality to the project would be an improvement. and make it more fun for the user if it were
This can be accomplished simply by giving 2 more implemented, and could be done by creating a
button inputs and allowing the ship to take positions variable for the max count of the rock’s next state
(states) other than 0, 4, and 8. Another possible clock, multiplying that variable by 1.5 every time the
modification could be controlling the asteroid’s next asteroid doesn’t hit, and resetting it to it’s initial value
state timing so that it starts slowly and increase every time the rock hits.
speed by 1.5x every time it misses the ship until it
gets a hit, where it would restart and become slow

FPGA Asteroid Game: Page 6


Step 7: Conclusion

This project has helped us to better understand finite of the ship, the rock, and end-of-game message.
state machines, clocks, and interactively displaying
on the seven-segment displays. We learned that more than one anode cannot be
displayed at the same time. The module given to us
The biggest thing about finite state machines is that it took advantage that the human eye can only see the
is important to know (remember) what state you are difference up to a certain frequency. So a higher
currently in in order to move to next desired state. frequency of switching anodes was chosen. The ship
Ironically, good life advice; you must know where you and rock being seen at the same time is actually an
are to know where you are going. allusion since each are displayed separately, but very
quickly. That concept was applied to display the
By manipulating different instances of clocks, we movement of the ship, the rock, and the “BAnG”
were able to randomly generate numbers, move the message.
rock to the next position, and manage the displaying

Download (https://cdn.instructables.com/ORIG/FPF/77RO/JAWTTMDY/FPF77ROJAWTTMDY.mov)
http://www.instructables.com/ORIG/FPF/77RO/JAWTTMDY/FPF77ROJAWTTMDY.mov

(https://cdn.instructables.com/ORIG/FPF/77RO/JAWTTMDY/FPF77ROJAWTTMDY.mov)

FPGA Asteroid Game: Page 7

You might also like