'                                Henry's House 
'
'                            LEVEL FOUR SOURCE CODE
'
'                          by : Gurmita & Sucha Singh
'
'----------------------------------------------------------------------------- 
' NOTE:This source code can not be Run through the AMOS editor as some files 
' need to be copied into memory which is done in the startup-sequence of the 
' full Game(see Intro source code).
'
' The following source code reseaves the Main variables LIVES,SC,EXSC and
' LEVEL.It then asks you to 'Press Fire' on the loading screen and then starts 
' the Level. 
'
' Memory Banks Used: 
'  1 - Sprites - Sprites 
'  5 - Sound - Main samples
'  6 - Sound - In Game Samples 
'  9 - Pac Pic - Control Panel 
' 10 - Pac Pic - Background Picture
' 11 - Pac Pic - Top half of Bath
' 12 - Pac Pic - Bottom hlf of bath
'
' Bobs and Sprites Used: 
' Bob  1 - Platform
' Bob  2 - Toilet Roll 
' Bob  3 - False Teeth 
' Bob  4 - Sponge
' Bob  5 - Fish
' Bob  6 - Frog
' Bob  7 - 2nd Frog
' Bob 10 - Henry Crying
' Bob 26 - Henry Hit 
' Bob 28 - Henry Hit(underwater) 
' Sprite  8 - Player 
' Sprite 10 - Player Swimming
' Sprite 13 to 21 - Items
' Sprite 22 - Bonus Entrance 
' Sprite 24 - Exit 
' Sprite 26 - Bubble 
'
' Variables Used:
' X     - Player sprites X coordinates.
' Y     - Player sprites Y coordinates.
' I     - Player sprite Image. 
' D     - Start direction image for player.
' A     - The number of items you have collected.
' F     - The platform colour which you collide with.
' N     - The current height of Henry when jumping.
' SC    - Your current score.
' EXSC  - Increases with your score but gets set to 0 if it equals 2000 when 
'         you get an extra life. 
' LEVEL - The level number which effects the images of the doors.
' LIVES - Number of lives Henry has. 
' BONUS - BONUS=1 when you're in the normal level or BONUS=0 when you enter
'         the bonus stage. 
' BLINK - Time taken for player to start blinking if left alone. 
' TIME  - The level time limit.
' COUNT - Used to slow down the time.
' GONG  - Timer for the Gong sfx.
' BS    - Holds the Bonus screen number. 
' BUB   - Used to offset the bubble when Henry turns left and right. 
' BI to BIH - Turns an item(in the bath) on or off depending on if they've 
'             been collected.
'
'----------------------------------------------------------------------------- 
'
' Increase sprite buffer.
Set Sprite Buffer 256
'
' Close the AMOS editor to save memory.
Close Editor 
'
' Make the variables global so the whole program can access them.
Global X,Y,I,D,A,F,N,SC,EXSC,LEVEL,LIVES,BONUS,BLINK,TIME,COUNT,GONG
Global BS,BUB,BI,BIA,BIB,BIC,BID,BIE,BIF,BIG,BIH
'
' Set the variables. 
X=340 : Y=215 : I=1 : D=0 : A=0 : BONUS=1 : BLINK=0 : TIME=60 : COUNT=0
GONG=60 : BS=3
'
'-----------------------------------------------------------------------------   
' Calls the SETUP procedure. 
_SETUP
'
' Creates a mask for the sprites,sets Autoback to manual,turns off the 
' automatic updating and updates every 2 vertical blank periods to make the
' Amal animations smoother.
Make Mask : Autoback 0 : Update Off : Update Every 2
'
'----------------------------------------------------------------------------- 
' Calls the BLINK procedure. 
_BLINK
'
' Calls the MAINLOOP procedure.
_MAINLOOP
'----------------------------------------------------------------------------- 
'
' Uses Screen Swap which updates everything at once so making the Game run 
' faster.Updates the timer,checks for collisions,the joystic,the platforms and 
' the soundfx. 
Procedure _MAINLOOP
   '
   ' Manualy updates all the bobs so there is no flicker at the start.
   Bob Clear : Bob Draw 
   '
   ' The loop is divided into two parts. The first is used to perform the 
   ' various instructions in your program and the secound part repeats the  
   ' above contents.This keeps the loop in sync.
   Do 
      ' Swaps between the Phisical and Logical screens then clears the screen  
      ' of bobs. 
      Screen Swap 0
      Wait Vbl 
      Bob Clear 
      '
      ' Calls the TIME and EXTRA LIFE procedures and sets the Joystic. 
      _TIME
      _EXTRA_LIFE
      J=Joy(1)
      '
      ' If Henry touches the moving platform then his Y axis equals the platforms. 
      If Spritebob Col(8,1 To 1) Then Y=Y Bob(1)+50 : _TIME
      ' Checks the collision between the player sprite and other bobs and sprites. 
      If Spritebob Col(8,2 To 4) Then _DEAD
      If Sprite Col(8,13 To 19) Then _GET_ITEM
      If Sprite Col(8,22 To 22) Then _BONUS
      If Sprite Col(8,24 To 24) Then _EXIT
      '
      ' Places the next wave of items. 
      If A=7 Then MORE_ITEMS
      '
      ' Places the Exit on screen when you have collected all the items. 
      If A=15 : Sprite 24,420,232,77 : A=16 : End If 
      '
      ' If all items are collected within the timelimit then the Bonus 
      ' entrance opens.  
      If A=16 and TIME>0 : Sprite 22,180,202, : Amal On 5 : TIME=0 : End If 
      '
      ' Checks for the joystic and floor,so if Henry is left alone on a  
      ' platform the variable 'BLINK' increases or else it equals 0. 
      If J=0 and F=2 Then Inc BLINK Else BLINK=0
      If BLINK>20 Then _BLINK
      '
      ' Checks Left & Right joystic directions.If the joystic has been moved 
      ' and Henry is away from the edge then he will either move left or right.  
      ' The variable D sets the starting frame depending on the joystic direction    
      ' you have moved.It then adds the frames to make Henry look like he's walking.     
      If J=4 and X>138 Then Dec X : _TIME : D=6 : Inc C : If C mod 4=0 Then Add I,1,1 To 6
      If J=8 and X<438 Then Inc X : _TIME : D=0 : Inc C : If C mod 4=0 Then Add I,1,1 To 6
      '
      ' Checks for Up,Up left and Up right directions.If the joystic has been  
      ' moved in either of the up directions and Henry is on a platform then   
      ' the relevant JUMP procedure is called. 
      If J=1 and F=2 or J=1 and Spritebob Col(8,1 To 1) Then JUMP_UP
      If J=5 and F=2 or J=5 and Spritebob Col(8,1 To 1) Then D=6 : JUMP_LEFT
      If J=9 and F=2 or J=9 and Spritebob Col(8,1 To 1) Then D=0 : JUMP_RIGHT
      '
      ' Play the Squish sfx depending on the Sponges image and the Bounce sfx  
      ' depending on the Toilet Roll's position.   
      If I Bob(4)=40 or I Bob(4)=58 or I Bob(4)=51 or I Bob(4)=56 Then Sam Bank 6 : Sam Play %1,1
      If X Bob(2)=176 and Y Bob(2)=67 or X Bob(2)=138 and Y Bob(2)=112 or X Bob(2)=100 and Y Bob(2)=153 or X Bob(2)=61 Then Sam Bank 6 : Sam Play %10,2
      ' Plays the Gong sfx when the Gong timer equals 0. 
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=60
      '
      ' Checks for a collision between a colour on screen and the player sprite. 
      F=Point(X Screen(X Sprite(8)),Y Screen(Y Sprite(8)))
      '
      ' If the colour is not equal to 2(the platform colour) then Henry will fall.   
      If F<>2 Then Inc Y
      '
      ' Updates the player sprite and draws all the bobs on screen.
      Sprite 8,X,Y,I+D
      Sprite Update 
      Bob Draw 
      '
      '----------------------------------------------------------------------- 
      ' Swaps between the Phisical and Logical screens then clears the screen  
      ' of bobs. 
      Screen Swap 0
      Wait Vbl 
      Bob Clear 
      J=Joy(1)
      ' If Henry touches moving platform then his Y axis equals the platforms. 
      If Spritebob Col(8,1 To 1) Then Y=Y Bob(1)+50
      '
      ' Checks for the joystic.By repeating it again it makes Henry walk faster. 
      If J=4 and X>138 Then Dec X : D=6 : Inc C : If C mod 4=0 Then Add I,1,1 To 6
      If J=8 and X<438 Then Inc X : D=0 : Inc C : If C mod 4=0 Then Add I,1,1 To 6
      '
      ' Checks for the collision between Henry and the platforms.
      F=Point(X Screen(X Sprite(8)),Y Screen(Y Sprite(8)))
      If F<>2 Then Inc Y
      '
      ' Updates the player sprite and draws the bobs on screen.
      Sprite 8,X,Y,I+D
      Sprite Update 
      Bob Draw 
   Loop 
   '
