Dual Tank Game using FPGA

Objective:

The objective of this project is to a game called “tank duel” that could be displayed on the VGA monitor and controlled by two players by one PS2 keyboard.

 

Design:

The tanks are realized as square boxes on the VGA monitor. They keep continuously moving back and forth on a horizontal line on the screen. Each tank can move with three different speeds. The direction of the tanks can be controlled using left and right keys. Both tanks shoot one bullet at a time; if it hits the opponent’s tank, it scores one point. A tank can shoot the second bullet only when the previous bullet goes out of the screen or hits the opponent. The score of both players is displayed on the LEDs. Whoever first scores 3 points wins. When a player wins, only the winner’s tank is displayed and the winner message is displayed in the LCD screen. The game resets on pressing the reset button.

Instructions:

– Two square shaped tanks facing each other on VGA screen with different colors (red and green). One tank appears on the top of the screen and the other appears on the bottom.

– Both tanks continuously move back and forth on a horizontal line on the screen. The directions of the tanks can be changed by pressing a button on the keyboard.

– Both tanks have 3 different moving speeds that are adjusted by keyboard inputs by the player.

-Both tanks shoot one bullet at a time; if it hits the opponent’s tank, it scores one point. A tank can shoot the second bullet only when the previous bullet goes out of the screen or hits the opponent.

– The score of both players are displayed on the 7-segment display. Whoever first scores 3 points wins.

-When one player reaches three points: Only the winner’s tank is displayed on the screen. A message declaring the winner should print out on the 16X2 screen.

– There is a reset button to resart the game

Hardware:

1. VGA Monitor

2. PS/2 Keyboard

3. 16X2 LCD Display (On Board)

4. 7-Segment Display (On Board)

5. Push Button and LEDs (On board)

Realization:

The project was designed and developed on the ALTERA DE-2 FPGA board. The coding was done using VHDL. The details of the entities are as follows:

VGA_top_level: This is the top level entity that structurally connects the VGA, LED and LCD components that display the output.

lcd : The lcd component maps de2lcd component and displays the winner message based on a_win and b_win values.

leddcd: This component decodes the hexadecimal score into seven-segment display for both the tanks.

pixelGenerator : The provided pixelGenerator component was modified to map ps2 component to read keyboard press values, decode them accordingly and make changes in the pixel values sent to the VGA control. To indentify keyboard values, scan_readyo, scan_code and hist1 signals were compared. As the clock speed is too high for human eye perception, counters were used to reduce the speed at which the bullet moves.

procedure: MY package was used to store two procedures SQ and SQ_B that display the tanks and bullet respectively.

Click Here for the Final Project Report and Code

15 thoughts on “Dual Tank Game using FPGA

  1. how did you create the procedure.vhd? i tried compiling it but i encountered an error “Top Level Design entity “procedure” is undefined. thanks 🙂

    • Hey Joan,
      I saw the link to the code and it is pretty much everything that you need. I would suggest you to use the following steps and let me know if it works or not.
      1. Make different .vhd files example procedure.vhd pixelGenerator,vhd and add it to your project.
      2. Then add VGA_top_level.vhd and make it your top level file. Compile and Run.

      Notes:
      – I was using QuartusII 13.0sp1 which is a student licence to burn and compile the code on FPGA board using ALTERA DE-2 Board.
      – I used Model SIM for trace evaluation.

      Hope this will help. Sorry for the delay in the reply.

      Best,
      Mahim

  2. hi thanks for the suggestion, the game’s already working only that the 16×2 lcd display of the de2 board does not display the “winner”. and still, i’m planning to speed up the firing of the bullet. which code should i edit and what do i need to change? thanks 🙂

    • Hey I am glad that it is working. So to speed up the bullet. In pixelGenerator.vhd you can go to the bullet logic section of the code and change SQ_B_Y3<=SQ_Y2+15; to
      SQ_B_Y3<=SQ_Y2+20;
      and
      SQ_B_Y4<=SQ_Y1+15; to
      SQ_B_Y4<=SQ_Y1+20;
      This would speed up the bullet by 5 in case you need it faster you can change 15 to a higher number.

      Secondly, is the 16×2 not working at all or only the winner is not displayed?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s