Difference between revisions of "F24: Space Fire"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Schedule)
(Project Video)
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Grading Criteria ===
 
<font color="green">
 
*  How well is Software & Hardware Design described?
 
*  How well can this report be used to reproduce this project?
 
*  Code Quality
 
*  Overall Report Quality:
 
**  Software Block Diagrams
 
**  Hardware Block Diagrams
 
**:  Schematic Quality
 
**  Quality of technical challenges and solutions adopted.
 
</font>
 
 
 
== Space Fire ==
 
== Space Fire ==
Parking Frenzy
 
  
 
== Abstract ==
 
== Abstract ==
Parking Frenzy is car parking video game. The player will be able to move the car in right or left direction, the road itself will be descending towards the car and will also consist of obstacles such as other vehicles. The road will have lanes through which the car must navigate to ultimately be able to slot itself into the right parking spot alongside the road. The parking spots will be randomly generated along the edge of the LED matrix and the player must navigate the car into the spot at the right time or else it will result in a crash. The difficulty of the game will increase as the player reaches a certain amount of points. The difficulty will increase in terms of the speed of the car and the number of obstacles. The final score of the player will be displayed at the end of every game. a speaker attached to the board will generate the game sounds.
+
Space Fire is an action-packed space shooting video game. The player pilots a spaceship that can move horizontally across the screen while enemy asteroids descend toward it. By using strategic maneuvers, the player must dodge incoming asteroids and fire projectiles to destroy them before they reach the spaceship. The objective is to survive as long as possible while accumulating a high score by eliminating asteroids. The game challenges the player with an increasing number of asteroids over time, at random sequences, requiring quick reflexes and tactical control. A detailed score breakdown and objective status are displayed on the screen, and immersive sound effects, generated through an attached speaker system controlled by an MP3 module, enhance the gameplay experience.
  
 
== Objectives & Introduction ==
 
== Objectives & Introduction ==
Line 50: Line 37:
 
* Create GitLab repository for project
 
* Create GitLab repository for project
 
|  
 
|  
* <span style="color:green">Completed</span>
+
* <span style="color: green">Completed</span>
* <span style="color:green">Completed</span>
+
* <span style="color: green">Completed</span>
 
|-
 
|-
 
! scope="row"| 2
 
! scope="row"| 2
Line 62: Line 49:
 
*Order necessary parts
 
*Order necessary parts
 
|
 
|
* <span style="color:green">Completed</span>
+
* <span style="color: green">Completed</span>
 
|-
 
|-
 
! scope="row"| 3
 
! scope="row"| 3
Line 72: Line 59:
 
*Read and familiarize with LED Matrix Datasheet
 
*Read and familiarize with LED Matrix Datasheet
 
|
 
|
* <span style="color:green">Completed</span>
+
* <span style="color: green">Completed</span>
  
  
Line 84: Line 71:
 
* Develop graphics driver for LED matrix and implement initial game objects
 
* Develop graphics driver for LED matrix and implement initial game objects
 
|
 
|
* <span style="color:orange">In progress</span>
+
* <span style="color:green"> Completed </span>
 
|-
 
|-
 
! scope="row"| 5
 
! scope="row"| 5
Line 104: Line 91:
 
* Additional accessories if required and finalization of hardware
 
* Additional accessories if required and finalization of hardware
 
|
 
|
* <span style="color:orange">In progress</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
 
|-
 
|-
 
! scope="row"| 6
 
! scope="row"| 6
Line 120: Line 107:
 
* Testing and debugging the game logic
 
* Testing and debugging the game logic
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color: green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
 
|-
 
|-
 
! scope="row"| 7
 
! scope="row"| 7
Line 134: Line 121:
 
* Integrate game sounds with game logic  
 
* Integrate game sounds with game logic  
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
 
|-
 
|-
 
! scope="row"| 8
 
! scope="row"| 8
Line 148: Line 135:
 
* Update the wiki page.
 
* Update the wiki page.
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
 
|-
 
|-
 
! scope="row"| 9
 
! scope="row"| 9
Line 161: Line 148:
 
* Test pause/play functionality
 
* Test pause/play functionality
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
* <span style="color:red">Not started</span>
+
* <span style="color: green"> Completed </span>
 
|-
 
|-
 
! scope="row"| 10
 
! scope="row"| 10
Line 183: Line 170:
 
*Update the wiki page.
 
*Update the wiki page.
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color:red">In progress</span>
* <span style="color:red">Not started</span>
+
* <span style="color:red">In progress</span>
* <span style="color:red">Not started</span>
+
* <span style="color:red">In progress</span>
* <span style="color:red">Not started</span>
+
* <span style="color:red">In progress</span>
 
|-
 
|-
 
|}
 
|}
Line 201: Line 188:
 
=== Hardware Design ===
 