End Proc
'
' Opens up a screen,sets the fonts,reseaves the variables from the last
' program then loads the bobs and sfx and waits until you have pressed fire
' on the loading screen to start the game. 
Procedure _SETUP
   '
   ' Hides mouse pointer,opens screen 0 and screen 2 then hides them both.
   Hide On 
   Screen Open 0,320,200,32,Lowres : Screen Hide 0
   Curs Off : Flash Off : Cls 0
   Screen Open 2,320,30,16,Lowres : Screen Hide 2
   Curs Off : Flash Off : Cls 0
   '
   ' Loads fonts from Disk2 then checks all fonts to make sure they have loaded.
   Get Disc Fonts 
   Screen 2
   For F=0 To 6
      Set Font F : T$="Amos 12345:"+Str$(F)
      Text 0,0,T$
   Next F
   Cls 0
   '
   ' Unpacks the Control Panel to screen 2 hides it,fades it to black then
   ' sets its display.
   Unpack 9 To 2 : Screen Hide 2 : Fade 1 : Wait 15
   Screen Display 2,130,252,320,30
   '
   ' Reseaves the command line$ then separates its contents into the 4 strings. 
   Set Font 6
   B$=Left$(Command Line$,3)
   C$=Mid$(Command Line$,4,6)
   D$=Mid$(Command Line$,10,5)
   E$=Right$(Command Line$,1)
   '
   ' Converts the 4 strings into variables. 
   LIVES=Val(B$) : SC=Val(C$) : EXSC=Val(D$) : LEVEL=Val(E$)
   '
   ' Prints the Lives,Score and Time onto the control panel.
   If LIVES<10 Then Ink 2,0 : Text 39,20,B$ : Text 144,20,C$
   If LIVES>9 Then Ink 2,0 : Text 27,20,B$ : Text 144,20,C$
   Ink 2,0 : Text 278,20,"60"
   '
   ' Loads the powerpacked bobs and sfx.
   Screen 0
   'Ppload "Henry's_HouseD2:Bobs/SpritesLev4" 
   'Ppload "Henry's_HouseD2:sound/MainSfx",5
   '
   ' Display message 'Press Fire To Start'. 
   Screen 1 : Paste Bob 115,180,115
   '
   ' Small loop which keeps you at the loading screen until you press Fire. 
   Do 
      J=Joy(1)
      If Fire(1)=-1 Then Exit 
      Paste Bob 115,180,115 : Bob Update 
      Wait Vbl 
   Loop 
   ' Small loop which repeats until you have released the fire button then
   ' fades the screen and closes it.
   Repeat 
   Until Fire(1)=0
   Screen 1 : Fade 1 : Wait 15 : Screen Close 1
   '
   ' Unpacks the background to screen 0,hides it then Double Buffers the  
   ' screen for no flicker. 
   Screen 0 : Unpack 10 To 0 : Screen Hide 0
   Double Buffer 
   '
   ' Sets the hot spot to bottom centre for the Player images and calls the   
   ' AMAL and ITEMS procedures. 
   For N=1 To 12 : Hot Spot N,$12 : Next 
   _AMAL
   _ITEMS
   '
   ' Fades background to black then fades the Control Panel and Background  
   ' picture into view. 
   Fade 1 : Wait 15
   Screen 2
   Screen Show 2
   Fade 1,$0,$BBB,$FFF,$EB0,$E90,$FD0,$B70,$840,$520,$CF,$6E,$F7E,$F0,$A01,$D01,$EC8
   Wait 15
   Screen 0
   Screen Show 0
   Fade 1,$0,$BBB,$559,$279,$5AB,$8DE,$CFF,$363,$484,$5A5,$986,$BA7,$DC9,$B77,$D99,$FBB,$34,$0,$888,$FFF,$520,$840,$B70,$FB0,$486,$5A8,$5CA,$8E,$8,$A01,$D01,$EC8
   Wait 15
   '
   ' Sets the volume for all channels to maximum. 
   Volume %1111,63
   '
End Proc
'
' Updates the Time.
Procedure _TIME
   '
   ' As long as the time is greater than 0 then the variable,to slow down the 
   ' timer,can keep on increasing.
   If TIME>0 Then Inc COUNT
   '
   ' Adds 1 to the TIME variable and decreases the GONG variable whenever COUNT=50. 
   If COUNT>50
      TIME=TIME-1 : Dec GONG : COUNT=0
      ' Convert TIME variable to a string so it can be printed using 'Text'. 
      A$=Str$(TIME)
      Screen 2 : L=Text Length(A$) : Text 304-L,20,A$
   End If 
   '
   ' Returns program back to screen 0.  
   If BONUS=1 Then Screen 0
   '
