DEFENDER





                     I.   CIRCUMSTANCES

                     Aliens from a distant solar system are swarming over the planet
                     Humanis. They're kidnapping Humanoids and mutating them into a
                     permanent part of the alien force. Their mission is to transform all
                     of the Humanoids before destroying the entire planet.

                      First, they infest the planet with Landers which close in on the
                     cities, abducting the Humanoids. Then the attack intensifies.
                     Baiters, Swarmers, and Bombers terrorize the skys. And then,
                     when you least expect it, a deadly Pod collides with your Spaceship,
                     and blasts you to pieces.

                     II. YOUR MISSION

                      As Captain of the Spaceship Defender, your mission is to destroy
                     the alien force and save the Humanoids. Your speed and skill have
                     earned you this heroic mission. When Humanoids are abducted, you'll
                     have to destroy the Lander and catch the falling Humanoid before
                     safely returning him to the city below.

                     MUTANT TAKEOVER

                      If Defender does not succeed in protecting a Humanoid, a Lander
                     abducts him and carries him up into space and transforms him into a
                     Mutant. Mutants then return to attack the planet. When all of the
                     Humanoids become Mutants, the cities blow up and disappear. 
 
                      III. SCORING

                     POINT VALUES: Aliens Destroyed
                     Lander........150
                     Mutant........150
                     Swarmer.......200
                     Baiter........200
                     Bomber........250
                     Pod..........1000

                     POINTS VALUES: Humanoid Rescue Mission
                     Points Plus 150 For Lander
                     Humanoid falls but lives.....................250
                     Caught but not brought back to the city......500
                     Caught and brought back to the city.........1000

               ABOVE IS A BRIEF INTRODUCTION TO THE GAME, BELOW IS THE
               STARTING POINT FOR OUR STRUCTURES AND VARIABLES.  ALSO
               INCLUDED IS A LIST THE BASIC FUNCTIONS AND THEIR INITIAL PURPOSE
               SORRY THIS SITE IS NOT GOING TO WIN POINTS FOR AESTHETIC BEAUTY.
            
 
Team Members:
  Mike Wigdzinski: Sound system, Input(keyboard and joystick), Intro, Credits, and Art work.
  Justin Lewis: Memory system.
  Mike Link: Graphics system.
  Brian Smith: AI.

Problem Description:
  Designing all of the systems seperately, and individually, then trying to combine them into a final working program.  We also had no template to go from, and no clear description of what it was we had to do.

Implementation:
  Video Subsystem: For each gameloop that something has changed, the list of structures are looped through and drawn on the radar and gamespace.  For the ships and bullets, sprites are used. Also
for the scrolling background, sprites are used.  Scrolling is performed by changing the starting
position of the screen when the Defender is close to the edges.

  Memory Subsystem: Keeps track of all the enemy ships and bullets in lists.  Essentially it's just an array of   ships, and an array of bullets.  There are 2 functions for getting items from the lists.  These just look through the list until they find an item that's not dead.  If there are no living ships a dead ship is returned.  To add a ship or bullet, it looks through the list until it finds a dead ship or bullet and just overwrites it with new info.

  AI Subsystem:  Everything on the screen moves towards the defender, this keeps the routines from having to check bounds.

  Sound subsystem:  Loads a sound file into the sound buffer.  Then input the length of the sound file.  First step is to set up the dma, then set up the soundsegment and initialize the dsp.  Next turn up the volume and turn on the speaker. Then write to the dsp.  Finally play the sound.

  Input subsystem:  Gets input from the keyboard or joystick.  This invloves polling the joystick which was calibrated at the beginning of the game.  Polling occurs every gameloop.  The keyboard input is pretty self-explanatory by using the keyboard interrupt.  The game is set up to use either of the inputs
 
  Intro, Credits, and art work:   All a product of good old fashioned hard work.  Loads pcx images and sprites and blasts them to the screen.  Those images are the beautiful and majestic artwork we created.

