home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD76727112000.psc / modDX.bas < prev    next >
Encoding:
BASIC Source File  |  2000-07-10  |  3.8 KB  |  100 lines

  1. Attribute VB_Name = "modDX"
  2. Option Explicit
  3.  
  4. 'This is a very basic program to help get people started in creating games.
  5. 'This has no sort of collision detection what-so-ever and I know about the end of
  6. 'the screen bug where the sprite just disappears. This also doesn't use Direct
  7. 'Input for the keystrokes. However, this is a good way of learning the basics
  8. 'of Direct Draw and Direct Sound despite the ugly sprite.
  9. '
  10. 'Thanks,
  11. 'Jason Shimkoski (basspler@aol.com)
  12.  
  13.  
  14. 'The Main DirectX Object
  15. Public dxMain As New DirectX7
  16.  
  17. 'The Sprites Current X and Y Values
  18. Public sX As Integer
  19. Public sY As Integer
  20.  
  21. 'Checks to See if The Main Loop should stop or not
  22. Public running As Boolean
  23.  
  24. 'This sets the screens display and the cooperative levels
  25. Sub DX_SetDisplayCoopLevel(Hdl As Long, sWidth As Long, sHeight As Long, sBPP As Long)
  26.     'This one is for the Direct Sound
  27.     Call dsMain.SetCooperativeLevel(Hdl, DSSCL_PRIORITY)
  28.     'This one is for Direct Draw
  29.     Call ddMain.SetCooperativeLevel(Hdl, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWMODEX)
  30.     'This sets the display mode
  31.     Call ddMain.SetDisplayMode(sWidth, sHeight, sBPP, 0, DDSDM_DEFAULT)
  32. End Sub
  33.  
  34. 'This restores everything to normal when the Program is exited
  35. Sub DX_RestoreDisplayCoopLevel(Hdl As Long)
  36.     'This sets the Direct Sound Cooperative Level to normal
  37.     Call dsMain.SetCooperativeLevel(Hdl, DSSCL_NORMAL)
  38.     'This sets the Direct Draw Cooperative Level to normal
  39.     Call ddMain.SetCooperativeLevel(Hdl, DDSCL_NORMAL)
  40.     'This restores the users default Display Mode
  41.     Call ddMain.RestoreDisplayMode
  42. End Sub
  43.  
  44. 'This is where everything comes together
  45. Sub DX_Init()
  46.  
  47.     'This tells the loop below that it is running
  48.     running = True
  49.  
  50.     On Error Resume Next
  51.     'This creates the Direct Draw object
  52.     Set ddMain = dxMain.DirectDrawCreate("")
  53.     'This creates the Direct Sound object
  54.     Set dsMain = dxMain.DirectSoundCreate("")
  55.     
  56.     'This calls the sub from above that sets the Display and the Cooperative Levels
  57.     Call DX_SetDisplayCoopLevel(frmMain.hWnd, 640, 480, 16)
  58.     'This calls a sub from modDD that creates the Primary Surface and the Backbuffer
  59.     DD_CreatePrimBackBuf
  60.  
  61.     'This calls a sub from modDD that Creates Graphics from their Files
  62.     DD_CreateGraphicsFromFile
  63.     'This calls a sub from modDS that Creates Sounds from their Files
  64.     DS_CreateSoundsFromFile
  65.  
  66.     'This calls a sub from modDS that Starts the Sound file and tells whether
  67.     'it should be looped or not
  68.     Call DS_PlaySound(False)
  69.  
  70.     'This is the main render loop
  71.     Do
  72.         'This blits a black color fill to the back buffer
  73.         Call BackBuf.BltColorFill(rBGSurf, RGB(0, 0, 0))
  74.         'This calls a sub from modDD that blits the Background to the back buffer
  75.         Call DD_BltFast(0, 0, 640, 480, BGSurf, rBGSurf, 0, 0, False)
  76.         'This calls a sub from modDD that blits the Sprite to the back buffer
  77.         Call DD_BltFast(0, 0, 50, 41, SpriteSurf, rSpriteSurf, sX, sY, True)
  78.         'This draws the text at the top of the form
  79.         'please note that if this was created before the sprite, the sprite wouldn't
  80.         'be able to cross behind it
  81.         Call BackBuf.DrawText(200, 25, "This is an Awesome Thing, Dude!", False)
  82.         'This flips everything to the Primary Surface
  83.         Call PrimBuf.Flip(Nothing, DDFLIP_WAIT)
  84.         'This is so windows can process other events
  85.         DoEvents
  86.     'This tells the program to loop until the user quits the program
  87.     Loop Until running = False
  88.  
  89. End Sub
  90.  
  91. 'This ends the app
  92. Sub DX_EndIt()
  93.     'This tells the render loop to stop working
  94.     running = False
  95.     'This calls a sub from above that sets everything to normal
  96.     Call DX_RestoreDisplayCoopLevel(frmMain.hWnd)
  97.     'This ends the application
  98.     End
  99. End Sub
  100.