'                                Henry's House 
'
'                            LEVEL TWO 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 - Bonus screen background 
'
' Bobs and Sprites Used: 
' Bob  1 - Bread 
' Bob  2 - Toaster 
' Bob  3 - Teapot
' Bob  4 - Fork
' Bob  6 to 10 - Water Drops 
' Bob 10 - Henry Crying
' Bob 26 - Henry Hit 
' Sprite  8 - Player 
' Sprite 10 - Flame
' Sprite 12 - Tea Drop 
' Sprite 13 to 20 - Items
' Sprite 24 - Exit 
'
' 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.
'
'----------------------------------------------------------------------------- 
'
' 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
'
' Set the variables. 
X=315 : Y=215 : I=1 : D=0 : A=0 : BONUS=1 : BLINK=0 : TIME=70 : COUNT=0 : GONG=70
'
'------------------------------------------------------------------------------  
' 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)
      '
      ' Checks the collision between the player sprite and other bobs and sprites. 
      If Spritebob Col(8,1 To 4) Then _DEAD
      If Sprite Col(8,10 To 12) Then _DEAD
      If Sprite Col(8,13 To 19) Then _GET_ITEM
      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,150,232,60 : End If 
      '
      ' If all items are collected within the timelimit then the 'open fridge  
      ' door' image gets pasted on both logical and phisical screens.  
      If A=15 and TIME>0 : Paste Bob 257,27,58 : Bob Draw : Screen Swap 0 : Wait Vbl : Bob Clear : Paste Bob 257,27,58 : TIME=0 : A=16 : End If 
      '
      ' If the player hits these coordinates then you enter the Bonus stage. 
      If A=16 and X>434 and Y<130 : Sprite Update : _BONUS : 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<436 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 the platform then   
      ' the relevant JUMP procedure is called. 
      If J=1 and F=2 Then JUMP_UP
      If J=5 and F=2 Then D=6 : JUMP_LEFT
      If J=9 and F=2 Then D=0 : JUMP_RIGHT
      '
      'Plays the Toaster and Drop sfx. 
      If Bob Col(1,2 To 2)=-1 Then Sam Bank 6 : Sam Play %1,2
      If I Sprite(12)=42 Then Sam Bank 6 : Sam Play %10,1
      ' Plays the Gong sfx when the Gong timer equals 0. 
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      '
      ' 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)
      '
      ' 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<436 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,"70"
   '
   ' Loads the powerpacked bobs and sfx.
   Screen 0
   'Ppload "Henry's_HouseD2:Bobs/SpritesLev2" 
   'Ppload "Henry's_HouseD2:sound/Mainsfx",5
   '
   ' Display message 'Press Fire To Start'. 
   Screen 1 : Paste Bob 115,180,68
   '
   ' 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,68 : 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 gets the sprite palette 
   ' and Double Buffers the screen for no flicker.  
   Screen 0 : Unpack 10 To 0 : Screen Hide 0
   Get Sprite Palette : 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,$34,$BBB,$602,$363,$484,$5B6,$410,$555,$765,$986,$BA8,$DC9,$7C,$29D,$5BE,$8DF,$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,64
   ' Set Amal animation.
   Channel 12 To Bob 26
   L$="A 0,(64,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,250,46"
   Amal 12,L$ : Amal On 12
   ' 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 Bob Col(1,2 To 2)=-1 Then Sam Bank 6 : Sam Play %1,2
      If I Sprite(12)=42 Then Sam Bank 6 : Sam Play %10,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      '
      Sprite Update 
      Bob Draw 
      '
      Screen Swap 0
      Wait Vbl 
      Bob Clear 
      '
      Sprite Update 
      Bob Draw 
   Until Y Bob(26)>249
   '
   ' 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 12 : X=315 : Y=212 : 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
      If BONUS=1 Then _TIME : Rem Call TIME proc when your not in the Bonus stage. 
      _EXTRA_LIFE
      If Sprite Col(8,10 To 12) Then N=34 : _DEAD
      If Spritebob Col(8,1 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 Bob Col(1,2 To 2)=-1 Then Sam Bank 6 : Sam Play %1,2
      If I Sprite(12)=42 Then Sam Bank 6 : Sam Play %10,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      If BONUS=0
         If I Bob(6)=50 or I Bob(7)=50 or I Bob(8)=50 or I Bob(9)=50 or I Bob(10)=50 : Sam Bank 6 : Sam Play %11,1 : End If 
         If Spritebob Col(8,6 To 10) : N=34 : _BDEAD : End If 
      End If 
      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
      If BONUS=1 Then _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 Sprite Col(8,10 To 12) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 4) Then N=34 : _DEAD
      If Sprite Col(8,13 To 19) Then _GET_ITEM
      '
      If Bob Col(1,2 To 2)=-1 Then Sam Bank 6 : Sam Play %1,2
      If I Sprite(12)=42 Then Sam Bank 6 : Sam Play %10,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      If BONUS=0
         If I Bob(6)=50 or I Bob(7)=50 or I Bob(8)=50 or I Bob(9)=50 or I Bob(10)=50 : Sam Bank 6 : Sam Play %11,1 : End If 
         If Spritebob Col(8,6 To 10) : N=34 : _BDEAD : End If 
      End If 
      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
      If BONUS=1 Then _TIME : Rem Call TIME proc when your not in the Bonus Stage. 
      Add I,1,1 To 6 : Dec Y : If X>140 Then Dec X
      '
      If Sprite Col(8,10 To 12) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 4) Then N=34 : _DEAD
      If Y Sprite(8)<60 Then N=34 : Rem So Henry dos'nt go off screen. 
      '
      If Bob Col(1,2 To 2)=-1 Then Sam Bank 6 : Sam Play %1,2
      If I Sprite(12)=42 Then Sam Bank 6 : Sam Play %10,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      If BONUS=0
         If I Bob(6)=50 or I Bob(7)=50 or I Bob(8)=50 or I Bob(9)=50 or I Bob(10)=50 : Sam Bank 6 : Sam Play %11,1 : End If 
         If Spritebob Col(8,6 To 10) : N=34 : _BDEAD : End If 
      End If 
      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
      If BONUS=1 Then _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 Sprite Col(8,10 To 12) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 4) Then N=34 : _DEAD
      '
      If Bob Col(1,2 To 2)=-1 Then Sam Bank 6 : Sam Play %1,2
      If I Sprite(12)=42 Then Sam Bank 6 : Sam Play %10,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      If BONUS=0
         If I Bob(6)=50 or I Bob(7)=50 or I Bob(8)=50 or I Bob(9)=50 or I Bob(10)=50 : Sam Bank 6 : Sam Play %11,1 : End If 
         If Spritebob Col(8,6 To 10) : N=34 : _BDEAD : End If 
      End If 
      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
      If BONUS=1 Then _TIME : Rem Call TIME proc when your not in the Bonus Stage.   
      Add I,1,1 To 6 : Dec Y : If X<436 Then Inc X
      '
      If Sprite Col(8,10 To 12) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 4) Then N=34 : _DEAD
      If Spritebob Col(8,5 To 5) Then N=34 : _BONUS
      If Y Sprite(8)<60 Then N=34 : Rem So Henry dos'nt go off screen. 
      '
      If Bob Col(1,2 To 2)=-1 Then Sam Bank 6 : Sam Play %1,2
      If I Sprite(12)=42 Then Sam Bank 6 : Sam Play %10,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      If BONUS=0
         If I Bob(6)=50 or I Bob(7)=50 or I Bob(8)=50 or I Bob(9)=50 or I Bob(10)=50 : Sam Bank 6 : Sam Play %11,1 : End If 
         If Spritebob Col(8,6 To 10) : N=34 : _BDEAD : End If 
      End If 
      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
      If BONUS=1 Then _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 Sprite Col(8,10 To 12) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 4) Then N=34 : _DEAD
      If Spritebob Col(8,5 To 5) Then N=34 : _BONUS
      '
      If Bob Col(1,2 To 2)=-1 Then Sam Bank 6 : Sam Play %1,2
      If I Sprite(12)=42 Then Sam Bank 6 : Sam Play %10,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      If BONUS=0
         If I Bob(6)=50 or I Bob(7)=50 or I Bob(8)=50 or I Bob(9)=50 or I Bob(10)=50 : Sam Bank 6 : Sam Play %11,1 : End If 
         If Spritebob Col(8,6 To 10) : N=34 : _BDEAD : End If 
      End If 
      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 13 To Sprite 8
   Sprite 8,X,Y,
   M$="A 0,(66,30)(67,10)(66,10)(67,10);"
   Amal 13,M$ : Amal On 13 : 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,1 To 4) Then Update Off : _DEAD : Exit 
      If Sprite Col(8,10 To 12) Then Update Off : _DEAD : Exit 
      '
      If Bob Col(1,2 To 2)=-1 Then Sam Bank 6 : Sam Play %1,2
      If I Sprite(12)=42 Then Sam Bank 6 : Sam Play %10,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      If BONUS=0
         If I Bob(6)=50 or I Bob(7)=50 or I Bob(8)=50 or I Bob(9)=50 or I Bob(10)=50 : Sam Bank 6 : Sam Play %11,1 : End If 
         If Spritebob Col(8,6 To 10) : Update Off : _BDEAD : Exit : End If 
      End If 
      '
      ' Check for any joystic movement then exits out of loop. 
      If J>0 Then Exit 
      ' Wait for a vertical blank. 
      Wait Vbl 
   Loop 
   '
   ' Turns off blinking animation,automatic updateing and reset the BLINK timer.    
   Amal Off 13 : Update Off : BLINK=0
   '
   ' Depending on the BONUS value the program updates the bobs,swaps the screen 
   ' and then clears the bobs on screen.This is so the program can stay in
   ' sync when returning to mainloop. 
   If BONUS=1
      Bob Clear : Bob Draw : Screen Swap 0 : Wait Vbl : Bob Clear 
   End If 
   If BONUS=0
      Bob Clear : Bob Draw : Screen Swap 1 : Wait Vbl : Bob Clear 
   End If 
   '
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,$12 : 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 Sprite 10
   Channel 2 To Bob 1
   Channel 3 To Bob 2
   Channel 4 To Bob 3
   Channel 5 To Sprite 12
   Channel 6 To Bob 4
   Sprite 10,186,156,13
   Bob 1,272,140,22
   Bob 2,272,144,19
   Bob 3,140,15,23
   Sprite 12,254,74,40
   Bob 4,340,188,62
   '
   ' Set Amal animation strings for each enemy. 
   A$="A 0,(45,5); M 0,0,40;"
   A$=A$+"Flame:A 1,(13,5)(14,5)(15,5)(16,5)(17,5)(18,5)(17,5)(16,5)(15,5)(14,5)(13,5); M 0,0,55; A 1,(45,10); M 30,0,10;"
   A$=A$+"A 1,(13,5)(14,5)(15,5)(16,5)(17,5)(18,5)(17,5)(16,5)(15,5)(14,5)(13,5); M 0,0,55; A 1,(45,10); M -30,0,10 Jump Flame"
   '
   B$="A 0,(19,40); M 0,0,40;"
   B$=B$+"A 0,(19,10)(20,10)(21,40);"
   '
   C$="A 0,(45,5); M 0,0,40;"
   C$=C$+"Bread:A 1,(22,50); M 0,-160,50; A 1,(45,10); M 0,160,10; Jump Bread"
   '
   D$="A 0,(23,40); M 0,0,40;"
   D$=D$+"Teapot:A 1,(23,5)(24,5)(25,10)(24,5)(23,5) ; M 0,0,30; A 1,(26,5)(27,5)(28,5)(29,5); M 0,0,20; A 0,(29,5)(30,5)(31,5)(32,5)(33,5); M 65,0,100"
   D$=D$+"A 1,(29,5)(34,5)(35,10)(34,5)(29,5); M 0,0,30; A 1,(29,5)(28,5)(27,5)(26,5); M 0,0,20; A 0,(23,5)(36,5)(37,5)(38,5)(39,5); M -65,0,100 Jump Teapot"
   '
   E$="A 0,(45,40); M 0,0,40;"
   E$=E$+"Drop:A 1,(45,10); M 0,0,10;A 0,(40,5)(41,30);M 0,80,35; A 1,(42,2)(43,5)(44,5); M 0,0,15; A 1,(45,100); M 0,-80,50; M 92,0,50;"
   E$=E$+"A 0,(40,5)(41,35); M 0,101,40; A 1,(42,2)(43,5)(44,5); M 0,0,15;A 1,(45,85); M 0,-101,40; M -92,0,45 Jump Drop"
   '
   F$="A 0,(62,40); M 0,0,40;"
   F$=F$+"Fork:A 0,(62,5); M -350,0,200; M 0,0,50; A 0,(63,5); M 350,0,200; M 0,0,50; Jump Fork"
   '
   ' Set the Channels to the strings then turn on the Amal animations.  
   Amal 1,A$ : Amal 2,C$ : Amal 3,B$ : Amal 4,D$ : Amal 5,E$ : Amal 6,F$
   Amal On 
   '