=== Hardware Design ===
 
Discuss your hardware design here.  Show detailed schematics, and the interface here.
 
Discuss your hardware design here.  Show detailed schematics, and the interface here.
 +
 +
[[File:240_proj_flow_hardware.png]]
  
 
=== Hardware Interface ===
 
=== Hardware Interface ===
Line 206: Line 195:
  
 
=== Software Design ===
 
=== Software Design ===
Show your software design.  For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level.  Do not show the details of the code.  For example, do not show exact code, but you may show psuedocode and fragments of code.  Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
+
Show your software design.  For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level.  Do not show the details of the code.  For example, do not show exact code, but you may show psuedocode and fragments of code.  Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
 +
[[File:Software_Flow_240.png]]
  
 
=== Implementation ===
 
=== Implementation ===
This section includes implementation, but again, not the details, just the high level. For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.
+
The implementation of the "Space Fire" game involves several key components that work together to deliver a seamless gaming experience.
 +
The following subsections outline the high-level steps required for each component within the game.
 +
 
 +
1. Game Initialization
 +
 
 +
  Hardware Setup:
 +
    Initialize the SJ2 board and configure GPIO pins for user inputs (buttons) and other hardware interfaces (e.g., display, audio).
 +
    Set up the UART interface to communicate with the MP3 module for audio playback.
 +
  Game Variables:
 +
    Initialize global variables for game state, score, lives, and current level.
 +
 
 +
2. Input Handling
 +
 
 +
  Button Polling:
 +
    Continuously check the state of the buttons in a loop.
 +
  Accelerometer Polling:
 +
    Continuously check the readings from accelerometer.
 +
    Respond to user inputs for spaceship movement (left/right) and firing projectiles.
 +
 
 +
3. Asteroid Management
 +
 
 +
  Asteroid Generation:
 +
    Randomly spawn asteroids at the top of the screen at regular intervals.
 +
    Each asteroid is assigned a position and marked as active.
 +
  Asteroid Movement:
 +
    Update the position of each active asteroid as they descend toward the spaceship.
 +
  Collision Detection:
 +
    Check for collisions between asteroids and the spaceship or projectiles.
 +
    Implement logic to handle these collisions (e.g., decrease lives, destroy asteroids).
 +
 
 +
4. Projectile Management
 +
 
 +
  Firing Mechanism:
 +
    On user input, create and fire projectiles from the spaceship.
 +
    Store active projectiles in an array or list for tracking.
 +
  Projectile Movement:
 +
    Update the position of each active projectile, moving it upward on the screen.
 +
  Collision Check with Asteroids:
 +
    Detect collisions between projectiles and asteroids, and trigger appropriate reactions (e.g., destroy asteroid, increase score).
 +
 
 +
5. Display Management
 +
 
 +
  Rendering Game Elements:
 +
    Continuously refresh the display to render the spaceship, asteroids, and projectiles.
 +
    Clear the display and redraw all game elements in their updated positions.
 +
  Score and Lives Display:
 +
    Render the current score  on the display.
 +
 
 +
6. Audio Management
 +
 
 +
  MP3 Playback Initialization:
 +
    Initialize the MP3 module and set the desired volume level.
 +
  Audio Playback Control:
 +
    Trigger background music or sound effects based on game events (e.g., start of the game, collisions).
 +
  Handling Input for Sound Effects:
 +
    Implement playback logic for different sounds (e.g., shooting, explosions) when certain events occur.
 +
 
 +
7. Game Loop
 +
 
 +
  Main Game Loop:
 +
    Continuously check for user inputs, update game state, manage asteroids and projectiles, render graphics, and control audio in a timed loop to keep the game responsive.
 +
  State Management:
 +
    Implement state transitions (e.g., from playing to game over) based on game events, ensuring a smooth user experience.
  
 
== Testing & Technical Challenges ==
 
== Testing & Technical Challenges ==
Line 219: Line 271:
 
=== <Bug/issue name> ===
 
=== <Bug/issue name> ===
 
Discuss the issue and resolution.
 
Discuss the issue and resolution.
 +
 +
=== Flickering Display Due to printf Statements ===
 +
Issue:
 +
During debugging, the use of printf statements to monitor game states caused the display to flicker. This was due to blocking calls that interfered with the continuous rendering of graphics on the display.
 +
 +
Resolution:
 +
Minimizing printf Usage: Reduced the frequency of printf calls within the display rendering loop. Implemented logging to UART for debugging purposes while ensuring the critical rendering loop remained responsive.
 +
 +
=== Game Restart and Semaphore Issues ===
 +
Issue:
 +
When attempting to restart the game, deadlock situations arose due to mismanaged semaphores. The semaphores used for signaling game state transitions were not properly released or cleared, causing the game to become unresponsive and preventing the restart process.
 +
 +
