the atari lunar lander game made with hardware!
A lunar lander game hardware design in synthesis-able VHDL. Designed to be implemented on a Spartan3 FPGA, and done using Xilinx ISE webpack 14.3. The vhdl code is intended to be as understandable as possible (e.g., process are written to be as close as the rt diagram, instead of wrapping various components in one process).
notice: most of the code is in Spanish. Make an issue if you want it translated.
There are two possible gameplay styles, which can be selected using a switch from the fpga board. Those are:
- sile style: the ship goes down the sile, and then it refuels at the bottom of it.
- base style: the ship lands on a base, and refuels there. If it goes down at too much velocity (red velocity at the indicator) it crashes. beware, the ship can slip at the base, be careful when landing and don't go out of the base.
As the design is quite big, I haven't captured it on paper first. If you want to see how I use to do such thing, you can take a look at other FPGA designs at https://github.com/viccuad/fpga-thingies.
Random positions of bases and world
A Linear feedback shift register is used for implementing a pseudo-random number generator, as seen in this paper. The pseudo random generator is used for generating the world and bases.
Ship movement with inertia and gravity
The movement of the ship is rendered in two steps:
- Velocities. The ship has vertical (up-down) and horizontal (left-right) velocities, which allow to have acceleration and correctly simulate the behaviour of the ship. This is implemented with two counters (the vertical counter is descending at a steady pace for simulating the gravity).
- Position in the screen. 2 counters, one for vertical, and the other for horizontal pixels, render the ship in the screen. The counters always change in +-1 pixel, but the values of the velocity counters determine the rate, and thus, the ship moves faster or slower in the screen.
The world is stored in a RAM, column by column. The first pixel of current column is randomly generated by summing/subtracting a fixed amount of pixels to the first pixel of the last painted column. For this, a FSM iterates each column, reading the first pixel of the last column from a register, which stores it.
PS2 module for interfacing with a keyboard
A little FSM with flag registers is used for taking into acount the key presses.
VGA sync and screen painting
2 counters are used for creating the vertical and horizontal sync, and are also used for adressing the ram for painting the screen.
All the source code present here is under the GPLv3 license. Please see the GPv3License.md attached to this repo for more information.