'                                Henry's House 
'
'                            LEVEL ONE 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 - Fish 
' Bob 2 - Squirral 
' Bob 3 - Bird 
' Bob 5 - Bonus Entrance 
' Bob 10 - Henry Crying
' Bob 26 - Henry Hit 
' Sprite 8 - Player
' Sprite 10 - Snail
' Sprite 12 to 23 - 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.
' SPLASH- Activates the drowning sequence. 
' CROW  - Timer for the Crow sfx.
' GONG  - Timer for the Gong sfx.
'
'----------------------------------------------------------------------------- 
'
' Closes the AMOS editor to save memory. 
Close Editor 
'
' Makes 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,SPLASH,CROW,GONG
'
'Sets the variables
X=310 : Y=184 : I=1 : D=0 : A=0 : BONUS=1 : BLINK=0 : TIME=70 : COUNT=0
CROW=0 : SPLASH=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 2) Then _DEAD
      If Sprite Col(8,10 To 10) Then _DEAD
      If Sprite Col(8,12 To 23) Then _GET_ITEM
      If Sprite Col(8,24 To 24) Then _EXIT
      '
      ' Places the next wave of itmes. 
      If A=7 Then MORE_ITEMS
      '
      ' Places the Exit on screen when you have collected all the items. 
      If A=15 : Sprite 24,150,66,85 : A=16 : End If 
      '
      ' If you have collected everything in the time limit the entrance to the 
      ' bonus stage opens. 
      If A=16 and TIME>0 : Bob 5,283,113,83 : 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 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
      '
      ' If Henry on the same level as the pond then it activates the splash. 
      If Y Sprite(8)>232 Then SPLASH=1 : _DEAD
      '
      ' Plays the Splosh sfx when the Fish is coming out and going into the
      ' water and plays the Gong sfx when the Gong timer equals 0. 
      If I Bob(1)=19 or I Bob(1)=29 Then Sam Bank 6 : Sam Play %1,1
      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<438 Then Inc X : D=0 : Inc C : If C mod 4=0 Then Add I,1,1 To 6
      If Y Sprite(8)>232 Then SPLASH=1 : _DEAD
      If I Bob(1)=19 or I Bob(1)=29 Then Sam Bank 6 : Sam Play %1,1
      '
      ' 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,"80"
   '
   ' Loads the powerpacked bobs and sfx.
   Screen 0
   'Ppload "Henry's_HouseD2:Bobs/SpritesLev1" 
   'Ppload "Henry's_HouseD2:sound/Mainsfx",5
   '
   ' Display message 'Press Fire To Start'. 
   Screen 1 : Paste Bob 115,180,91
   '
   ' 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,91 : 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,covers up the 
   ' hole in the tree and calls AMAL and ITEMS procedure. 
   For N=1 To 12 : Hot Spot N,$12 : Next 
   Paste Bob 272,96,82
   _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,$340,$5A,$7C,$555,$A60,$951,$632,$422,$51,$61,$72,$92,$A3,$B4,$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
   If SPLASH=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,87
      ' Set Amal animation.
      Channel 5 To Bob 26
      E$="A 0,(87,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 5,E$ : Amal On 5
      ' Turn off player sprite,play Ouch sfx and update bobs.
      Sprite Off 8
      Sam Bank 5 : Sam Play %1110,2
      Bob Clear : Bob Draw 
   End If 
   '
   If SPLASH=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,90
      ' Turn off player sprite,play Ouch sfx and update bobs.
      Sprite Off 8
      Sam Bank 6 : Sam Play %1110,2
      Bob Clear : Bob Draw 
   End If 
   '    
   ' 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 BONUS=1 Then FISH=I Bob(1) : If FISH=19 or FISH=29 Then Sam Bank 6 : Sam Play %1,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      '
      ' The SPLASH variable is now used as a timer for how long Henry will 
      ' stay in the water. 
      Inc SPLASH
      '
      Sprite Update 
      Bob Draw 
      '
      Screen Swap 0
      Wait Vbl 
      Bob Clear 
      '
      If BONUS=1 Then FISH=I Bob(1) : If FISH=19 or FISH=29 Then Sam Bank 6 : Sam Play %1,1
      Sprite Update 
      Bob Draw 
   Until Y Bob(26)>249 or SPLASH>40
   '
   ' Turn off the player bob,check to see if the player has lost all their
   ' lives if so then call the GAMEOVER procedure.
   If SPLASH>40 Then Bob Off 26
   If LIVES=0 Then _GAMEOVER
   '
   ' Turn off Death animation,reset SPLASH,reset player starting position and 
   ' image then swap screen and clear bobs to help stay in sync with mainloop.
   Amal Off 5 : SPLASH=0 : X=315 : Y=182 : 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 10) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 2) Then N=34 : _DEAD
      If BONUS=0 and Spritebob Col(8,3 To 3) Then N=34 : _BDEAD
      If Sprite Col(8,12 To 19) Then _GET_ITEM
      If Y Sprite(8)<60 Then N=34 : Rem So Henry dos'nt go off screen. 
      '
      If BONUS=1 Then FISH=I Bob(1) : If FISH=19 or FISH=29 Then Sam Bank 6 : Sam Play %1,1
      If BONUS=0 and CROW>40 Then Sam Bank 6 : Sam Play %11,3 : CROW=0
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      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 10) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 2) Then N=34 : _DEAD
      If BONUS=0 and Spritebob Col(8,3 To 3) Then N=34 : _BDEAD
      If Sprite Col(8,12 To 19) Then _GET_ITEM
      '
      If BONUS=1 Then FISH=I Bob(1) : If FISH=19 or FISH=29 Then Sam Bank 6 : Sam Play %1,1
      If BONUS=0 and CROW>40 Then Sam Bank 6 : Sam Play %11,3 : CROW=0
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      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>138 Then Dec X
      '
      If Sprite Col(8,10 To 10) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 2) Then N=34 : _DEAD
      If BONUS=0 and Spritebob Col(8,3 To 3) Then N=34 : _BDEAD
      If Sprite Col(8,24 To 24) Then _EXIT
      If Y Sprite(8)<60 Then N=34 : Rem So Henry dos'nt go off screen. 
      '
      If BONUS=1 Then FISH=I Bob(1) : If FISH=19 or FISH=29 Then Sam Bank 6 : Sam Play %1,1
      If BONUS=0 and CROW>40 Then Sam Bank 6 : Sam Play %11,3 : CROW=0
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      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>138 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 10) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 2) Then N=34 : _DEAD
      If BONUS=0 and Spritebob Col(8,3 To 3) Then N=34 : _BDEAD
      If Sprite Col(8,24 To 24) Then _EXIT
      '
      If BONUS=1 Then FISH=I Bob(1) : If FISH=19 or FISH=29 Then Sam Bank 6 : Sam Play %1,1
      If BONUS=0 and CROW>40 Then Sam Bank 6 : Sam Play %11,3 : CROW=0
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      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<438 Then Inc X
      '
      If Sprite Col(8,10 To 10) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 2) Then N=34 : _DEAD
      If BONUS=0 and Spritebob Col(8,3 To 3) Then N=34 : _BDEAD
      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 BONUS=1 Then FISH=I Bob(1) : If FISH=19 or FISH=29 Then Sam Bank 6 : Sam Play %1,1
      If BONUS=0 and CROW>40 Then Sam Bank 6 : Sam Play %11,3 : CROW=0
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      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<438 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 10) Then N=34 : _DEAD
      If Spritebob Col(8,1 To 2) Then N=34 : _DEAD
      If BONUS=0 and Spritebob Col(8,3 To 3) Then N=34 : _BDEAD
      If Spritebob Col(8,5 To 5) Then N=34 : _BONUS
      '
      If BONUS=1 Then FISH=I Bob(1) : If FISH=19 or FISH=29 Then Sam Bank 6 : Sam Play %1,1
      If BONUS=0 and CROW>40 Then Sam Bank 6 : Sam Play %11,3 : CROW=0
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      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 6 To Sprite 8
   Sprite 8,X,Y,
   F$="A 0,(88,30)(89,10)(88,10)(89,10);"
   Amal 6,F$ : Amal On 6 : 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 2) Then Update Off : _DEAD : Exit 
      If Sprite Col(8,10 To 10) Then Update Off : _DEAD : Exit 
      If BONUS=0 and Spritebob Col(8,3 To 3) Then Update Off : _BDEAD : Exit 
      '
      If BONUS=1 Then FISH=I Bob(1) : If FISH=19 or FISH=29 Then Sam Bank 6 : Sam Play %1,1
      If GONG=0 Then Sam Bank 5 : Sam Play %1110,3 : GONG=70
      If BONUS=0 : Inc CROW
         If CROW>80 : Sam Bank 6 : Sam Play %11,3 : CROW=0 : 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 resets the BLINK timer. 
   Amal Off 6 : Update Off : BLINK=0 : CROW=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
   Sprite 10,290,211,13
   Bob 1,114,188,19
   Bob 2,260,26,54
   '
   ' Set Amal animation strings for each enemy. 
   A$="A 0,(13,5); M 0,0,40;"
   A$=A$+"Snail:A 0,(13,180); M 120,0,180; A 1,(14,5)(15,5)(16,5)(17,5); M 0,0,20;"
   A$=A$+"A 0,(18,180); M -120,0,180; A 1,(17,5)(16,5)(15,5)(14,5); M 0,0,20; Jump Snail;"
   '
   B$="A 0,(33,5); M 0,0,40;"
   B$=B$+"Fish:A 1,(19,2)(20,6)(21,6); M 0,0,14; A 1,(22,50); M 0,-70,50 ; A 1,(23,6)(24,6)(25,6); M -5,-5,18; A 1,(26,6)(27,6); M -5,5,12;"
   B$=B$+"A 1,(28,50); M 0,70,50; A 1,(29,1)(30,6)(31,6)(32,6); M 0,0,19; A 1,(33,20);M 10,0,20; Jump Fish;"
   '
   C$="A 1,(54,20); M 0,0,40;"
   C$=C$+"Squirral:A 0,(54,10)(55,10); M 0,0,40; A 1,(56,8)(57,8)(58,8)(59,8); M 0,0,32; A 1,(59,5)(61,5)(62,5); M -3,0,15; A 0,(63,5)(64,5)(65,5)(66,5)(67,5); M -150,0,150"
   C$=C$+"A 1,(62,5)(61,5)(59,5); M 0,0,15; A 0,(59,10)(60,10); M 0,0,40; A 1,(59,8)(58,8)(57,8)(56,8); M 0,0,32; A 1,(54,5)(68,5)(69,5); M 3,0,15; A 0,(70,5)(71,5)(72,5)(73,5)(74,5); M 150,0,150; A 1,(69,5)(68,5)(54,5); M 0,0,15; Jump Squirral;"
   '
   ' Set the Channels to the strings then turn on the Amal animations.
   Amal 1,A$ : Amal 2,B$ : Amal 3,C$
   Amal On 
   '
