home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / 226-250 / apd245 / simple_breakout.amos / simple_breakout.amosSourceCode < prev    next >
AMOS Source Code  |  1991-06-12  |  6KB  |  169 lines

  1. '
  2. ' * SIMPLE BREAKOUT BY STEVE BENNETT *   
  3. ' Written during one boring hour on saturday 8th june 91.  
  4. ' If you want to speed it up alter dx-dy values. 
  5. '
  6. ' This is as simple as I could make a breakout game and was written for  
  7. ' people who are new to AMOS. If you take your time you should be able 
  8. ' to follow the code through to see how it works. Although it is very
  9. ' basic it does contain almost all you would need to create a far better 
  10. ' version, better graphics - sound etc. Try adding a title screen and
  11. ' the brick size - Colour and create your own enhanced version.  
  12. '
  13. '            first open screen 0 320 pixels wide, 256 high, 8 colours, lowres  
  14. Screen Open 0,320,256,8,Lowres
  15. '           now use double buffer to stop the bobs flickering  
  16. Double Buffer 
  17. '           turn off the cursor - flash and mouse pointer  
  18. Curs Off : Flash Off : Hide On 
  19. '           now clear the screen black 
  20.  Cls 0
  21. '           reserve space for the brick zones
  22. Reserve Zone(60)
  23. '           set up values for each brick x and y 
  24. Dim WHEREZONEX(60),WHEREZONEY(60)
  25. Global X,Y,DX,DY,UPDOWN,BALLS,WHEREZONEX(),WHEREZONEY(),BRICKSLEFT
  26. '           make colour 1 (white) then choose white to draw in 
  27. Colour 1,$FFF : Ink 1
  28. '           set background colour to black and write in white  
  29. Paper 0 : Pen 1
  30. '           draw the ball on the screenfill it then grab the image as bob 1
  31. Circle 10,10,2 : Paint 10,10 : Get Bob 1,8,8 To 13,13
  32. '           draw the bat and grab it as bob 2
  33. Bar 0,0 To 30,5 : Get Bob 2,0,0 To 30,5
  34. '
  35. NEWGAME:
  36. '           set screen colours and draw borders around the screen
  37. Cls 0 : Ink 1
  38. Bar 0,20 To 320,25
  39. Bar 0,20 To 5,230
  40. Bar 315,20 To 320,230
  41. '           set speed at 2 - set random position for ball to appear
  42. '           set direction as down (0) and balls at 3 
  43. DX=2 : DY=2 : X=40+Rnd(4) : Y=40+Rnd(150) : UPDOWN=0 : BALLS=3
  44. '
  45. '           jump to routine to draw the bricks and set up a zone for each
  46. BREAKOUT
  47. '           jump to routine to set the bat onto the mouse pointer - amal 
  48. SETBAT
  49. '
  50. KEYPRESS:
  51. '           put the cursor 10 across and 20 down the screen
  52. Locate 10,20
  53. '           write message to the centre of the screen- wait for a keypress 
  54. Centre "PRESS SPACE TO START" : Wait Key 
  55. '           ok key press so erase message
  56. Centre "                      "
  57. '
  58. ' the main routine checks for a hit between bat and ball (bob col1,2to2) 
  59. ' if it has hit then it jumps to the routine to bounce the ball off it.
  60. ' It then checks if the ball has hit any walls Y<26  top wall    
  61. '                                              Y>260 ball out of play    
  62. '                                              X<5   left wall 
  63. '                                              X>310 right wall  
  64. MAIN:
  65. Repeat 
  66.    If Bob Col(1,2 To 2) : Shoot : BOUNCEBALLBAT : End If 
  67.    If Y Bob(2)<26 : Shoot : BOUNCEBALLTOPWALL : End If 
  68.    If Y Bob(2)>260 : Dec BALLS : Goto NEWBALL : End If 
  69.    If X Bob(2)<5 : Shoot : BOUNCEBALLLEFTWALL : End If 
  70.    If X Bob(2)>310 : Shoot : BOUNCEBALLRIGHTWALL : End If 
  71.    If BRICKSLEFT=<0 : Goto GAMEOVER : End If 
  72. '  check if ball has hit a brick, if it has then clear the zone and erase
  73. '  the brick that is there by drawing a black bar over it. 
  74.    TESTZONE=Zone(X Bob(2)+3,Y Bob(2)+3)
  75.    If TESTZONE>0 : Ink 0 : Bar WHEREZONEX(TESTZONE),WHEREZONEY(TESTZONE) To WHEREZONEX(TESTZONE)+23,WHEREZONEY(TESTZONE)+6
  76. '  clear the zone that is hit so it doesn't hit it again 
  77.       Reset Zone(TESTZONE)
  78. '  change the direction of the ball travel 0 down - 1 up 
  79.       Add UPDOWN,1,0 To 1
  80.       If UPDOWN=0 : BOUNCEBALLTOPWALL : End If 
  81.       If UPDOWN=1 : BOUNCEBALLBAT : End If 
  82. ' add x - y with speed (2) then move the ball  
  83.       Add X,DX : Add Y,DY
  84.       Bob 2,X+DX,Y+DY,1
  85. ' make booooom! sound  
  86.       Boom 
  87. ' decrease the number of bricks left 
  88.       Dec BRICKSLEFT
  89.    End If 
  90. ' add x - y with speed (2) then move the ball  
  91.    Add X,DX : Add Y,DY
  92.    Bob 2,X+DX,Y+DY,1
  93. ' wait for a vertical blank to slow it all down  
  94.    Wait Vbl 
  95. '  the loop will now repeat until you press the mouse button 
  96. Until Mouse Click
  97. '
  98. NEWBALL:
  99. If BALLS=<0
  100.    Locate 10,20 : Centre "YOU LOSE THIS TIME" : Wait 100
  101.    Centre "PRESS SPACE FOR NEW GAME " : Wait Key : Goto NEWGAME
  102. End If 
  103. Locate 10,20 : Centre "BALLS LEFT" : Print BALLS
  104. Wait 100
  105. Bob 2,40+Rnd(150),150,1
  106. X=X Bob(2) : Y=150 : DX=3 : DY=3
  107. Goto KEYPRESS
  108. '
  109. GAMEOVER:
  110. Locate 10,20 : Centre "BRICKS CLEARED"
  111. Wait 100
  112. Centre "PRESS SPACE FOR NEW GAME " : Wait Key : Goto NEWGAME
  113. Goto NEWGAME
  114. '
  115. Procedure SETBAT
  116. ' this routine puts bob 2 (the bat) over the mouse pointer and moves it
  117. ' to wherever the mouse pointer would be if we could see it. left/right only.
  118.    X Mouse=268
  119.    STEVE$="AU (I R0<>XM JU ; X"
  120.    STEVE$=STEVE$+"U: L R0=XM-130 ; D M)"
  121.    STEVE$=STEVE$+"M: L X=R0 ; W"
  122.    Bob 1,150,240,2
  123.    Channel 1 To Bob 1
  124.    Amal 1,STEVE$
  125.    Amal On 
  126. End Proc
  127. '
  128. Procedure BREAKOUT
  129. ' draw the bricks and set up a zone for each brick 
  130.    Limit Mouse 131,179 To 420,241
  131.    X=11 : Y=50 : BEGIN=1 : FINISH=12 : WHICHZONE=1 : C=2
  132.    For ROUND=1 To 5
  133.       Ink C
  134.       For T=BEGIN To FINISH
  135.          Bar X,Y To X+23,Y+5
  136.          Set Zone WHICHZONE,X,Y To X+23,Y+5
  137.          WHEREZONEX(WHICHZONE)=X : WHEREZONEY(WHICHZONE)=Y
  138.          Inc WHICHZONE
  139.          Add X,25
  140.       Next T
  141.       X=11 : Add Y,8 : Inc C
  142.    Next ROUND
  143.    X=41 : Y=137 : DX=3 : DY=3 : BRICKSLEFT=60
  144.    Bob 2,41,137,1
  145. End Proc
  146. '
  147. Procedure BOUNCEBALLBAT
  148. ' if the ball hits the bat change the direction of the ball
  149.    WHICHWAY=Rnd(2)
  150.    If WHICHWAY=0 : DX=0 : DY=-DY : End If 
  151.    If WHICHWAY=>1
  152.    If(X Bob(2)<X Bob(1)+10) : DY=-3 : DX=-3 Else DY=-3 : DX=3 : End If 
  153.    End If 
  154.    Bob 2,X Bob(2)+Rnd(6),, : X=X Bob(2)
  155.    UPDOWN=1
  156. End Proc
  157. '
  158. Procedure BOUNCEBALLLEFTWALL
  159. If UPDOWN=1 : DY=-3 : DX=3 Else DY=3 : DX=3 : End If 
  160. End Proc
  161. '
  162. Procedure BOUNCEBALLRIGHTWALL
  163. If UPDOWN=0 : DY=3 : DX=-3 : Else DY=-3 : DX=-3 : End If 
  164. End Proc
  165. '
  166. Procedure BOUNCEBALLTOPWALL
  167. If X Bob(2)-X Bob(2)=0 : DY=3 Else DX=-DX : DY=3 : End If 
  168.    UPDOWN=0
  169. End Proc