Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
All support for Intel NUC 7 - 13 systems has transitioned to ASUS. Read latest update.
20577 Discussions

Implementing "Snake" game on DE2

Honored Contributor II

Hello all. I am implementing the classic "Snake" game on a DE2 Cyclone II setup. I have already developed the logic for how the snake moves and the general operations of the game like win/lose, level up, etc. The big step I'm having trouble with is taking the keyboard input scan codes and converting them into movements. I understand keyboard.vhd, but I don't know how I can take those outputs and have another component comprehend the data. If anyone can help or has any advice, it would be GREATLY appreciated.

0 Kudos
1 Reply

Implementing the classic game "Snake" on a DE2 FPGA board is a fun project that can help you learn about hardware design and programming. Here are the steps that  I used to implement:

  1. Connect the DE2 board to your computer and set up the development environment. You will need to install Quartus II software to program the FPGA board, and ModelSim software for simulation.

  2. Define the hardware components for the game. This will include the display (such as a VGA monitor), the input (such as a keyboard or joystick), and the memory (such as on-chip RAM).

  3. Write the Verilog code to implement the game logic. The basic algorithm for the game is as follows:

  • Initialize the snake with a head and tail, and place it on the board.
  • Place a randomly generated food on the board.
  • Read the user input to change the direction of the snake.
  • Move the snake in the current direction.
  • Check for collisions with the walls, food, or the snake's body.
  • If the snake eats the food, grow its length and generate a new food.
  • If the snake collides with the wall or its own body, end the game.
  1. Simulate and debug the Verilog code using ModelSim.

  2. Generate the programming file for the FPGA and download it to the board using Quartus II.

  3. Connect the display and input devices to the board, and play the game!

0 Kudos