This project implements a simple car racing game using VHDL (VHSIC Hardware Description Language) for FPGA (Field-Programmable Gate Array) implementation. The game features a car that can be moved left and right to avoid obstacles, a scrolling background, and a score display.
- Car Control: Move the car left and right using buttons.
- Obstacle Avoidance: Avoid oncoming obstacles to score points.
- Scrolling Background: The track scrolls vertically to simulate movement.
- Score Display: A seven-segment display shows the player's score.
- Collision Detection: The game detects collisions between the car and obstacles.
- VGA Output: The game is displayed on a VGA monitor.
- Multiple Obstacle Types: Obstacles come in three different car colors (blue, black, brown).
- car_control.vhd: Handles car movement based on button inputs. The car's position is updated according to the left and right button inputs.
- car_obstacle.vhd: Manages obstacle generation, movement, collision detection, and score updates. Obstacle positions are updated, and collisions with the car are detected.
- debouncer.vhd: Debounces button inputs to prevent glitches. Ensures that button presses are registered correctly without noise.
- hvsync_generator.vhd: Generates horizontal and vertical sync signals for VGA display. Responsible for video signal synchronization.
- led_control.vhd: Controls LEDs based on button inputs. The LED state toggles based on clock and reset signals.
- racegame_top.vhd: Top-level module connecting all components. It integrates all sub-modules and handles the overall game logic.
- rendering_logic.vhd: Renders the game graphics on the VGA display. Manages the pixel data and display output.
- scrolling_logic.vhd: Handles the scrolling of the background. Updates the scroll position to simulate movement.
- seven_segment_display.vhd: Controls the seven-segment display for the score. Converts the score value to the appropriate display format.
- pll.vhd: Phase-locked loop for clock generation.
- original/: Contains the original PNG images for the car and track.
- VHDL/: Contains VHDL files generated from the PNG images using a Python script. These files define constants for image data used in the game.
- convert_images.py: Converts PNG images into VHDL constants.
- run_conversion.py: Runs the conversion process.
- setup.py: Sets up the environment for running the Python scripts.
- Synthesis and Implementation: Synthesize and implement the VHDL code using your preferred FPGA development tools (e.g., Xilinx Vivado, Intel Quartus).
- Programming: Program the generated bitstream onto your FPGA development board.
- Connect VGA: Connect a VGA monitor to the FPGA board.
- Start the Game: The game should start automatically after programming.
- Control: Use the left and right buttons to move the car and avoid obstacles.
- Scoring: Your score increases as you successfully avoid obstacles.
- Game Over: The game ends if you collide with an obstacle.
- Obstacle Speed: Adjust the
SLOW_DOWN_FACTOR
incar_obstacle.vhd
to control the speed of obstacles. - Scroll Speed: Modify the
SCROLL_SPEED
constant inracegame_top.vhd
to change the scrolling speed. - Car/Obstacle Graphics: Replace the car image data in the
_car_graphic.vhd
files to use different car sprites. - Track Graphics: Modify the
STREET_IMAGE
data inrendering_logic.vhd
to change the track appearance.
- Python Packages:
Pillow
,numpy
(listed inrequirements.txt
) - IEEE Libraries:
std_logic_1164
,numeric_std
,std_logic_unsigned
- Custom Libraries:
red_car_graphic
,street_graphic
,blue_car_graphic
,black_car_graphic
,brown_car_graphic
(these should be included in your project)
This script converts PNG images into VHDL constants. The images are processed and the pixel data is extracted and formatted into VHDL syntax to be used in the game.
- Ensure you have
Pillow
andnumpy
installed. You can install them using:pip install -r requirements.txt
- Run the script:
python convert_images.py
This script automates the conversion process by calling convert_images.py
for all necessary images.
- Run the script:
python run_conversion.py
This script sets up the environment needed to run the image conversion scripts.
- Run the script:
python setup.py install
- This project is intended for educational purposes and can be expanded with additional features.
- Ensure that the PLL module (
pll.vhd
) is correctly configured for your FPGA board if you are using it. - The Python script in the
racegame/assets
directory is used to convert PNG images into VHDL files for the car and track graphics.