End Proc
'
' Updates the lives,sets the death animation then plays it until its finished. 
Procedure _DEAD
   '
   ' Decrease the LIVES by 1,convert variable into a string to display your lives.  
   Screen 2
   LIVES=LIVES-1
   B$=Str$(LIVES) : LD=Text Length(B$) : Text 64-LD,20,B$
   '
   Screen 0
   ' Match the Bob starting position with the Player sprite position. 
   DX=X Screen(X Sprite(8)) : DY=Y Screen(Y Sprite(8))
   Bob 26,DX,DY,111
   ' Set Amal animation.
   Channel 11 To Bob 26
   K$="A 0,(111,0); M 0,-20,20; M 0,-4,4; M 0,-3,3; M 0,-3,4; M 0,2,4; M 0,3,3; M 0,15,5; M 0,260,46"
   Amal 11,K$ : Amal On 11
   ' Turn off player sprite,play Ouch sfx and update bobs.
   Sprite Off 8
   Sam Bank 5 : Sam Play %1110,2
   Bob Clear : Bob Draw 
   '    
   ' Small loop to allow Henry to finish death sequence without causing any   
   ' problems to the main loop eg,colliding while still playing the death anim. 
   Repeat 
      Screen Swap 0
      Wait Vbl 
      Bob Clear 
      _TIME
      If I Bob(4)=40 or I Bob(4)=58 or I Bob(4)=51 or I Bob(4)=56 Then Sam Bank 6 : Sam Play %1,1
      If X Bob(2)=176 and Y Bob(2)=67 or X Bob(2)=138 and Y Bob(2)=112 or X Bob(2)=100 and Y Bob(2)=153 or X Bob(2)=61 Then Sam Bank 6 : Sam Play %10,2
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=60
      '
      Sprite Update 
      Bob Draw 
      '
      Screen Swap 0
      Wait Vbl 
      Bob Clear 
      '
      Sprite Update 
      Bob Draw 
   Until Y Bob(26)>259
   '
   ' Check to see if the player has lost all their lives if so then call the
   ' GAMEOVER procedure.
   If LIVES=0 Then _GAMEOVER
   '
   ' Turn off Death animation,reset player starting position,'N' variable and 
   ' image then swap screen and clear bobs to help stay in sync with mainloop.    
   Amal Off 11 : X=340 : Y=213 : N=34 : I=2 : Sprite Update : Wait Vbl 
   Screen Swap 0 : Wait Vbl : Bob Clear 
   '
End Proc
'
' Makes Henry Jump up. 
Procedure JUMP_UP
   '
   ' Change sample bank then play the Jumping sfx.
   Sam Bank 5 : Sam Play %1100,5
   '
   ' First 'for next' loop makes Henry move up,tests for collisions and plays   
   ' the soundfx. 
   For N=1 To 34
      Dec Y
      _TIME
      _EXTRA_LIFE
      If Spritebob Col(8,2 To 4) Then N=34 : _DEAD
      If Sprite Col(8,13 To 19) Then _GET_ITEM
      If Y Sprite(8)<60 Then N=34 : Rem So Henry dos'nt go off screen. 
      '
      If I Bob(4)=40 or I Bob(4)=58 or I Bob(4)=51 or I Bob(4)=56 Then Sam Bank 6 : Sam Play %1,1
      If X Bob(2)=176 and Y Bob(2)=67 or X Bob(2)=138 and Y Bob(2)=112 or X Bob(2)=100 and Y Bob(2)=153 or X Bob(2)=61 Then Sam Bank 6 : Sam Play %10,2
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=60
      Sprite 8,X,Y,I+D
      Update 
      Wait Vbl 
   Next 
   '
   ' Secound loop makes Henry come down and checks for collisions with any    
   ' platforms and other Sprites & Bobs and plays the soundfx.
   For N=1 To 34
      _TIME
      _EXTRA_LIFE
      F=Point(X Screen(X Sprite(8)),Y Screen(Y Sprite(8)))
      If F<>2 Then Inc Y
      ' If Henry touches a platform before N=34 then N=34 and exits out of loop.   
      If F=2 Then N=34
      '
      If Spritebob Col(8,1 To 1) Then N=34
      If Spritebob Col(8,2 To 4) Then N=34 : _DEAD
      If Sprite Col(8,13 To 19) Then _GET_ITEM
      '
      If I Bob(4)=40 or I Bob(4)=58 or I Bob(4)=51 or I Bob(4)=56 Then Sam Bank 6 : Sam Play %1,1
      If X Bob(2)=176 and Y Bob(2)=67 or X Bob(2)=138 and Y Bob(2)=112 or X Bob(2)=100 and Y Bob(2)=153 or X Bob(2)=61 Then Sam Bank 6 : Sam Play %10,2
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=60
      Sprite 8,X,Y,I+D
      Update 
      Wait Vbl 
   Next 
   '
   ' Reset 'N' variable and clear the bobs to keep in sync with mainloop. 
   N=1
   Bob Clear 
   '
End Proc
'
' Makes Henry Jump up and left.
Procedure JUMP_LEFT
   '
   ' Change sample bank,play the Jumping sfx and call the EXTRA LIFE procedure. 
   Sam Bank 5 : Sam Play %1100,5
   _EXTRA_LIFE
   '
   ' First 'for next' loop makes Henry move up and left,tests for collisions  
   ' and plays the soundfx. 
   For N=1 To 34
      _TIME
      Add I,1,1 To 6 : Dec Y : If X>140 Then Dec X
      If Spritebob Col(8,2 To 4) Then N=34 : _DEAD
      If Y Sprite(8)<60 Then N=34 : Rem So Henry dos'nt go off screen. 
      '
      If I Bob(4)=40 or I Bob(4)=58 or I Bob(4)=51 or I Bob(4)=56 Then Sam Bank 6 : Sam Play %1,1
      If X Bob(2)=176 and Y Bob(2)=67 or X Bob(2)=138 and Y Bob(2)=112 or X Bob(2)=100 and Y Bob(2)=153 or X Bob(2)=61 Then Sam Bank 6 : Sam Play %10,2
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=60
      Sprite 8,X,Y,I+D
      Update 
      Wait Vbl 
   Next N
   '
   ' Secound loop makes Henry come down and move left checks for collisions   
   ' with any platforms and other Sprites & Bobs and plays the soundfx. 
   For N=1 To 34
      _TIME
      F=Point(X Screen(X Sprite(8)),Y Screen(Y Sprite(8)))
      Add I,1,1 To 6 : If X>140 Then Dec X
      If F<>2 Then Inc Y
      ' If Henry touches a platform before N=34 then N=34 and exits out of loop.   
      If F=2 Then N=34
      '
      If Spritebob Col(8,1 To 1) Then N=34
      If Spritebob Col(8,2 To 4) Then N=34 : _DEAD
      If Sprite Col(8,22 To 22) Then _BONUS
      '
      If I Bob(4)=40 or I Bob(4)=58 or I Bob(4)=51 or I Bob(4)=56 Then Sam Bank 6 : Sam Play %1,1
      If X Bob(2)=176 and Y Bob(2)=67 or X Bob(2)=138 and Y Bob(2)=112 or X Bob(2)=100 and Y Bob(2)=153 or X Bob(2)=61 Then Sam Bank 6 : Sam Play %10,2
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=60
      Sprite 8,X,Y,I+D
      Update 
      Wait Vbl 
   Next N
   '
   ' Reset 'N' variable and clear the bobs to keep in sync with mainloop. 
   N=1
   Bob Clear 
   '
