ECE5760 Project

Space Shooter

Group Members

Hardik Hedaoo (hgh36)

Mahathi Andavolu (ma2339)

Koushani Das (kd496)

Lianzhi Zhu (lz566)

Introduction


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.

Flowdiagram

Figure 1. Block Diagram of Space Shooter.

Mathematical Background


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.

path

Figure 2. Path followed by the enemies

RTL Design


Board

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.

VGA Controller

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.

VGA Pixel Drawing

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.

Coordinate and Color Calculation

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.

VGA color

Figure 4. Coordinate and Color Calculation

Player and Enemy Positioning

Position Update Logic

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.

Boundary Conditions

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 and Scoring

Collision Logic

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.

Scoring System

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 and Input Handling

Memory-Mapped I/O

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

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.

Main Game Loop

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.

Synchronization and Timing

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.

qsys

Figure 5. Qsys Layout

HPS Design for Space Shooter


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.

User Interactions

The HPS facilitates several critical user interactions, making the game both dynamic and responsive:

Player Movement

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:

Firing Bullets

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.

Game Controls

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.

Initialization and Game State 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.

Initialization Protocol

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 Mapping

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.

Memory Mapping Code

Communication Protocol

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.

Player and Enemy Position Updates

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:

PEU image

Handling User Inputs

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.

HUI image

VGA Display Management

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.

VGA image

Score and Time Tracking

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.

STT image

Results & Testing


Results

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.

Game Demonstration

The video and accompanying images demonstrate key features of the game, including:

These elements highlight the system's ability to process inputs and update the game state in real-time, ensuring a smooth and engaging user experience.

1

2

3

4

5

Figure 6. Development of the Game

Performance Metrics

Compilation Time

Figure 7. Compilation Report

Testing

To ensure the correctness and robustness of our design, we employed a rigorous testing methodology that included both simulation and hardware testing.

Unit Testing in ModelSim

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:

By validating each module independently, we built confidence in the system's overall correctness and limited the scope of potential issues during integration.
modelsim

Figure 8. Gravity Motion Solver in Polar Coordinates

Integration Testing

Once individual modules were verified, we integrated them into the complete game system and simulated the entire design in ModelSim. This step included:

FPGA Implementation and Testing

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:

Experimentation and Challenges

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.

Implementing Gravitational Motion

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:

Despite extensive efforts and multiple iterations, we were unable to achieve the desired gravitational effects in the hardware implementation. This led us to focus on a more simplified, yet engaging, game mechanic for "Space Shooter."

matlab

Figure 9. MATLAB Implementation.

Exploring Different Game Ideas

Throughout the project, we explored various game concepts to find the most suitable one for FPGA implementation. This exploration included:

After evaluating these options, we concluded that a space shooter game offered the best balance of complexity and engagement, making it an ideal candidate for FPGA implementation. This decision allowed us to focus on showcasing real-time graphics, collision detection, and user interaction effectively.

Hardware and Timing Constraints

Another significant challenge was managing hardware and timing constraints inherent to FPGA development. Specific issues included:

Lessons Learned

Through these challenges, we gained valuable insights and experience in FPGA development, particularly in the areas of:

By documenting these complications and our responses to them, we aim to provide a comprehensive view of the development process, showcasing both our problem-solving skills and the practical challenges of FPGA-based game development.

Conclusion


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.

Demonstration Video


References


[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


Appendix A


The group approves this report for inclusion on the course website.
The group approves the video for inclusion on the course YouTube channel.


Appendix B


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