Shop lifter!!!
 

Team Members

 Introduction
ShopLifter! is a networked 2 player game in which you have to gain enough money to pay for your senior trip to Hawaii. Instead of staying in class, you decided to bust free and head to the mall hoping to steal enough merchandise to pawn for big bucks later. You've got to avoid the mall-trash or you'll loose your life and your sunbathing dreams.
 Major Goals
 Problem Description and Implementation
We beleive this program will provide certain challenges that set it apart from an ordinairy machine problem.  The game will include sound capabilities, including the ability to play both wav and midi files. The graphics used are 256 color bitmaps and the game levels will be implemented using a graphical tile-based system and a double buffer. Gameplay issues will need to be addressed, including timing,  animation, collision detection.

We will be implementing a smooth-scrolling screen in 2 directions for 6 different levels. We will implement this in mode 13h VGA graphics. The images will be saved as BMP tiles and the levels will be decoded from a text file containing the level data. The tiles will be stored in the Tile Segment of our program. To achieve smooth-scrolling, we will be using a combination of double buffering and position relation. The player will remain in the center of the screen, and the background will move accordingly. Enemies will be randomly generated according to the level's associated difficulty.

The networking will be peer-to-peer with each player sending packets containing the necessary information. Networking will be implemented  using NetBIOS.

The sound portion of the game consists of both MIDI and WAV files. The MIDI files will be general background music. The WAV files will be event driven and dependent on the player's actions. WAV files will also be used for other characters appearing on the screen.

We forsee the biggest obsticle with this project to be with the networking. Providing accurate data transfers will be crutial to the success so that the right player "wins."
 

 
Constants
 
 
HELLO EQU 1
UPDATE EQU 2
GOODBYE EQU 3
CHATMES EQU 4
 
 
 
 
RandConstOne      EQU 55821     ; Constants used for random number generation 
 
RandConstTwo     EQU 1 
 
NewEnemyConst  EQU 500        ; Constant used for enemy generation 

GameOnePlyr       EQU    0          ; Constants used by main menu routine 
GameTwoPlyr      EQU    1 

 
 
NoMove          EQU    0      ; Constants used for player movement 
MoveUp          EQU    1 
MoveDown      EQU    2 
MoveLeft          EQU    3 
MoveRight        EQU    4 
Pickup              EQU    5 
 
 
MainMenu1T    EQU    80      ; Constants used for main menu items 
MainMenu1B    EQU    100 
MainMenu2T    EQU    101 
MainMenu2B    EQU    127 
MainMenu3T    EQU    128 
MainMenu3B    EQU    150 
MainMenu4T    EQU    151 
MainMenu4B    EQU    175 
MainMenu5T    EQU    176 
MainMenu5B    EQU    195 
MainMenuLB    EQU    196 
MainMenuRB    EQU    295
 
 
OptMenu1         EQU     0          ; Contants used for option menu items 
OptMenu1         EQU     0 
OptMenu2         EQU     0 
OptMenu2         EQU     0 
OptMenu3         EQU     0 
OptMenu3         EQU     0
 
 
 
GameMenu1     EQU    48      ; Constants used for game menu items 
GameMenu2     EQU    82 
GameMenu3     EQU    120 
GameMenu4     EQU    191 
GameMenu5     EQU    226 
GameMenu6     EQU    272
 
 
MaxLevelLen        EQU 1440 ; Maximum length of level = 3 screens 

NumTiles          EQU    27    ;How many graphic tiles we're using 

NumChars       EQU    2     ; how many character images we have 

ScrollMax      EQU    40    ; how many tiles we can scroll max 
 

L1Difficulty   EQU    1     ; difficulty settings for each level 
L2Difficulty   EQU    2 
L3Difficulty   EQU    2 
L4Difficulty   EQU    3 
L5Difficulty   EQU    4 

SizeLevelFile  EQU    962   ; size in bytes of the level files 

Transparency   EQU    166   ; the color in the palette that we use 
                                             ; to indicate an invisible pixel

 
 
VidGrSeg EQU 0A000h
Money EQU %
Shirt EQU &
Box EQU '
Hat EQU (
Coat EQU )
Wallet EQU *
Necklace EQU +
 

Segments
 