End Proc
'
' Makes Henry Jump up and right. 
Procedure JUMP_RIGHT
   '
   ' Change sample bank,play the Jumping sfx and calls the EXTRA LIFE procedure.
   Sam Bank 5 : Sam Play %1100,5
   _EXTRA_LIFE
   '
   ' First 'for next' loop makes Henry move up and right,tests for collisions   
   ' and plays the soundfx. 
   For N=1 To 34
      _TIME
      Add I,1,1 To 6 : Dec Y : If X<436 Then Inc X
      If Spritebob Col(8,2 To 4) Then N=34 : _DEAD
      If Y Sprite(8)<60 Then N=34 : Rem So Henry dos'nt go off screen. 
      '
      If I Bob(4)=40 or I Bob(4)=58 or I Bob(4)=51 or I Bob(4)=56 Then Sam Bank 6 : Sam Play %1,1
      If X Bob(2)=176 and Y Bob(2)=67 or X Bob(2)=138 and Y Bob(2)=112 or X Bob(2)=100 and Y Bob(2)=153 or X Bob(2)=61 Then Sam Bank 6 : Sam Play %10,2
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=60
      Sprite 8,X,Y,I+D
      Update 
      Wait Vbl 
   Next 
   '
   ' Secound loop makes Henry come down and move right checks for collisions  
   ' with any platforms and other Sprites & Bobs and plays the soundfx. 
   For N=1 To 34
      _TIME
      F=Point(X Screen(X Sprite(8)),Y Screen(Y Sprite(8)))
      Add I,1,1 To 6 : If X<436 Then Inc X
      If F<>2 Then Inc Y
      ' If Henry touches a platform before N=34 then N=34 and exits out of loop.   
      If F=2 Then N=34
      '
      If Spritebob Col(8,1 To 1) Then N=34
      If Spritebob Col(8,2 To 4) Then N=34 : _DEAD
      If Sprite Col(8,22 To 22) Then _BONUS
      '
      If I Bob(4)=40 or I Bob(4)=58 or I Bob(4)=51 or I Bob(4)=56 Then Sam Bank 6 : Sam Play %1,1
      If X Bob(2)=176 and Y Bob(2)=67 or X Bob(2)=138 and Y Bob(2)=112 or X Bob(2)=100 and Y Bob(2)=153 or X Bob(2)=61 Then Sam Bank 6 : Sam Play %10,2
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=60
      Sprite 8,X,Y,I+D
      Update 
      Wait Vbl 
   Next 
   '
   ' Reset 'N' variable and clear the bobs to keep in sync with mainloop. 
   N=1
   Bob Clear 
   '
End Proc
'
' Makes Henry start blinking.
Procedure _BLINK
   '
   ' Set the Amal animation of Henry blinking and turn the automatic updating on.   
   Channel 12 To Sprite 8
   Sprite 8,X,Y,
   L$="A 0,(113,30)(114,10)(113,10)(114,10);"
   Amal 12,L$ : Amal On 12 : Update On 
   '
   ' Small loop which repeats itself until you move Henry.
   Do 
      ' Call TIME procedure,set joystic,check for collisions between the 
      ' player and enemy and play the soundfx. 
      _TIME
      J=Joy(1)
      If Spritebob Col(8,2 To 4) Then Update Off : _DEAD : Exit 
      '
      If I Bob(4)=40 or I Bob(4)=58 or I Bob(4)=51 or I Bob(4)=56 Then Sam Bank 6 : Sam Play %1,1
      If X Bob(2)=176 and Y Bob(2)=67 or X Bob(2)=138 and Y Bob(2)=112 or X Bob(2)=100 and Y Bob(2)=153 or X Bob(2)=61 Then Sam Bank 6 : Sam Play %10,2
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=60
      '
      ' Check for any joystic movement then exits out of loop. 
      If J>0 Then Exit 
      Sprite 8,X,Y,
      ' Wait for a vertical blank. 
      Wait Vbl 
   Loop 
   '
   ' Turns off blinking animation,automatic updateing and reset the BLINK timer.    
   Amal Off 12 : Update Off : BLINK=0
   '
   ' Update bobs,Swaps the screen then clears the bobs on screen.This is so   
   ' the program can stay in sync when returning to the Mainloop.   
   Bob Clear : Bob Draw : Screen Swap 0 : Wait Vbl : Bob Clear 
   '
End Proc
'
' Reverses the player images to make Henry's left facing images. 
Procedure _REVERSESPRITES
   '
   ' Goes through the image of player,gets the image,sets the hot spot then 
   ' pastes the fliped image. 
   For N=1 To 6
      Bob 1,16,27,N : Wait Vbl : Get Bob N+6,9,1 To 25,28
      Hot Spot N+6,$6 : Paste Bob 500,500,Hrev(N+6)
   Next : Bob Off 1 : Wait Vbl 
   '
