home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming for Teens (2nd Edition) / 3DGPFT2E.iso / Source / Chapter13 / demo13-04.bb < prev    next >
Encoding:
Text File  |  2009-01-21  |  1.8 KB  |  92 lines

  1. ;demo13-04.bb - A chase camera!
  2. ;_______________
  3.  
  4.  
  5. camdistance=10
  6.  
  7. Graphics3D 640,480
  8. SetBuffer BackBuffer()
  9.  
  10. ;Key Constants
  11. Const ESC_KEY = 1
  12. Const UP_KEY = 200
  13. Const DOWN_KEY = 208
  14. Const LEFT_KEY = 203
  15. Const RIGHT_KEY = 205
  16. Const S_KEY = 31
  17.  
  18.  
  19. ; Creating the types
  20.  
  21. type_player=1
  22. type_ground=2
  23.  
  24.  
  25. ; Create camera
  26. camera=CreateCamera()
  27.  
  28.  
  29. ; Creating a light
  30.  
  31. light=CreateLight()
  32.  
  33. ;Create a texture
  34. grid_tex=CreateTexture( 32,32,8 )
  35. ScaleTexture grid_tex,10,10
  36. SetBuffer TextureBuffer( grid_tex )
  37. Color 0,0,64:Rect 0,0,32,32
  38. Color 0,0,255:Rect 0,0,32,32,False
  39. SetBuffer BackBuffer()
  40.  
  41. ;Set up texture
  42. grid_plane=CreatePlane()
  43. EntityTexture grid_plane,grid_tex
  44. EntityBlend grid_plane,1
  45. EntityAlpha grid_plane,.6
  46. EntityFX grid_plane,1
  47. EntityType grid_plane, type_ground
  48. PositionEntity grid_plane, 0,-1,0
  49.  
  50. ; Creating a cone
  51.  
  52. cone=CreateCone(64)
  53. EntityType cone,type_player
  54. PositionEntity cone, 0,1,5
  55. ScaleEntity cone ,0.4,0.4,0.4
  56. EntityRadius cone, 0.5
  57. Texture=CreateTexture(16,16): SetBuffer TextureBuffer(texture)
  58. ClsColor 256,6,56
  59. Cls
  60. Color 12,126,256
  61. Rect 0,0,8,8,1
  62. Rect 8,8,8,8,1
  63. ScaleTexture Texture,.2,.2
  64. EntityTexture cone,texture
  65.  
  66. ; This following code makes our program run
  67.  
  68. While Not KeyDown(ESC_KEY)
  69.  
  70.  
  71. If KeyDown(DOWN_KEY)=True Then velocity#=velocity#-0.001
  72. If KeyDown(UP_KEY)=True Then velocity#=velocity#+0.001
  73. If KeyDown (S_KEY) Then velocity#=0
  74. If KeyDown (S_KEY) Then xvelocity#=0
  75. If KeyDown(LEFT_KEY)=True Then xvelocity#=xvelocity#-0.001
  76. If KeyDown(RIGHT_KEY)=True Then xvelocity#=xvelocity#+0.001
  77.  
  78.  
  79. MoveEntity cone,xvelocity#,0,velocity#
  80. TranslateEntity cone, 0,-0.03,0
  81.  
  82. Collisions type_player,type_ground,2,2
  83. Collisions type_ground,type_player,2,2
  84.  
  85. UpdateWorld
  86. RenderWorld
  87. Flip
  88. Wend
  89.  
  90. End
  91.  
  92.