ImageSeg This is storage for larger imags like enemies and main characters.
TileSeg All bmps used to develop game will be included in this segment
DoubleBTempSeg This is temp storage to draw screen before draing to video
Variables
 
 
MainMenuImg          db  'mainmenu.bmp',0 
OptionMenuImg       db  'option.bmp', 0 
GameMenuImg         db  'gamemenu.bmp', 0 
 

ThisPlayer                  PlayerType <> 

OldKbdVO              dw  ?     ; holds address of default keyboard handler 

OldKbdVS               dw  ? 

PlayerAction             db  0   ; action the player has taken based on keypressed 

ExitFlag                    db 0    ; indicates to the game that it should exit 
ButtonState               db 0    ; indicates the state of the mouse button 
                                            ; 1=button down  0=button up 

MouseX                   dw 0    ; horizontal mouse positon 
MouseY                   dw 0    ; vertical mouse position 

RandSeed                 dw  ?   ; seed used by random number generator 

PlayerDifficulty          db 1  ; difficulty level as chosen by the player 

GameType               db 0  ; type of game (one player of two) 

SelectedLevel          dw 0  ; which level the used selected to play 

EnemyArray            EnemyType 50 dup(<>) 

SizeEnemyType      dw sizeof EnemyType 

CurrentLevel LevelType <> 

CurrentPosition dw 0000h 

GameOver   db 0 

; offsets for the rows where enemies will be drawn 
EnemyPlanes  dw    40*320, 56*320, 72*320, 88*320, 104*320

 
 

 (null terminated filename strings)
SoundFXZero  db  'pickitem.wav',0 
SoundFXOne  db 'caught.wav',0
SoundFXTwo  db 'caught.wav',0
SoundFXThree  db 'rolling.wav',0
SoundFXFoiur  db 'flyby.wav',0
 
 (null terminated filename strings)
MidiZero   db 'Ppanther.xmi',0
MidiOne  db  '007.xmi',0
MidiTwo  db 'army.xmi',0
MidiThree  db 'lowrider.xmi',0
MidiFour  db 'Test.xmi',0
 
(lengths for midi files)
MidiZeroLength  dw  9654
MidiOneLength  dw 8456
MidiTwoLength  dw 21740
MidiThreeLength  dw 12444 
MidiFourLength  dw 23762
MidiLength  dw  ?
(used by SBLIB291.asm)
SB_BaseAddr  dw   ? 
sbuf_page  db  ?
sbuf_offset  dw  ?
sbuf_length  dw 8192
Pbuf  db  7 dup (?) 
finalbuffersize  dw  ?
mycounter  dw  -1
needrefill  dw  0
loadbuf Wave <>
 
 
MyNum the player's unique number
PlayerTwoScore other player's score
grp_name group identifier for networking
my_name identifier for player for networking
RXBuffer buffer for networking
TXBuffer buffer for networking
Message message to send to other player
crlf carriage return and line feed
Exit exit flag
Join join flag
Lost lost flag
Talk talk flag
TwoPlayer set if in 2 player mode 
BufLength used in ProcessKey
NetworkMsg String "Establishing Networking..."
SuccessNet String "Networking Established...Press Any Key"
 

Structures
 
 
GenericMsg STRUC  
MsgType   db ?  
PlayerNum db 63  
GenericMSG ENDS
generic structure for network packets.
HelloMsg STRUC  
MsgType   db HELLO 
PlayerNum db 63 
HelloMsg ENDS
Structure which contains Hello message, meaning player is joining game.
ChatMsg STRUC 
MsgType db CHAT 
PlayerNum db 63 
ChatStr db 20 dup(?) 
ChatMsg ENDS
Structure contains a message sent from a player.
UpdateMsg STRUC  
MsgType   db UPDATE 
PlayerNum db 63 
Money dw 0 
UpdateMsg ENDS
An update structure which updates opposing player's amount of points and whether they have won yet.
GoodByeMsg STRUC  
MsgType db GOODBYE 
PlayerNum db 63 
Won db 0  
GoodByeMsg ENDS
Goodbye message means player is leaving game
 
 
PlayerType struc  
   PlayerNum     db  0  
   PositionX       dw  0  
   PositionY       dw  0  
   Items             db  0  
   Score            db  5  
   Lives             db  0  
   ImageUp       db  0  
   ImageDown   db  0  
   ImageLeft       db  0  
   ImageRight     db  0 
   CurrentImage  db  0  