ShipStruct:
 Word X,Y                     Current position
 Word TypeS                 Type of ship
 Word Firing                  Whether or not it has a bullet on the screen.
 Word BulletNum          The number of that bullet.
 Word MoveDir              Direction ship is moving.
 Word CapturePerson   Is it capturing a person.
 Word OnScreen           Is it on the current gamescreen
Justin Lewis 

BulletStruct
 Word X,Y                    Current position
 Word TX, TY               Target X and Y positions.
 Word E                        E for drawing lines(moving bullets)
 Word TypeB                Type of bullet
 Word ShipNum           The number of the ship that shot it..
 Word Onscreen           Is it off the viewable screen? If so delete
Justin Lewis 

DefenderStruct
 Word X,Y                    Current position.
 Word LocalX                 X position on the viewable screen.
 Word BombsLeft         Number of bombs left
 Word ShipsLeft           Number of ships we have left.
 Word ExhaustFlame    Is the exhaust flame currently on?
 Word Speed                Defender's current speed.
 Word Direction            The current direction we're facing.
Justin Lewis



 
Routines:
 
Gameloop
Purpose:  Loops through gameplay procedures until game is over
  Inputs:
    enemytimer, deftimer, bultimer, bulmax, defmax, enemymax
    all flags from polljoystick and intkeyboard  
   Outputs:
    calls updatedefender, aimain, movebullets, and polljoystick
Justin Lewis

 Routines For Enemy Ships:
         All of these procedures will be used for keeping track of
         modifying, adding, and deleting enemy ships throughout the game
 
GetFirstShip
  Purpose: Get the first ship from the list.
    Inputs: None
    Outputs: ShipStruct WShip
Justin Lewis

GetNextShip
  Purpose: Get the next ship from the list.
     Inputs:None
     Outputs: ShipStruct WShip
Justin Lewis

GetShip
 Purpose: Get a specific ship, can be used for modifying ships.
   Inputs:
     Word ShipNum
   Outputs:
     ShipStruct WShip
Justin Lewis

SetShip
  Purpose:  Set info for a specific ship.
    Inputs:
      Word ShipNum
       ShipStruct WShip
    Ourputs: None
Justin Lewis

UpdateShip
 Purpose: Write new data to a ship struct in memory.
   Inputs: WShip, CurrentShipNum
   Outputs:
     none
Justin Lewis
 
AddNewShip
 Purpose: Add a new predefined ship.
   Inputs:
     ShipStruct WShip
   Outputs:
     none
 Justin Lewis

GetCurrentShipNum
  Purpose: Get the current ship number
    Inputs:none
    Outputs:
      AX: CurrentShipNum

Routines for the Bullets:
 
GetFirstBullet
  Purpose: Get the first bullet from the list.
    Inputs: None
    Outputs: BulletStruct WBullet
Justin Lewis

GetNextBullet
  Purpose: Get the next bullet from the list.
     Inputs:None
     Outputs: BulletStruct WBullet
Justin Lewis

UpdateBullets
 Purpose:  Modify Bullet info.
   Inputs:
      Word CurrentBulletNum
     BulletStruct WBullet
   Outputs:
    none
Justin Lewis

GetBullet
 Purpose: Get a specific bullet from our list.
   Inputs:
     Word BulletNum
   Outputs:
     BulletStruct WBullet
Justin Lewis

SetBullet
  Purpose: Set a specific bullet to our list
    Inputs:
      Word BulletNum
       BulletStruct WBullet
   Outputs: None
Justin Lewis
 
UpdateBullet
 Purpose:  Modify the data stored in a specific bullet in our list.
   Inputs:
     Word CurrentBulletNum
     BulletStruct WBullet
   Outputs: None
Justin Lewis
 
AddNewBullet
 Purpose:  Add a new predefined bullet to the list.
   Inputs:
     BulletStruct WBullet
   Outputs: None
Justin Lewis

GetCurrentBulletNum
  Purpose: Get the current bullet number
    Inputs:none
    Outputs:
      AX: CurrentBulletNum
Justin Lewis

 
Routines for the defender:

UpdateDefender
Purpose:  Update the defender position and add bullets if necessary (determined from flags).
   Inputs:
    Movement flags
    DefenderStruct Defender
   Outputs: None.
