home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / sources / chapter08 / ScrollWorld / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2004-11-03  |  3.0 KB  |  83 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   3195
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3195
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12. Attribute VB_Name = "Form1"
  13. Attribute VB_GlobalNameSpace = False
  14. Attribute VB_Creatable = False
  15. Attribute VB_PredeclaredId = True
  16. Attribute VB_Exposed = False
  17. '---------------------------------------------------------------
  18. ' Visual Basic Game Programming for Teens
  19. ' Chapter 8 - ScrollWorld program
  20. ' Requires: Globals.bas, Direct3D.bas, TileScroller.bas
  21. '---------------------------------------------------------------
  22. Option Explicit
  23. Option Base 0
  24. Private Sub Form_Load()
  25.     'set up the main form
  26.     Form1.Caption = "ScrollWorld"
  27.     Form1.ScaleMode = 3
  28.     Form1.width = Screen.TwipsPerPixelX * (SCREENWIDTH + 12)
  29.     Form1.height = Screen.TwipsPerPixelY * (SCREENHEIGHT + 30)
  30.     Form1.Show
  31.     'initialize Direct3D
  32.     InitDirect3D Me.hwnd, SCREENWIDTH, SCREENHEIGHT, FULLSCREEN
  33.     'get reference to the back buffer
  34.     Set backbuffer = d3ddev.GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO)
  35.     'load the bitmap file
  36.     Set tiles = LoadSurface(App.Path & "\map1.bmp", 1024, 640)
  37.     'load the map data from the Mappy export file
  38.     LoadMap App.Path & "\map1.txt"
  39.     'create the small scroll buffer surface
  40.     Set scrollbuffer = d3ddev.CreateImageSurface( _
  41.         SCROLLBUFFERWIDTH, _
  42.         SCROLLBUFFERHEIGHT, _
  43.         dispmode.Format)
  44.     'this helps to keep a steady framerate
  45.     Dim start As Long
  46.     start = GetTickCount()
  47.     'clear the screen to black
  48.     d3ddev.Clear 0, ByVal 0, D3DCLEAR_TARGET, C_BLACK, 1, 0
  49.     'main loop
  50.     Do While (True)
  51.         'update the scroll position
  52.         UpdateScrollPosition
  53.        
  54.         'draw tiles onto the scroll buffer
  55.         DrawTiles
  56.         
  57.         'draw the scroll window onto the screen
  58.         DrawScrollWindow
  59.         'set the screen refresh to about 40 fps
  60.         If GetTickCount - start > 25 Then
  61.             d3ddev.Present ByVal 0, ByVal 0, 0, ByVal 0
  62.             start = GetTickCount
  63.             DoEvents
  64.         End If
  65.     Loop
  66. End Sub
  67. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  68.     'move mouse on left side to scroll left
  69.     If X < SCREENWIDTH / 2 Then SpeedX = -STEP
  70.     'move mouse on right side to scroll right
  71.     If X > SCREENWIDTH / 2 Then SpeedX = STEP
  72.     'move mouse on top half to scroll up
  73.     If Y < SCREENHEIGHT / 2 Then SpeedY = -STEP
  74.     'move mouse on bottom half to scroll down
  75.     If Y > SCREENHEIGHT / 2 Then SpeedY = STEP
  76. End Sub
  77. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  78.     If KeyCode = 27 Then Shutdown
  79. End Sub
  80. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  81.     Shutdown
  82. End Sub
  83.