Hardik Hedaoo (hgh36)
Mahathi Andavolu (ma2339)
Koushani Das (kd496)
Lianzhi Zhu (lz566)
This project involves the development of a real-time game called "Space Shooter" on the DE1-SoC FPGA platform, utilizing the ARM/FPGA capabilities of the system. "Space Shooter" leverages memory-mapped I/O for graphical output on a VGA display and direct interaction with hardware components for responsive gameplay. Players control a spaceship using keyboard inputs to move and shoot bullets at on-screen enemies, with the game tracking player scores and collision detection in real-time. The implementation emphasizes efficient use of hardware resources, precise timing for smooth animation, and effective collision detection algorithms to ensure engaging and dynamic gameplay. This report details the design, implementation, and testing phases of the project, highlighting the challenges encountered and solutions developed to achieve the desired performance and functionality.
Figure 1. Block Diagram of Space Shooter.
The "Space Shooter" project involves several mathematical concepts and techniques that are essential for its development and functionality. Here are the key mathematical elements involved:
Summary: The "Space Shooter" game combines these mathematical principles to create an engaging and dynamic gaming experience. From coordinate geometry and vector mathematics for movement and collision detection to timing control for smooth animations, these mathematical concepts form the backbone of the game's implementation.
Figure 2. Path followed by the enemies
Figure 3. FPGA Board
The RTL design for Space Shooter includes the VGA controller for rendering graphics, player and enemy positioning, collision detection, and scoring. The design emphasizes efficient pixel drawing using parallel processing, real-time updates with combinational logic, and memory-mapped I/O for interaction with hardware components.
The first step in our design was to implement the VGA controller, a crucial component for rendering the game's graphics on the screen. This controller generates the necessary synchronization signals and manages pixel color data based on the current game state.
To ensure efficient pixel drawing, we utilized parallel processing wherever possible. The VGA controller takes the coordinates and color information and outputs the correct pixel data to the screen. By processing multiple pixels in parallel, we reduced the critical path and avoided overflow issues that could occur with serial processing. This parallel approach ensures smooth and flicker-free graphics rendering.
The VGA controller uses combinational logic to calculate the color of each pixel based on the game objects' positions and states. We employed fixed-point arithmetic with a precision of 1.17 to maintain a high level of accuracy without excessive resource usage. This precision is sufficient for the graphical requirements of the game and ensures that each pixel's color is computed accurately.
Figure 4. Coordinate and Color Calculation
The player and enemies' positions are updated using combinational logic that takes the current position, velocity, and input signals. This approach allows for real-time updates and immediate feedback to user inputs. For example, the player's position is adjusted based on keyboard inputs, and enemies' positions are updated based on predefined movement patterns.
To handle boundary conditions, such as the player or enemies moving off-screen, we implemented checks within the position update logic. If an object reaches the edge of the screen, its position is constrained to stay within the visible area. This ensures that all game objects remain within the playable area and interact correctly with other objects.
Collision detection is performed using bounding box calculations, which check for overlaps between the player, enemies, and bullets. This combinational module computes whether any two bounding boxes intersect, indicating a collision. By implementing this logic in parallel for multiple objects, we achieved efficient and timely collision detection without a significant increase in the critical path.
The scoring system is tightly integrated with the collision detection logic. Whenever a bullet collides with an enemy, the enemy is marked as inactive, the bullet is deactivated, and the player's score is incremented. The score update is handled using combinational logic, ensuring that the score is updated immediately upon a collision.
Memory mapping is crucial for interfacing with the FPGA's hardware components. The VGA character and pixel buffers, as well as enemy position registers, are mapped into the HPS address space. This allows the software to read and write directly to these hardware components using standard memory instructions.
Keyboard input is handled using a separate thread, allowing the main game loop to run uninterrupted. The keyboard thread reads inputs in non-canonical mode, providing immediate feedback to the player's actions. This approach ensures a responsive gaming experience, as the player's inputs are processed in real time.
The main game loop integrates all the components described above, managing the overall game state and coordinating the interactions between the player, enemies, bullets, and the VGA controller. The game loop updates the player and enemy positions, checks for collisions, updates the score, and renders the updated game state to the screen.
To maintain a consistent frame rate and ensure smooth gameplay, the game loop includes a delay mechanism. By measuring the time taken for each iteration and adjusting the delay accordingly, we achieved a consistent frame rate. This approach ensures that the game runs smoothly, providing a seamless experience for the player.
Figure 5. Qsys Layout
The onboard HPS (Hard Processor System) in the "Space Shooter" project serves as the central interface for the user, enabling a range of interactions and controls that enhance the gameplay experience. Through the HPS, users can perform various actions such as:
While the user cannot directly manipulate the game's internal logic or rendering process, the HPS provides a robust interface through various GPIO ports and memory-mapped I/O regions, allowing for seamless interaction with the game mechanics and hardware.
The HPS facilitates several critical user interactions, making the game both dynamic and responsive:
Users can control the movement of the player's spaceship using keyboard inputs. The HPS processes these inputs in real-time, updating the spaceship's position on the VGA display instantly. The controls include:
Pressing the 'F' key allows the player to fire bullets. The HPS handles the detection of this key press and initiates the bullet firing process, updating the bullet's position and state.
Additional controls provided by the HPS include starting, stopping, and resetting the game. These controls ensure that the player can manage the game state effectively, providing a user-friendly interface for gameplay management.
A significant function of the HPS is to initialize the game and manage its state throughout the gameplay. This involves setting up initial positions, scores, and other game parameters, ensuring the game starts in a well-defined state.
The initialization process is crucial for setting up the game environment. This involves configuring the VGA display, initializing player and enemy positions, and setting initial game parameters such as score and time.
Memory-mapped I/O is used extensively to facilitate communication between the HPS and FPGA. This allows the HPS to read and write directly to hardware components, such as the VGA display and enemy position registers, using standard memory instructions.
The communication between the HPS and FPGA is handled through a well-defined protocol, ensuring smooth and efficient data exchange. This protocol allows the HPS to manage game state updates, such as player movements and bullet firing, in real-time.
The HPS reads the current positions of the player and enemies from memory-mapped registers and updates them based on user inputs and game logic. This involves:
A dedicated thread is used to handle user inputs, ensuring that the main game loop runs uninterrupted. This thread reads keyboard inputs in non-canonical mode, allowing for immediate response to user actions.
The HPS manages the VGA display, ensuring that all game objects are rendered correctly and in real-time. This involves setting pixel values, drawing shapes, and updating the screen with the latest game state.
The HPS also tracks the player's score and the time elapsed since the game started. This information is displayed on the VGA screen, providing real-time feedback to the player.
To validate the functionality and performance of the "Space Shooter" project, we documented various aspects of the system's behavior and collected performance metrics. While photos alone cannot fully convey the effectiveness of our implementation, we have included key images to illustrate specific results. The demo video is present in the demonstration section of the page.
The video and accompanying images demonstrate key features of the game, including:
Figure 6. Development of the Game
Figure 7. Compilation Report
To ensure the correctness and robustness of our design, we employed a rigorous testing methodology that included both simulation and hardware testing.
We began by unit testing individual RTL modules in ModelSim, verifying their functionality in isolation before integrating them into the larger system. This approach helped identify and resolve issues early in the development process. Specific tests included:
Figure 8. Gravity Motion Solver in Polar Coordinates
Once individual modules were verified, we integrated them into the complete game system and simulated the entire design in ModelSim. This step included:
After successful simulations, we transferred the Verilog code to the FPGA and conducted extensive hardware testing. Using the SignalTap feature in Quartus, we monitored internal signals to debug and optimize the design. Key testing steps included:
During the development of the "Space Shooter" project, we encountered several challenges that required creative problem-solving and adaptation. This section outlines the key complications we faced and the approaches we took to address them.
One of the initial goals of our project was to incorporate realistic gravitational motion for game objects, such as the player's spaceship and bullets. We successfully implemented this feature in MATLAB, where the physics calculations could be handled more straightforwardly. However, translating these complex behaviors to Verilog and running them on the FPGA proved to be a significant challenge. The primary issues included:
Figure 9. MATLAB Implementation.
Throughout the project, we explored various game concepts to find the most suitable one for FPGA implementation. This exploration included:
Another significant challenge was managing hardware and timing constraints inherent to FPGA development. Specific issues included:
Through these challenges, we gained valuable insights and experience in FPGA development, particularly in the areas of:
The "Space Shooter" project has been a comprehensive and enriching endeavor, blending elements of hardware design, software development, and real-time system integration. Through the use of FPGA and HPS, we successfully created a responsive and interactive game that highlights the capabilities of parallel processing and memory-mapped I/O. Despite facing challenges such as implementing gravitational motion and managing hardware constraints, we adapted our approach to focus on achievable and engaging game mechanics. This project not only demonstrates the practical application of theoretical concepts but also underscores the importance of flexibility and problem-solving in engineering. The final product, supported by rigorous testing and optimization, showcases our ability to deliver a robust and enjoyable gaming experience.
[1] Quartus 18.1 Webpage [Online]. Available: https://people.ece.cornell.edu/land/courses/ece5760/DE1_SOC/HPS_peripherials/Examples_version_18.html
[2] VGA Graphics [Online]. Available: https://people.ece.cornell.edu/land/courses/ece5760/DE1_SOC/HPS_peripherials/univ_pgm_computer.index.html
[3] De1-SoC board Datasheet [Online]. Available: https://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=167&No=836
[4] Physics Simulation [Online]. Available: http://mw.concord.org/modeler/?gad_source=1&gclid=Cj0KCQjwgJyyBhCGARIsAK8LVLNm1rU12j-7_3ywOgdvYhqIBCkFwXqeGUJzpXynFjign6uH8Gj6dO0aAu4oEALw_wcB
The group approves this report for inclusion on the course website.
The group approves the video for inclusion on the course YouTube channel.
This appendix contains the Verilog source codes and other necessary files we used in this project.
The top-level module: space_shooter.v
C code: space_shooter.c