Justin Lewis 
   



Routines for Updating the Screen:
 
InitScreenBuffer
   Purpose:  Initialize ScreenBuffer with the frame pcx file.
     Input: pcx file,ScreenBuffer
     Output:  Changed ScreenBuffer
Michael Link

InitBuffers
   Purpose:  Initialize SpaceBuffer,RadarBuffer,and ScoreBuffer with their default contents.
     Input: bacground pcx file,SpaceBuffer,RadarBuffer,ScoreBuffer
     Output:  Changed ScreenBuffer
        Scrolls the background pcx image.
Michael Link

CheckScroll
   Purpose:  Check to see if screen should scroll
     Input: Defender Structure,ScreenPosition
     Output: Changed ScreenPosition
Michael Link

CheckOnScreen
   Purpose:  Check to see if a structure is Onscreen and set its flag.
     Input: Structure X, Y,ScreenPosition
     Output: Changed OnScreen flag
Michael Link
 
UpdateScreenBuffer
   Purpose:  Loops through all structures and draws them onto the screen.
     Input: All Structures
     Output:  Changed ScreenBuffer
        Main Screen Update Routine
Michael Link

DrawRadar
 Purpose: Draws the Ship positons to RadarBuffer.
   Inputs: Current Ship X, Y, and Type, RadarBuffer
   Outputs: Changed RadarBuffer
Michael Link

DrawSpace
 Purpose: Draws the Ships and Bullets to the SpaceBuffer.
   Inputs: Current Ship X, Y, and Type, SpaceBuffer 
   Outputs: Changed SpaceBuffer
Michael Link

DrawScore, DrawLives, DrawBombs
 Purpose: Draws the Score,Lives, and Bombs into their Buffers.
   Inputs: Score, Lives, and Bombs ScoreBuffer 
   Outputs: Changed ScoreBuffer
Michael Link
    
UpdateRadar
 Purpose: Draws the RadarBuffer to the ScreenBuffer.
   Inputs: RadarBuffer
   Outputs: Changed ScreenBuffer
Michael Link

 UpdateSpace
 Purpose: Draws the SpaceBuffer to the ScreenBuffer.
   Inputs: SpaceBuffer
   Outputs: Changed ScreenBuffer
Michael Link
       
UpdateBottomScreen
 Purpose:  Draws the Bottom Bar items to the ScreenBuffer.
   Inputs: Score,Lives Left, and Bombs Left
   Outputs: Changed ScreenBuffer
      Calls UpdateScore, UpdateBombs, UpdateLives
Michael Link

UpdateScore,UpdateBombs,UpdateLives
 Purpose:
   Inputs: BottomBar Buffer
   Outputs: Changed ScreenBuffer
       Copies the BottomBar Buffer to the ScreenBuffer
Michael Link
 
DrawScreen
Purpose:  Draw Screen Buffer to videomem.
  Inputs:
  Outputs:
     Write to video memory.
Justin Lewis:From MP4

Displaysprite
 Purpose:  display the sprites...images with invisible pixels in the background.
   Inputs:
    vscratchseg
   Outputs:
    image to the screen on top of other images.
Michael Wigdzinski
Michael Link - Changed to detect collisions

LoadPCX
 Purpose:  Load PCX file to a buffer.
   Inputs:
    filename, buffer
   Outputs:
    image data in buffer.
MP4 with a few modifications....

Updatescreen
 Purpose:  Display those sprites and pcx images
   Inputs:
    vbufseg.
   Outputs:
    writes to the video sement.
Michael Wigdzinski



Functions for sound:
 
PlayWav
 Purpose:  Plays back a wavefile
   Inputs:
    dx, offset of the soundfile
   Outputs:
    sound (listen!!)
Michael Wigdzinski

Initdsp
 Purpose:  Initialize the dsp
   Inputs:
    none
   Outputs:
    Resets the dsp
Michael Wigdzinski

Dspwrite
 Purpose:  Writes to the dsp
   Inputs:
     none
   Outputs:
    write to the dsp
Michael Wigdzinski

