home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
226-250
/
apd245
/
simple_breakout.amos
/
simple_breakout.amosSourceCode
< prev
next >
Wrap
AMOS Source Code
|
1991-06-12
|
6KB
|
169 lines
'
' * SIMPLE BREAKOUT BY STEVE BENNETT *
' Written during one boring hour on saturday 8th june 91.
' If you want to speed it up alter dx-dy values.
'
' This is as simple as I could make a breakout game and was written for
' people who are new to AMOS. If you take your time you should be able
' to follow the code through to see how it works. Although it is very
' basic it does contain almost all you would need to create a far better
' version, better graphics - sound etc. Try adding a title screen and
' the brick size - Colour and create your own enhanced version.
'
' first open screen 0 320 pixels wide, 256 high, 8 colours, lowres
Screen Open 0,320,256,8,Lowres
' now use double buffer to stop the bobs flickering
Double Buffer
' turn off the cursor - flash and mouse pointer
Curs Off : Flash Off : Hide On
' now clear the screen black
Cls 0
' reserve space for the brick zones
Reserve Zone(60)
' set up values for each brick x and y
Dim WHEREZONEX(60),WHEREZONEY(60)
Global X,Y,DX,DY,UPDOWN,BALLS,WHEREZONEX(),WHEREZONEY(),BRICKSLEFT
' make colour 1 (white) then choose white to draw in
Colour 1,$FFF : Ink 1
' set background colour to black and write in white
Paper 0 : Pen 1
' draw the ball on the screenfill it then grab the image as bob 1
Circle 10,10,2 : Paint 10,10 : Get Bob 1,8,8 To 13,13
' draw the bat and grab it as bob 2
Bar 0,0 To 30,5 : Get Bob 2,0,0 To 30,5
'
NEWGAME:
' set screen colours and draw borders around the screen
Cls 0 : Ink 1
Bar 0,20 To 320,25
Bar 0,20 To 5,230
Bar 315,20 To 320,230
' set speed at 2 - set random position for ball to appear
' set direction as down (0) and balls at 3
DX=2 : DY=2 : X=40+Rnd(4) : Y=40+Rnd(150) : UPDOWN=0 : BALLS=3
'
' jump to routine to draw the bricks and set up a zone for each
BREAKOUT
' jump to routine to set the bat onto the mouse pointer - amal
SETBAT
'
KEYPRESS:
' put the cursor 10 across and 20 down the screen
Locate 10,20
' write message to the centre of the screen- wait for a keypress
Centre "PRESS SPACE TO START" : Wait Key
' ok key press so erase message
Centre " "
'
' the main routine checks for a hit between bat and ball (bob col1,2to2)
' if it has hit then it jumps to the routine to bounce the ball off it.
' It then checks if the ball has hit any walls Y<26 top wall
' Y>260 ball out of play
' X<5 left wall
' X>310 right wall
MAIN:
Repeat
If Bob Col(1,2 To 2) : Shoot : BOUNCEBALLBAT : End If
If Y Bob(2)<26 : Shoot : BOUNCEBALLTOPWALL : End If
If Y Bob(2)>260 : Dec BALLS : Goto NEWBALL : End If
If X Bob(2)<5 : Shoot : BOUNCEBALLLEFTWALL : End If
If X Bob(2)>310 : Shoot : BOUNCEBALLRIGHTWALL : End If
If BRICKSLEFT=<0 : Goto GAMEOVER : End If
' check if ball has hit a brick, if it has then clear the zone and erase
' the brick that is there by drawing a black bar over it.
TESTZONE=Zone(X Bob(2)+3,Y Bob(2)+3)
If TESTZONE>0 : Ink 0 : Bar WHEREZONEX(TESTZONE),WHEREZONEY(TESTZONE) To WHEREZONEX(TESTZONE)+23,WHEREZONEY(TESTZONE)+6
' clear the zone that is hit so it doesn't hit it again
Reset Zone(TESTZONE)
' change the direction of the ball travel 0 down - 1 up
Add UPDOWN,1,0 To 1
If UPDOWN=0 : BOUNCEBALLTOPWALL : End If
If UPDOWN=1 : BOUNCEBALLBAT : End If
' add x - y with speed (2) then move the ball
Add X,DX : Add Y,DY
Bob 2,X+DX,Y+DY,1
' make booooom! sound
Boom
' decrease the number of bricks left
Dec BRICKSLEFT
End If
' add x - y with speed (2) then move the ball
Add X,DX : Add Y,DY
Bob 2,X+DX,Y+DY,1
' wait for a vertical blank to slow it all down
Wait Vbl
' the loop will now repeat until you press the mouse button
Until Mouse Click
'
NEWBALL:
If BALLS=<0
Locate 10,20 : Centre "YOU LOSE THIS TIME" : Wait 100
Centre "PRESS SPACE FOR NEW GAME " : Wait Key : Goto NEWGAME
End If
Locate 10,20 : Centre "BALLS LEFT" : Print BALLS
Wait 100
Bob 2,40+Rnd(150),150,1
X=X Bob(2) : Y=150 : DX=3 : DY=3
Goto KEYPRESS
'
GAMEOVER:
Locate 10,20 : Centre "BRICKS CLEARED"
Wait 100
Centre "PRESS SPACE FOR NEW GAME " : Wait Key : Goto NEWGAME
Goto NEWGAME
'
Procedure SETBAT
' this routine puts bob 2 (the bat) over the mouse pointer and moves it
' to wherever the mouse pointer would be if we could see it. left/right only.
X Mouse=268
STEVE$="AU (I R0<>XM JU ; X"
STEVE$=STEVE$+"U: L R0=XM-130 ; D M)"
STEVE$=STEVE$+"M: L X=R0 ; W"
Bob 1,150,240,2
Channel 1 To Bob 1
Amal 1,STEVE$
Amal On
End Proc
'
Procedure BREAKOUT
' draw the bricks and set up a zone for each brick
Limit Mouse 131,179 To 420,241
X=11 : Y=50 : BEGIN=1 : FINISH=12 : WHICHZONE=1 : C=2
For ROUND=1 To 5
Ink C
For T=BEGIN To FINISH
Bar X,Y To X+23,Y+5
Set Zone WHICHZONE,X,Y To X+23,Y+5
WHEREZONEX(WHICHZONE)=X : WHEREZONEY(WHICHZONE)=Y
Inc WHICHZONE
Add X,25
Next T
X=11 : Add Y,8 : Inc C
Next ROUND
X=41 : Y=137 : DX=3 : DY=3 : BRICKSLEFT=60
Bob 2,41,137,1
End Proc
'
Procedure BOUNCEBALLBAT
' if the ball hits the bat change the direction of the ball
WHICHWAY=Rnd(2)
If WHICHWAY=0 : DX=0 : DY=-DY : End If
If WHICHWAY=>1
If(X Bob(2)<X Bob(1)+10) : DY=-3 : DX=-3 Else DY=-3 : DX=3 : End If
End If
Bob 2,X Bob(2)+Rnd(6),, : X=X Bob(2)
UPDOWN=1
End Proc
'
Procedure BOUNCEBALLLEFTWALL
If UPDOWN=1 : DY=-3 : DX=3 Else DY=3 : DX=3 : End If
End Proc
'
Procedure BOUNCEBALLRIGHTWALL
If UPDOWN=0 : DY=3 : DX=-3 : Else DY=-3 : DX=-3 : End If
End Proc
'
Procedure BOUNCEBALLTOPWALL
If X Bob(2)-X Bob(2)=0 : DY=3 Else DX=-DX : DY=3 : End If
UPDOWN=0
End Proc