Resolution:
 +
Proper Semaphore Handling: Upon game state reset, ensure that all semaphores are properly given (released) or deleted if no longer needed. Special attention was given to ensure that after the game over state, the semaphores would allow a new game instance to start correctly. Implemented a clear reset function that ensures all necessary variables and semaphores are initialized properly at the start of a new game. This approach reduces the risk of lingering states from previous sessions affecting new gameplay.
 +
 +
===MP3 Playback Timing Issues===
 +
Issue:
 +
Audio sometimes started late or unintentionally overlapped with gameplay actions, affecting the audio cues and overall user experience.
 +
 +
Resolution:
 +
Task Priority Adjustment: Increased the priority of the audio management task to ensure it could respond swiftly to commands and avoid interference from lower-priority tasks.
 +
Synchronized Playback Control: Implemented a mechanism to track the state of playback, ensuring new commands only executed once previous audio finished.
  
 
== Conclusion ==
 
== Conclusion ==
Line 225: Line 299:
 
=== Project Video ===
 
=== Project Video ===
 
Upload a video of your project and post the link here.
 
Upload a video of your project and post the link here.
 +
[[File:WhatsApp Image 2024-12-19 at 3.44.25 PM.jpeg]]
  
 
=== Project Source Code ===
 
=== Project Source Code ===

Latest revision as of 00:58, 20 December 2024

Space Fire

Abstract

Space Fire is an action-packed space shooting video game. The player pilots a spaceship that can move horizontally across the screen while enemy asteroids descend toward it. By using strategic maneuvers, the player must dodge incoming asteroids and fire projectiles to destroy them before they reach the spaceship. The objective is to survive as long as possible while accumulating a high score by eliminating asteroids. The game challenges the player with an increasing number of asteroids over time, at random sequences, requiring quick reflexes and tactical control. A detailed score breakdown and objective status are displayed on the screen, and immersive sound effects, generated through an attached speaker system controlled by an MP3 module, enhance the gameplay experience.

Objectives & Introduction

Show list of your objectives. This section includes the high level details of your project. You can write about the various sensors or peripherals you used to get your project completed.

Team Members & Responsibilities

  • Mehul Mangave
  • Parth Mhakavekar
  • Smitha Kedila


Schedule

Week# Start Date End Date Task Status
1
  • 10/12/2024
  • 10/13/2024
  • 10/18/2024
  • 10/13/2024
  • Read previous projects, gather information and discuss among the group members.
  • Create GitLab repository for project
  • Completed
  • Completed
2
  • 10/19/2024
  • 10/20/2024
  • Order necessary parts
  • Completed
3
  • 10/26/2024
  • 11/01/2024
  • Read and familiarize with LED Matrix Datasheet
  • Completed


4
  • 11/02/2020
  • 11/08/2020
  • Develop graphics driver for LED matrix and implement initial game objects
  • Completed
5
  • 11/09/2020
  • 11/09/2020
  • 11/09/2020
  • 11/09/2020
  • 11/10/2020
  • 11/15/2020
  • 11/15/2020
  • 11/15/2020
  • Finalize wiki schedule
  • Order circuit boards components and complete the design for printing
  • circuit board and component assembly
  • Circuit board testing
  • Additional accessories if required and finalization of hardware
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
6
  • 11/16/2020
  • 11/22/2020
  • Integration of circuit boards and microcontroller
  • Game logic development
  • Testing and debugging the game logic
  • Completed
  • Completed
  • Completed
7
  • 11/23/2020
  • 11/29/2020
  • Integrate game logic code with LED matrix
  • Integrate game sounds with game logic
  • Completed
  • Completed
8
  • 11/30/2020
  • 12/06/2020
  • Integrate subsystem
  • Finalizing the video game
  • Update the wiki page.
  • Completed
  • Completed
  • Completed
9
  • 12/07/2020
  • 12/13/2020
  • Address bugs during testing of integrated system
  • Test pause/play functionality
  • Completed
  • Completed
  • Completed
10
  • 12/16/2020
  • 12/14/2020
  • 12/14/2020
  • 12/14/2020
  • 12/16/2020
  • 12/16/2020
  • 12/16/2020
  • 12/16/2020
  • Final Demo
  • Update Gitlab repo with final code.
  • Update test video.
  • Update the wiki page.
  • In progress
  • In progress
  • In progress
  • In progress


Parts List & Cost

Give a simple list of the cost of your project broken down by components. Do not write long stories here.

Design & Implementation

The design section can go over your hardware and software design. Organize this section using sub-sections that go over your design and implementation.

Hardware Design

Discuss your hardware design here. Show detailed schematics, and the interface here.

240 proj flow hardware.png

Hardware Interface