End Proc
'
' Sets the positions for the first wave of items.
Procedure _ITEMS
   '
   Sprite 12,147,74,75
   Sprite 13,180,150,78
   Sprite 14,184,101,79
   Sprite 15,145,185,76
   Sprite 16,340,82,77
   Sprite 17,360,175,78
   Sprite 18,430,130,75
   '
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 12,148,126,77
   Sprite 13,255,163,75
   Sprite 14,239,86,76
   Sprite 15,370,82,79
   Sprite 16,145,185,78
   Sprite 17,200,185,77
   Sprite 18,425,133,76
   '
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,Y and N variables and turns on the enemy animations.
   Screen 0 : A=0 : BONUS=1 : X=310 : Y=182 : N=34 : Sprite Update : Wait Vbl : _AMAL
   '
   ' Place Exit back on screen and fade screen into view. 
   Sprite 24,150,66,85
   Screen Show 0
   Fade 1,$34,$BBB,$340,$5A,$7C,$555,$A60,$951,$632,$422,$51,$61,$72,$92,$A3,$B4,$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 %1100,1
   Sprite 24,150,66,86
   Sprite Off 8
   Update 
   Wait Vbl 
   Wait 30
   ' Fade screen,close it then reset player position. 
   Screen 0 : Fade 2 : Wait 30 : Screen Close 0
   X=310 : Y=182
   '
   ' 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,94
   F$="A 0,(94,5)(95,5)(96,5)(97,5)(98,5)(99,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,92 : Paste Bob 164,10,93
   Fade 1 : Wait 15
   Screen Show 0
   Fade 1,$0,$BBB,$340,$5A,$7C,$555,$A60,$951,$632,$422,$51,$61,$72,$92,$A3,$B4,$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 : Sprite Update : Bob Off : Amal Off : Screen Hide 0
   '
   ' Call the BSETUP procedure. 
   _BSETUP
   ' Alter the player starting coordinates. 
   X=434 : Y=205
   '
   ' 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.
   ' Loop ends when you have collected all of the items 
   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.
      J=Joy(1)
      _EXTRA_LIFE
      If Spritebob Col(8,3 To 3) Then _BDEAD
      If Sprite Col(8,12 To 23) 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<438 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
      '
      ' Checks to see if Henry has hit the bottom of the screen. 
      If Y Sprite(8)>250 Then _BDEAD
      ' Play Crow sfx every time the CROW variable equals 40 then reset it.  
      Inc CROW : If CROW>40 Then Sam Bank 6 : Sam Play %11,3 : CROW=0
      '
      ' 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 
      '
      ' Sets the joystic and check for collisions. 
      J=Joy(1)
      If Spritebob Col(8,3 To 3) Then _BDEAD
      If Sprite Col(8,12 To 23) Then _GET_ITEM
      '
      ' Checks for joystic and if you have hit the bottom. 
      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
      If Y Sprite(8)>250 Then _BDEAD
      '
      ' 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=27
   '
   ' 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 channel for the Bird and its animation. 
   Channel 4 To Bob 3
   Bob 3,-40,10,44
   D$=" A 0,(44,10); M 0,0,10;"
   D$=D$+"Bird:A 0,(44,5)(45,5)(46,5)(47,5)(48,5)(49,5)(50,5)(51,5)(52,5)(53,5); M 390,0,250; M 0,50,30;"
   D$=D$+"A 0,(34,5)(35,5)(36,5)(37,5)(38,5)(39,5)(40,5)(41,5)(42,5)(43,5); M -390,0,250; M 0,50,40;"
   D$=D$+"A 0,(44,5)(45,5)(46,5)(47,5)(48,5)(49,5)(50,5)(51,5)(52,5)(53,5); M 390,0,250; M 0,60,40;"
   D$=D$+"A 0,(34,5)(35,5)(36,5)(37,5)(38,5)(39,5)(40,5)(41,5)(42,5)(43,5); M -390,0,250; M 0,-60,50;"
   D$=D$+"A 0,(44,5)(45,5)(46,5)(47,5)(48,5)(49,5)(50,5)(51,5)(52,5)(53,5); M 390,0,250;M 0,-30,50;"
   D$=D$+"A 0,(34,5)(35,5)(36,5)(37,5)(38,5)(39,5)(40,5)(41,5)(42,5)(43,5); M -390,0,250; M 0,-35,50;"
   D$=D$+"A 0,(44,5)(45,5)(46,5)(47,5)(48,5)(49,5)(50,5)(51,5)(52,5)(53,5); M 390,0,250; M 0,-35,50;"
   D$=D$+"A 0,(34,5)(35,5)(36,5)(37,5)(38,5)(39,5)(40,5)(41,5)(42,5)(43,5); M -390,0,250; Jump Bird"
   Amal 4,D$ : Amal On 4
   '
   ' Set the positions for the items. 
   Sprite 12,148,71,75
   Sprite 13,210,166,78
   Sprite 14,372,165,77
   Sprite 16,145,197,77
   Sprite 17,145,135,79
   Sprite 18,210,231,75
   Sprite 19,370,230,78
   Sprite 20,435,134,84
   Sprite 21,435,70,79
   Sprite 22,210,103,77
   Sprite 23,372,102,78
   '    
   ' 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,87
   ' Set Amal animation.
   Channel 5 To Bob 26
   E$="A 0,(87,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 5,E$ : Amal On 5
   ' 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 
      Inc CROW : If CROW>40 Then Sam Bank 6 : Sam Play %11,3 : CROW=0
      '
      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 5 : X=434 : Y=205 : N=34 : I=2 : Sprite Update : Wait Vbl 
   Screen Swap 1 : Wait Vbl : Bob Clear 
   '
End Proc
