home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming for Teens (2nd Edition) / 3DGPFT2E.iso / Source / Chapter01 / demo01-01.bb next >
Encoding:
Text File  |  2009-01-21  |  2.5 KB  |  114 lines

  1. ;demo01-01.bb - Jumping Cone, your first program!
  2. ;---------------------------------------
  3.  
  4. ;Set up the graphics 
  5. Graphics3D 640, 480
  6. SetBuffer BackBuffer()
  7.  
  8. ;Define constants
  9. Const ESC_KEY   = 1
  10. Const UP_KEY    = 200
  11. Const DOWN_KEY  = 208
  12.  
  13. ;Define variables 
  14. camdistance = 10
  15. type_player = 1
  16. type_ground = 2
  17.  
  18. ;track the position and jump of the cone
  19. velocity#   = 0
  20.  
  21. ;Create the camera, which is what the user sees
  22. camera=CreateCamera()
  23. RotateEntity camera, 45, 0, 0
  24.  
  25. ;Create the light, so the user can see!
  26. light=CreateLight()
  27.  
  28. ;Create a plane and texture, the actual objects on the screen
  29. ;Create texture
  30. grid_text = CreateTexture(32, 32, 8)
  31. ScaleTexture(grid_text, 10, 10)
  32.  
  33. ;Draw the texture, and reset the drawing back to the main screen
  34. SetBuffer TextureBuffer(grid_text)
  35.  
  36. ;Create two rectangles
  37. Color 0,0,64
  38. Rect 0,0,32,32
  39. Color 0,0,255
  40. Rect 0,0,32,32
  41.  
  42. SetBuffer BackBuffer()
  43.  
  44. ;Create the plane
  45. grid_plane = CreatePlane()
  46.  
  47.  
  48. CreateMirror()
  49.  
  50. HandleEntities(grid_plane, grid_text)
  51.  
  52. ;Create a cone
  53. cone = CreateCone(64)
  54. EntityType cone, type_player
  55. PositionEntity cone, 0, 1, 5
  56. ScaleEntity cone, 0.4, 0.4, 0.4
  57. EntityRadius cone, 0.5
  58.  
  59. ;Create texture for the cone
  60. texture = CreateTexture(16,16):SetBuffer TextureBuffer(texture)
  61. ClsColor 256, 6, 56
  62. Cls
  63. ;assign a color for the texture
  64. Color 12, 126, 256
  65. Rect 0, 0, 8, 8, 1
  66. Rect 8, 8, 8, 8, 1
  67. ScaleTexture texture, .2, .2
  68. ;put the texture on the cone
  69. EntityTexture cone, texture
  70.  
  71. ;MAIN LOOP
  72. While Not KeyDown(ESC_KEY)
  73.  
  74.  
  75.      
  76.     ;Handle User Input
  77.     If KeyDown(UP_KEY)    
  78.         velocity = velocity - .001
  79.     EndIf
  80.     If KeyDown(DOWN_KEY)  
  81.         velocity = velocity + 0.001 
  82.     EndIf
  83.     ;Move the cone and camera around to see everything
  84.     MoveEntity cone, 0, velocity, 0
  85.     TranslateEntity cone, 0, -0.03, 0
  86.     PositionEntity camera, EntityX(cone), 0, EntityZ(cone)
  87.     MoveEntity camera, 0, 0, -5
  88.     
  89.     ;Test for collisions so things can't go through walls
  90.     Collisions type_player, type_ground, 2, 2
  91.     Collisions type_ground, type_player, 2, 2
  92.     
  93.     UpdateWorld
  94.     RenderWorld
  95.     Flip
  96.     
  97.     Wend ;END MAIN LOOPS
  98.  
  99. End ;End of the program
  100.  
  101.  
  102. ;FUNCTIONS
  103.  
  104. ;Function HandleEntities() - this function assigns the texture to the grid plane and deals with Entities
  105. Function HandleEntities(grid_plane, grid_text)
  106.     ;Make texture and plane appear on screen
  107.  
  108.     EntityTexture grid_plane, grid_text
  109.     EntityBlend grid_plane, 1
  110.     EntityAlpha grid_plane, .6
  111.     EntityFX grid_plane, 1
  112.     EntityType grid_plane, type_ground
  113.  
  114. End Function