PlayerType ENDS
EnemyType STRUC 
  Active           db  0 
  Kind             db  0 
  Position         dw  0 
  Speed            db  0 
  Direction        db  0 
  ImageRight     db  0 
  ImageLeft      db  0 
EnemyType ENDS
LevelType struc  
  BkgTile       db  0  
  FloorTile     db  0 
  BkgData     db  480 dup (?)  
  Items          db  480 dup (?)  
LevelType ENDS
 
 
BMPTYPE STRUC 
 
 BFType db 'BM' 
 BFSize dd ? 
 BFReserved1 dw 0 
 BFReserved2 dw 0 
 BFOffBits dd ? 

 BISize dd ? 
 BIWidth dd ? 
 BIHeight dd ? 
 BIPlanes dw 1 
 BIBitCount dw ? 
 BICompression dd 0 
 BISizeImage dd ? 
 BIXPelsPerMeter dd ? 
 BIYPelsPerMeter dd ? 
 BIColorsUsed dd 0 
 BIColorsImportant dd 0 

 RGBQuad db 256 dup (4 dup(?)) 
BMPTYPE ENDS

 
 

Procedures

Sound Functions--Chris Roth

These functions are for playing WAV sound files, our sound effects.  Adapted from SBTEST.

InitSoundFX

Purpose: Initializes the SoundBlaster DSP for use for playing WAV files.
Inputs:     None
Outputs:    CF set if an error occurred
                 SB_BaseAddr set to correct value
                 SB_IRQ set to correct value
                 SB_DMA_Low set to correct value
Notes:    Installs an ISR for use for playing WAV files
              Uses the SoundLib291 Function SB_Init
              Clears other variables to allow restarting of playback
KillSoundFX

                    Purpose: Called before exit to reset original values created by InitSoundFX
                    Inputs: None
                    Outputs: None
                    Notes:  Clears all values set by InitSoundFX
                                Uses the SoundLib291 Function SB_Clean

LoadSoundFX

                    Purpose: Loads a WAV file into a buffer for output via PlaySoundFX
                    Input:   BX - Pointer to the null-terminated string with the file name
                                DL – Position in the sound buffer where file should be stored
                    Output: CF set if an error occurred
                    Notes:  This saves the WAV files in a buffer where it can be played back later.
                                Sound file stored in a place designated by a constant.
                                All sounds should be between one half to one second in length

PlaySoundFX

                    Purpose: Plays a WAV file from the specified buffer on the computer speakers
                    Input: DL – The position in the sound buffer where the file is stored
                    Output: CF set if an error occurred
                    Notes:  This plays the WAV file stored in buffer through the computer speakers.
                                Uses the SoundLib291 functions SB_Play and SB_Stop if necessary

PlayIt

                    Purpose: To simplify the calling of a sound
                    Input:  AH - 00 for midi / 01 for wave
                               AL - Index of file to play   example 00 / 01 / 02 for first second third
                    Output: None
                    Notes: This is the function which the gameplay calls
 

These functions are for playing our MID files, our background music.  Uses MidPak.

LoadMidi

                    Purpose: Loads a MID file into a buffer for output.
                    Input: DS:DX segment offset for the null terminated filename string
                    Output: None
                    Notes:  This saves the MID file in a buffer where it can be played back later.
                                Size of MID file should be under 60k

PlayMidi

                    Purpose: Plays a midi file through the SoundBlaster.
                    Input: DS: DX segment offset for the null terminated filename string
                    Output: None
                    Notes:  This plays the midi file stored in the buffer.
                                It continues playing and it restarts when finished.

KillMidi

                    Purpose: Ends playback of all midi sound.
                    Input: None
                    Output: None
                    Notes: Ends all midi playback.
 
 

Network Functions--Guanyao Cheng

NetPost

                    Purpose: Process the received packets from the network
                    Input:   AX - length of data received
                                BX - receive buffer
                    Output: Join, Exit, Lost, Talk maybe set depending on msg received

InitNetwork

                    Purpose: Screen which will allow the player to start the two player game
                    Input: Network
                    Output: Network

SendChat
 
                    Purpose: Sends a message to the other player
                    Input: keyboard
                    Output: Message string stores the message to be sent

