Set ddMain = DXMain.DirectDrawCreate("") 'Set the ddMain object to a new instance of DirectDraw
Me.Show 'Shows the form
ddMain.SetCooperativeLevel Me.hWnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN 'We want to monopolize the computer and display the thing in full screen
ddMain.SetDisplayMode 640, 480, 16, 0, DDSDM_DEFAULT 'sets the screen size and bit depth, DDSM_DDEFAULT is same in all projects
'Describe the Primary Surface
sdMain.lFlags = DDSD_CAPS 'Enables the DDSD_CAPS member
sdMain.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE 'This is a primary surface, is a complex surface and can be flipped
'Describes the back buffer
sdBack.ddsCaps.lCaps = DDSCAPS_SYSTEMMEMORY
sdBack.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
sdBack.lWidth = 640
sdBack.lHeight = 480
Set dsPrim = ddMain.CreateSurface(sdMain) 'Make a new surface that fits our description
Set dsBbuf = ddMain.CreateSurface(sdBack) 'Mack the back buffer
Set dsClip = ddMain.CreateClipper(0) 'Create the clipper object
dsClip.SetHWnd frmMain.hWnd
dsBbuf.SetClipper dsClip
dsPrim.SetClipper dsClip
'The DirectInput Initialization
Set diMain = DXMain.DirectInputCreate 'Create an instance of DirectInput
Set diDev = diMain.CreateDevice("GUID_SysKeyboard") 'Create an instance of the device
diDev.SetCommonDataFormat DIFORMAT_KEYBOARD 'Set data format to keyboard
diDev.SetCooperativeLevel Me.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE 'Set Co-operative level to Background and non_exclusive to give other applications some room
diDev.Acquire 'Get The Device
dsBbuf.SetForeColor vbWhite 'Set the forecolor to white to draw text
dsBbuf.SetFont Me.Font 'Set the font to the form font
End Sub
Private Sub Form_Unload(Cancel As Integer)
ShowCursor 1
End Sub
Public Sub Game_Loop()
Do_Keys 'Check out the key action
DxBlit 'Blit The Sprites
DoEvents
End Sub
Public Sub Do_Keys()
diDev.GetDeviceStateKeyboard diState
If diState.Key(DIK_ESCAPE) <> 0 Then
DxEnd
End If
'Check right key press
If diState.Key(DIK_RIGHT) <> 0 Then
Car.ShiftRight
End If
'Check left key press
If diState.Key(DIK_LEFT) <> 0 Then
Car.ShiftLeft
End If
'Check Up key press
If diState.Key(DIK_UP) <> 0 Then
Car.ShiftUP
End If
'Check left key press
If diState.Key(DIK_DOWN) <> 0 Then
Car.ShiftDown
End If
End Sub
Private Sub DxBlit()
Dim rect2 As RECT
Dim DestRect As RECT
FPS = FPS + 1
dsBbuf.SetFillColor Me.BackColor
'dsBbuf.SetForeColor Me.BackColor
dsBbuf.DrawBox 0, 0, 640, 480
dsBbuf.SetForeColor vbWhite
dsBbuf.DrawText 540, 440, "By: Cyril M Gupta", False