End Proc
'
' Sets the Amal animations for the enemy.
Procedure _AMAL
   '
   ' Set the Channels for each enemy and their starting positions.
   Channel 1 To Bob 1
   Channel 2 To Bob 2
   Channel 3 To Bob 3
   Channel 4 To Bob 4
   Channel 5 To Sprite 22
   Bob 1,65,165,13
   Bob 2,176,-30,14
   Bob 3,234,123,22
   Bob 4,20,182,40
   '
   ' Set Amal animation strings for each enemy. 
   A$="A 1,(13,20);M 0,0,20;Platform:A 0,(13,5);M 0,0,20;M 0,-127,170;M 0,0,20;M 0,128,220;J Platform"
   '
   B$="A 0,(14,20); M 0,0,20;"
   B$=B$+"Roll:A 0,(14,60);M 0,97,60;"
   B$=B$+"A 0,(15,5)(16,5)(17,5)(18,5)(19,5)(20,5)(21,5)(14,5);M -8,-16,15;M -6,-8,15;M -3,2,5;M -1,0,3;M -3,2,4;M -8,18,24;M -9,47,34;"
   B$=B$+"M -8,-16,15;M -6,-8,15;M-3,2,5;M -1,0,3;M-3,2,4;M -8,18,24;M -9,43,34;"
   B$=B$+"M -8,-16,15;M -6,-8,15;M-3,2,5;M -1,0,3;M-3,2,4;M -8,18,20;M -9,36,30;"
   B$=B$+"M -80,0,60;A 1,(68,10);M 0,-217,5;M 194,0,5;J Roll"
   '
   C$="A 0,(22,20); M 0,0,20;"
   C$=C$+"Teeth:A 0,(22,4)(23,4)(24,4)(26,4)(27,4)(26,4)(25,4)(24,4)(23,4);M 70,0,112"
   C$=C$+"A 1,(22,5)(28,5)(29,5)(30,5)(31,5)(32,5)(33,5)(34,5);M 0,0,40"
   C$=C$+"A 0,(34,4)(35,4)(36,4)(37,4)(38,4)(39,4)(37,4)(36,4)(35,4);M -70,0,112"
   C$=C$+"A 1,(34,5)(33,5)(32,5)(31,5)(30,5)(29,5)(28,5)(22,5);M 0,0,40;J Teeth"
   '
   D$="A 1,(40,20);M 0,0,20;"
   D$=D$+"Sponge:A 1,(40,3)(41,3)(42,3);M 2,0,9;A 1,(43,5)(44,10)(45,5)(46,10);M 30,0,30;A 1,(47,3)(48,3);M 2,0,6;"
   D$=D$+"A 1,(40,3)(41,3)(42,3);M 2,0,9;A 1,(43,5)(44,10)(45,5)(46,10);M 30,0,30;A 1,(47,3)(48,3);M 2,0,6;"
   D$=D$+"A 1,(40,3)(41,3)(42,3);M 2,0,9;A 1,(43,5)(44,10)(45,5)(46,10);M 30,0,30;A 1,(47,3)(48,3);M 2,0,6;"
   D$=D$+"A 1,(40,3)(41,3)(42,3);M 2,0,9;A 1,(43,5)(44,10)(45,5)(46,10);M 30,0,30;A 1,(47,3)(48,3);M 2,0,6;"
   D$=D$+"A 1,(40,3)(41,3)(42,3);M 2,0,9;A 1,(43,5)(44,10)(45,5)(46,10);M 30,0,30;A 1,(47,3)(48,3);M 2,0,6;"
   D$=D$+"A 1,(40,3)(41,3)(42,3);M 2,0,9;A 1,(43,5)(44,10)(45,5)(46,10);M 30,0,30;A 1,(47,3)(48,3);M 2,0,6;"
   D$=D$+"A 1,(40,3)(41,3)(42,3);M 2,0,9;A 1,(43,5)(44,10)(45,5)(46,10);M 30,0,30;A 1,(47,3)(48,3);M 2,0,6;"
   D$=D$+"A 1,(40,3)(41,3)(42,3);M 2,0,9;A 1,(43,5)(44,10)(45,5)(46,10);M 30,0,30;A 1,(47,3)(48,3)(40,5);M 2,0,9;"
   D$=D$+"A 1,(49,5)(50,5)(51,5)(52,5)(53,5)(54,5)(55,5)(56,5)(57,5);M 0,0,45"
   '
   D$=D$+"A 1,(58,3)(59,3)(60,3);M -2,0,9;A 1,(61,5)(62,10)(63,5)(64,10);M -30,0,30;A 1,(65,3)(66,3);M -2,0,6;"
   D$=D$+"A 1,(58,3)(59,3)(60,3);M -2,0,9;A 1,(61,5)(62,10)(63,5)(64,10);M -30,0,30;A 1,(65,3)(66,3);M -2,0,6;"
   D$=D$+"A 1,(58,3)(59,3)(60,3);M -2,0,9;A 1,(61,5)(62,10)(63,5)(64,10);M -30,0,30;A 1,(65,3)(66,3);M -2,0,6;"
   D$=D$+"A 1,(58,3)(59,3)(60,3);M -2,0,9;A 1,(61,5)(62,10)(63,5)(64,10);M -30,0,30;A 1,(65,3)(66,3);M -2,0,6;"
   D$=D$+"A 1,(58,3)(59,3)(60,3);M -2,0,9;A 1,(61,5)(62,10)(63,5)(64,10);M -30,0,30;A 1,(65,3)(66,3);M -2,0,6;"
   D$=D$+"A 1,(58,3)(59,3)(60,3);M -2,0,9;A 1,(61,5)(62,10)(63,5)(64,10);M -30,0,30;A 1,(65,3)(66,3);M -2,0,6;"
   D$=D$+"A 1,(58,3)(59,3)(60,3);M -2,0,9;A 1,(61,5)(62,10)(63,5)(64,10);M -30,0,30;A 1,(65,3)(66,3);M -2,0,6;"
   D$=D$+"A 1,(58,3)(59,3)(60,3);M -2,0,9;A 1,(61,5)(62,10)(63,5)(64,10);M -30,0,30;A 1,(65,3)(66,3);M -2,0,6;"
   D$=D$+"A 1,(57,5)(56,5)(55,5)(54,5)(53,5)(52,5)(51,5)(50,5)(49,5);M 0,0,45; J Sponge"
   '
   E$="A 0,(74,5)(75,5)(76,5)"
   '
   ' Set the Channels to the strings then turn on the Amal animations.  
   Amal 1,A$ : Amal 2,B$ : Amal 3,C$ : Amal 4,D$ : Amal 5,E$
   Amal On 1 : Amal On 2 : Amal On 3 : Amal On 4
   '
End Proc
'
' Sets the positions for the first wave of items.
Procedure _ITEMS
   '
   Sprite 13,146,208,69
   Sprite 14,408,112,70
   Sprite 15,274,164,71
   Sprite 16,308,121,72
   Sprite 17,430,174,73
   Sprite 18,148,70,72
   Sprite 19,270,238,70
   '
End Proc
'
' Sets the positions for the secound wave of items.
Procedure MORE_ITEMS
   '
   A=8 : Rem Sets number of items so the Mainloop only calls this procedure once.   
   Sprite 13,144,130,73
   Sprite 14,282,80,70
   Sprite 15,422,80,69
   Sprite 16,396,174,71
   Sprite 17,274,150,69
   Sprite 18,350,230,72
   Sprite 19,196,180,70
   '
End Proc
'
' Updates your score and turns off a sprite when you collect an item.
Procedure _GET_ITEM
   '
   ' Turns off the sprite you have collided with,plays the Collect sfx and  
   ' updates the EXSC variable. 
   Sprite Off Col(-1) : Sam Bank 5 : Sam Play %1100,4 : A=A+1 : EXSC=EXSC+50
   '
   Screen 2
   ' Updates your score variable. 
   SC=SC+50
   ' Turn score variable to string so it can be printed using 'Text'. 
   C$=Str$(SC) : Text 144,20,C$
   ' Return to screen 0.
   Screen 0
   '
End Proc
'
' Restarts the game after finishing the Bonus stage. 
Procedure _RESTART
   '
   ' Fades the bonus screen,turns off all sprites,bobs,Amal animations and  
   ' hides both Bonus screens.
   Screen BS : Fade 1 : Wait 15 : Sprite Off : Bob Off : Amal Off : Screen Hide 1 : Screen Hide 3 : Screen Close 1 : Screen Close 3
   '
   ' Unpack the level background back to screen 0,hide it then fade it to 
   ' black.Next Double Buffer it for no flicker,set Autoback to manual and
   ' turn the automatic updateing off and Update Every 2 for smoother animation.    
   Unpack 10 To 0 : Screen 0 : Screen Hide 0 : Fade 1 : Wait 15
   Double Buffer : Autoback 0 : Update Off : Update Every 2
   '
   ' Resets the A,BONUS,X and Y variables and turns on the enemy animations.
   Screen 0 : A=0 : BONUS=1 : X=340 : Y=213 : Sprite Update : Wait Vbl : _AMAL
   '
   ' Place Exit back on screen and fade screen into view. 
   Sprite 24,420,232,77
   Screen Show 0
   Fade 1,$0,$BBB,$559,$279,$5AB,$8DE,$CFF,$363,$484,$5A5,$986,$BA7,$DC9,$B77,$D99,$FBB,$34,$0,$888,$FFF,$520,$840,$B70,$FB0,$486,$5A8,$5CA,$8E,$8,$A01,$D01,$EC8
   Wait 15
   '