DisplayChat

                    Purpose: Displays the received chat message
                    Input: RecvMsg holds the string received
                    Output: RecvMsg displayed to the Screen

InitBuffer

                    Purpose: Clears the Screen
                    Input: none
                    Output: none

ProcessKey
                    Purpose: puts a letter into a string
                    Input: al
                    Output: Message
                    Note: Taken from mp2 given code

DrawEmptyBox
                    Purpose: draws a 200x20 solid, outlined box on the screen
                    Input: none
                    Output: None
                    Note: Heavily modified mp4 DrawEmptyBox code

StringCopy
                    Purpose: copies strings of length 20
                    Input: di points to string to be copied
                    Output: si points to string to write out to
                    Note: Was fully implemented before I saw the given macros.inc code strcpy

PrintString
                    Purpose: prints string of a certain foreground and background color at a certain row and
                                  column
                    Input: dl=column number, dh=row number, bh=background color, bl= foreground color
                              di = pointer to string
                    Output: screen

PrintChar
                    Purpose: prints a char of a certain foreground and background color at a certain row and
                                  column
                    Input: dl=column number, dh=row number, bh=background color, bl= foreground color
                              di = pointer to string
                    Output: screen
 
FillScreen
                    Input: None
                    Ouput: None
                    Purpose: Double buffer is cleared to black
 

Graphics --Amy Devine

Set_Palette 

         Inputs: Register BX must contain pointer to color table
                    Register CX is number of colors * 3 bytes
         Outputs: None
         Purpose: Sets the current color palette of the video card
 