Play
 Purpose: play the sound
   Inputs:
    none
   Outputs:
    sound (listen!!)
Michael Wigdzinski

Volume
 Purpose:  Control the volume of the wav file
   Inputs:
    none
   Outputs:
    none
Michael Wigdzinski

PlayMidi
 Purpose:  Play back a midi file
   Inputs:
    bx, offset of the soundfile
   Outputs:
    none
Michael Wigdzinski

Midistop
 Purpose:  Stop playing the file
   Inputs:
    ax
   Outputs:
    none
Michael Wigdzinski

Midiplay
 Purpose:  Play back a midi file
   Inputs:
    ax, bx (segue)
   Outputs:
    none
Michael Wigdzinski

Registermidi
 Purpose:  Load up the file
   Inputs:
    ax
   Outputs:
    none
Michael Wigdzinski



Functions for user input:
 
CalibrateJoystick
 Purpose:  To calibrate the joystick
   Inputs:
    none
   Outputs:
    calibrates the joystick
    joyflag, ctx, cty, lwrtx, lwrty, uplftx, uplfty, but1, but2, offstx, offsty, bothb
Michael Wigdzinski
 
Joystickpoll
 Purpose:  To continuously check for user input
   Inputs:
    none
   Outputs:
    shootflag, leftflag, upflag, rightflag, downflag, bombflag, hyperflag, gameover
Michael Wigdzinski
 
InstallKeyboard:
Purpose: To grab game commands from the keyboard
               Saves the default interrupt vector.
   Inputs:
    none
   Outputs:
    oldkeybrd
MP3 with a few modifications.....
Michael Wigdzinski

DeinstallKeyboard:
Purpose: To grab game commands from the keyboard
               Restores the default interrupt vector.
   Inputs:
    oldkeybrd
   Outputs:
    none
MP3 with a few modifications.....
Michael Wigdzinski

Inkeyboard:
 Purpose: To grab game commands from the keyboard
   Inputs:
    none
   Outputs:
    joyflag, gameover, leftflag, rightflag, upflag, downflag, shootflag, bombflag, hyperflag
Michael Wigdzinski

 
InstallTimer:
Purpose: To control the pace of the game, saves the default timer
                in oldtimer and configure the timer to 72 times per sec
   Inputs:
    none
   Outputs:
    oldtimer
MP3 with a few modifications...
Michael Wigdzinski

DeinstallTimer:
Purpose:  To control the pace of the game, restore the default timer
                in oldtimer and configure the timer to 18 times per second
   Inputs:
    oldtimer
   Outputs:
    none
MP3 with a few modifications...
Michael Wigdzinski

IntTimer:
 Purpose: To keep track of the timer
   Inputs:
    none
   Outputs:
    none
Michael Wigdzinski
Justin Lewis 



Functions to Display the Intro and the Credits

 
Intro
 Purpose:  To display an intro screen
   Inputs:
    none
   Outputs:
    A cool and exciting introduction to the game
Michael Wigdzinski
 
Credits
 Purpose:  To display the finishing credits
   Inputs:
    none
   Outputs:
    A cool and exciting conclusion to the game
Michael Wigdzinski

 



For AI:

AIMain
 Purpose:  Loops through the list of ships and calls AIMove for each ship
                 to move it
   Inputs:
    none
   Outputs:
    none
Brian Smith

AIMove
 Purpose:  Actually moves the enemy ship towards the defender and fires
                 bullets at the defender
   Inputs:
     WShip structure
   Outputs:
     Updated enemy position and any new bullets that were fired
Brian Smith

MoveBullets
 Purpose:  Moves each bullet towards their respective target position
   Inputs:
    WBullet structure
   Outputs:
    Updated bullet postion
Brian Smith

MainProgram Steps

 1)      Initialize segments
 2)      Call joystick calibration function
 3)      Install keyboard
 4)      Put video screen in VGA mode
 5)      Call Intro procedure
 6)      Install timer
 7)      Call Gameloop
 8)      Call Credits
 9)      Deinstall Timer
 10)     Deinstall Keyboard
 11)     Put display back into text-mode
 12)     Exit to DOS