ECE 476 Final Project -- Spring 2003
Once the player has chosen the song in the introduction screen, the game will start and our program will ask the sound board to start to play the music. According to music beat, our program will draw arrows on the TV. The arrows will gradually rise up to the top of the screen. Arrows (10 different combinations altogether) will be drawn continuously in different direction to ensure the continuity of motion (dance). When an arrow reach the top of the screen, the player has to press the corresponding directional button at the same time. Once the player has pushed the button, the scoring system will run and calculate how much time has elapsed between the arrow reach the top of the screen and the button pressed, much like the human reaction timer in the lab. When the reaction time is calculated, one of the 4 comments, "Perfect", "Good", "Bad" and "Missed" will be displayed on the left hand side of the screen. We define a scoring system which points will be awarded base on the reaction time. Once the song is completed, points will be added and an overall grade will be displayed. To avoid cheating, player who pressed any of the 4 directional buttons for more than 1 second continuously will be regarded as cheating. The game will terminate immediately with all the statistics before the cheating occurs erased.
After the song is played and all the arrows are shown, the game will terminate and the player will be redirected to a end game statistics screen where player can review the accuracy of his/ her game play and the score will be shown. When player presses start again, the game will reset and the introduction screen will be shown.
Points are awarded according to the following scheme:
Highest score is stored in the memory so player can review their improvement over continuous game play and how their skills compare to other players.
Arrows and logo are drawn as above.
Music is stored in the flash memory in the form of a 2-D array. One array stores the musical notes to be played and the other array stores the length of the notes to be played. The arrow pattern is also stored in the form of a 2-D array in the flash memory. One array stores the pattern of the arrow to be shown and the other array stores the frame number where the arrow will be displayed.
Besides the above, some phrase of English characters and numbers are stored in flash so they can be displayed on the game screen.
The highest score is stored in eeprom so the value will be saved even the programming board is switched off.
Display and Gaming Programming Issues
The program is based on two state machines: 1) Non-game time state machine, and 2) Game time state machine. When the game has started, the game time state machine is turned on while the other is turned off. Otherwise, the non-game time state machine is turned on. Since we use TV as our main display, we have to make sure all the game logic and calculation must fit in 60 lines of video code. Thus, the main structure of our code is placed after the line 231 and carried out in between line 231 and line 30 of the next frame.
The display part of our design is modified from Video Generation with AVR demonstration code. However, we have customized several functions and also added several others to accommodate our needs. We have modified all the characters drawing code to take in parameters from flash to save memory in SRAM. We have also added several arrows drawing related functions. In addition, we have added keypad polling code to poll the button pressed by the player.
To make sure the animation display seems continuous to human, we have to make sure there are 30 frames displayed in each second. Due to this restriction, we are not able to draw all the graphics on the screen in one frame. We have derived a scheme to divide the graphics to be drawn in multiple frame by making use of a state counter. Once the program switches to a particular state, the internal counter is turned on and portions of graphics are drawn according to the count of the counter.
To display moving arrows, we have to continuously draw and erase the arrows. However, due to the time limit restriction, we are able to draw two arrows and delete two arrows at the same frame. Because of the need of displaying multiple arrows on the same screen, we have to draw the arrows at different frame. The 4 different sets of arrows can be drawn on the same screen according to the game time internal counter. The first set of arrows are drawn at the frame which remainder of division by 4 is 1. The second set of arrows are drawn at the frame which remainder of division by 4 is 2, where the same logic follows for the others. This pattern recycles until the end of the song. The position of each set of arrows in the whole song pattern are stored in an array. When the arrows are displayed and moved, their value in the corresponding position array will be updated. If it has reached the top, the arrows will not be processed anymore. To read the arrays storing the array pattern and array showing time, the program will turn to its state internal counter. Once the specified frame number is reached by the counter, the program will draw the arrow specified by the same position in another array.
The arrows need to move 80 position to reach the top from their starting position. We tried to move it by one position every frame. However, the program is not able to draw more than two arrows per frame, meaning that only one arrow can be shown on the same screen at the same time which is quite demanding to the game play. Thus, we are settled with having the arrows move by one position every 6 frames.
Another gaming programming issue is to determine the cheating condition. If this is not implemented, the player can always pressed all 4 buttons all the time to achieve 100% accuracy. Thus, we make use of the state internal counter to make sure no same key is pressed continuously for a whole second (30 frames).
Sound Programming Issues
One main part of our game is the functioning of playing the sound track at the right time. Our design is inspired by the Russian Bloc game in Spring 2002 Final Project. When a song is chosen by the player, the game board sends a signal to the sound board through the input and output port. When the game ends, the game board will send another signal to the sound board to turn off the music. Otherwise, the same song will be played continuously. The musically notes are made by the specified frequency of the musical notes (which can be found here in the code). We have written 4 songs which is:
To play the musical notes, the program will read the 2-D array storing the songs. The program will play the notes following the orders in the array. Once the data in the second array, which contains the length of the musical notes, reach the same number as the internal counter, the program will play the next notes. This scheme serves us well and we are able to play perfect melody resembled the real life music.