In this section, you can describe how your hardware communicates, such as which BUSes used. You can discuss your driver implementation here, such that the Software Design section is isolated to talk about high level workings rather than inner working of your project.

Software Design

Show your software design. For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level. Do not show the details of the code. For example, do not show exact code, but you may show psuedocode and fragments of code. Keep in mind that you are showing DESIGN of your software, not the inner workings of it. Software Flow 240.png

Implementation

The implementation of the "Space Fire" game involves several key components that work together to deliver a seamless gaming experience. The following subsections outline the high-level steps required for each component within the game.

1. Game Initialization

 Hardware Setup: 
   Initialize the SJ2 board and configure GPIO pins for user inputs (buttons) and other hardware interfaces (e.g., display, audio).
   Set up the UART interface to communicate with the MP3 module for audio playback.
 Game Variables: 
   Initialize global variables for game state, score, lives, and current level.

2. Input Handling

 Button Polling:
   Continuously check the state of the buttons in a loop.
 Accelerometer Polling:
   Continuously check the readings from accelerometer.
   Respond to user inputs for spaceship movement (left/right) and firing projectiles.

3. Asteroid Management

 Asteroid Generation:
   Randomly spawn asteroids at the top of the screen at regular intervals.
   Each asteroid is assigned a position and marked as active.
 Asteroid Movement:
   Update the position of each active asteroid as they descend toward the spaceship.
 Collision Detection:
   Check for collisions between asteroids and the spaceship or projectiles.
   Implement logic to handle these collisions (e.g., decrease lives, destroy asteroids).

4. Projectile Management

 Firing Mechanism:
   On user input, create and fire projectiles from the spaceship.
   Store active projectiles in an array or list for tracking.
 Projectile Movement:
   Update the position of each active projectile, moving it upward on the screen.
 Collision Check with Asteroids:
   Detect collisions between projectiles and asteroids, and trigger appropriate reactions (e.g., destroy asteroid, increase score).

5. Display Management

 Rendering Game Elements:
   Continuously refresh the display to render the spaceship, asteroids, and projectiles.
   Clear the display and redraw all game elements in their updated positions.
 Score and Lives Display:
   Render the current score  on the display.

6. Audio Management

 MP3 Playback Initialization:
   Initialize the MP3 module and set the desired volume level.
 Audio Playback Control:
   Trigger background music or sound effects based on game events (e.g., start of the game, collisions).
 Handling Input for Sound Effects:
   Implement playback logic for different sounds (e.g., shooting, explosions) when certain events occur.

7. Game Loop

 Main Game Loop:
   Continuously check for user inputs, update game state, manage asteroids and projectiles, render graphics, and control audio in a timed loop to keep the game responsive.
 State Management:
   Implement state transitions (e.g., from playing to game over) based on game events, ensuring a smooth user experience.

Testing & Technical Challenges

Describe the challenges of your project. What advise would you give yourself or someone else if your project can be started from scratch again? Make a smooth transition to testing section and described what it took to test your project.

Include sub-sections that list out a problem and solution, such as:

<Bug/issue name>

Discuss the issue and resolution.

Flickering Display Due to printf Statements

Issue: During debugging, the use of printf statements to monitor game states caused the display to flicker. This was due to blocking calls that interfered with the continuous rendering of graphics on the display.

Resolution: Minimizing printf Usage: Reduced the frequency of printf calls within the display rendering loop. Implemented logging to UART for debugging purposes while ensuring the critical rendering loop remained responsive.

Game Restart and Semaphore Issues

Issue: When attempting to restart the game, deadlock situations arose due to mismanaged semaphores. The semaphores used for signaling game state transitions were not properly released or cleared, causing the game to become unresponsive and preventing the restart process.

Resolution: Proper Semaphore Handling: Upon game state reset, ensure that all semaphores are properly given (released) or deleted if no longer needed. Special attention was given to ensure that after the game over state, the semaphores would allow a new game instance to start correctly. Implemented a clear reset function that ensures all necessary variables and semaphores are initialized properly at the start of a new game. This approach reduces the risk of lingering states from previous sessions affecting new gameplay.

MP3 Playback Timing Issues

Issue: Audio sometimes started late or unintentionally overlapped with gameplay actions, affecting the audio cues and overall user experience.

Resolution: Task Priority Adjustment: Increased the priority of the audio management task to ensure it could respond swiftly to commands and avoid interference from lower-priority tasks. Synchronized Playback Control: Implemented a mechanism to track the state of playback, ensuring new commands only executed once previous audio finished.

Conclusion

Conclude your project here. You can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?

Project Video

Upload a video of your project and post the link here. WhatsApp Image 2024-12-19 at 3.44.25 PM.jpeg

Project Source Code

References

Acknowledgement

Any acknowledgement that you may wish to provide can be included here.

References Used

List any references used in project.

Appendix

You can list the references you used.