LoadBMP

    Input: Register DX = pointer to null-terminated string with file name
             Register BP = the # of bytes that make up the
                                    image itself (rows*cols) (doesn't include header)
    Output: Variable TempBuf = the raw data from the bitmap file
    Purpose: Loads a file from disk into the TempBuf
 

StoreBMP

   Input: Registers ES:DI = pointer to where the bitmap image will be put
            Register BP = the # of bytes that make up the
            image itself (rows*cols) (doesn't include header)
   Output: Mode 13h formatted bytes are written to the specified address
   Purpose: Converts the 16 color BMP data to a VGA mode-13h array of bytes
 
DumpBuffer

    Input: None
    Output: Contents of double buffer output to video
    Purpose: Dumps the double buffer to the video screen
                   using efficient string transfer instructions

LoadLevel

     Input: Register AX = the number of the level want to load
     Output: Variable CurrentLevel constains data for the level
     Purpose: Loads the data for the specified level into memory
 

Input, Gameplay and Graphics functions -- Dominick Gallo

KbdInstall
   (Code from MP3)

   Input: None
   Output: Variable oldKbdV == pointer to the default keyboard handler
   Purpose: Installs KbdHandler's address in the vector table at interrupt 9
              and preserves the far pointer to the default keyboard handler
 

KbdUninstall
    (Code from MP3)

    Input: Variable oldKbdV == pointer to the default keyboard handler
    Output: None
    Purpose: Restores the keyboard interrupt vector to its original value

 
KbdHandler

    Input: None
    Output: Variable ExitFlag = set if the player hit escape to exit
                Variable PlayerAction = set to whether the player wants
                      to pick up an item or which direction the
                      player wants to move in
    Purpose: Interprets the keyboard scancodes and sets the appropriate
                  variables to indicate the action the user wants taken
 

MouseInstall

     (Code from MP3 )
     Input: None
     Output: None
     Purpose: Instructs the mouse driver to call MouseHandler when a there is
                   a click of the left mouse button or when the mouse is moved.
 

MouseUninstall

    (Code from MP3)
    Input: None
    Output: None
    Purpose: Hides the mouse cursor, then resets the mouse driver
 

MouseHandler

    Input: (only the inputs used in the procedure are listed)
            Register CX = Horizontal mouse position in pixels
            Register DX = Vertical mouse position in pixels
   Output: Variable ButtonState = set to 1 if left button clicked
            Variable MouseX = current horizontal position of mouse
            Variable MouseY = current vertical position of mouse

 
Randomize

   Input: None
   Output: Variable RandSeed = set to value based on system time
   Purpose: Sets the initial value of the randseed by using the
                 current system time
 

Random

   (written from specs of an old mp's function)
   Input: NONE
   Output: Variable RandSeed = the newly generated random seed
   Purpose: Generates a pseudo-random number between 0 and AX
 

RandNum

   (written from specs of an old mp's function)
   Input: Register AX = maximum desired value of random number
   Output: Register AX = the generated pseudo-random number
   Purpose: Returns a pseudo-random number in the range 0 .. AX

 
MainMenu

    Input: None
   Output: Variable MenuChoice = what option was selected from the main menu
    Purpose: Implements the game's mouse driven main menu

 
GameMenu

    Input: None
    Output: Variable SelectedLevel = set to the number of the chosen level
                Variable ExitFlag = set if the user chose to exit
    Purpose: Implements the main menu of the game, from which the player
                  can choose which level they wish to play
 

GenerateEnemy

    Input: None
    Output: Variable EnemyArray is uupdated to include the new enemy
    Purpose: Generates a new enemy in a random plane of the screen

 
MoveEnemies

    Input: NONE
    Output: Variable EnemyArray's elements are updated to reflect new positions
    Purpose: Moves each enemy to a new position depending on it's speed. If an
                  enemy moves off screen, it is removed from the game
 

CheckNewEnemies

    Input: None
    Output: None
    Purpose: Determines whether a new enemy should be generated
                  by taking into account both the difficulty of the
                  current level and the user selected difficulty

MovePlayer

    Input: Variable PlayerAction
    Output: Variable CurrentPosition indicates new positon of player
    Purpose: Updates the player's positon to reflect the last movement

 
DrawEnemies

    Input: Variable EnemyArray
    Output: None
    Purpose: Draws the enemies to the appropriate place in the double buffer
 

CheckCollision

     Input: Variable EnemyArray
     Output: elements of EnemyArray are updated if there is a collision
     Purpose: check to see whether the player has collided with an enmemy, and
                   if so, handle the collision.
 

CheckPickUp

     Input: Variable CurrentLevel: holds infomation for the level being played
     Output: Item data for this level is updated to remove an item if
                 it has been picked up
                Player's score is updated
     Purpose:  Checks whether the user tried to take an item. if there is an item,
                     allow him to take it and remove that item from the screen. if the
                    user wants to exit the level, allow him to do so.
 

DrawTile

      Input: DI = offset in double buffer to draw tile to
               SI = the number of the tile you want to draw
      Output: Specified tile is stored in appropriate location
                  in the the double buffer
      Purpose: Places the specified tile into the double buffer
 

DrawTileTrans

     Input: DI = offset in double buffer to draw tile to
              SI = the number of the tile you want to draw
     Output: Specified tile is stored in appropriate location
                  in the the double buffer
     Purpose: draws the specified tile to screen taking into
                   account the tranparency of a set color
 

DrawCharacter

    Input: DI = offset in double buffer to draw character
             SI = which character image to draw
    Output: None
    Purpose: Draws the specified character from the character array
               at the specified position
 

DrawLevelTiles

     Input: Variable CurrentLevel = contains map for current level's graphics
     Output: Writes to the double buffer
     Purpose: Draws the tiles that make up background objects as well as
               the tiles that represent gameplay items to the screen
 

LoadTiles

        Input: None
        Output: Variable TileArray now contains all the graphic tiles
        Purpose: Loads the graphic tiles into the tile array

LoadCharacters

    Input: None
    Output: Variable CharacterArray now contains the character images
    Purpose: Loads the graphics used for the player and enemies into
                  the CharacterArray

DrawBackground

    Input: None
    Output: Writes to the double buffer
    Purpose: draws the background and floor tiles for the current level in the
                  appropriate position

DoGame

     Input: None
     Output: None
     Purpose: Basically implements the main game loop and calls other necessary
                   functions
 
 

Basic Flow of Main Game Loop:

 
         Wait Until Player Chooses Level
         Check if player chose to exit, if so exit to the Main Menu
         Load the level the player selected
        .......
GameLoop:
        CALL    MovePlayer
        CALL    DrawBackground
        CALL    DrawLevelTiles
        CALL    DrawEnemies
        ........
        Wait some small amount of time by polling system timer
        .......
        CALL    DumpBuffer
        CALL    CheckCollision
        CALL    CheckPickup
        ........
        Chcek if player's score is zero, if so exit game
        .........
 
        CALL    MoveEnemies
        CALL    CheckNewEnemies
        JMP     GameLoop