End Proc
'
' Sets the positions for the first wave of items.
Procedure _ITEMS
   '
   Sprite 13,140,69,53
   Sprite 14,258,112,55
   Sprite 15,148,173,54
   Sprite 16,430,235,56
   Sprite 17,388,90,54
   Sprite 18,170,235,55
   Sprite 19,200,138,56
   '
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,195,96,56
   Sprite 14,358,174,55
   Sprite 15,300,70,57
   Sprite 16,433,142,54
   Sprite 17,342,114,53
   Sprite 18,434,224,56
   Sprite 19,200,224,53
   '
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 the relevant game screen.
   If BONUS=1 Then Screen 0
   If BONUS=0 Then Screen 1
   '
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 screen.
   Screen 1 : Fade 1 : Wait 15 : Sprite Off : Bob Off : Amal Off : Screen Hide 1
   '
   ' Resets the A,BONUS,X and Y variables,turns on the enemy animations then  
   ' pastes the 'closed fridge door' image on screen.   
   Screen 0 : A=0 : BONUS=1 : X=315 : Y=212 : Sprite Update : Wait Vbl : _AMAL
   Paste Bob 257,27,59 : Bob Draw : Screen Swap 0 : Wait Vbl : Bob Clear : Paste Bob 257,27,59
   '
   ' Place Exit back on screen and fade screen into view. 
   Sprite 24,150,232,60
   Screen Show 0
   Fade 1,$34,$BBB,$602,$363,$484,$5B6,$410,$555,$765,$986,$BA8,$DC9,$7C,$29D,$5BE,$8DF,$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,150,232,61
   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=315 : 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 1 : 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
      Screen 1 : Fade 2 : Wait 30 : Cls 0 : Sprite Off : Sprite Update : Wait Vbl : Bob Off : Amal Off : Screen Close 1
      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,71
   F$="A 0,(71,5)(72,5)(73,5)(74,5)(75,5)(76,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,69 : Paste Bob 164,10,70
   Fade 1 : Wait 15
   Screen Show 0
   Fade 1,$0,$BBB,$602,$363,$484,$5B6,$410,$555,$765,$986,$BA8,$DC9,$7C,$29D,$5BE,$8DF,$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 repeats until you have collected all of the items.
