home *** CD-ROM | disk | FTP | other *** search
/ Game Programming for Teens / GameProgrammingForTeens.iso / Source / chapter06 / demo06-08.bb < prev    next >
Encoding:
Text File  |  2003-04-06  |  4.9 KB  |  230 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;demo06-08.bb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;By Maneesh Sethi;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ;This program allows the user to draw a picture.;;;;;
  5. ;There are no input variables required;;;;;;;;;;;;;;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8.  
  9. ;INITIALIZATION
  10. ;Set up Windowed Graphics Mode
  11. Graphics 640,480,0,2 
  12. ;Backbuffer
  13. SetBuffer BackBuffer() 
  14.  
  15.  
  16. ;Constant the keyboard keys
  17. Const ESCKEY = 1, ONEKEY = 2,TWOKEY = 3, THREEKEY = 4, FOURKEY = 5, FIVEKEY = 6, F10KEY = 68 
  18.  
  19. ;Tweak these numbers
  20. Const BUFFERHEIGHT = 480, BUFFERWIDTH = 640 
  21.  
  22. ;GLOBAL IMAGES
  23. Global greenimage = LoadImage("greencolor.bmp")
  24. Global redimage = LoadImage("redcolor.bmp")
  25. Global blueimage = LoadImage("bluecolor.bmp")
  26. Global blackimage = LoadImage("blackcolor.bmp")
  27. Global whiteimage = LoadImage("whitecolor.bmp")
  28. Global mouseimage = LoadImage("mousearrow.bmp")
  29. ; Create a blank image that will be used to draw on
  30. Global picturebuffer = CreateImage(BUFFERWIDTH,BUFFERHEIGHT) 
  31. ;VARIABLES
  32. ;Automatically select green as the color
  33. Global selectedcolor = 1 
  34.  
  35. ;MASKS
  36. ;Mask the white around icon
  37. MaskImage mouseimage,255,255,255 
  38. ;change mask so black is visible
  39. MaskImage blackimage,255,255,255 
  40. ;END INITIALIZATION
  41.  
  42. ;MAIN LOOP
  43. While Not KeyDown(ESCKEY)
  44.  
  45. ;Clears the screen
  46. Cls 
  47. ;Draws everything text related
  48. DrawAllText() 
  49.  
  50. ;Draws the mouse cursor
  51. DrawMouse() 
  52.  
  53. ;Test what keyboard buttons were pressed
  54. TestKeyboardInput() 
  55.  
  56. ;Test to see if user pressed any mouse buttons
  57. TestMouseInput() 
  58.  
  59. ;draw the picture
  60. DrawImage picturebuffer,0,100 
  61.  
  62. ;flip the buffers
  63. Flip 
  64. Wend 
  65. ;END MAIN LOOP
  66. ;EXIT
  67. ;
  68. ;END EXIT
  69.  
  70. ;FUNCTIONS
  71.  
  72. ;;;;;;;;;;;;;;;;;;
  73. ;Function DrawAllText()
  74. ;Calls functions that draw HUD of program
  75. ;No Parameters
  76. ;;;;;;;;;;;;;;;;;;
  77.  
  78. Function DrawAllText()
  79.  
  80. ;Draws the color choices
  81. DrawTextInfo() 
  82. ;Draws the selected color
  83. ColorText() 
  84.  
  85. ;Draws the location of the text
  86. MouseText() 
  87. End Function
  88.  
  89.  
  90. ;;;;;;;;;;;;;;;;;;
  91. ;Function TestMouseInput()
  92. ;If player presses on mouse, draw the color
  93. ;No Parameters
  94. ;;;;;;;;;;;;;;;;;;
  95. Function TestMouseInput()
  96.  
  97.  
  98. ;If player presses the left mouse button, draw the selected color
  99. If MouseDown(1) 
  100.     
  101.  
  102.     ;Begin drawing only on image
  103.     SetBuffer(ImageBuffer(picturebuffer)) 
  104.  
  105.     ; draw the selected color at the mouse location
  106.     Select (selectedcolor) 
  107.     Case 1
  108.         DrawImage(greenimage,MouseX(),MouseY()-100)
  109.     Case 2
  110.         DrawImage(redimage,MouseX(),MouseY()-100)
  111.     Case 3
  112.         DrawImage(blueimage,MouseX(),MouseY()-100)
  113.  
  114.     Case 4
  115.         DrawImage(blackimage,MouseX(),MouseY()-100)
  116.  
  117.     Case 5    
  118.         DrawImage(whiteimage,MouseX(),MouseY()-100)
  119.  
  120. End Select
  121. End If
  122.  
  123. ;reset the buffer back to the back buffer
  124. SetBuffer BackBuffer() 
  125.  
  126. End Function
  127.  
  128.  
  129. ;;;;;;;;;;;;;;;;;;
  130. ;Function TestKeyboardInput()
  131. ;Tests if the keyboard wants to change the selected color or take a screenshot
  132. ;No Parameters
  133. ;;;;;;;;;;;;;;;;;;
  134.  
  135.  
  136. Function TestKeyboardInput()
  137.  
  138. ;If user presses a number, select the corresponding color
  139. If KeyDown(ONEKEY)
  140.     selectedcolor = 1
  141. ElseIf KeyDown(TWOKEY)
  142.     selectedcolor = 2
  143. ElseIf KeyDown(THREEKEY)
  144.     selectedcolor = 3
  145. ElseIf KeyDown(FOURKEY)
  146.     selectedcolor = 4
  147. ElseIf KeyDown(FIVEKEY)
  148.     selectedcolor = 5
  149. EndIf
  150.  
  151.  
  152. ;If user presses F10, take a screenshot
  153. If KeyDown(F10KEY) 
  154.     ;Save the picture buffer as screenshot.bmp
  155.     SaveBuffer ImageBuffer(picturebuffer), "screenshot.bmp" 
  156. EndIf
  157.  
  158. End Function 
  159.  
  160.  
  161. ;;;;;;;;;;;;;;;;;;
  162. ;Function DrawMouse()
  163. ;Draws the Mouse Cursor
  164. ;No Parameters
  165. ;;;;;;;;;;;;;;;;;;
  166. Function DrawMouse()
  167.  
  168. ;Draw the mouse at the mouses location
  169. DrawImage mouseimage,MouseX(),MouseY() 
  170. End Function
  171.  
  172.  
  173. ;;;;;;;;;;;;;;;;;;
  174. ;Function ColorText()
  175. ;Chooses the selected color and writes it on the scren
  176. ;No Parameters
  177. ;;;;;;;;;;;;;;;;;;
  178. Function ColorText()
  179.  
  180. ;Assign the name of the color to selectedcolortext$
  181. Select (selectedcolor) 
  182.     Case 1
  183.             selectedcolortext$ = "Green"
  184.     Case 2
  185.             selectedcolortext$ = "Red"
  186.     Case 3
  187.             selectedcolortext$ = "Blue"
  188.     Case 4
  189.             selectedcolortext$ = "Black"
  190.     Case 5
  191.             selectedcolortext$ = "White"
  192. End Select
  193.  
  194. ;Write out the selected color
  195. Text 240, 20, "Selected Color: " + selectedcolortext$ 
  196.  
  197. End Function
  198.  
  199. ;;;;;;;;;;;;;;;;;;
  200. ;Function MouseText()
  201. ;Writes the mouses location on the screen
  202. ;No Parameters
  203. ;;;;;;;;;;;;;;;;;;
  204.  
  205. Function MouseText()
  206. mousextext$ = "Mouse X: " + MouseX()
  207. mouseytext$ = "Mouse Y: " + MouseY()
  208. Text 540,20,mousextext$
  209. Text 540,40,mouseytext$
  210. End Function
  211.  
  212. ;;;;;;;;;;;;;;;;;;
  213. ;Function DrawTextInfo()
  214. ;Displays the user's color choices
  215. ;No Parameters
  216. ;;;;;;;;;;;;;;;;;;
  217. Function DrawTextInfo()
  218. Locate 0,0 ;Put cursor at top left of screen
  219. ;Display color choice
  220. Print "Press the number of the color you wish to draw"
  221. Print "Colors:"
  222. Print "1. Green"
  223. Print "2. Red"
  224. Print "3. Blue"
  225. Print "4. Black"
  226. Print "5. White"
  227. Print "Press F10 to save image (text WILL NOT be saved)"
  228. End Function
  229.  
  230. ;END FUNCTIONS