dog3 game project

Upload: tobechi-ohaeri

Post on 08-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 DOG3 Game Project

    1/33

    mDog - 1

    ***************************************************************

    AVE THE DOG - THE GAME

    el free to re-use any of this code that you find useful. Theme is not complete, you will notice that the artwork is missing unfinished in most cases, but the playability is intact and theding has been finished. This serves as an example for the use basic DirectDraw, DirectInput, and DirectSound functions.

    ouse support is provided via the windows API.

    [email protected]://members.home.net/theluckyleper

    ***************************************************************

    vate Sub Form_Load()

    DDraw.Initialize FrmDog.hWnd 'Initialize DirectDrawDInput.Initialize FrmDog.hWnd 'Initialize DirectInputDSound.Initialize FrmDog.hWnd 'Initialize DirectSoundCursor.Initialize 'Initialize (remove) the CursorMe.Show 'Show the formMainLoop 'Run the main loop

    d Sub

    vate Sub MainLoop()

    On Error GoTo ErrOut

    'Set up the control booleansEntryRunning = TrueInfoRunning = FalseGameRunning = FalseEntryInitialized = FalseInfoInitialized = FalseGameInitialized = False

    Do While TrueIf EntryRunning Then

    'Run the entry screenIf EntryInitialized = False Then EntryScreen.InitializeEntryScreen.Physics 'Handle animations and physicsEntryScreen.Display 'Display the appropriate frame of the spritesDDraw.Flip 'Flip the backbuffer to the screenDDraw.ClearBuffer 'Erase the backbuffer so that it can be drawn on againDoEvents 'Give windows its chance to do thingsIf Not EntryRunning Then EntryScreen.Terminate

    ElseIf InfoRunning Then'Run the info screenIf InfoInitialized = False Then InfoScreen.InitializeInfoScreen.Display 'Display the appropriate frame of the sprites

    DDraw.Flip 'Flip the backbuffer to the screenDDraw.ClearBuffer 'Erase the backbuffer so that it can be drawn on againDoEvents 'Give windows its chance to do thingsIf Not InfoRunning Then InfoScreen.Terminate

    ElseIf GameRunning Then'Run the game portionIf GameInitialized = False Then GameScreen.InitializeGameScreen.HandleKeys 'Check the DirectInput data for significant keypressesGameScreen.Physics 'Handle animations and physicsGameScreen.Display 'Display the appropriate frame of the spritesDDraw.Flip 'Flip the backbuffer to the screenDDraw.ClearBuffer 'Erase the backbuffer so that it can be drawn on againDoEvents 'Give windows its chance to do thingsIf Not GameRunning Then GameScreen.Terminate

    End IfLoop

    Out:

    ExitProgram 'If an error occurs, leave the program

    d Sub

  • 8/7/2019 DOG3 Game Project

    2/33

    mDog - 2

    vate Sub Form_Click()

    'Handle mouse clicksIf InfoRunning = True Then InfoScreen.ClickIf GameRunning = True Then GameScreen.Click

    d Sub

    blic Sub ExitProgram()

    If EntryRunning = True Then EntryScreen.Terminate 'Unload game objectsIf GameRunning = True Then GameScreen.Terminate 'Unload game objectsDDraw.Terminate (FrmDog.hWnd) 'Unload the DirectDraw variablesDInput.Terminate 'Unload the DirectInput variablesDSound.Terminate 'Unload the DirectSound variablesCursor.Terminate 'Redisplay the cursorEnd 'End the program

    d Sub

  • 8/7/2019 DOG3 Game Project

    3/33

    mDog - 1

    RSION 5.00gin VB.Form FrmDogBackColor = &H00000000&BorderStyle = 0 'NoneCaption = "Dog"ClientHeight = 3195ClientLeft = 0ClientTop = 0ClientWidth = 4680LinkTopic = "Form1"ScaleHeight = 3195ScaleWidth = 4680ShowInTaskbar = 0 'FalseStartUpPosition = 3 'Windows Default

    d

  • 8/7/2019 DOG3 Game Project

    4/33

  • 8/7/2019 DOG3 Game Project

    5/33

    Cursor - 1

    '***************'

    'This module con'restore the mou

    'to call the xPo'know the precis'''Lucky

    ''

  • 8/7/2019 DOG3 Game Project

    6/33

    sor - 2

    ShowCursor CURVISIBLE

    d Sub

  • 8/7/2019 DOG3 Game Project

    7/33

    aw - 1

    jor DX Objectsm dx As New DirectX7m dd As DirectDraw7

    m Primary As DirectDrawSurface7 'Primary surfacem BackBuffer As DirectDrawSurface7 'Backbuffer surfacem ddsdPrimary As DDSURFACEDESC2 'Primary surface descriptionm ddsdBackBuffer As DDSURFACEDESC2 'Backbuffer surface description

    bal FrameTime As Long 'System time that last frame was flipped atnst FrameRate = 100 'How many MS per frame?

    blic Sub Initialize(WindowHandle As Long)

    'This routine initializes the display mode, and the primary/backbuffer complex

    'Handles errorsOn Local Error GoTo ErrOut

    'Creates the directdraw objectSet dd = dx.DirectDrawCreate("")

    'Set the cooperative level and displaymode...Call dd.SetCooperativeLevel(FrmDog.hWnd, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWREBO

    Call dd.SetDisplayMode(800, 600, 8, 0, DDSDM_DEFAULT)

    'Create the primary complex surface with one backbufferddsdPrimary.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNTddsdPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEXddsdPrimary.lBackBufferCount = 1Set Primary = dd.CreateSurface(ddsdPrimary)

    'Get the backbuffer from the primary surfaceDim caps As DDSCAPS2caps.lCaps = DDSCAPS_BACKBUFFERSet BackBuffer = Primary.GetAttachedSurface(caps)

    'Clears the bufferClearBuffer

    Exit Sub

    Out:FrmDog.ExitProgram 'If there's an error, exit the program

    d Sub

    blic Sub ClearBuffer()

    m DestRect As RECT

    'Clears the backbufferWith DestRect

    .Bottom = 600

    .Left = 0

    .Right = 800

    .Top = 0End WithBackBuffer.BltColorFill DestRect, 0

    d Sub

    blic Function LoadSurface(Path As String, ddsd As DDSURFACEDESC2) As DirectDrawSurface7

    'Loads the surface using the given path and descriptionSet LoadSurface = dd.CreateSurfaceFromFile(Path, ddsd)

    d Function

    blic Sub DisplaySprite(DestRect As RECT, Sprite As DirectDrawSurface7, SrcRect As RECT, Optionalt As Boolean, Optional xCoord As Long, Optional yCoord As Long)

    If Fast = True Then'Blit the sprite fast to the backbufferBackBuffer.BltFast xCoord, yCoord, Sprite, SrcRect, DDBLTFAST_WAIT

    Else

  • 8/7/2019 DOG3 Game Project

    8/33

    aw - 2

    'Clip the sprite if any part will be off screenWith DestRect

    If .Bottom > 600 ThenSrcRect.Bottom = SrcRect.Bottom - (.Bottom - 600).Bottom = 600

    End IfIf .Left < 0 Then

    SrcRect.Left = SrcRect.Left - .Left.Left = 0

    End IfIf .Right > 800 Then

    SrcRect.Right = SrcRect.Right - (.Right - 800).Right = 800

    End IfIf .Top < 0 Then

    SrcRect.Top = SrcRect.Top - .Top.Top = 0

    End IfEnd With'Blit the sprite with colour key to the backbufferBackBuffer.Blt DestRect, Sprite, SrcRect, DDBLT_KEYSRC Or DDBLT_WAIT

    End If

    d Sub

    blic Sub Flip()

    'Slow the frame rate downDo While Timer.Time - FrameTime < FrameRate

    DoEventsLoop

    'Flip the attached surface (the backbuffer) to the screenPrimary.Flip Nothing, DDFLIP_WAIT

    'Record the time of the flipFrameTime = Timer.Time

    d Sub

    blic Sub TextOut(OutText As String, x As Integer, y As Integer, Colour As Long)

    'This function writes text to the backbufferBackBuffer.SetForeColor ColourCall BackBuffer.DrawText(x, y, OutText, False)

    d Sub

    blic Sub Terminate(WindowHandle As Long)

    m i As Integer

    'This routine must destroy all surfaces and restore display modeSet Primary = Nothing

    Set BackBuffer = NothingSet BackGround = Nothing

    Call dd.RestoreDisplayModeCall dd.SetCooperativeLevel(WindowHandle, DDSCL_NORMAL)

    d Sub

  • 8/7/2019 DOG3 Game Project

    9/33

    put - 1

    X Variablesm dx As New DirectX7m di As DirectInputm diDEV As DirectInputDevicem diState As DIKEYBOARDSTATE

    op counterm i As Integer

    ublic array showing which keys are activeblic aKeys(211) As Boolean

    ycode constantsbal Const DIK_ESCAPE = 1bal Const DIK_1 = 2bal Const DIK_2 = 3bal Const DIK_3 = 4bal Const DIK_4 = 5bal Const DIK_5 = 6bal Const DIK_6 = 7bal Const DIK_7 = 8bal Const DIK_8 = 9bal Const DIK_9 = 10bal Const DIK_0 = 11bal Const DIK_MINUS = 12bal Const DIK_EQUALS = 13

    bal Const DIK_BACKSPACE = 14bal Const DIK_TAB = 15bal Const DIK_Q = 16bal Const DIK_W = 17bal Const DIK_E = 18bal Const DIK_R = 19bal Const DIK_T = 20bal Const DIK_Y = 21bal Const DIK_U = 22bal Const DIK_I = 23bal Const DIK_O = 24bal Const DIK_P = 25bal Const DIK_LBRACKET = 26bal Const DIK_RBRACKET = 27

    bal Const DIK_RETURN = 28bal Const DIK_LCONTROL = 29bal Const DIK_A = 30bal Const DIK_S = 31bal Const DIK_D = 32bal Const DIK_F = 33bal Const DIK_G = 34bal Const DIK_H = 35bal Const DIK_J = 36bal Const DIK_K = 37bal Const DIK_L = 38bal Const DIK_SEMICOLON = 39bal Const DIK_APOSTROPHE = 40bal Const DIK_GRAVE = 41

    bal Const DIK_LSHIFT = 42bal Const DIK_BACKSLASH = 43bal Const DIK_Z = 44bal Const DIK_X = 45bal Const DIK_C = 46bal Const DIK_V = 47bal Const DIK_B = 48bal Const DIK_N = 49bal Const DIK_M = 50bal Const DIK_COMMA = 51bal Const DIK_PERIOD = 52bal Const DIK_SLASH = 53bal Const DIK_RSHIFT = 54bal Const DIK_MULTIPLY = 55

    bal Const DIK_LALT = 56bal Const DIK_SPACE = 57bal Const DIK_CAPSLOCK = 58bal Const DIK_F1 = 59bal Const DIK_F2 = 60bal Const DIK_F3 = 61bal Const DIK_F4 = 62bal Const DIK_F5 = 63bal Const DIK_F6 = 64

  • 8/7/2019 DOG3 Game Project

    10/33

    put - 2

    bal Const DIK_F7 = 65bal Const DIK_F8 = 66bal Const DIK_F9 = 67bal Const DIK_F10 = 68bal Const DIK_NUMLOCK = 69bal Const DIK_SCROLL = 70bal Const DIK_NUMPAD7 = 71bal Const DIK_NUMPAD8 = 72bal Const DIK_NUMPAD9 = 73bal Const DIK_SUBTRACT = 74bal Const DIK_NUMPAD4 = 75bal Const DIK_NUMPAD5 = 76bal Const DIK_NUMPAD6 = 77bal Const DIK_ADD = 78bal Const DIK_NUMPAD1 = 79bal Const DIK_NUMPAD2 = 80bal Const DIK_NUMPAD3 = 81bal Const DIK_NUMPAD0 = 82bal Const DIK_DECIMAL = 83bal Const DIK_F11 = 87bal Const DIK_F12 = 88bal Const DIK_NUMPADENTER = 156bal Const DIK_RCONTROL = 157bal Const DIK_DIVIDE = 181bal Const DIK_RALT = 184bal Const DIK_HOME = 199

    bal Const DIK_UP = 200bal Const DIK_PAGEUP = 201bal Const DIK_LEFT = 203bal Const DIK_RIGHT = 205bal Const DIK_END = 207bal Const DIK_DOWN = 208bal Const DIK_PAGEDOWN = 209bal Const DIK_INSERT = 210bal Const DIK_DELETE = 211

    blic Sub Initialize(WindowHandle As Long)

    'Create the direct input objectSet di = dx.DirectInputCreate()

    'Aquire the keyboard as the deviceSet diDEV = di.CreateDevice("GUID_SysKeyboard")

    'Get input nonexclusively, only when in foreground modediDEV.SetCommonDataFormat DIFORMAT_KEYBOARDdiDEV.SetCooperativeLevel WindowHandle, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVEdiDEV.Acquire

    d Sub

    blic Sub CheckKeys()

    'Get the current state of the keyboard

    diDEV.GetDeviceStateKeyboard diState

    'Scan through all the keys to check which are depressedFor i = 1 To 211

    If diState.Key(i) 0 ThenaKeys(i) = True 'If the key is pressed, set the appropriate array index to

    eElse

    aKeys(i) = False 'If the key is not pressed, set the appropriate array index false

    End IfNext

    d Sub

    blic Sub Terminate()

    'Unaquire the keyboard when we quitdiDEV.Unacquire

    d Sub

  • 8/7/2019 DOG3 Game Project

    11/33

    und - 1

    rectX Variablesm ds As DirectSoundm dx As New DirectX7

    er defined type to determine a buffer's capabilitiesvate Type BufferCapsVolume As Boolean 'Can this buffer's volume be changed?Frequency As Boolean 'Can the frequency be altered?Pan As Boolean 'Can we pan the sound from left to right?Loop As Boolean 'Is this sound looping?Delete As Boolean 'Should this sound be deleted after playing?

    d Type

    er defined type to contain sound datavate Type SoundArrayDSBuffer As DirectSoundBuffer 'The buffer that contains the soundDSState As String 'Describes the current state of the buffer (ie. "Playing", "Stod")DSNotification As Long 'Contains the event reference returned by the DirectX7 objectDSCaps As BufferCaps 'Describes the buffer's capabilitiesDSSourceName As String 'The name of the source fileDSFile As Boolean 'Is the source in a seperate file?DSResource As Boolean 'Or is it in a resource?DSEmpty As Boolean 'Is this SoundArray index empty?

    d Typem Sound() As SoundArray 'Contains all the data needed for sound manipulation

    nstant that contains the path inside the app.path in which the sounds are storedst DataLocation = "\data\"

    nstants that describe the contents of the sound buffersbal Const SndBoyShoot = 0bal Const SndClick = 1bal Const SndDogDead = 2bal Const SndDogHit = 3bal Const SndDogYap = 4bal Const SndIntro = 5bal Const SndManHit = 6bal Const SndYouLose = 7bal Const SndYouWin = 8

    ray to contain the ID's for the soundsbal SoundID(8) As Integer

    ve Format Setting Contantsnst NumChannels = 2 'How many channels will we be playing on?st SamplesPerSecond = 22050 'How many cycles per second (hertz)?nst BitsPerSample = 16 'What bit-depth will we use?

    blic Sub Initialize(ByRef Handle As Long)

    'If we can't initialize properly, trap the errorOn Local Error GoTo ErrOut

    'Make the DirectSound objectSet ds = dx.DirectSoundCreate("")

    'Set the DirectSound object's cooperative level (Priority gives us sole control)ds.SetCooperativeLevel Handle, DSSCL_PRIORITY

    'Initialize our Sound array to zeroReDim Sound(0)Sound(0).DSEmpty = TrueSound(0).DSState = "empty"

    'Load all of the sounds into buffersSoundID(SndBoyShoot) = LoadSound("boyshoot.wav", True, False, False, False, False, False, False

    FrmDog)

    SoundID(SndClick) = LoadSound("click.wav", True, False, False, False, False, False, False, FrmD

    SoundID(SndDogDead) = LoadSound("dogdead.wav", True, False, False, False, False, False, False,mDog)

    SoundID(SndDogHit) = LoadSound("doghit.wav", True, False, False, False, False, False, False, Frg)SoundID(SndDogYap) = LoadSound("dogyap.wav", True, False, False, False, False, False, False, Fr

    g)SoundID(SndIntro) = LoadSound("intro.wav", True, False, False, False, False, False, False, FrmD

  • 8/7/2019 DOG3 Game Project

    12/33

    und - 2

    SoundID(SndManHit) = LoadSound("manhit.wav", True, False, False, False, False, False, False, Frg)SoundID(SndYouLose) = LoadSound("youlose.wav", True, False, False, False, False, False, False,

    mDog)SoundID(SndYouWin) = LoadSound("youwin.wav", True, False, False, False, False, False, False, Fr

    g)

    'Exit sub before the error codeExit Sub

    Out:'Display an error message and exit if initialization failedMsgBox "Unable to initialize DirectSound."End

    d Sub

    blic Function LoadSound(SourceName As String, IsFile As Boolean, IsResource As Boolean, IsDeleteBoolean, IsFrequency As Boolean, IsPan As Boolean, IsVolume As Boolean, IsLoop As Boolean, FormOct As Form) As Integer

    m i As Integerm Index As Integerm DSBufferDescription As DSBUFFERDESCm DSFormat As WAVEFORMATEX

    m DSPosition(0) As DSBPOSITIONNOTIFY

    'Search the sound array for any empty spacesIndex = -1For i = 0 To UBound(Sound)

    If Sound(i).DSEmpty = True Then 'If there is an empty space, us itIndex = iExit For

    End IfNextIf Index = -1 Then 'If there's no empty space, make a new spot

    ReDim Preserve Sound(UBound(Sound) + 1)Index = UBound(Sound)

    End If

    LoadSound = Index 'Set the return value of the function

    'Load the Sound array with the data givenWith Sound(Index)

    .DSEmpty = False 'This Sound(index) is now occupied with data

    .DSFile = IsFile 'Is this sound to be loaded from a file?

    .DSResource = IsResource 'Or is it to be loaded from a resource?

    .DSSourceName = SourceName 'What is the name of the source?

    .DSState = "Stopped" 'Set the current state to "Stopped"

    .DSCaps.Delete = IsDelete 'Is this sound to be deleted after it is played?

    .DSCaps.Frequency = IsFrequency 'Is this sound to have frequency altering capabilities?

    .DSCaps.Loop = IsLoop 'Is this sound to be looped?

    .DSCaps.Pan = IsPan 'Is this sound to have Left and Right panning capabilities?

    .DSCaps.Volume = IsVolume 'Is this sound capable of altered volume settings?

    End With

    'Set the buffer description according to the data providedWith DSBufferDescription

    If Sound(Index).DSCaps.Delete = True Then .lFlags = .lFlags Or DSBCAPS_CTRLPOSITIONNOTIFYIf Sound(Index).DSCaps.Frequency = True Then .lFlags = .lFlags Or DSBCAPS_CTRLFREQUENCYIf Sound(Index).DSCaps.Pan = True Then .lFlags = .lFlags Or DSBCAPS_CTRLPANIf Sound(Index).DSCaps.Volume = True Then .lFlags = .lFlags Or DSBCAPS_CTRLVOLUME

    End With

    'Set the Wave FormatWith DSFormat

    .nFormatTag = WAVE_FORMAT_PCM

    .nChannels = NumChannels

    .lSamplesPerSec = SamplesPerSecond

    .nBitsPerSample = BitsPerSample

    .nBlockAlign = .nBitsPerSample / 8 * .nChannels

    .lAvgBytesPerSec = .lSamplesPerSec * .nBlockAlignEnd With

    'Load the sound into the bufferIf Sound(Index).DSFile = True Then 'If it's in a file...

    Set Sound(Index).DSBuffer = ds.CreateSoundBufferFromFile(App.Path & DataLocation & Sound(In

  • 8/7/2019 DOG3 Game Project

    13/33

    und - 3

    x).DSSourceName, DSBufferDescription, DSFormat)ElseIf Sound(Index).DSResource = True Then 'If it's in a resource...

    Set Sound(Index).DSBuffer = ds.CreateSoundBufferFromResource("", Sound(Index).DSSourceName,BufferDescription, DSFormat)End If

    'If the sound is to be deleted after it plays, we must create an event for itIf Sound(Index).DSCaps.Delete = True Then

    Sound(Index).DSNotification = dx.CreateEvent(FormObject) 'Make the event (has to beated in a Form Object) and get its handle

    DSPosition(0).hEventNotify = Sound(Index).DSNotification 'Place this event handle inn DSBPOSITIONNOTIFY variable

    DSPosition(0).lOffset = DSBPN_OFFSETSTOP 'Define the position withinhe wave file at which you would like the event to be triggered

    Sound(Index).DSBuffer.SetNotificationPositions 1, DSPosition() 'Set the "notification posin" by passing the DSBPOSITIONNOTIFY variableEnd If

    d Function

    blic Sub RemoveSound(Index As Integer)

    'Destroy the event associated with the ending of this sound, if there was oneIf Sound(Index).DSCaps.Delete = True And Sound(Index).DSNotification 0 Then dx.DestroyEvent

    nd(Index).DSNotification

    'Reset all the variables in the sound arrayWith Sound(Index)

    Set .DSBuffer = Nothing.DSCaps.Delete = False.DSCaps.Frequency = False.DSCaps.Loop = False.DSCaps.Pan = False.DSCaps.Volume = False.DSEmpty = True.DSFile = False.DSNotification = 0.DSResource = False.DSSourceName = "".DSState = "empty"

    End With

    d Sub

    blic Sub PlaySound(Index As Integer)

    'Check to make sure there is a sound loaded in the specified bufferIf Sound(Index).DSEmpty Then Exit Sub

    'If the sound is not "paused" then reset it's position to the beginningIf Sound(Index).DSState "paused" Then Sound(Index).DSBuffer.SetCurrentPosition 0

    'Play looped or singly, as appropriateIf Sound(Index).DSCaps.Loop = False Then Sound(Index).DSBuffer.Play DSBPLAY_DEFAULT

    If Sound(Index).DSCaps.Loop = True Then Sound(Index).DSBuffer.Play DSBPLAY_LOOPING

    'Set the state to "playing"Sound(Index).DSState = "playing"

    d Sub

    blic Sub StopSound(Index As Integer)

    'Check to make sure there is a sound loaded in the specified bufferIf Sound(Index).DSEmpty Then Exit Sub

    'Stop the buffer and reset to the beginningSound(Index).DSBuffer.Stop

    Sound(Index).DSBuffer.SetCurrentPosition 0Sound(Index).DSState = "stopped"

    d Sub

    blic Sub PauseSound(Index As Integer)

    'Check to make sure there is a sound loaded in the specified bufferIf Sound(Index).DSEmpty Then Exit Sub

  • 8/7/2019 DOG3 Game Project

    14/33

    und - 4

    'Stop the bufferSound(Index).DSBuffer.StopSound(Index).DSState = "paused"

    d Sub

    blic Sub SetFrequency(Index As Integer, Freq As Long)

    'Check to make sure there is a sound loaded in the specified bufferIf Sound(Index).DSEmpty Then Exit Sub

    'Check to make sure that the buffer has the capability of altering its frequencyIf Sound(Index).DSCaps.Frequency = False Then Exit Sub

    'Alter the frequency according to the Freq providedSound(Index).DSBuffer.SetFrequency Freq

    d Sub

    blic Sub SetVolume(Index As Integer, Vol As Long)

    'Check to make sure there is a sound loaded in the specified bufferIf Sound(Index).DSEmpty Then Exit Sub

    'Check to make sure that the buffer has the capability of altering its volume

    If Sound(Index).DSCaps.Volume = False Then Exit Sub

    'Alter the volume according to the Vol providedSound(Index).DSBuffer.SetVolume Vol

    d Sub

    blic Sub SetPan(Index As Integer, Pan As Long)

    'Check to make sure there is a sound loaded in the specified bufferIf Sound(Index).DSEmpty Then Exit Sub

    'Check to make sure that the buffer has the capability of altering its panIf Sound(Index).DSCaps.Pan = False Then Exit Sub

    'Alter the pan according to the Pan providedSound(Index).DSBuffer.SetPan Pan

    d Sub

    blic Function GetFrequency(Index As Integer) As Long

    'Check to make sure there is a sound loaded in the specified bufferIf Sound(Index).DSEmpty Then Exit Function

    'Check to make sure that the buffer has the capability of altering its frequencyIf Sound(Index).DSCaps.Frequency = False Then Exit Function

    'Return the frequency valueGetFrequency = Sound(Index).DSBuffer.GetFrequency()

    d Function

    blic Function GetVolume(Index As Integer) As Long

    'Check to make sure there is a sound loaded in the specified bufferIf Sound(Index).DSEmpty Then Exit Function

    'Check to make sure that the buffer has the capability of altering its volumeIf Sound(Index).DSCaps.Volume = False Then Exit Function

    'Return the volume value

    GetVolume = Sound(Index).DSBuffer.GetVolume()

    d Function

    blic Function GetPan(Index As Integer) As Long

    'Check to make sure there is a sound loaded in the specified bufferIf Sound(Index).DSEmpty Then Exit Function

  • 8/7/2019 DOG3 Game Project

    15/33

    und - 5

    'Check to make sure that the buffer has the capability of altering its panIf Sound(Index).DSCaps.Pan = False Then Exit Function

    'Return the pan valueGetPan = Sound(Index).DSBuffer.GetPan()

    d Function

    blic Function GetState(Index As Integer) As String

    'Returns the current state of the given soundGetState = Sound(Index).DSState

    d Function

    blic Function DXCallback(ByVal eventid As Long) As Integer

    m i As Integer

    'Find the sound that caused this event to be triggeredFor i = 0 To UBound(Sound)

    If Sound(i).DSNotification = eventid ThenExit For

    End IfNext

    'Return the IDDXCallback = i

    d Function

    blic Sub Terminate()

    m i As Integer

    'Delete all of the sounds createdFor i = 0 To UBound(Sound)

    RemoveSound iNext

    d Sub

  • 8/7/2019 DOG3 Game Project

    16/33

    ryScreen - 1

    m BackGround As DirectDrawSurface7 'Contains the "BackGround" bitmapm DogJump(4) As DirectDrawSurface7 'Contains the "DogJump" bitmapsm Shovel(11) As DirectDrawSurface7 'Contains the "Shovel" bitmapsm Title(10) As DirectDrawSurface7 'Contains the "Title" bitmaps

    bal EntryRunning As Boolean 'Determines if the entry screen is running or notbal EntryInitialized As Boolean 'Determines if the Screen has been initialized

    rite Size Constantsnst BackgroundWidth = 800st BackgroundHeight = 600st DogJumpWidth = 150nst DogJumpHeight = 250m ShovelWidth(11) As Integer 'Will contain the constant widths of all 12 shovelsm ShovelHeight(11) As Integer 'Will contain the constant heights of all 12 shovelsm TitleWidth(10) As Integer 'Will contain the constant widths of all 11 title bitmapsm TitleHeight(10) As Integer 'Will contain the constant heights of all 11 title bitmaps

    rite Location/Condition Constantsst DogJumpX = 325st DogJumpY = 200nst ShovelSpeed = 10nst TimeBeforeTitleBmp = 32st DurationOfTitleScreen = -40

    rite Location/Condition Variables

    m DogJumpAnim As Integer 'Which frame of DogJump animation are we at?m ShovelX(11) 'X Coordinates of the shovelsm ShovelY(11) 'Y Coordinates of the shovelsm TitleDelay As Integer 'Delay before the title bitmaps show upm TitleAnim As Integer 'Which frame of the title bitmap are we showing?

    blic Sub Initialize()

    'Initialize the variablesEntryRunning = TrueDogJumpAnim = 0ShovelWidth(0) = 100ShovelHeight(0) = 300ShovelWidth(1) = 237

    ShovelHeight(1) = 310ShovelWidth(2) = 310ShovelHeight(2) = 237ShovelWidth(3) = 300ShovelHeight(3) = 100ShovelWidth(4) = 310ShovelHeight(4) = 237ShovelWidth(5) = 237ShovelHeight(5) = 310ShovelWidth(6) = 100ShovelHeight(6) = 300ShovelWidth(7) = 237ShovelHeight(7) = 310ShovelWidth(8) = 310

    ShovelHeight(8) = 237ShovelWidth(9) = 300ShovelHeight(9) = 100ShovelWidth(10) = 310ShovelHeight(10) = 237ShovelWidth(11) = 237ShovelHeight(11) = 310ShovelX(0) = 350ShovelY(0) = -400ShovelX(1) = 804ShovelY(1) = -400ShovelX(2) = 890ShovelY(2) = 17ShovelX(3) = 900

    ShovelY(3) = 250ShovelX(4) = 890ShovelY(4) = 346ShovelX(5) = 804ShovelY(5) = 690ShovelX(6) = 350ShovelY(6) = 700ShovelX(7) = -241ShovelY(7) = 690

  • 8/7/2019 DOG3 Game Project

    17/33

    ryScreen - 2

    ShovelX(8) = -400ShovelY(8) = 349ShovelX(9) = -400ShovelY(9) = 250ShovelX(10) = -400ShovelY(10) = 17ShovelX(11) = -241ShovelY(11) = -400TitleWidth(0) = 40TitleHeight(0) = 30TitleWidth(1) = 80TitleHeight(1) = 60TitleWidth(2) = 100TitleHeight(2) = 75TitleWidth(3) = 200TitleHeight(3) = 150TitleWidth(4) = 240TitleHeight(4) = 180TitleWidth(5) = 280TitleHeight(5) = 210TitleWidth(6) = 300TitleHeight(6) = 225TitleWidth(7) = 400TitleHeight(7) = 300TitleWidth(8) = 600TitleHeight(8) = 450

    TitleWidth(9) = 640TitleHeight(9) = 480TitleWidth(10) = 720TitleHeight(10) = 540TitleDelay = TimeBeforeTitleBmpTitleAnim = -1EntryInitialized = True

    'Turn the mouse offCursor.CursorToggle

    'Load the spritesLoadSurfaces

    'Play the intro soundDSound.PlaySound SoundID(SndIntro)

    d Sub

    vate Sub LoadSurfaces()

    m i As Integerm CKey As DDCOLORKEYm ddsdNewSprite As DDSURFACEDESC2

    'This routine loads all of the surfaces we're going to be using

    'Set up those components of the surface description that will stay the same

    ddsdNewSprite.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHTddsdNewSprite.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

    'Set up those components of the colour key that will stay the sameCKey.low = 0CKey.high = 0

    'Load the backgroundddsdNewSprite.lWidth = BackgroundWidthddsdNewSprite.lHeight = BackgroundHeightSet BackGround = DDraw.LoadSurface(App.Path & "\data\background_entry.bmp", ddsdNewSprite)

    'Load the "DogJump" bitmapsddsdNewSprite.lWidth = DogJumpWidth

    ddsdNewSprite.lHeight = DogJumpHeightFor i = 0 To 4

    Set DogJump(i) = DDraw.LoadSurface(App.Path & "\data\dogjump" & i + 1 & ".bmp", ddsdNewSpri

    DogJump(i).SetColorKey DDCKEY_SRCBLT, CKeyNext

    'Load the "Shovel" bitmapsFor i = 0 To 11

  • 8/7/2019 DOG3 Game Project

    18/33

    ryScreen - 3

    ddsdNewSprite.lWidth = ShovelWidth(i)ddsdNewSprite.lHeight = ShovelHeight(i)Set Shovel(i) = DDraw.LoadSurface(App.Path & "\data\shovel" & i + 1 & ".bmp", ddsdNewSprite

    Shovel(i).SetColorKey DDCKEY_SRCBLT, CKeyNext

    'Load the "Title" bitmapsFor i = 0 To 10

    ddsdNewSprite.lWidth = TitleWidth(i)ddsdNewSprite.lHeight = TitleHeight(i)Set Title(i) = DDraw.LoadSurface(App.Path & "\data\title" & i + 1 & ".bmp", ddsdNewSprite)Title(i).SetColorKey DDCKEY_SRCBLT, CKey

    Next

    d Sub

    blic Sub Display()

    m i As Integerm SrcRect As RECTm DestRect As RECT

    'Fill the backbuffer with the background bitmapWith SrcRect

    .Bottom = BackgroundHeight

    .Left = 0

    .Right = BackgroundWidth

    .Top = 0End WithDDraw.DisplaySprite DestRect, BackGround, SrcRect, True, 0, 0

    'Display the dogWith SrcRect

    .Bottom = DogJumpHeight

    .Left = 0

    .Right = DogJumpWidth

    .Top = 0End WithWith DestRect

    .Bottom = DogJumpHeight + DogJumpY

    .Left = DogJumpX

    .Right = DogJumpWidth + DogJumpX

    .Top = DogJumpYEnd WithDDraw.DisplaySprite DestRect, DogJump(DogJumpAnim), SrcRect

    'Display the shovelsFor i = 0 To 11

    With SrcRect.Bottom = ShovelHeight(i).Left = 0.Right = ShovelWidth(i).Top = 0

    End WithWith DestRect

    .Bottom = ShovelY(i) + ShovelHeight(i)

    .Left = ShovelX(i)

    .Right = ShovelX(i) + ShovelWidth(i)

    .Top = ShovelY(i)End WithDDraw.DisplaySprite DestRect, Shovel(i), SrcRect

    Next

    'Display the title bitmapIf TitleAnim >= 0 Then

    With SrcRect.Bottom = TitleHeight(TitleAnim)

    .Left = 0

    .Right = TitleWidth(TitleAnim)

    .Top = 0End WithWith DestRect

    .Bottom = 300 + TitleHeight(TitleAnim) / 2

    .Left = 400 - TitleWidth(TitleAnim) / 2

    .Right = 400 + TitleWidth(TitleAnim) / 2

    .Top = 300 - TitleHeight(TitleAnim) / 2

  • 8/7/2019 DOG3 Game Project

    19/33

    ryScreen - 4

    End WithDDraw.DisplaySprite DestRect, Title(TitleAnim), SrcRect

    End If

    d Sub

    blic Sub Physics()

    m i As Integer

    'Animate the jumping dogIf DogJumpAnim = 4 Then

    DogJumpAnim = 0Else

    DogJumpAnim = DogJumpAnim + 1End If

    'Move the shovels inwardFor i = 0 To 11

    If Sqr((ShovelX(i) + ShovelWidth(i) / 2 - 400) ^ 2 + (ShovelY(i) + ShovelHeight(i) / 2 - 30^ 2) > 220 Then

    If ShovelX(i) + ShovelWidth(i) / 2 > 550 ThenShovelX(i) = ShovelX(i) - ShovelSpeed

    ElseIf ShovelX(i) + ShovelWidth(i) / 2 < 250 ThenShovelX(i) = ShovelX(i) + ShovelSpeed

    End If

    If ShovelY(i) + ShovelHeight(i) / 2 > 450 ThenShovelY(i) = ShovelY(i) - ShovelSpeed

    ElseIf ShovelY(i) + ShovelHeight(i) / 2 < 150 ThenShovelY(i) = ShovelY(i) + ShovelSpeed

    End IfEnd If

    Next

    'Handle title animationTitleDelay = TitleDelay - 1If TitleDelay

  • 8/7/2019 DOG3 Game Project

    20/33

    meScreen - 1

    m Man(7) As DirectDrawSurface7 'Contains the "Man" bitmapsm ManHit As DirectDrawSurface7 'Contains the "Man Hit" bitmapm Boy(2) As DirectDrawSurface7 'Contains the "Boy" bitmapsm BoyFire(2) As DirectDrawSurface7 'Contains the "Boy Firing" bitmapsm Dog(4) As DirectDrawSurface7 'Contains the "Dog" bitmapsm Rock As DirectDrawSurface7 'Contains the "Rock" bitmapm BackGround As DirectDrawSurface7 'Contains the "BackGround" bitmapm Button(2) As DirectDrawSurface7 'Contains the "Button" bitmapsm Pause As DirectDrawSurface7 'Contains the "Pause" bitmapm ManWin(9) As DirectDrawSurface7 'Contains the "ManWin" bitmapsm ManFall(4) As DirectDrawSurface7 'Contains the "ManFall" bitmapsm BoyHappy(9) As DirectDrawSurface7 'Contains the "BoyHappy" bitmapsm BoySad(4) As DirectDrawSurface7 'Contains the "BoySad" bitmapsm YouWin As DirectDrawSurface7 'Contains the "YouWin" bitmapm YouLose As DirectDrawSurface7 'Contains the "YouLose" bitmap

    bal GameRunning As Boolean 'Determines if the game portion of the program should still runningbal GameInitialized As Boolean 'Determines if the Screen has been initialized

    rite Size Constantsnst BackgroundWidth = 800st BackgroundHeight = 600st ManWidth = 302nst ManHeight = 328st BoyWidth = 195

    nst BoyHeight = 203st DogWidth = 72nst DogHeight = 64nst RockWidth = 10st RockHeight = 10nst ButtonWidth = 200st ButtonHeight = 200st PauseWidth = 800nst PauseHeight = 600nst ManWinWidth = 600st ManWinHeight = 340st ManFallWidth = 302nst ManFallHeight = 328nst BoyHappyWidth = 250

    st BoyHappyHeight = 203nst BoySadWidth = 250st BoySadHeight = 203nst YouWinWidth = 800st YouWinHeight = 600st YouLoseWidth = 800nst YouLoseHeight = 600

    rite Location Constantsst BaseLine = 480 'Where's the baseline for sprites on the background bitmap?st DogYapFreq = 200 'How many frames must pass before the do yaps?st ManY = 125 'What is the man's Y coordinate?st BoyX = 560 'What is the boy's X coordinate?st BoyY = 260 'What is the boy's Y coordinate?

    st DogX = 510 'What is the dog's X coordinate?st DogY = 390 'What is the dog's Y coordinate?st Gravity = 10 'How strong is the gravity on the rocknst RockStart1X = 600 'Rock's starting X-coordinatesnst RockStart1Y = 315 'Rock's starting Y-coordinatesnst RockStart2X = 600 'Rock's starting X-coordinatesnst RockStart2Y = 300 'Rock's starting Y-coordinatesnst RockStart3X = 605 'Rock's starting X-coordinatesnst RockStart3Y = 280 'Rock's starting Y-coordinates

    rite Animation/Physics Constantsst ManSpeed = 1 'How many frames does it take for the man to animate?st ManMoveSpeed = 1 'How many frames does it take for the man to move?st ManMoveStop = 280 'How far can the man move before he has to stop?

    st ManSwingStart = 250 'How far along will the man start to swing?st DogSpeed = 1 'How many frames does it take for the dog to animate?st DogYapSpeed = 24 'How many frames does it take for the dog to yap?st Grav = 1 'How strong is gravity?st FinalAnimationSpeed = 2 'How fast do we display the final animation sequence?

    rite Location/Condition Variablesm GameWon As Boolean 'Has the game been won?m GameWonTime As Integer 'How much time has passed since game was won?

  • 8/7/2019 DOG3 Game Project

    21/33

    meScreen - 2

    m GameLost As Boolean 'Has the game been lost?m GameLostTime As Integer 'How much time has passed since game was lost?m IsManHit As Boolean 'Is the man currently hit?m ManHitLength As Integer 'How long should the "manhit" bitmap be displayed?m ManAnim As Integer 'Which frame of man animation are we at?m ManX As Integer 'What is the man's X coordinate?m BoyAnim As Integer 'Which frame of boy animation are we at?m IsBoyFire As Boolean 'Is the boy firing or not?m BoyFireLength As Integer 'How long should the boy be firing?m DogAnim As Integer 'Which Frame of dog animation are we at?m IsDogYap As Boolean 'How long has it been since the last yap?m DogHits As Integer 'How many times has the dog been hit?m IsDogHit As Boolean 'Is the dog hit?m DogHitLength As Integer 'How long should the dog be hit for?m IsDogDead As Boolean 'Is the dog dead?m IsButtonDepressed(2) As Boolean 'Are any of the buttons pressed?m IsPaused As Boolean 'Is the game paused?m FinalAnimationRate As Integer 'How long have we been waiting since the last anim screen?m SlingHold As Integer 'How long did the boy hold the slingshot?vate Type RockType 'A special type to contain rock dataxCoord As Integer 'Rock's x coordyCoord As Integer 'Rock's y coordxSpeed As Integer 'Rocks horizontal speedySpeed As Integer 'Rocks vertical speedExists As Boolean

    d Type

    m Rocks() As RockType

    blic Sub Initialize()

    'Initialize the variablesGameRunning = TrueGameWon = FalseGameLost = FalseGameWonTime = 0GameLostTime = 0ReDim Rocks(0)Rocks(0).Exists = FalseSlingHold = 0IsButtonDepressed(0) = False

    IsButtonDepressed(1) = FalseIsButtonDepressed(2) = FalseIsManHit = FalseManHitLength = 0ManAnim = 4ManX = 60BoyAnim = 0IsBoyFire = FalseBoyFireLength = 0DogAnim = 0IsDogYap = FalseDogHits = 0IsDogHit = FalseDogHitLength = 0

    IsDogDead = FalseGameInitialized = TrueIsPaused = False

    'Load the spritesLoadSurfaces

    d Sub

    vate Sub LoadSurfaces()

    m i As Integerm CKey As DDCOLORKEYm ddsdNewSprite As DDSURFACEDESC2

    'This routine loads all of the surfaces we're going to be using

    'Set up those components of the surface description that will stay the sameddsdNewSprite.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHTddsdNewSprite.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

    'Set up those components of the colour key that will stay the sameCKey.low = 0

  • 8/7/2019 DOG3 Game Project

    22/33

    meScreen - 3

    CKey.high = 0

    'Load the backgroundddsdNewSprite.lWidth = BackgroundWidthddsdNewSprite.lHeight = BackgroundHeightSet BackGround = DDraw.LoadSurface(App.Path & "\data\background_game.bmp", ddsdNewSprite)

    'Load the "Man" bitmapsddsdNewSprite.lWidth = ManWidthddsdNewSprite.lHeight = ManHeightFor i = 0 To 7

    Set Man(i) = DDraw.LoadSurface(App.Path & "\data\man" & i + 1 & ".bmp", ddsdNewSprite)Man(i).SetColorKey DDCKEY_SRCBLT, CKey

    NextSet ManHit = DDraw.LoadSurface(App.Path & "\data\manhit.bmp", ddsdNewSprite)ManHit.SetColorKey DDCKEY_SRCBLT, CKey

    'Load the "Boy" bitmapsddsdNewSprite.lWidth = BoyWidthddsdNewSprite.lHeight = BoyHeightSet Boy(0) = DDraw.LoadSurface(App.Path & "\data\boyaim1.bmp", ddsdNewSprite)Boy(0).SetColorKey DDCKEY_SRCBLT, CKeySet Boy(1) = DDraw.LoadSurface(App.Path & "\data\boyaim3.bmp", ddsdNewSprite)Boy(1).SetColorKey DDCKEY_SRCBLT, CKeySet Boy(2) = DDraw.LoadSurface(App.Path & "\data\boyaim5.bmp", ddsdNewSprite)Boy(2).SetColorKey DDCKEY_SRCBLT, CKey

    Set BoyFire(0) = DDraw.LoadSurface(App.Path & "\data\boyfire1.bmp", ddsdNewSprite)BoyFire(0).SetColorKey DDCKEY_SRCBLT, CKeySet BoyFire(1) = DDraw.LoadSurface(App.Path & "\data\boyfire3.bmp", ddsdNewSprite)BoyFire(1).SetColorKey DDCKEY_SRCBLT, CKeySet BoyFire(2) = DDraw.LoadSurface(App.Path & "\data\boyfire5.bmp", ddsdNewSprite)BoyFire(2).SetColorKey DDCKEY_SRCBLT, CKey

    'Load the "Dog" bitmapsddsdNewSprite.lWidth = DogWidthddsdNewSprite.lHeight = DogHeightSet Dog(0) = DDraw.LoadSurface(App.Path & "\data\dog1.bmp", ddsdNewSprite)Dog(0).SetColorKey DDCKEY_SRCBLT, CKeySet Dog(1) = DDraw.LoadSurface(App.Path & "\data\dog2.bmp", ddsdNewSprite)Dog(1).SetColorKey DDCKEY_SRCBLT, CKey

    Set Dog(2) = DDraw.LoadSurface(App.Path & "\data\dogyap.bmp", ddsdNewSprite)Dog(2).SetColorKey DDCKEY_SRCBLT, CKeySet Dog(3) = DDraw.LoadSurface(App.Path & "\data\doghit.bmp", ddsdNewSprite)Dog(3).SetColorKey DDCKEY_SRCBLT, CKeySet Dog(4) = DDraw.LoadSurface(App.Path & "\data\dogdead.bmp", ddsdNewSprite)Dog(4).SetColorKey DDCKEY_SRCBLT, CKey

    'Load the "Rock" bitmapddsdNewSprite.lWidth = RockWidthddsdNewSprite.lHeight = RockHeightSet Rock = DDraw.LoadSurface(App.Path & "\data\rock.bmp", ddsdNewSprite)Rock.SetColorKey DDCKEY_SRCBLT, CKey

    'Load the "Button" bitmaps

    ddsdNewSprite.lWidth = ButtonWidthddsdNewSprite.lHeight = ButtonHeightFor i = 0 To 2

    Set Button(i) = DDraw.LoadSurface(App.Path & "\data\depress_button" & i + 2 & ".bmp", ddsdNprite)

    Button(i).SetColorKey DDCKEY_SRCBLT, CKeyNext

    'Load the "Pause" bitmapddsdNewSprite.lWidth = PauseWidthddsdNewSprite.lHeight = PauseHeightSet Pause = DDraw.LoadSurface(App.Path & "\data\pause.bmp", ddsdNewSprite)Pause.SetColorKey DDCKEY_SRCBLT, CKey

    'Load the "YouWin" bitmapddsdNewSprite.lWidth = YouWinWidthddsdNewSprite.lHeight = YouWinHeightSet YouWin = DDraw.LoadSurface(App.Path & "\data\youwin.bmp", ddsdNewSprite)YouWin.SetColorKey DDCKEY_SRCBLT, CKey

    'Load the "YouLose" bitmapddsdNewSprite.lWidth = YouLoseWidthddsdNewSprite.lHeight = YouLoseHeight

  • 8/7/2019 DOG3 Game Project

    23/33

    meScreen - 4

    Set YouLose = DDraw.LoadSurface(App.Path & "\data\youlose.bmp", ddsdNewSprite)YouLose.SetColorKey DDCKEY_SRCBLT, CKey

    'Load the "ManWin" bitmapsddsdNewSprite.lWidth = ManWinWidthddsdNewSprite.lHeight = ManWinHeightFor i = 0 To 9

    Set ManWin(i) = DDraw.LoadSurface(App.Path & "\data\manwin" & i + 1 & ".bmp", ddsdNewSprite

    ManWin(i).SetColorKey DDCKEY_SRCBLT, CKeyNext

    'Load the "ManFall" bitmapsddsdNewSprite.lWidth = ManFallWidthddsdNewSprite.lHeight = ManFallHeightFor i = 0 To 4

    Set ManFall(i) = DDraw.LoadSurface(App.Path & "\data\manfall" & i + 1 & ".bmp", ddsdNewSpri

    ManFall(i).SetColorKey DDCKEY_SRCBLT, CKeyNext

    'Load the "BoyHappy" bitmapsddsdNewSprite.lWidth = BoyHappyWidthddsdNewSprite.lHeight = BoyHappyHeightFor i = 0 To 9

    Set BoyHappy(i) = DDraw.LoadSurface(App.Path & "\data\boyhappy" & i + 1 & ".bmp", ddsdNewSp

    e)BoyHappy(i).SetColorKey DDCKEY_SRCBLT, CKey

    Next

    'Load the "BoySad" bitmapsddsdNewSprite.lWidth = BoySadWidthddsdNewSprite.lHeight = BoySadHeightFor i = 0 To 4

    Set BoySad(i) = DDraw.LoadSurface(App.Path & "\data\boysad" & i + 1 & ".bmp", ddsdNewSprite

    BoySad(i).SetColorKey DDCKEY_SRCBLT, CKeyNext

    d Sub

    blic Sub HandleKeys()

    'Get the current state of the keyboardDInput.CheckKeys

    'Has the escape key been pressed?If DInput.aKeys(DIK_ESCAPE) Then FrmDog.ExitProgram

    'Determine if the player wishes to play again after winning or losingIf (GameWon Or GameLost) And DInput.aKeys(DIK_Y) Then

    TerminateInitialize

    End If

    'Determine if the player wishes to quit after winning or losingIf (GameWon Or GameLost) And DInput.aKeys(DIK_N) Then

    FrmDog.ExitProgramEnd If

    'If the game has been won or lost, don't check for other keystrokesIf GameWon Or GameLost Then Exit Sub

    'Check for unpausingIf DInput.aKeys(DIK_F1) Then

    IsPaused = FalseIsButtonDepressed(2) = False

    End If

    'If the game is paused, don't check other keystrokesIf IsPaused Then Exit Sub

    'Move the boys arms up if user presses upStatic UpKey As BooleanIf DInput.aKeys(DIK_UP) And UpKey = False Then

    UpKey = TrueIf BoyAnim < 2 Then BoyAnim = BoyAnim + 1

  • 8/7/2019 DOG3 Game Project

    24/33

    meScreen - 5

    ElseIf Not (DInput.aKeys(DIK_UP)) ThenUpKey = False

    End If

    'Move the boys arms down if user presses upStatic DownKey As BooleanIf DInput.aKeys(DIK_DOWN) And DownKey = False Then

    DownKey = TrueIf BoyAnim > 0 Then BoyAnim = BoyAnim - 1

    ElseIf Not (DInput.aKeys(DIK_DOWN)) ThenDownKey = False

    End If

    'Determine how fast to shoot the bullet (spacebar)Static SpaceKey As BooleanIf DInput.aKeys(DIK_SPACE) And SpaceKey = False Then

    SpaceKey = TrueElseIf Not (DInput.aKeys(DIK_SPACE)) And SpaceKey = True Then

    SpaceKey = FalseFireRock

    End IfIf SpaceKey = True Then SlingHold = SlingHold + 1

    d Sub

    blic Sub Physics()

    m i As Integer

    'Animate and step the physics functions

    'If the game is won or lost then skip the physicsIf GameWon Or GameLost Then Exit Sub

    'If the game is paused, skip the physicsIf IsPaused Then Exit Sub

    'Animate the manStatic ManRate As IntegerIf ManRate >= ManSpeed And ManX >= ManSwingStart Then

    ManRate = 0If ManAnim < 7 Then ManAnim = ManAnim + 1If ManAnim = 7 Then ManAnim = 0

    ElseManRate = ManRate + 1

    End If

    'Move the manStatic ManMoveRate As IntegerIf ManMoveRate = ManMoveSpeed Then

    ManMoveRate = 0If ManX ManMoveStop - 18 Then ManX = ManMoveStop

    Else

    ManMoveRate = ManMoveRate + 1End If

    'Animate the dogStatic DogRate As IntegerIf DogRate = DogSpeed Then

    DogRate = 0IsDogYap = FalseIf DogAnim = 0 Then

    DogAnim = 1Else

    DogAnim = 0End If

    Else

    DogRate = DogRate + 1End If

    'Is the dog yapping?Static DogYapRate As IntegerIf DogYapRate = DogYapSpeed Then

    DogYapRate = 0IsDogYap = TrueIf IsDogDead = False And IsDogHit = False Then DSound.PlaySound SoundID(SndDogYap)

  • 8/7/2019 DOG3 Game Project

    25/33

    meScreen - 6

    ElseDogYapRate = DogYapRate + 1

    End If

    'Has the dog been hit?If ManX >= ManMoveStop And ManAnim = 0 Then

    DSound.PlaySound SoundID(SndDogHit)DogHitLength = 0DogHits = DogHits + 1IsDogHit = True

    End If

    'Is the dog dead?If ManX >= ManMoveStop And ManAnim = 0 And DogHits >= 6 Then

    DSound.PlaySound SoundID(SndDogDead)GameLost = TrueGameLostTime = 0IsDogDead = True

    End If

    'Is the man over the edge?If ManX = 575 Then RemoveRock iIf Rocks(i).xCoord

  • 8/7/2019 DOG3 Game Project

    26/33

    meScreen - 7

    If IsBoyFire = True ThenIf BoyFireLength < 3 Then

    BoyFireLength = BoyFireLength + 1DDraw.DisplaySprite DestRect, BoyFire(BoyAnim), SrcRect

    ElseIsBoyFire = False

    End IfEnd IfIf IsBoyFire = False Then DDraw.DisplaySprite DestRect, Boy(BoyAnim), SrcRect

    End If

    'Display the dogWith SrcRect

    .Bottom = DogHeight

    .Left = 0

    .Right = DogWidth

    .Top = 0End WithWith DestRect

    .Bottom = DogHeight + DogY

    .Left = DogX

    .Right = DogWidth + DogX

    .Top = DogYEnd WithIf Not (GameLost) Then

    If IsDogHit = True And IsDogDead = False Then

    If DogHitLength < 3 ThenDogHitLength = DogHitLength + 1DDraw.DisplaySprite DestRect, Dog(3), SrcRect

    ElseIsDogHit = False

    End IfEnd IfIf IsDogYap = False And IsDogHit = False And IsDogDead = False Then DDraw.DisplaySprite Des

    ct, Dog(DogAnim), SrcRectIf IsDogYap And IsDogHit = False And IsDogDead = False Then DDraw.DisplaySprite DestRect, D

    2), SrcRectIf IsDogDead Then DDraw.DisplaySprite DestRect, Dog(4), SrcRect

    End If

    'Display the manWith SrcRect

    .Bottom = ManHeight

    .Left = 0

    .Right = ManWidth

    .Top = 0End WithWith DestRect

    .Bottom = ManHeight + ManY

    .Left = ManX

    .Right = ManWidth + ManX

    .Top = ManYEnd WithIf Not (GameWon Or GameLost) Then

    If IsManHit = False And ManX >= ManSwingStart ThenDDraw.DisplaySprite DestRect, Man(ManAnim), SrcRect

    ElseIf IsManHit = False ThenDDraw.DisplaySprite DestRect, Man(4), SrcRect

    End IfIf IsManHit = True And ManHitLength < 3 Then

    ManHitLength = ManHitLength + 1DDraw.DisplaySprite DestRect, ManHit, SrcRect

    ElseIsManHit = False

    End IfEnd If

    'Display the buttons if depressed

    With SrcRect.Bottom = ButtonHeight.Left = 0.Right = ButtonWidth.Top = 0

    End WithWith DestRect

    .Bottom = 600

    .Left = 0

  • 8/7/2019 DOG3 Game Project

    27/33

  • 8/7/2019 DOG3 Game Project

    28/33

    meScreen - 9

    'Check to see if the mouse is over a buttonIf Sqr((Cursor.xPos - 95) ^ 2 + (Cursor.yPos - 517) ^ 2) < 20 Then IsButtonDepressed(0) = TrueIf Sqr((Cursor.xPos - 699) ^ 2 + (Cursor.yPos - 505) ^ 2) < 15 Then IsButtonDepressed(1) = TrueIf Sqr((Cursor.xPos - 712) ^ 2 + (Cursor.yPos - 525) ^ 2) < 15 Then

    IsButtonDepressed(2) = TrueDSound.PlaySound SoundID(SndClick) 'Play the click sound

    End If

    d Sub

    vate Sub FireRock()

    m i As Integerm FreeRock As Integer

    'This routine creates a new rock and set it in motion

    'Set the boy anim to "fire"IsBoyFire = TrueBoyFireLength = 0

    'Play the rock soundDSound.PlaySound SoundID(SndBoyShoot)

    'Check if there's a free spot in the rocks array

    FreeRock = -1For i = 0 To UBound(Rocks)

    If Rocks(i).Exists = False ThenFreeRock = iExit For

    End IfNext

    'If there's no free spot, then make a new oneIf FreeRock = -1 Then

    ReDim Preserve Rocks(UBound(Rocks) + 1)FreeRock = UBound(Rocks)

    End If

    'Set this rock as "existing"Rocks(FreeRock).Exists = True

    'Set the rock's horizontal speedRocks(FreeRock).xSpeed = SlingHold * 5

    'Set the rock's vertical speedIf BoyAnim = 0 Then Rocks(FreeRock).ySpeed = 0If BoyAnim = 1 Then Rocks(FreeRock).ySpeed = 5If BoyAnim = 2 Then Rocks(FreeRock).ySpeed = 10

    'Set the rock's initial X and Y coordsIf BoyAnim = 0 Then

    Rocks(FreeRock).xCoord = RockStart1X

    Rocks(FreeRock).yCoord = RockStart1YElseIf BoyAnim = 1 Then

    Rocks(FreeRock).xCoord = RockStart2XRocks(FreeRock).yCoord = RockStart2Y

    ElseIf BoyAnim = 2 ThenRocks(FreeRock).xCoord = RockStart3XRocks(FreeRock).yCoord = RockStart3Y

    End If

    'Reset the sling strength valueSlingHold = 0

    d Sub

    vate Sub RemoveRock(Index As Integer)

    'Remove a rock from the rock arrayRocks(Index).Exists = False

    d Sub

    vate Sub GameLostDisplay()

  • 8/7/2019 DOG3 Game Project

    29/33

    meScreen - 10

    m DestRect As RECTm SrcRect As RECT

    GameLostTime = GameLostTime + 1

    'Display the man animationWith SrcRect

    .Bottom = ManWinHeight

    .Left = 0

    .Right = ManWinWidth

    .Top = 0End WithWith DestRect

    .Bottom = ManY + ManWinHeight

    .Left = ManX - 300

    .Right = ManX - 300 + ManWinWidth

    .Top = ManYEnd WithIf GameLostTime < 10 * FinalAnimationSpeed Then

    DDraw.DisplaySprite DestRect, ManWin(GameLostTime \ FinalAnimationSpeed), SrcRectElse

    DDraw.DisplaySprite DestRect, ManWin(9), SrcRectEnd If

    'Display the boy animationWith SrcRect

    .Bottom = BoySadHeight

    .Left = 0

    .Right = BoySadWidth

    .Top = 0End WithWith DestRect

    .Bottom = BoyY + BoySadHeight

    .Left = BoyX

    .Right = BoyX + BoySadWidth

    .Top = BoyYEnd WithIf GameLostTime < 5 * FinalAnimationSpeed Then

    DDraw.DisplaySprite DestRect, BoySad(GameLostTime \ FinalAnimationSpeed), SrcRectElse

    DDraw.DisplaySprite DestRect, BoySad(4), SrcRectEnd If

    'Display the text boxWith SrcRect

    .Bottom = YouLoseHeight

    .Left = 0

    .Right = YouLoseWidth

    .Top = 0End WithIf GameLostTime > 10 * FinalAnimationSpeed Then DDraw.DisplaySprite SrcRect, YouLose, SrcRect

    d Sub

    vate Sub GameWonDisplay()

    m DestRect As RECTm SrcRect As RECT

    GameWonTime = GameWonTime + 1

    'Display the boy animationWith SrcRect

    .Bottom = BoyHappyHeight

    .Left = 0

    .Right = BoyHappyWidth

    .Top = 0End With

    With DestRect.Bottom = BoyY + BoyHappyHeight.Left = BoyX.Right = BoyX + BoyHappyWidth.Top = BoyY

    End WithIf GameWonTime < 10 * FinalAnimationSpeed Then

    DDraw.DisplaySprite DestRect, BoyHappy(GameWonTime \ FinalAnimationSpeed), SrcRectElse

  • 8/7/2019 DOG3 Game Project

    30/33

    meScreen - 11

    DDraw.DisplaySprite DestRect, BoyHappy(9), SrcRectEnd If

    'Display the boy animationWith SrcRect

    .Bottom = ManFallHeight

    .Left = 0

    .Right = ManFallWidth

    .Top = 0End WithWith DestRect

    .Bottom = ManY + ManFallHeight

    .Left = ManX

    .Right = ManX + ManFallWidth

    .Top = ManYEnd WithIf GameWonTime < 5 Then

    DDraw.DisplaySprite DestRect, ManFall(GameWonTime \ FinalAnimationSpeed), SrcRectElse

    DDraw.DisplaySprite DestRect, ManFall(4), SrcRectEnd If

    'Display the text boxWith SrcRect

    .Bottom = YouWinHeight

    .Left = 0

    .Right = YouWinWidth

    .Top = 0End WithIf GameWonTime > 10 * FinalAnimationSpeed Then DDraw.DisplaySprite SrcRect, YouWin, SrcRect

    d Sub

    blic Sub Terminate()

    m i As Integer

    'Reset the running variablesGameRunning = FalseGameInitialized = False

    'Destroys all of the game objectsFor i = 0 To 7

    Set Man(i) = NothingSet ManHit = Nothing

    NextFor i = 0 To 2

    Set Boy(i) = NothingSet BoyFire(i) = Nothing

    NextFor i = 0 To 4

    Set Dog(i) = NothingNextSet BackGround = Nothing

    Set Rock = Nothing

    d Sub

  • 8/7/2019 DOG3 Game Project

    31/33

    oScreen - 1

    m BackGround As DirectDrawSurface7 'Contains the "BackGround" bitmapm DepressButton As DirectDrawSurface7 'Contains the "Depress_Button1" bitmap

    bal InfoRunning As Boolean 'Determines if the entry screen is running or notbal InfoInitialized As Boolean 'Determines if the Screen has been initialized

    rite Size Constantsnst BackgroundWidth = 800st BackgroundHeight = 600nst DepressButtonWidth = 200st DepressButtonHeight = 200

    rite Location Constantsst DepressButtonX = 600st DepressButtonY = 400

    rite Location/Condition Variablesm IsButtonDepressed As Boolean

    blic Sub Initialize()

    'Redisplay the mouse cursorCursor.CursorToggle

    'Initialize the globalsInfoRunning = True

    IsButtonDepressed = FalseInfoInitialized = True

    'Load the spritesLoadSurfaces

    d Sub

    vate Sub LoadSurfaces()

    m i As Integerm CKey As DDCOLORKEYm ddsdNewSprite As DDSURFACEDESC2

    'This routine loads all of the surfaces we're going to be using

    'Set up those components of the surface description that will stay the sameddsdNewSprite.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHTddsdNewSprite.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

    'Set up those components of the colour key that will stay the sameCKey.low = 0CKey.high = 0

    'Load the backgroundddsdNewSprite.lWidth = BackgroundWidthddsdNewSprite.lHeight = BackgroundHeightSet BackGround = DDraw.LoadSurface(App.Path & "\data\background_info.bmp", ddsdNewSprite)

    'Load the backgroundddsdNewSprite.lWidth = DepressButtonWidthddsdNewSprite.lHeight = DepressButtonHeightSet DepressButton = DDraw.LoadSurface(App.Path & "\data\depress_button1.bmp", ddsdNewSprite)DepressButton.SetColorKey DDCKEY_SRCBLT, CKey

    d Sub

    blic Sub Display()

    m i As Integerm SrcRect As RECTm DestRect As RECT

    'Fill the backbuffer with the background bitmapWith SrcRect

    .Bottom = BackgroundHeight

    .Left = 0

    .Right = BackgroundWidth

    .Top = 0End WithDDraw.DisplaySprite DestRect, BackGround, SrcRect, True, 0, 0

  • 8/7/2019 DOG3 Game Project

    32/33

    oScreen - 2

    'Display the depressed button if clickedIf IsButtonDepressed Then

    With SrcRect.Bottom = DepressButtonHeight.Left = 0.Right = DepressButtonWidth.Top = 0

    End WithWith DestRect

    .Bottom = DepressButtonY + DepressButtonHeight

    .Left = DepressButtonX

    .Right = DepressButtonX + DepressButtonWidth

    .Top = DepressButtonYEnd WithDDraw.DisplaySprite DestRect, DepressButton, SrcRect 'Show the depressed buttonDSound.PlaySound SoundID(SndClick) 'Play the click soundInfoRunning = False 'Remove the info screen, start the

    me!GameRunning = True 'Start the game screen running

    End If

    d Sub

    blic Sub Click()

    'Check to see if the mouse is over the buttonIf Sqr((Cursor.xPos - 640) ^ 2 + (Cursor.yPos - 455) ^ 2) < 40 Then IsButtonDepressed = True

    d Sub

    blic Sub Terminate()

    'Reset the running variableInfoRunning = FalseInfoInitialized = False

    'Destroy the objectsSet BackGround = Nothing

    Set DepressButton = Nothing

    d Sub

  • 8/7/2019 DOG3 Game Project

    33/33

    mer - 1

    vate Declare Function GetTickCount Lib "kernel32" () As Long

    blic Function Ticker(Optional Reset As Boolean) As Long

    tic oldtime As Long

    If Reset Then'reset timer and return zerooldtime = GetTickCount()Ticker = 0

    Else'return difference between oldtime and current timeTicker = GetTickCount() - oldtime

    End If

    d Function

    blic Function Time() As Long

    'Simply returns the system tickcountTime = GetTickCount()

    d Function