Procedure _BONUS
   '
   ' Set the collect variable 'A',BONUS variable and jump variable so you do'nt 
   ' continue jumping when you enter the bonus stage. 
   A=16
   BONUS=0 : N=34
   ' Fade screen,turn off all sprites,bobs and animations then hide screen. 
   Screen 0 : Fade 1 : Wait 15 : Sprite Off : Bob Off : Amal Off : Screen Hide 0
   '
   ' Call the BSETUP procedure. 
   _BSETUP
   ' Alter the player starting coordinates. 
   X=400 : Y=108
   '
   ' 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 when you have collected all of the items or touched the  
   ' bottom of the screen.    
   Repeat 
      '
      ' Swaps between the Phisical and Logical screens then clears the screen  
      ' of bobs. 
      Screen Swap 1
      Wait Vbl 
      Bob Clear 
      '
      ' Sets the joystic,Call the EXTRA LIFE proc and check for collisions.  
      _EXTRA_LIFE
      J=Joy(1)
      If Spritebob Col(8,6 To 10) Then _BDEAD
      If Sprite Col(8,13 To 20) Then _GET_ITEM
      '
      ' If Henry is left alone on a platform variable 'BLINK' increases or equals 0. 
      If J=0 and F=2 Then Inc BLINK Else BLINK=0
      If BLINK>20 Then _BLINK
      '
      ' Checks for joystic directions and if you have jumped.  
      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<436 Then Inc X : D=0 : Inc C : If C mod 4=0 Then Add I,1,1 To 6
      If J=1 and F=2 Then JUMP_UP
      If J=5 and F=2 Then D=6 : JUMP_LEFT
      If J=9 and F=2 Then D=0 : JUMP_RIGHT
      ' Plays the Drop sfx whenever a water drop's image is that of it splashing.  
      If I Bob(6)=50 or I Bob(7)=50 or I Bob(8)=50 or I Bob(9)=50 or I Bob(10)=50 Then Sam Bank 6 : Sam Play %11,1
      '
      ' Checks for the collision between Henry and the platform colour.
      F=Point(X Screen(X Sprite(8)),Y Screen(Y Sprite(8)))
      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 1
      Wait Vbl 
      Bob Clear 
      J=Joy(1)
      '
      ' Sets the joystic and check for collisions. 
      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<436 Then Inc X : D=0 : Inc C : If C mod 4=0 Then Add I,1,1 To 6
      '  
      ' Checks for the platform colour collision and updates the player sprite.
      F=Point(X Screen(X Sprite(8)),Y Screen(Y Sprite(8)))
      If F<>2 Then Inc Y
      Sprite 8,X,Y,I+D
      Sprite Update 
      Bob Draw 
   Until A=24 or Y Sprite(8)>240
   '
   ' Calls the RESTART procedure. 
   _RESTART
   '