End Proc
'
' Exits out of game once you have finished the level.
Procedure _EXIT
   '
   ' Play Door sfx,make door open then turn off player sprite.
   Sam Bank 5 : Sam Play %1110,1
   Sprite 24,420,232,78
   Sprite Off 8
   Sprite Update 
   Wait 30
   ' Fade screen,close it then reset player position. 
   Screen 0 : Fade 2 : Wait 30 : Screen Close 0
   X=340 : Y=212
   '
   ' Create 4 Main strings to hold the 4 main variables(LIVES,SC,EXSC,LEVEL). 
   A$="   " : B$="      " : C$="     " : D$="  "
   '
   ' Convert the 4 variables into strings.
   L$=Str$(LIVES) : S$=Str$(SC) : E$=Str$(EXSC) : LEV$=Str$(LEVEL)
   '
   ' Then place those strings into the above Main strings.
   Right$(A$,3)=L$ : Left$(B$,6)=S$ : Right$(C$,5)=E$ : Right$(D$,2)=LEV$
   '
   ' Lastly place the final 4 strings into the Command Line$ to be passed   
   ' through to the next program. 
   Command Line$=A$+B$+C$+D$
   '
   ' Fade control panel,close it,turn off all Amal animations,erase memory
   ' banks then load the Select Level program.  
   Screen 2 : Fade 2 : Wait 30 : Screen Close 2
   Amal Off 
   For B=0 To 15 : Erase B : Next B
   Run "HenryGame/Selectlevel"
   '
End Proc
'
' Updates your lives every 2000 points.
Procedure _EXTRA_LIFE
   '
   If EXSC=2000
      Screen 2
      ' Play Extra life sfx. 
      Sam Bank 5 : Sam Play %1110,6
      '
      ' Update LIVES variable by 1 and convert it to a string. 
      LIVES=LIVES+1 : B$=Str$(LIVES)
      ' Print the score string and depending on whether its a single or  
      ' double number offset the text position.  
      If LIVES>9 : Text 27,20,B$ : End If 
      If LIVES<10 : Text 40,20,B$ : End If 
      '
      ' Reset EXSC variable to 0 and then return to the relevant screen. 
      EXSC=0
      If BONUS=1 : Screen 0 : End If 
      If BONUS=0 : Screen BS : End If 
   End If 
   '
End Proc
'
' Plays the Game Over animation then loads the Title program.
Procedure _GAMEOVER
   '
   ' Close the relevant screens depending on whether you died in the main game  
   ' or the Bonus stage.  
   If BONUS=1
      Screen 0 : Fade 2 : Wait 30 : Cls 0 : Sprite Off : Sprite Update : Wait Vbl : Bob Off : Amal Off : Screen Close 0
      Screen 2 : Fade 2 : Wait 30 : Cls 0 : Screen Close 2
   End If 
   If BONUS=0
      If BS=1 : Screen 1 : Fade 2 : Wait 30 : Cls 0 : Sprite Off : Sprite Update : Wait Vbl : Bob Off : Amal Off : Screen Close 3 : Screen Close 1 : End If 
      If BS=3 : Screen 3 : Fade 2 : Wait 30 : Cls 0 : Sprite Off : Sprite Update : Wait Vbl : Bob Off : Amal Off : Screen Close 1 : Screen Close 3 : End If 
      Screen 2 : Fade 2 : Wait 30 : Cls 0 : Screen Close 2
   End If 
   '
   ' Open up new screen for animation,get the sprite palette,Double Buffer
   ' screen for no flicker and turn update on.  
   Screen Open 0,320,200,32,Lowres : Screen Hide 0
   Curs Off : Flash Off : Cls 0
   Get Sprite Palette 
   Double Buffer : Update On 
   '
   ' Set Amal animation.
   Channel 15 To Bob 10
   Bob 10,160,110,118
   F$="A 0,(118,5)(119,5)(120,5)(121,5)(122,5)(123,5)"
   Amal 15,F$ : Amal On 
   '
   ' Paste the 'Game Over' words on screen,fade screen to black then fade the 
   ' screen into view.  
   Paste Bob 70,10,116 : Paste Bob 164,10,117
   Fade 1 : Wait 15
   Screen Show 0
   Fade 1,$0,$BBB,$559,$279,$5AB,$8DE,$CFF,$363,$484,$5A5,$986,$BA7,$DC9,$B77,$D99,$FBB,$34,$0,$888,$FFF,$520,$840,$B70,$FB0,$486,$5A8,$5CA,$8E,$8,$A01,$D01,$EC8
   Wait 15
   '
   ' Small loop which exits when the GO variable equals 120 or you press Fire.
   Do 
      Bob 10,160,110,
      If Fire(1)=-1 Then Exit 
      Inc GO
      If GO>120 Then Exit 
      Wait Vbl 
   Loop 
   ' Small loop which exits once you have released the Fire button. 
   Repeat 
      Bob 10,160,110,
      Wait Vbl 
   Until Fire(1)=0
   Fade 2 : Wait 30
   '
   ' Prepare a string to hold the score string. 
   A$="      "
   ' Convert the score to a string. 
   S$=Str$(SC)
   ' Place score string into 'A$' then place it in the command line$. 
   Left$(A$,6)=S$
   Command Line$=A$
   '
   ' Turn off Amal animations,close screen,erase memory banks then run the
   ' Title program. 
   Amal Off 
   Screen Close 0
   For B=0 To 15 : Erase B : Next B
   Run "HenryGame/Title"
   '
