home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / sources / chapter09 / SpriteTest / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2004-10-20  |  3.8 KB  |  117 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   3045
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4260
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   3045
  13.    ScaleWidth      =   4260
  14.    StartUpPosition =   2  'CenterScreen
  15. Attribute VB_Name = "Form1"
  16. Attribute VB_GlobalNameSpace = False
  17. Attribute VB_Creatable = False
  18. Attribute VB_PredeclaredId = True
  19. Attribute VB_Exposed = False
  20. '----------------------------------------------------------------------
  21. ' Visual Basic Game Programming With DirectX
  22. ' SpriteTest Source Code File
  23. '----------------------------------------------------------------------
  24. Option Explicit
  25. Option Base 0
  26. 'Windows API functions and structures
  27. Private Declare Function GetTickCount Lib "kernel32" () As Long
  28. 'program constants
  29. Const SCREENWIDTH As Long = 640
  30. Const SCREENHEIGHT As Long = 480
  31. Const FULLSCREEN As Boolean = False
  32. Dim tavernSprite As TSPRITE
  33. Dim tavernImage As Direct3DTexture8
  34. Dim terrain As Direct3DSurface8
  35. Dim backbuffer As Direct3DSurface8
  36. Private Sub Form_Load()
  37.     Static lStartTime As Long
  38.     Static lCounter As Long
  39.     Static lNewTime As Long
  40.     'set up the main form
  41.     Form1.Caption = "SpriteTest"
  42.     Form1.AutoRedraw = False
  43.     Form1.BorderStyle = 1
  44.     Form1.ClipControls = False
  45.     Form1.KeyPreview = True
  46.     Form1.ScaleMode = 3
  47.     Form1.width = Screen.TwipsPerPixelX * (SCREENWIDTH + 12)
  48.     Form1.height = Screen.TwipsPerPixelY * (SCREENHEIGHT + 30)
  49.     Form1.Show
  50.     'initialize Direct3D
  51.     '*** note the changes made to this subroutine! I know, I know...
  52.     '*** this will be changed in an earlier chapter during AR
  53.     InitDirect3D Me.hwnd, SCREENWIDTH, SCREENHEIGHT, FULLSCREEN
  54.     Set backbuffer = d3ddev.GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO)
  55.     Set terrain = LoadSurface(App.Path & "\terrain.bmp", 640, 480)
  56.     If terrain Is Nothing Then
  57.         MsgBox "Error loading bitmap"
  58.         Shutdown
  59.     End If
  60.     Set tavernImage = LoadTexture(d3ddev, App.Path & "\tavern.bmp")
  61.     InitSprite d3ddev, tavernSprite
  62.     With tavernSprite
  63.         .width = 220
  64.         .height = 224
  65.         .ScaleFactor = 1
  66.         .x = 200
  67.         .y = 100
  68.     End With
  69.     Dim start As Long
  70.     start = GetTickCount()
  71.     'start main game loop
  72.     Do While True
  73.         If GetTickCount - start > 25 Then
  74.             
  75.             DrawSurface terrain, 0, 0
  76.             
  77.             'start rendering
  78.             d3ddev.BeginScene
  79.             
  80.             'draw the sprite
  81.             DrawSprite tavernImage, tavernSprite, &HFFFFFFFF
  82.         
  83.             'stop rendering
  84.             d3ddev.EndScene
  85.         
  86.             'draw the back buffer to the screen
  87.             d3ddev.Present ByVal 0, ByVal 0, 0, ByVal 0
  88.                         
  89.             start = GetTickCount
  90.             DoEvents
  91.         End If
  92.     Loop
  93. End Sub
  94. Public Sub DrawSurface(ByRef source As Direct3DSurface8, ByVal x As Long, ByVal y As Long)
  95.     Dim r As DxVBLibA.RECT
  96.     Dim point As DxVBLibA.point
  97.     Dim desc As D3DSURFACE_DESC
  98.     source.GetDesc desc
  99.     'set dimensions of the source image
  100.     r.Left = x
  101.     r.Top = y
  102.     r.Right = x + desc.width
  103.     r.bottom = y + desc.height
  104.         
  105.     'set the destination point
  106.     point.x = 0
  107.     point.y = 0
  108.     'draw the scroll window
  109.     d3ddev.CopyRects source, r, 1, backbuffer, point
  110. End Sub
  111. Private Sub Form_Unload(Cancel As Integer)
  112.     Shutdown
  113. End Sub
  114. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  115.     If KeyCode = 27 Then Shutdown
  116. End Sub
  117.