Software Design:

 

In summary, the four most important portions of our 3,500 line code are:

Creation of Different Characters

Shooting down different characters

Sharp Shooter Game Code

TV Video Code provided by Professor Bruce Land

 

Creation of Different Characters

When the game starts, the program initially erases all of the animation in the introductory screen and draws all of the lines, bullets, and life bars in a series of 16 frames because the microprocessor only has limited time to draw the animations during the TV scan lines 230-260 and 1-30 to avoid visual artifacts. If one of the 9 buttons is pressed by the man maker and if that particular does not exist yet, a new man would be created at the corresponding square. If the player desires to create a particular type of man from the four available, he can press one of the 4 pushbuttons first to choose the man he wants to create. From left to right, the four types of people, each with unique properties, you can create are:

 

Normal Guy: He dies in one shot but if not killed in 5 seconds, he jumps up and the opposing player loses 1 health.

Bomb: If the bomb is shot, bomb explodes and the opposing player loses one health. Disappears in 5 seconds with no penalty to life if not shot.

Samurai Guy: He also dies in one shot but opposing player stands to lose one

health if the gunman shoots the samurai guy while he holds his dual swords. Disappears in 6 seconds and the opposing player loses 1 health if not shot.

Headless Super Man: He is the “tank” of the game and takes 3 shots to kill.

However, gunman stands to gain one health if Headless Super Man is killed. He disappears in 8 seconds and the opposing player loses 1 health if not killed.

 

Whatever man the player chooses to create, all four types of characters would move around in his designated square and up to 9 characters can dance around in their respective square. Moving all 9 relatively large characters simultaneously was a tricky code to write because of significant timing issues since each frame had only has enough time to create and erase a single man. To allow up to 9 characters to move at the same time without visual artifacts, each of the nine men is updated one of 9 frames. In a single frame, one man would be erased, its position would be updated, and the new updated man with the new position would be drawn. Then the next frame will erase the next man in the next square, its position would be updated, and the new updated man with the new position would be drawn. This would continue until all 9 men have been updated with their new position and then the program would go back to update the first man's position and the process repeats itself. This means that each of the 9 men's positions is updated every 9/60 seconds since each frame is 1/60 seconds. Whenever a man attempts to cross over its square, the man's velocity changes in the opposite direction so that it bounces back into its own square.

 

Shooting down different characters

As described in the hardware section, the gun operates by having a photodiode that outputs a 1 when white light is detected and a 0 otherwise. The trickiest part of the code was to use this photodiode information from the gun to be able to distinguish which of the 9 possible men the gun shot at if any at all.

When the trigger is pulled, the program goes into a whole new state consisting of another 11 frames. In the first frame, all of the men are deleted from the screen and the photodiode checks if any white light is observed. If white light has been observed while all of the men are deleted from the screen, that means that the person is probably pointing at a stationary position with white light such as the white video lines in the grid, the timer, the life bar, or the bullets in the screen. If this happens, the program ignores the white light in later frames and knows that no men have been shot even though the gun's photodiode may say white light is detected.

After all men have been deleted in the first frame, the second frame will create the first man (if it exists) and the photodiode detects whether a white light has been detected in that frame. If the photodiode detects a white light in this frame and has not detected any white light in the first frame, the program concludes that the gun has shot at the first man. Otherwise, the third frame will then delete the first man (if it exists) and create the second man (if it exists). If the photodiode detects a white light in this third frame and has not detected any white light in the second frame, the gun has shot at the second man. This process repeats until it reaches the 9 th man in the 10 th frame where the 10 th frame will delete the 8 th guy and create the 9 th guy. In the 11 th frame, the 9 th man is deleted and the state is reset back to where it updates the men's movements. Assuming that the gun is stationary during these frames after the gun is shot, at most one target will be shot at any given time and zero will be shot at if the player with the gun misses. The drawback of implementing the code this way to detect where the gun shot at is that any men that have been created will blink 11/60 th of a second every time the trigger is pulled.

 

Sharp Shooter Game Code

The rest of the game consisted of creating the peripherals of the game that made it exciting and challenging at the same time. In the main menu, it displays the game name “Sharp Shooter” along with a guy running around the screen waiting to be shot. The game starts once the gun player pulls the trigger. The gun player begins with 5 lives and the objective would be to survive for 60 seconds without losing all of his lives. A timer on the bottom right of the screen will display the amount of seconds left he must survive for to win. The objective of the man maker would be obviously to kill the gunman within the 60 seconds by making a variety of men to baffle the gunman. The game ends when either the 60 seconds has elapsed or the gunman is left with 0 lives and the conclusion screen is displayed.

The gun is limited to shoot at a max speed of 3 times per second so that people don't go trigger happy and forget to aim. This reduces the constant flashing of the men each time the trigger is pulled. The limited rate that a gunman can shoot also would make him think more before he makes each shot. The player has a maximum of 6 bullets and must step on the pedal to replenish his 6 bullet supply. The gun would not shoot if the gunman has run out of bullets.

Our game has various sound effects when the gun is shot, a life is lost, a life is gained, and when a man is killed consisting of between 1-3 notes. It also has a beginning and ending melody played in the main menu and the conclusion of the battle. The code to generate sound is similar to the one in Professor Land 's example code in lab 4 that uses the timer0 square wave generator to make tones.

When the game ends, the conclusion screen displays the winner's name (either Man Maker or Gunman) and the game will start over to the main menu once the gunman steps on the reload pedal.

 

Things you tried which did not work

  We initially used a bitmap to draw our characters and we ran into timing issues and visual artifacts. Drawing a bitmap is inefficient since drawing video_pt of black points is meaningless and wastes precious drawing time. Instead, we later created each man using functions containing every video_pt of a character instead of a bitmap.

In the planning phase of our game, we originally planned to have each of the 9 squares connected to a motor that will raise a man up one at a time. The player will then physically hit the man down and the television will then display what has been hit. This idea was abandoned partially because we realized that the costs of the 9 motors would easily make us over budget and that adding a gun to our game and using switches instead to make it an one on one game would make the game much more entertaining.