End Proc
'
'----------------------------------------------------------------------------- 
'              *******  Procedures for the Bonus Stage. *******
'
' Bonus stage mainloop which flicks through two screens which make up the bath 
' and exits once you reach the top of the bath.
Procedure _BONUS
   '
   ' Set the collect variable 'A',BONUS variable,starting Bonus Screen and the
   ' SPLASH(Used to exit out of bath) variable. 
   A=16
   BONUS=0 : BS=3 : SPLASH=0
   ' Fade screen,turn off all sprites,bobs and animations then hide screen and
   ' close it to save memory.   
   Screen 0 : Fade 1 : Wait 15 : Sprite Off : Sprite Update : Bob Off : Amal Off : Screen Hide 0 : Screen Close 0
   '
   ' Call the BSETUP procedure. 
   _BSETUP
   '
   ' Loop handled in the same way as Mainloop(using screen swap).By using   
   ' another mainloop for the Bonus stage the Game runs faster and smoother.
   ' Exits out of Loop once you have reached the top of the bath(SPLASH=1). 
   Repeat 
      '
      ' Swaps between the Phisical and Logical screens then clears the screen  
      ' of bobs. 
      Screen Swap BS
      Wait Vbl 
      Bob Clear 
      '
      ' Sets the joystic,Call the EXTRA LIFE proc and check for collisions.  
      _EXTRA_LIFE
      J=Joy(1)
      If BS=3 and Spritebob Col(10,5 To 6) Then _BDEAD
      If BS=1 and Spritebob Col(10,7 To 7) Then _BDEAD
      If Sprite Col(10,13 To 21) Then _BGETITEM
      '
      ' If your on the bottom half of the bath and you touch the top of the
      ' screen then it flicks to the top half of the bath. 
      If BS=3 and Y Sprite(10)<70
         ' Freezes bob animations and turns off the items.
         Screen 3 : Amal Freeze 7 : Amal Freeze 8 : For SO=13 To 17 : Sprite Off SO : Next : Update : Wait Vbl : Bob Clear 
         ' Brings the top half of the bath into view. 
         Screen 1 : Screen To Back 3 : Screen To Front 1
         ' Sets the player coordinates,the new screen number(BS) and turns on 
         ' the Bob animation and the items.   
         Y=238 : BS=1 : Amal On 9 : _BITEMS : Bob Draw : Update : Wait Vbl : Bob Clear 
      End If 
      '
      ' If your on the top half of the bath and you touch the bottom of the
      ' screen then it flicks to the bottom half of the bath.  
      If BS=1 and Y Sprite(10)>244
         ' Freezes bob animation and turns off the items. 
         Screen 1 : Amal Freeze 9 : For SO=18 To 21 : Sprite Off SO : Next : Update : Wait Vbl : Bob Clear 
         ' Brings the bottom half of the bath into view.  
         Screen 3 : Screen To Back 1 : Screen To Front 3
         ' Sets the player coordinates,the new screen number(BS) and turns on 
         ' the Bob animations and the items.  
         Y=80 : BS=3 : Amal On 7 : Amal On 8 : _BITEMS : Update : Wait Vbl : Bob Clear 
      End If 
      '
      ' Checks if you have gone out of the water then plays the Splash sfx 
      ' and sets SPLASH to 1.
      If BS=1 and Y Sprite(10)=110 : Sam Bank 6 : Sam Play %11,4 : Screen 1 : SPLASH=1 : End If 
      '
      ' Places the Bubble above Henry depending on the direction you have  
      ' pushed on the joystic. 
      If Jright(1) or Jup(1) and BUB=0 or Jdown(1) and BUB=0 or J=0 and BUB=0 Then Sprite 26,X Sprite(10)+2,Y Sprite(10)-28, : BUB=0
      If Jleft(1) or Jup(1) and BUB=1 or Jdown(1) and BUB=1 or J=0 and BUB=1 Then Sprite 26,X Sprite(10)-9,Y Sprite(10)-28, : BUB=1
      '
      ' Makes Henry move up if any of these joystic directions are moved.  
      If J=1 or J=5 or J=9 or J=17 or J=21 or J=25 Then Dec Y
      '
      ' Stops Henry when he goes to the edge of a screen.  
      If X Sprite(10)>446 Then Sprite 10,446,Y,
      If X Sprite(10)<130 Then Sprite 10,130,Y,
      ' Plays the Bubble sfx.
      If I Sprite(26)=105 Then Sam Bank 6 : Sam Play %1110,3
      '
      ' Checks for the collision between Henry and a colour. 
      F=Point(X Screen(X Sprite(10)),Y Screen(Y Sprite(10)))
      ' If Henry is not on the platform colour and moves the joystic in the  
      ' following directions then he falls.  
      If F<>2 and J=0 or F<>2 and J=16 or F<>2 and J=20 or F<>2 and J=24 Then Inc Y
      If F<>2 and J=4 or F<>2 and J=8 or F<>2 and J=6 or F<>2 and J=10 or F<>2 and Jdown(1) Then Inc Y
      '
      ' Updates the player sprite and draws all the bobs on screen.
      Sprite 10,,Y,
      Sprite Update 
      Bob Draw 
      '
      '----------------------------------------------------------------------- 
      ' Swaps between the Phisical and Logical screens then clears the screen  
      ' of bobs. 
      Screen Swap BS
      Wait Vbl 
      Bob Clear 
      J=Joy(1)
      '
      ' Checks if you have gone out of the water then plays the Splash sfx and 
      ' sets SPLASH to 1.    
      If BS=1 and Y Sprite(10)=110 : Sam Bank 6 : Sam Play %1110,4 : Screen 1 : SPLASH=1 : End If 
      '
      ' Makes Henry move up if any of these joystic directions are moved.
      If J=1 or J=5 or J=9 or J=17 or J=21 or J=25 Then Dec Y
      ' Stops Henry when he goes to the edge of a screen 
      If X Sprite(10)>446 Then Sprite 10,446,Y,
      If X Sprite(10)<130 Then Sprite 10,130,Y,
      '
      ' Checks for the collision between Henry and a colour. 
      F=Point(X Screen(X Sprite(10)),Y Screen(Y Sprite(10)))
      ' If Henry is not on the platform colour and moves the joystic in the  
      ' following directions then he falls.  
      If F<>2 and J=0 or F<>2 and J=16 or F<>2 and J=20 or F<>2 and J=24 Then Inc Y
      If F<>2 and J=4 or F<>2 and J=8 or F<>2 and J=6 or F<>2 and J=10 or F<>2 and Jdown(1) Then Inc Y
      '
      ' Updates the player sprite and draws all the bobs on screen.
      Sprite 10,,Y,
      Sprite Update 
      Bob Draw 
   Until SPLASH=1
   '
   ' Calls the RESTART procedure. 
   _RESTART
   '
End Proc
'
' Sets up the 2 Bonus background screens,enemy animations and item positions.
Procedure _BSETUP
   '
   ' Unpacks the top half of the bath to screen 1,hides screen,makes mask for 
   ' sprites,double buffers screen for no flicker,turns autoback to manual and
   ' turns update off.    
   Unpack 11 To 1 : Screen Hide 1
   Screen 1
   Double Buffer 
   Make Mask : Autoback 0 : Update Off 
   '
   ' Set the Amal animation for the 2nd Frog. 
   Channel 9 To Bob 7
   Bob 7,340,80,95
   I$="Fgtwo:A 0,(95,5)(96,5)(97,5)(98,5)(99,5);M -360,0,250;M 0,20,30"
   I$=I$+"A 0,(100,5)(101,5)(102,5)(103,5)(104,5);M 360,0,250;M 0,40,30"
   I$=I$+"A 0,(95,5)(96,5)(97,5)(98,5)(99,5);M -360,0,250;M 0,-20,30"
   I$=I$+"A 0,(100,5)(101,5)(102,5)(103,5)(104,5);M 360,0,250;M 0,-40,30;J Fgtwo"
   Amal 9,I$
   '
   ' Unpacks the bottom half of the bath to screen 3,makes mask for sprites,double  
   ' buffers screen for no flicker,turns autoback to manual and turns update off.   
   Unpack 12 To 3
   Screen 3
   Double Buffer 
   Make Mask : Autoback 0 : Update Off 
   '
   ' Sets the player starting coordinates and the Channels for the animatons.     
   X=280 : Y=244
   Channel 6 To Sprite 10
   Channel 7 To Bob 5
   Channel 8 To Bob 6
   Channel 10 To Sprite 26
   Sprite 10,280,244,79
   Bob 5,340,50,85
   Bob 6,-20,120,100
   Sprite 26,X Sprite(10)+2,Y Sprite(10)-28,
   '
   ' Calls the BITEMS procedure.
   _BITEMS
   '  
   ' Sets the Amal animation string for the player's left & right movement. 
   F$="Let R0=1;"
   F$=F$+"A: If J1&4 then Jump C ;" : Rem left         
   F$=F$+"B: If J1&8 then Jump D ;" : Rem right      
   F$=F$+"Jump A ;"
   F$=F$+"C: A 0,(82,4)(83,4)(82,4)(84,4);M -8,0,16; Jump A;"
   F$=F$+"D: A 0,(79,4)(80,4)(79,4)(81,4);M  8,0,16; Jump B;"
   '
   ' Set Amal animation strings for the Fish,Frog and Bubble. 
   G$="Fish:A 0,(85,5)(86,5)(87,5)(88,5)(89,5);M -360,0,250;M 0,30,20"
   G$=G$+"A 0,(90,5)(91,5)(92,5)(93,5)(94,5);M 360,0,250;M 0,20,20"
   G$=G$+"A 0,(85,5)(86,5)(87,5)(88,5)(89,5);M -360,0,250;M 0,50,20"
   G$=G$+"A 0,(90,5)(91,5)(92,5)(93,5)(94,5);M 360,0,250;M 0,-40,20"
   G$=G$+"A 0,(85,5)(86,5)(87,5)(88,5)(89,5);M -360,0,250;M 0,-20,20"
   G$=G$+"A 0,(90,5)(91,5)(92,5)(93,5)(94,5);M 360,0,250;M 0,-40,20;J Fish"
   '
   H$="Frog:A 0,(100,5)(101,5)(102,5)(103,5)(104,5);M 360,0,260;M 0,30,30"
   H$=H$+"A 0,(95,5)(96,5)(97,5)(98,5)(99,5);M -360,0,260;M 0,-60,30"
   H$=H$+"A 0,(100,5)(101,5)(102,5)(103,5)(104,5);M 360,0,260;M 0,-30,3"
   H$=H$+"A 0,(95,5)(96,5)(97,5)(98,5)(99,5);M -360,0,260;M 0,60,30;J Frog"
   '
   J$="A 0,(105,4)(106,5)(107,5)(108,5)(109,5)(110,5)(68,40)"
   '
   ' Set the Channels to the strings then turn on the Amal animations.
   Amal 6,F$ : Amal 7,G$ : Amal 8,H$ : Amal 10,J$
   Amal On 6 : Amal On 7 : Amal On 8 : Amal On 10
   '
   ' Show the top half of bath which is behind the bottom half. 
   Screen Show 1
   '