End Proc
'
' Sets up the Bonus background,enemy animations and item positions.
Procedure _BSETUP
   '
   ' Unpack the Bonus Background to screen 1 then hide it.
   Unpack 11 To 1 : Screen Hide 1
   Screen 1
   ' Double Buffer screen for no flicker,turn Autoback to manual,turn Update  
   ' off then Update every 2 for smoother animation.  
   Double Buffer 
   Autoback 0 : Update Off : Update Every 2
   '
   ' Set the Amal channels for the 5 Water drops.   
   Channel 7 To Bob 6
   Channel 8 To Bob 7
   Channel 9 To Bob 8
   Channel 10 To Bob 9
   Channel 11 To Bob 10
   Bob 6,220,20,45
   Bob 7,70,76,45
   Bob 8,160,76,45
   Bob 9,270,132,45
   Bob 10,140,132,45
   '
   ' Set Amal animation strings for each Water Drop.  
   G$="Wdropone:M 0,0,10;A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,1);M 0,-33,1;M -50,0,1;"
   G$=G$+"A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,1);M 0,-33,1;M -60,0,1;"
   G$=G$+"A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,1);M 0,-33,1;M 60,0,1;"
   G$=G$+"A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,1);M 0,-33,1;M 50,0,1 Jump Wdropone"
   '
   H$="Wdroptwo:M 0,0,20;A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,20);M 0,-33,10;M 50,0,5;"
   H$=H$+"A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,20);M 0,-33,10;M -50,0,5 Jump Wdroptwo"
   '
   I$="Wdropthree:M 0,0,5;A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,20);M 0,-33,10;M 80,0,5;"
   I$=I$+"A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,20);M 0,-33,10;M -80,0,5 Jump Wdropthree"
   '
   J$="Wdropfour:M 0,0,20;A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,20);M 0,-33,10;M -50,0,5;"
   J$=J$+"A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,20);M 0,-33,10;M 50,0,5 Jump Wdropfour"
   '
   K$="Wdropfive:M 0,0,26;A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,20);M 0,-33,10;M -40,0,5;"
   K$=K$+"A 0,(46,6)(47,6)(48,6);M 0,0,18;A 0,(49,30);M 0,33,30;A 1,(50,2)(51,5)(52,5);M 0,0,15;A 0,(45,20);M 0,-33,10;M 40,0,5 Jump Wdropfive"
   '
   ' Set the Channels to the strings then turn on the Amal animations.  
   Amal 7,G$ : Amal 8,H$ : Amal 9,I$ : Amal 10,J$ : Amal 11,K$
   Amal On 7 : Amal On 8 : Amal On 9 : Amal On 10 : Amal On 11
   '
   ' Set the positions for the items. 
   Sprite 13,330,102,53
   Sprite 14,250,102,54
   Sprite 15,210,158,56
   Sprite 16,310,158,54
   Sprite 17,400,138,54
   Sprite 18,370,214,55
   Sprite 19,300,214,56
   Sprite 20,200,196,53
   '
   ' Show Bonus screen. 
   Screen Show 1
   '
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 1
   ' 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,65
   ' Set Amal animation.
   Channel 12 To Bob 26
   L$="A 0,(65,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,250,46"
   Amal 12,L$ : Amal On 12
   ' 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 Bonus mainloop eg,colliding while still playing the death anim.  
   Repeat 
      Screen Swap 1
      Wait Vbl 
      Bob Clear 
      If BONUS=0
         If I Bob(6)=50 or I Bob(7)=50 or I Bob(8)=50 or I Bob(9)=50 or I Bob(10)=50 : Sam Bank 6 : Sam Play %11,1 : End If 
      End If 
      '
      Sprite Update 
      Bob Draw 
      '
      Screen Swap 1
      Wait Vbl 
      Bob Clear 
      '
      Sprite Update 
      Bob Draw 
   Until Y Bob(26)>249
   '
   ' If player has lost all their lives then call the GAMEOVER procedure. 
   If LIVES=0 Then _GAMEOVER
   '
   ' Turn off Death animation,reset player starting position and image then     
   ' swap screen and clear bobs to help stay in sync with Bonus mainloop. 
   Amal Off 12 : X=400 : Y=108 : N=34 : I=2 : Sprite Update : Wait Vbl 
   Screen Swap 1 : Wait Vbl : Bob Clear 
   '
End Proc