End Proc
'
' Sets the Item positions on the two Bonus screens.
Procedure _BITEMS
   '
   ' If the relevant BI variable equals 0 on the relevant Bonus screen then 
   ' the item gets displayed.This stops the items being displayed on both 
   ' screens makeing up the bath. 
   If BI=0 and BS=3 Then Sprite 13,150,178,69
   If BIA=0 and BS=3 Then Sprite 14,258,96,70
   If BIB=0 and BS=3 Then Sprite 15,400,122,72
   If BIC=0 and BS=3 Then Sprite 16,338,200,73
   If BID=0 and BS=3 Then Sprite 17,288,146,69
   If BIE=0 and BS=1 Then Sprite 18,370,150,73
   If BIF=0 and BS=1 Then Sprite 19,386,208,72
   If BIG=0 and BS=1 Then Sprite 20,280,120,69
   If BIH=0 and BS=1 Then Sprite 21,146,180,70
   '
End Proc
'
' Updates your score and turns off a sprite when you collect an item.
Procedure _BGETITEM
   '
   ' Turns off the sprite you have collided with,plays the Collect sfx and  
   ' updates the EXSC variable. 
   Sprite Off Col(-1) : Sam Bank 5 : Sam Play %1100,4 : A=A+1 : EXSC=EXSC+50
   ' Sets the BI variable to 1 so the program dos'nt display that item.   
   If Col(13)=-1 Then BI=1
   If Col(14)=-1 Then BIA=1
   If Col(15)=-1 Then BIB=1
   If Col(16)=-1 Then BIC=1
   If Col(17)=-1 Then BID=1
   If Col(18)=-1 Then BIE=1
   If Col(19)=-1 Then BIF=1
   If Col(20)=-1 Then BIG=1
   If Col(21)=-1 Then BIH=1
   '
   Screen 2
   ' Updates your score variable. 
   SC=SC+50
   ' Turn score variable to string so it can be printed using 'Text'. 
   C$=Str$(SC) : Text 144,20,C$
   ' Return to relevant bonus screen. 
   Screen BS
   '
End Proc
'
' Updates the lives,sets the death animation then plays it on the Bonus screen.
Procedure _BDEAD
   '
   ' This is a seperate DEAD procedure for the Bonus stage. 
   ' Decrease the LIVES by 1 then convert variable to string to display lives.    
   Screen 2
   LIVES=LIVES-1
   B$=Str$(LIVES) : LD=Text Length(B$) : Text 64-LD,20,B$
   '
   Screen BS
   ' Match the Bob starting position with the Player sprite position. 
   DX=X Screen(X Sprite(10)) : DY=Y Screen(Y Sprite(10))
   Bob 28,DX,DY,112
   ' Set Amal animation.
   Channel 11 To Bob 28
   K$="A 0,(112,0); M 0,-20,20; M 0,-4,4; M 0,-3,3; M 0,-3,4; M 0,2,4; M 0,3,3; M 0,15,5; M 0,240,46"
   Amal 11,K$ : Amal On 11
   ' Turn off player sprite and Bubble then plays Ouch sfx and update bobs. 
   Sprite Off 10 : Sprite Off 26
   Sam Bank 5 : Sam Play %1110,2
   Bob Clear : Bob Draw 
   '    
   ' Small loop to allow Henry to finish death sequence without causing any   
   ' problems to the Bonus mainloop eg,colliding while still playing the death anim.  
   Repeat 
      Screen Swap BS
      Wait Vbl 
      Bob Clear 
      '
      Sprite Update 
      Bob Draw 
      '
      Screen Swap BS
      Wait Vbl 
      Bob Clear 
      '
      Sprite Update 
      Bob Draw 
   Until Y Bob(28)>239
   '
   ' Turns off player bob and animation.
   Bob Off 28 : Amal Off 11
   ' If player has lost all their lives then call the GAMEOVER procedure.   
   If LIVES=0 Then _GAMEOVER
   '
   ' Resets the Amal Channels and player starting positions.  
   Channel 6 To Sprite 10
   Channel 10 To Sprite 26
   Y=242 : Sprite 10,280,Y,79
   BUB=0 : Sprite 26,X Sprite(10)+2,Y Sprite(10)-28,
   ' Set the player and Bubble Amal animation strings.    
   F$="Let R0=1;"
   F$=F$+"A: If J1&4 then Jump C ;" : Rem left         
   F$=F$+"B: If J1&8 then Jump D ;" : Rem right      
   F$=F$+"Jump A ;"
   F$=F$+"C: A 0,(82,4)(83,4)(82,4)(84,4);M -8,0,16; Jump A;"
   F$=F$+"D: A 0,(79,4)(80,4)(79,4)(81,4);M  8,0,16; Jump B;"
   J$="A 0,(105,5)(106,5)(107,5)(108,5)(109,5)(110,5)(68,40)"
   ' Set the Channels to the strings then turn on the Amal animation. 
   Amal 6,F$ : Amal 10,J$ : Amal On 6 : Amal On 10
   '
   ' Returns you back to the bottom half of the bath. 
   If BS=1
      ' Freezes bob animation and turns off the items. 
      Screen 1 : Amal Freeze 9 : For SO=18 To 21 : Sprite Off SO : Next : Update : Wait Vbl : Bob Clear 
      ' Brings the bottom half of the bath into view.
      Screen 3 : Screen To Back 1 : Screen To Front 3
      ' Sets the player coordinates,the new screen number(BS) and turns on 
      ' the Bob animations and the items.
      BS=3 : Amal On 7 : Amal On 8 : _BITEMS : Update : Wait Vbl : Bob Clear 
   End If 
   '
   ' Update bobs,Swaps the relevant Bonus screen and clears the bobs on screen. 
   Bob Clear : Bob Draw : Screen Swap BS : Wait Vbl : Bob Clear 
   '
End Proc
