' *******************************************************************
'
'                             PARTICLE MAN 
'
'                         - By Paul Nordovics -
'
' Please note that this was my very first attempt at writing a game
' and so most of the code is fairly simple but it might be helpful 
' to anybody new to coding or for the curious. 
' don't try and run this listing coz it won't work as some files are 
' missing - sorry kidz !!! 
' if you want a working version get Assasins Disk 105
' *******************************************************************
'
' *****************************************  
' Start off by making some variables global
' *****************************************  
' ************ 
' player stuff 
' ************ 
Global _PLAYER_X,_PLAYER_Y,_PLAYER_X_COPY,_PLAYER_Y_COPY
Global _PLAYER_DIRECTION,_PLAYER_FRAME,_PLAYER_FRAME_DELAY
Global _PLAYER_SPEED,_PLAYER_STATE,_PLAYER_COLLECT_DELAY,DIAGONAL
Global ENERGY,LIVES,_MAX_LIVES
'
' ***********
' baddy stuff
' ***********
Dim BADDY_X(4) : Dim BADDY_Y(4) : Dim BADDY_X_COPY(4) : Dim BADDY_Y_COPY(4)
Global BADDY_X(),BADDY_Y(),BADDY_X_COPY(),BADDY_Y_COPY()
Dim BADDY_DIRECTION(4) : Dim BADDY_FRAME(4) : Dim BADDY_FRAME_START(4) : Dim BADDY_STEP(4)
Global BADDY_DIRECTION(),BADDY_FRAME(),BADDY_FRAME_START(),BADDY_SPEED,BADDY_STEP()
Global DROP_DELAY,DROP_DELAY_MAX,DROP_DELAY_PORTAL
'
' ********** 
' bomb stuff 
' ********** 
Dim BOMB_X(5) : Dim BOMB_Y(5) : Dim BOMB_FRAME(5) : Dim BOMB_STATE(5)
Dim BOMB_DECAY(5)
Global BOMB_X(),BOMB_Y(),BOMB_FRAME(),BOMB_FRAME_DELAY,BOMBS_ON
Global BOMB_STATE(),BOMB_DECAY(),BOMB_DECAY_RATE,BOMBS_TO_COLLECT
'
' *********
' map stuff
' *********
Dim MAP(20,13)
Global MAP(),FLOOR_START,WALL_START
FLOOR_START=19 : WALL_START=45
'
' *******************  
' miscellaneous stuff  
' *******************  
Global GAME_CYCLE,LEVEL_COMPLETE
Global LEVEL,LAST_LEVEL,SCORE,DIFFICULTY,_MUSIC,SOUND
'
' ******************************** 
' this string animates the portals 
' ******************************** 
_PORTAL$="A0,(92,1)(93,1)(94,1)(95,1)(96,1)(97,1)(98,1)(99,1)(100,1)(101,1)(102,1)(103,1)"
'
' ***************************************
' this is used to load in default options
' ***************************************
Open Random 2,"mygame:options"
Field 2,2 As D$
R=1
Get 2,R
_MAX_LIVES=Val(D$)
Inc R
Get 2,R
DIFFICULTY=Val(D$)
Inc R
Get 2,R
_MUSIC=Val(D$)
Inc R
Get 2,R
SOUND=Val(D$)
Inc R
Get 2,R
_PLAYER_SPEED=Val(D$)
Inc R
Get 2,R
DIAGONAL=Val(D$)
Inc R
Close 2
If _MUSIC=1
   Music 1
End If 
DROP_DELAY_PORTAL=50
'
' ---------------------------------------------------------------------- 
'
' ************ 
' TITLE SCREEN 
' ************ 
TITLE_SCREEN:
' *********************
' get title page set up
' *********************
Hide 
Unpack 4 To 0
Curs Off : Flash Off 
Screen Display 0,128,45,,
'
' *****************************************
' this cycles colours of PARTICLE MAN title
' *****************************************
Shift Up 4,4,9,1
'
' ************** 
' set up pointer 
' ************** 
_POINTER_Y=122
Bob 0,80,_POINTER_Y,9
'
' ************************** 
' animate pointer using amal 
' ************************** 
Channel 0 To Bob 0
Amal 0,"A0,(9,4)(10,4)(11,4)(12,4)"
Amal On 0
'
' ********************** 
' this moves the pointer 
' ********************** 
Repeat 
   ' ** 
   ' up 
   ' ** 
   If Jup(1) and _POINTER_Y>122
      For A=0 To 19
         Add _POINTER_Y,-1
         Wait Vbl 
         Bob 0,80,_POINTER_Y,
      Next A
   End If 
   ' **** 
   ' down 
   ' **** 
   If Jdown(1) and _POINTER_Y<162
      For A=0 To 19
         Add _POINTER_Y,1
         Wait Vbl 
         Bob 0,80,_POINTER_Y,
      Next A
   End If 
   Bob 0,80,_POINTER_Y,
Until Fire(1)
'
' ******************************************************** 
' fire button was pressed so we must have picked an option 
' ******************************************************** 
' *******
' tidy up
' *******
Shift Off 
Amal Off 0
Fade 5 : Wait 75
Bob Off 0
Screen Close 0
'
' ***********************************************************
' now decide what option was chosen and goto relevant section
' ***********************************************************
' *********
' play game
' *********
If _POINTER_Y=122 Then Goto NEW_GAME
'
' *****************
' read instructions
' *****************
If _POINTER_Y=142 Then Goto _INSTRUCTIONS
'
' ************** 
' change options 
' ************** 
If _POINTER_Y=162 Then Goto OPTIONS
'
' ---------------------------------------------------------------------
'
' ************ 
' INSTRUCTIONS 
' ************ 
_INSTRUCTIONS:
' *************
' set up screen
' *************
Screen Open 0,320,256,16,Lowres
Curs Off : Flash Off : Hide 
'
' ***************
' put colours = 0
' ***************
For A=0 To 15 : Colour A,$0 : Next A
'
Pen 1 : Paper 0
'
' ****************** 
' print instructions 
' ****************** 
Cls 0
Locate 0,0
Centre "INSTRUCTIONS"
Locate 0,2
Print "THE IDEA WITH PARTICLE MAN IS TO"
Print "COLLECT AND DISPOSE OF A NUMBER OF"
Print "BOMBS WHICH ARE PLACED IN THE MAZE AT"
Print "RANDOM BY THE MONSTERS."
Print "THE BOMBS HAVE A LIMITED LIFE AND IF"
Print "LEFT ALONE FOR TOO LONG WILL EXPLODE."
Print "IF THIS HAPPENS, PARTICLE MAN LOSES"
Print "SOME ENERGY AND IF ALL HIS ENERGY IS"
Print "LOST HE LOSES A LIFE. A COLLISION"
Print "WITH ANY OF THE MONSTERS ALSO RESULTS"
Print "IN A LOSS OF LIFE."
Print "AS A WARNING, WHEN A BOMB'S TIMER IS"
Print "BELOW THE HALF-WAY STAGE, IT WILL FLASH."
Print 
Print "TO DISPOSE OF A BOMB PARTICLE MAN FIRST"
Print "NEEDS TO ABSORB IT. IF THE BOMBS ARE"
Print "CLOSE TOGETHER, RUN OVER THE ONE YOU"
Print "WANT AND PRESS FIRE. IF THE BOMBS ARE"
Print "FAR APART HOLD DOWN FIRE AND PARTICLE"
Print "MAN WILL ABSORB THE FIRST BOMB HE"
Print "ENCOUNTERS. THE BOMB WILL STAY ABSORBED"
Print "UNTIL YOU LET GO OF THE FIRE BUTTON."
Print "ONCE PARTICLE MAN HAS ABSORBED A BOMB"
Print "HE CAN DISPOSE OF IT BY SIMPLY RUNNING"
Print "OVER A PORTAL."
Locate 0,31
Centre "PRESS <FIRE>"
'
' ************ 
' fade in text 
' ************ 
Fade 5,-1,%1111111111111110
'
' ********************************** 
' wait for fire button to be pressed 
' ********************************** 
Repeat 
Until Fire(1)
'
' *************  
' fade out text
' *************  
Fade 5 : Wait 75
'
' *********
' next page
' *********
Cls 0
Locate 0,0 : Centre "INSTRUCTIONS"
Locate 0,2
Print "IF A BOMB IS ABSORBED IT'S TIMER IS"
Print "TEMPORARILY DISABLED AND IF RETURNED"
Print "TO THE SCREEN (BY LETTING GO OF FIRE)"
Print "WILL COUNTDOWN FROM THE BEGINING AGAIN."
Print 
Print "TO COMPLETE THE LEVEL YOU MUST DISPOSE"
Print "OF THE AMOUNT OF BOMBS INDICATED ON THE"
Print "STATUS PANEL AT THE BOTTOM OF THE"
Print "SCREEN."
Print 
Print "PARTICLE MAN IS CONTROLLED USING A"
Print "JOYSTICK IN PORT 1 AND YOU CAN ABORT"
Print "A GAME BY PRESSING THE <ESC> KEY."
Print 
Print "YOU'LL NEED 1 MEG FOR THIS GAME TO WORK.";
Print "(SORRY 1/2 MEG OWNERS!)"
Locate 0,31 : Centre "PRESS <FIRE>"
'
' *******
' fade in
' *******
Fade 5,-1,%1111111111111110
'
' ********************************** 
' wait for fire button to be pressed 
' ********************************** 
Repeat 
Until Fire(1)
'
' ******** 
' fade out 
' ******** 
Fade 5 : Wait 75
'
' *********
' next page
' *********
Cls 0
Locate 0,0 : Centre "INSTRUCTIONS"
Locate 0,2
Print "OPTIONS PAGE:"
Print "MOVE THE JOYSTICK UP AND DOWN TO SELECT"
Print "AN OPTION AND PRESS FIRE TO CYCLE"
Print "THROUGH THE SETTINGS."
Print 
Print "LIVES (1-8):"
Print "A LOW SETTING GIVES YOU A HIGHER SCORE."
Print 
Print "DIFFICULTY (EASY-MANIC!):"
Print "CHOOSE 'VERY HARD' OR 'MANIC' IF YOU"
Print "WANT TO PLAY THE WHOLE GAME."
Print 
Print "MUSIC (ON/OFF): OBVIOUS!"
Print 
Print "SOUND (ON/OFF): OBVIOUS!"
Print 
Print "GAME SPEED (SLOW/FAST):"
Print "IF YOU FIND PARTICLE MAN A BIT"
Print "DIFFICULT TO CONTROL, TRY THE SLOWER"
Print "SETTING."
Print 
Print "DIAGONAL MOVEMENT (ON/OFF):"
Print "TURN OFF TO STOP THE JOYSTICK DIAGONALS"
Print "FROM BEING READ."
Locate 0,31 : Centre "PRESS <FIRE>."
'
' *******
' fade in
' *******
Fade 5,-1,%1111111111111110
'
' ********************************** 
' wait for fire button to be pressed 
' ********************************** 
Repeat 
Until Fire(1)
'
' ******** 
' fade out 
' ******** 
Fade 5 : Wait 75
'
' *********
' next page
' *********
Cls 0
Locate 0,0 : Centre "INSTRUCTIONS"
Locate 0,2
Print "SAVE OPTIONS:"
Print "CHOOSE THIS IF YOU WANT YOUR NEW"
Print "SETTINGS SAVED ONTO THE DISC. CAREFUL"
Print "AS THERE IS NO WAY OF GETTING THE"
Print "ORIGINAL SETTINGS BACK."
Print 
Print "EXIT:"
Print "TAKES YOU BACK TO THE TITLE PAGE."
Locate 0,31 : Centre "PRESS <FIRE>."
'
' *******
' fade in
' *******
Fade 5,-1,%1111111111111110
'
' ********************************** 
' wait for fire button to be pressed 
' ********************************** 
Repeat 
Until Fire(1)
'
' ******** 
' fade out 
' ******** 
Fade 5 : Wait 75
'
' *********
' next page
' *********
Cls 0
Locate 0,0 : Centre "INSTRUCTIONS"
Locate 0,2
Centre "THIS GAME WAS WRITTEN AND COMPILED"
Print 
Centre "USING AMOS AND IS PUBLIC DOMAIN."
Print 
Print 
Print 
Print 
Print "IF ANYBODY HAS ANY COMMENTS ON THIS"
Print "GAME OR JUST WANTS TO DROP ME A LINE"
Print "WRITE TO:"
Print 
Print "PAUL NORDOVICS"
Print "4 KATHARINE STREET"
Print "MILLOM"
Print "CUMBRIA LA18 4AQ"
Print 
Print "I AM ALSO LOOKING FOR A DECENT ARTIST"
Print "TO DO SOME GRAPHICS FOR MY NEXT GAME"
Print "SO IF YOU WANT TO HELP PLEASE WRITE."
Print 
Print "IF YOU LIKE THIS GAME AND WOULD LIKE AN"
Print "ENHANCED VERSION CONTAINING MORE LEVELS"
Print "MONSTERS/MAP EDITOR ETC SEND £5 TO THE"
Print "ABOVE ADDRESS."
Print 
Print "HAVE FUN!!!"
Locate 0,31 : Centre "PRESS <FIRE>."
'
' *******
' fade in
' *******
Fade 5,-1,%1111111111111110
'
' ********************************** 
' wait for fire button to be pressed 
' ********************************** 
Repeat 
Until Fire(1)
'
' ******** 
' fade out 
' ******** 
Fade 5 : Wait 75
'
' *******************************  
' set up instructions iff picture  
' *******************************  
Load Iff "mygame:instr.iff",0
Curs Off : Flash Off 
Double Buffer 
Screen Hide 
'
' **************************** 
' set up animations using amal 
' ****************************   
Bob 0,59,44,9
Channel 0 To Bob 0
Amal 0,"A0,(9,5)(10,5)(11,5)(12,5)"
Bob 1,129,34,75
Channel 1 To Bob 1
Amal 1,"A0,(75,5)(76,5)"
Bob 2,132,54,86
Channel 2 To Bob 2
Amal 2,"A0,(86,5)(87,5)"
Bob 3,149,46,81
Channel 3 To Bob 3
Amal 3,"A0,(81,5)(82,5)"
Bob 4,218,50,92
Channel 4 To Bob 4
Amal 4,"A0,(92,3)(93,3)(94,3)(95,3)(96,3)(97,3)(98,3)(99,3)(100,3)(101,3)(102,3)(103,3)"
Bob 5,128,158,63
Channel 5 To Bob 5
Amal 5,"A0,(63,5)(64,5)(65,5)(66,5)"
Bob 6,128,193,59
Channel 6 To Bob 6
Amal 6,"A0,(59,5)(60,5)(61,5)(62,5)"
Bob 7,164,158,67
Channel 7 To Bob 7
Amal 7,"A0,(67,5)(68,5)(69,5)(70,5)"
Bob 8,166,193,71
Channel 8 To Bob 8
Amal 8,"A0,(71,5)(72,5)(73,5)(74,5)"
Amal On 
Wait Vbl 
'
' *****************************
' show instructions iff picture
' *****************************
Screen Show 
'
' ********************************** 
' wait for fire button to be pressed 
' ********************************** 
Repeat 
Until Fire(1)
'
' *******
' tidy up
' *******
For A=0 To 8 : Amal Off A : Next A
'
Fade 5 : Wait 75
'
For A=0 To 8 : Bob Off A : Next A
'
Screen Close 0
'
' ********************************** 
' and bugger off back 2 title screen 
' ********************************** 
Goto TITLE_SCREEN
'
' -------------------------------------------------------------------- 
'
' *******
' OPTIONS
' *******
OPTIONS:
' *************
' set up screen
' *************
Screen Open 0,320,256,2,Lowres
Curs Off : Flash Off : Hide 
Cls 0
Double Buffer : Bob Update On 
Colour 1,$AAA
'
' *******************************
' set initial position of pointer
' *******************************
_POINTER_Y=82
'
' **************************** 
' show current option settings 
' **************************** 
Locate 0,6
Centre "OPTIONS"
Locate 9,10 : Print "LIVES=";_MAX_LIVES
If DIFFICULTY=0
   DIFFICULTY$="EASY"
End If 
If DIFFICULTY=1
   DIFFICULTY$="NORMAL"
End If 
If DIFFICULTY=2
   DIFFICULTY$="HARD"
End If 
If DIFFICULTY=3
   DIFFICULTY$="VERY HARD"
End If 
If DIFFICULTY=4
   DIFFICULTY$="MANIC!"
End If 
Locate 9,12 : Print "DIFFICULTY IS ";DIFFICULTY$
If _MUSIC=0
   _MUSIC$="OFF"
End If 
If _MUSIC=1
   _MUSIC$="ON"
End If 
Locate 9,14 : Print "MUSIC IS ";_MUSIC$
If SOUND=0
   SOUND$="OFF"
End If 
If SOUND=1
   SOUND$="ON"
End If 
Locate 9,16 : Print "SOUND FX ARE ";SOUND$
Locate 9,18
If _PLAYER_SPEED=2
   Print "GAME SPEED IS SLOW"
End If 
If _PLAYER_SPEED=4
   Print "GAME SPEED IS FAST"
End If 
If DIAGONAL=0
   DIAGONAL$="OFF"
End If 
If DIAGONAL=1
   DIAGONAL$="ON"
End If 
Locate 9,20 : Print "DIAGONAL MOVEMENT IS ";DIAGONAL$
Locate 9,22 : Print "SAVE OPTIONS"
Locate 9,24 : Print "EXIT"
'
' ****************** 
' option screen loop 
' ****************** 
Repeat 
   Wait 10
   ' ***************
   ' move pointer up
   ' ***************
   If Jup(1) and _POINTER_Y>82
      Add _POINTER_Y,-16
   End If 
   ' *****************
   ' move pointer down
   ' *****************
   If Jdown(1) and _POINTER_Y<194
      Add _POINTER_Y,16
   End If 
   ' **************************************** 
   ' if fire button is pressed we need to 
   ' change an option or SAVE options or EXIT 
   ' **************************************** 
   If Fire(1)
      ' ************ 
      ' change lives 
      ' ************   
      If _POINTER_Y=82
         Add _MAX_LIVES,1
         If _MAX_LIVES>8
            _MAX_LIVES=1
         End If 
         Locate 9,10 : Print "LIVES=";_MAX_LIVES
      End If 
      ' *****************  
      ' change difficulty  
      ' *****************  
      If _POINTER_Y=98
         Inc DIFFICULTY
         If DIFFICULTY>4
            DIFFICULTY=0
         End If 
         Locate 23,12 : Print "           "
         Locate 9,12
         If DIFFICULTY=0
            DIFFICULTY$="EASY"
         End If 
         If DIFFICULTY=1
            DIFFICULTY$="NORMAL"
         End If 
         If DIFFICULTY=2
            DIFFICULTY$="HARD"
         End If 
         If DIFFICULTY=3
            DIFFICULTY$="VERY HARD"
         End If 
         If DIFFICULTY=4
            DIFFICULTY$="MANIC!"
         End If 
         Print "DIFFICULTY IS ";DIFFICULTY$
      End If 
      ' ********************** 
      ' change music to on/off 
      ' ********************** 
      _DONE=0
      If _POINTER_Y=114
         If _MUSIC=0 and _DONE=0
            _MUSIC=1
            Locate 18,14 : Print "   "
            Locate 9,14 : Print "MUSIC IS ON"
            Music 1
            _DONE=1
         End If 
         If _MUSIC=1 and _DONE=0
            _MUSIC=0
            Locate 18,14 : Print "   "
            Locate 9,14 : Print "MUSIC IS OFF"
            Music Off 
            _DONE=1
         End If 
      End If 
      ' *************************  
      ' change sound fx to on/off
      ' *************************  
      _DONE=0
      If _POINTER_Y=130
         If SOUND=0 and _DONE=0
            SOUND=1
            Locate 22,16 : Print "   "
            Locate 9,16 : Print "SOUND FX ARE ON"
            _DONE=1
         End If 
         If SOUND=1 and _DONE=0
            SOUND=0
            Locate 22,16 : Print "   "
            Locate 9,16 : Print "SOUND FX ARE OFF"
            _DONE=1
         End If 
      End If 
      ' *****************  
      ' change game speed  
      ' *****************  
      If _POINTER_Y=146
         _PLAYER_SPEED=_PLAYER_SPEED*2
         If _PLAYER_SPEED>4
            _PLAYER_SPEED=2
         End If 
         Locate 9,18
         If _PLAYER_SPEED=2
            Print "GAME SPEED IS SLOW"
         End If 
         If _PLAYER_SPEED=4
            Print "GAME SPEED IS FAST"
         End If 
      End If 
      ' ********************************** 
      ' change diagonal movement to on/off 
      ' ********************************** 
      _DONE=0
      If _POINTER_Y=162
         If DIAGONAL=0 and _DONE=0
            DIAGONAL=1
            Locate 30,20 : Print "    "
            Locate 9,20 : Print "DIAGONAL MOVEMENT IS ON"
            _DONE=1
         End If 
         If DIAGONAL=1 and _DONE=0
            DIAGONAL=0
            Locate 30,20 : Print "    "
            Locate 9,20 : Print "DIAGONAL MOVEMENT IS OFF"
            _DONE=1
         End If 
      End If 
      ' ******************** 
      ' save options to disk 
      ' ******************** 
      If _POINTER_Y=178
         Open Random 2,"mygame:options"
         Field 2,2 As D$
         R=1
         D$=Str$(_MAX_LIVES)
         Put 2,R
         Inc R
         D$=Str$(DIFFICULTY)
         Put 2,R
         Inc R
         D$=Str$(_MUSIC)
         Put 2,R
         Inc R
         D$=Str$(SOUND)
         Put 2,R
         Inc R
         D$=Str$(_PLAYER_SPEED)
         Put 2,R
         Inc R
         D$=Str$(DIAGONAL)
         Put 2,R
         Inc R
         Close 2
      End If 
   End If 
   ' ************ 
   ' show pointer 
   ' ************ 
   Bob 0,48,_POINTER_Y,169
Until Fire(1) and _POINTER_Y=194
'
' ***************************************************************  
' comes to here if EXIT option was chosen and fire button pressed  
' ***************************************************************  
' ******** 
' fade out 
' ******** 
Fade 5 : Wait 75
'
' *******
' tidy up
' *******
Screen Close 0
'
' *******************
' back 2 title screen
' *******************
Goto TITLE_SCREEN
'
' ---------------------------------------------------------------------- 
'
' *****************
' PLAY THE GAME !!!
' *****************
NEW_GAME:
' *************************************  
' restore values of some game variables
' *************************************  
LIVES=_MAX_LIVES-1
ENERGY=3
LEVEL=1
SCORE=0
STATUS_SCREEN_ON=0
'
' *********************************************
' work out how many levels we are allowed to do
' depends on which difficulty level was chosen 
' *********************************************
LAST_LEVEL=20
If DIFFICULTY=0
   LAST_LEVEL=5
End If 
If DIFFICULTY=1
   LAST_LEVEL=10
End If 
If DIFFICULTY=2
   LAST_LEVEL=15
End If 
Goto NEW_LEVEL
'
' ---------------------------------------------------------------------- 
'
' ********************************************************************** 
'
'                               MAIN LOOP
'
' ***********************************************************************  
_START_GAME:
Repeat 
   Wait Vbl 
   Bob Clear 
   ' ************** 
   ' player routine 
   ' ************** 
   MOVE_PLAYER
   If GAME_CYCLE=0
      Wait Vbl 
      ' *********************
      ' quit if <Esc> pressed
      ' *********************
      If Key State($45)
         LIVES=-1
      End If 
      ' **************************** 
      ' complete level if F1 pressed 
      ' **************************** 
      If Key State($50)
         LEVEL_COMPLETE=1
      End If 
      ' *************
      ' baddy routine
      ' *************
      MOVE_BADDY
   End If 
   If GAME_CYCLE=1
      Wait Vbl 
      ' ************ 
      ' bomb routine 
      ' ************ 
      BOMB
   End If 
   Bob Draw 
   Add GAME_CYCLE,1,0 To 1
   Screen Swap 
Until LEVEL_COMPLETE=1 or LIVES=-1 or(LIVES<=0 and ENERGY=0)
'
' *******************************************
' we come here when either the game has ended  
' or we have completed the current level 
' *******************************************
' *******************
' level was completed
' *******************
If LEVEL_COMPLETE=1 Then Goto LEVEL_COMPLETE
'
' *********
' game over
' *********
If LIVES<=0 Then Goto GAME_OVER
'
' ------------------------------------------------------------------------ 
'
' *********
' NEW LEVEL
' *********
NEW_LEVEL:
' ******************************** 
' restore values of game variables 
' ******************************** 
' ****** 
' player 
' ****** 
_PLAYER_DIRECTION=8 : _PLAYER_FRAME=9
_PLAYER_STATE=0 : _PLAYER_COLLECT_DELAY=16
'
' ******** 
' monsters 
' ******** 
For A=0 To 3
   BADDY_DIRECTION(A)=1 : BADDY_SPEED=_PLAYER_SPEED/2
   BADDY_STEP(A)=128
Next A
'
' *****
' bombs
' *****
For COUNT=0 To 4 : BOMB_STATE(COUNT)=0 : Next COUNT
BOMBS_ON=0
'
' **** 
' misc 
' **** 
_PORTAL_COUNT=0 : Rem keeps track of how many bases in map 
LEVEL_COMPLETE=0
'
' ************************************ 
' set level information  
' i.e how many bombs need disposing of 
' bomb decay rate etc... 
' ************************************ 
If LEVEL=1
   BOMBS_TO_COLLECT=5
   BOMB_DECAY_RATE=(500-(DIFFICULTY*50))*(4/_PLAYER_SPEED)
   For A=0 To 3
      BADDY_FRAME_START(A)=59
   Next A
End If 
If LEVEL=2
   BOMBS_TO_COLLECT=6
   For A=0 To 3
      BADDY_FRAME_START(A)=63
   Next A
End If 
If LEVEL=3
   BOMBS_TO_COLLECT=7
   For A=0 To 3
      BADDY_FRAME_START(A)=67
   Next A
End If 
If LEVEL=4
   BOMBS_TO_COLLECT=8
   For A=0 To 3
      BADDY_FRAME_START(A)=71
   Next A
End If 
If LEVEL=5
   BOMBS_TO_COLLECT=9
End If 
If LEVEL=6
   BOMBS_TO_COLLECT=5
   BOMB_DECAY_RATE=(480-(DIFFICULTY*50))*(4/_PLAYER_SPEED)
End If 
If LEVEL=7
   BOMBS_TO_COLLECT=6
End If 
If LEVEL=8
   BOMBS_TO_COLLECT=7
End If 
If LEVEL=9
   BOMBS_TO_COLLECT=8
End If 
If LEVEL=10
   BOMBS_TO_COLLECT=9
End If 
If LEVEL=11
   BOMBS_TO_COLLECT=5
   BOMB_DECAY_RATE=(460-(DIFFICULTY*50))*(4/_PLAYER_SPEED)
End If 
If LEVEL=12
   BOMBS_TO_COLLECT=6
End If 
If LEVEL=13
   BOMBS_TO_COLLECT=7
End If 
If LEVEL=14
   BOMBS_TO_COLLECT=8
End If 
If LEVEL=15
   BOMBS_TO_COLLECT=9
End If 
If LEVEL=16
   BOMBS_TO_COLLECT=5
   BOMB_DECAY_RATE=(440-(DIFFICULTY*50))*(4/_PLAYER_SPEED)
End If 
If LEVEL=17
   BOMBS_TO_COLLECT=6
End If 
If LEVEL=18
   BOMBS_TO_COLLECT=7
End If 
If LEVEL=19
   BOMBS_TO_COLLECT=8
End If 
If LEVEL=20
   BOMBS_TO_COLLECT=9
End If 
If LEVEL>4
   For A=0 To 3
      BADDY_FRAME_START(A)=(Rnd(3)*4)+59
   Next A
End If 
'
' **************************************** 
' give monsters the correct starting frame 
' **************************************** 
For A=0 To 3
   BADDY_FRAME(A)=BADDY_FRAME_START(A)
Next A
'
' ************************************************ 
' work out how fast bombs can be dropped into maze 
' ************************************************ 
DROP_DELAY_MAX=DROP_DELAY_PORTAL-((LEVEL*2)-2)
DROP_DELAY=DROP_DELAY_MAX
'
' ***********************************************  
' set up our big screen - where the maze is drawn
' ***********************************************  
Screen Open 0,320,224,16,Lowres
Curs Off : Flash Off : Hide 
Screen Hide 
Screen Display 0,128,45,320,208
'
' ***************
' put colours = 0
' ***************
For A=0 To 15 : Colour A,$0 : Next A
'
Cls 0
'
Bob Update On 
'
' *****************************************  
' Load in map data and player/baddy co-ords  
' *****************************************  
Open Random 1,"mygame:Map_data"
Field 1,4 As D$
R=((LEVEL-1)*270)+1
For D=0 To 12
   For A=0 To 19
      Get 1,R
      MAP(A,D)=Val(D$)
      Inc R
   Next A
Next D
Get 1,R
_PLAYER_X=Val(D$) : _PLAYER_X_COPY=_PLAYER_X
Inc R
Get 1,R
_PLAYER_Y=Val(D$) : _PLAYER_Y_COPY=_PLAYER_Y
Inc R
For A=0 To 3
   Get 1,R
   BADDY_X(A)=Val(D$) : BADDY_X_COPY(A)=BADDY_X(A)
   Inc R
   Get 1,R
   BADDY_Y(A)=Val(D$) : BADDY_Y_COPY(A)=BADDY_Y(A)
   Inc R
Next A
Close 1
'
' ******** 
' draw map 
' ******** 
For D=0 To 12
   For A=0 To 19
      If MAP(A,D)>0
         Paste Bob A*16,D*16,MAP(A,D)+91
      End If 
      ' ************************************** 
      ' if a portal is found we need to assign 
      ' an AMAL channel to it so it animates 
      ' ************************************** 
      If MAP(A,D)=1
         Bob _PORTAL_COUNT,A*16,D*16,MAP(A,D)+91
         Channel _PORTAL_COUNT To Bob _PORTAL_COUNT
         Amal _PORTAL_COUNT,_PORTAL$
         Amal On _PORTAL_COUNT
         Inc _PORTAL_COUNT
      End If 
   Next A
Next D
'
Double Buffer 
'
' *******************
' set up status panel
' *******************
If STATUS_SCREEN_ON=0
   Unpack 2 To 1
   Curs Off : Flash Off 
   Colour 0,$0
   Screen Display 1,128,254,320,48
   STATUS_SCREEN_ON=1
End If 
'
' *****************************  
' put numbers onto status panel  
' *****************************  
STATUS_ENERGY
STATUS_LIVES
STATUS_BOMBS
STATUS_LEVEL
'
' *****************************
' display message - "let's go!"
' *****************************
Bob 20,136,64,163
Bob 21,144,78,164
'
' *****************
' show baddy/player
' *****************
Bob 15,BADDY_X(0),BADDY_Y(0),BADDY_FRAME(0)
Bob 16,BADDY_X(1),BADDY_Y(1),BADDY_FRAME(1)
Bob 17,BADDY_X(2),BADDY_Y(2),BADDY_FRAME(2)
Bob 18,BADDY_X(3),BADDY_Y(3),BADDY_FRAME(3)
Bob 19,_PLAYER_X,_PLAYER_Y,_PLAYER_FRAME
'
' *****************
' show both screens
' *****************
Screen Show 0 : Screen Show 1
'
' ****************** 
' fade in big screen 
' ****************** 
Screen 0
Fade 5 To -1,%1111111111111110
Wait 75
'
' ************************** 
' get rid of "let's go!" bit 
' ************************** 
Bob Off 20 : Bob Off 21
'
Autoback 0 : Bob Update Off 
'
' ******************** 
' go to game main loop 
' ******************** 
Goto _START_GAME
'
' ---------------------------------------------------------------------
'
' ************** 
' LEVEL COMPLETE 
' ************** 
LEVEL_COMPLETE:
' *******************************************
' set up extra screen which is coloured white
' *******************************************
Screen Open 2,320,256,2,Lowres
Curs Off : Flash Off : Hide 
Screen Hide 2
Colour 0,$888
Colour 1,$AAA
Cls 1
'
' ************************************ 
' make the screen flash by switching 
' between maze screen and white screen 
' ************************************ 
For C=0 To 19
   Screen Hide 2
   Screen Show 0
   Wait 2
   Screen Hide 0
   Screen Show 2
   Wait Vbl 
   If SOUND=1
      Sam Raw 3,Start(10)+8212+5940,796,10000
   End If 
Next C
'
' *******************
' remove white screen
' *******************
Screen Close 2
'
' *******
' tidy up
' *******
Screen 0
Screen Show 0
Autoback 2
Bob Update On 
Amal Off 
For A=4 To 14 : Bob Off A : Next A
'
' *****************************
' display message - "well done"
' *****************************  
For A=-40 To 142 Step 4
   Bob 20,A,64,165
   Wait 1
Next A
For A=360 To 136 Step -4
   Bob 21,A,78,166
   Wait 1
Next A
'
Wait 100
'
' ******************** 
' fade out main screen 
' ******************** 
Fade 5 : Wait 75
'
' ************************** 
' remove "well done" message 
' ************************** 
Bob Off 20 : Bob Off 21
'
Screen Close 0
'
' ************************** 
' calls this to add on score 
' ************************** 
STATUS_SCORE
'
' ************************************** 
' have we completed all available levels 
' ************************************** 
If LEVEL=LAST_LEVEL Then Goto FINISHED_GAME
'
' *************************
' if not go onto next level
' *************************
Inc LEVEL
Goto NEW_LEVEL
'
' ---------------------------------------------------------------------- 
'
' *********
' GAME OVER
' *********
GAME_OVER:
' *******
' tidy up
' *******
Screen 0
Screen Swap 
Amal Off 
For C=0 To 19 : Bob Off C : Next C
'
Autoback 1
'
' *****************************
' clear screen using box effect
' *****************************
Wait 50
_BOX_COUNT=0
Repeat 
   Repeat 
      X=Rnd(19) : Y=Rnd(12)
   Until MAP(X,Y)<>-5
   Cls 0,X*16,Y*16 To(X*16)+16,(Y*16)+16
   MAP(X,Y)=-5
   Inc _BOX_COUNT
Until _BOX_COUNT=260
'
Wait 50
'
' ************************ 
' show message "game over" 
' ************************ 
Bob 20,138,64,167
Bob 21,138,78,168
'
Wait 150
'
' **************************** 
' fade out "game over" message 
' **************************** 
Fade 5 : Wait 75
'
' *******
' tidy up
' *******
Screen Close 0
Screen 1
Fade 5 : Wait 75
Screen Close 1
'
' *******************
' back 2 title screen
' *******************
Goto TITLE_SCREEN
'
' -------------------------------------------------------------------
'
' *************
' FINISHED GAME
' *************
FINISHED_GAME:
Wait 50
' *************
' set up screen
' *************
Screen Open 0,320,200,16,Lowres
Curs Off : Flash Off 
'
' **************** 
' put colours to 0 
' **************** 
For C=0 To 15 : Colour C,$0 : Next C
'
Cls 0 : Paper 0 : Pen 1
'
' *********************************************
' print message depending on how far player got
' *********************************************
If LAST_LEVEL<20
   Locate 0,4 : Centre "-WELL DONE!- "
   Locate 0,5 : Centre "NOW IF YOU WANT TO SEE ANY"
   Locate 0,6 : Centre "MORE OF THIS GAME USE A HIGHER"
   Locate 0,7 : Centre "DIFFICULTY SETTING"
End If 
If LAST_LEVEL=20
   Locate 0,4 : Centre "-CONGRATULATIONS!!!-"
   Locate 0,5 : Centre "YOU HAVE COMPLETED PARTICLE MAN"
   Locate 0,6 : Centre "IF YOU ENJOYED THIS GAME"
   Locate 0,7 : Centre "WHY NOT SEND OFF FOR THE"
   Locate 0,8 : Centre "ENHANCED VERSION"
   Locate 0,9 : Centre "WHICH HAS NEW LEVELS"
   Locate 0,10 : Centre "AND MORE MAZE MONSTERS."
End If 
'
' ***************
' fade in message
' ***************
Fade 5 To -1,%1111111111111110
'
' *************
' wait for fire
' *************
Repeat 
Until Fire(1)
'
' *********************  
' fade out both screens
' *********************  
Fade 5 : Wait 75
Screen Close 0
Screen 1
Fade 5 : Wait 75
Screen Close 1
'
' ************************ 
' and back to title screen 
' ************************ 
Goto TITLE_SCREEN
'
' -------------------------------------------------------------
'
Procedure MOVE_PLAYER
   If _PLAYER_STATE<2
      ' ************** 
      ' reads joystick 
      ' ************** 
      ' ** 
      ' up 
      ' ** 
      If(Joy(1)=1 or Joy(1)=17) and MAP(Int(_PLAYER_X/16),Int((_PLAYER_Y-1)/16))<WALL_START and MAP(Int(_PLAYER_X+15)/16,Int((_PLAYER_Y-1)/16))<WALL_START
         _PLAYER_DIRECTION=0
      End If 
      ' *****
      ' right
      ' *****
      If(Joy(1)=8 or Joy(1)=24) and MAP(Int(_PLAYER_X+16)/16,Int(_PLAYER_Y/16))<WALL_START and MAP(Int(_PLAYER_X+16)/16,Int((_PLAYER_Y+15)/16))<WALL_START
         _PLAYER_DIRECTION=2
      End If 
      ' **** 
      ' down 
      ' **** 
      If(Joy(1)=2 or Joy(1)=18) and MAP(Int(_PLAYER_X/16),Int((_PLAYER_Y+16)/16))<WALL_START and MAP(Int(_PLAYER_X+15)/16,Int((_PLAYER_Y+16)/16))<WALL_START
         _PLAYER_DIRECTION=4
      End If 
      ' **** 
      ' left 
      ' **** 
      If(Joy(1)=4 or Joy(1)=20) and MAP(Int(_PLAYER_X-1)/16,Int((_PLAYER_Y)/16))<WALL_START and MAP(Int(_PLAYER_X-1)/16,Int((_PLAYER_Y+15)/16))<WALL_START
         _PLAYER_DIRECTION=6
      End If 
      ' *****************************************
      ' checks diagonal movement if option chosen
      ' *****************************************
      If DIAGONAL=1
         ' ******** 
         ' up-right 
         ' ******** 
         If(Joy(1)=9 or Joy(1)=25)
            _PLAYER_DIRECTION=1
         End If 
         ' *********
         ' down-right 
         ' *********
         If(Joy(1)=10 or Joy(1)=26)
            _PLAYER_DIRECTION=3
         End If 
         ' *********
         ' down-left
         ' *********
         If(Joy(1)=6 or Joy(1)=22)
            _PLAYER_DIRECTION=5
         End If 
         ' *******
         ' up-left
         ' *******
         If(Joy(1)=5 or Joy(1)=21)
            _PLAYER_DIRECTION=7
         End If 
         ' ********************************** 
         ' if joystick not moved we try and 
         ' change direction to a non-diagonal 
         ' ********************************** 
         If(Joy(1)=0 or Joy(1)=16)
            ' ** 
            ' up 
            ' ** 
            If(_PLAYER_DIRECTION=1 or _PLAYER_DIRECTION=7) and MAP(Int(_PLAYER_X)/16,Int((_PLAYER_Y-1)/16))<WALL_START and MAP(Int(_PLAYER_X+15)/16,Int((_PLAYER_Y-1)/16))<WALL_START
               _PLAYER_DIRECTION=0
            End If 
            ' **** 
            ' down 
            ' **** 
            If(_PLAYER_DIRECTION=3 or _PLAYER_DIRECTION=5) and MAP(Int(_PLAYER_X)/16,Int((_PLAYER_Y+16)/16))<WALL_START and MAP(Int(_PLAYER_X+15)/16,Int((_PLAYER_Y+16)/16))<WALL_START
               _PLAYER_DIRECTION=4
            End If 
            ' *****  
            ' right  
            ' *****
            If(_PLAYER_DIRECTION=1 or _PLAYER_DIRECTION=3) and MAP(Int(_PLAYER_X+16)/16,Int(_PLAYER_Y/16))<WALL_START and MAP(Int(_PLAYER_X+16)/16,Int((_PLAYER_Y+15)/16))<WALL_START
               _PLAYER_DIRECTION=2
            End If 
            ' **** 
            ' left   
            ' **** 
            If(_PLAYER_DIRECTION=5 or _PLAYER_DIRECTION=7) and MAP(Int(_PLAYER_X-1)/16,Int((_PLAYER_Y)/16))<WALL_START and MAP(Int(_PLAYER_X-1)/16,Int((_PLAYER_Y+15)/16))<WALL_START
               _PLAYER_DIRECTION=6
            End If 
         End If 
      End If 
      ' *******************************************  
      ' test for arrow squares before moving player
      ' if player has crossed an arrow square
      ' direction is changed to opposite of arrow
      ' *******************************************  
      ' ******** 
      ' up-arrow 
      ' ******** 
      If MAP(Int((_PLAYER_X+7)/16),Int((_PLAYER_Y+7)/16))=13
         _PLAYER_DIRECTION=0
      End If 
      ' ***********
      ' right-arrow
      ' ***********
      If MAP(Int((_PLAYER_X+7)/16),Int((_PLAYER_Y+7)/16))=14
         _PLAYER_DIRECTION=2
      End If 
      ' ********** 
      ' down-arrow 
      ' ********** 
      If MAP(Int((_PLAYER_X+7)/16),Int((_PLAYER_Y+7)/16))=15
         _PLAYER_DIRECTION=4
      End If 
      ' ********** 
      ' left-arrow 
      ' ********** 
      If MAP(Int((_PLAYER_X+7)/16),Int((_PLAYER_Y+7)/16))=16
         _PLAYER_DIRECTION=6
      End If 
      ' ***********  
      ' move player  
      ' ***********  
      ' ** 
      ' up 
      ' ** 
      If _PLAYER_DIRECTION=0 or _PLAYER_DIRECTION=1 or _PLAYER_DIRECTION=7
         ' ************** 
         ' animate player 
         ' ************** 
         ' ***********
         ' normal mode
         ' ***********
         If _PLAYER_STATE=0 and _PLAYER_DIRECTION=0 and _PLAYER_FRAME_DELAY=0
            Add _PLAYER_FRAME,1,13 To 16
         End If 
         ' ***********
         ' absorb mode
         ' ***********
         If _PLAYER_STATE=1 and _PLAYER_DIRECTION=0 and _PLAYER_FRAME_DELAY=0
            Add _PLAYER_FRAME,1,34 To 37
         End If 
         ' ***********
         ' move player
         ' ***********
         Add _PLAYER_Y,-_PLAYER_SPEED
         ' *************
         ' test for wall
         ' *************
         If MAP(Int(_PLAYER_X/16),Int(_PLAYER_Y/16))>=WALL_START or MAP(Int(_PLAYER_X+15)/16,Int(_PLAYER_Y/16))>=WALL_START
            Add _PLAYER_Y,_PLAYER_SPEED
         End If 
      End If 
      ' **** 
      ' down 
      ' **** 
      If _PLAYER_DIRECTION=4 or _PLAYER_DIRECTION=3 or _PLAYER_DIRECTION=5
         ' ************** 
         ' animate player 
         ' ************** 
         ' ***********
         ' normal mode  
         ' ***********
         If _PLAYER_STATE=0 and _PLAYER_DIRECTION=4 and _PLAYER_FRAME_DELAY=0
            Add _PLAYER_FRAME,1,9 To 12
         End If 
         ' ***********
         ' absorb mode
         ' ***********
         If _PLAYER_STATE=1 and _PLAYER_DIRECTION=4 and _PLAYER_FRAME_DELAY=0
            Add _PLAYER_FRAME,1,30 To 33
         End If 
         ' ***********
         ' move player
         ' ***********
         Add _PLAYER_Y,_PLAYER_SPEED
         ' *************
         ' test for wall
         ' *************
         If MAP(Int(_PLAYER_X/16),Int((_PLAYER_Y+15)/16))>=WALL_START or MAP(Int(_PLAYER_X+15)/16,Int((_PLAYER_Y+15)/16))>=WALL_START
            Add _PLAYER_Y,-_PLAYER_SPEED
         End If 
      End If 
      ' *****
      ' right
      ' *****
      If _PLAYER_DIRECTION=2 or _PLAYER_DIRECTION=1 or _PLAYER_DIRECTION=3
         ' ************** 
         ' animate player 
         ' ************** 
         ' ***********
         ' normal mode
         ' ***********
         If _PLAYER_STATE=0 and _PLAYER_FRAME_DELAY=0
            Add _PLAYER_FRAME,1,1 To 4
         End If 
         ' ***********
         ' absorb mode
         ' ***********
         If _PLAYER_STATE=1 and _PLAYER_FRAME_DELAY=0
            Add _PLAYER_FRAME,1,22 To 25
         End If 
         ' ***********
         ' move player
         ' ***********
         Add _PLAYER_X,_PLAYER_SPEED
         ' *************
         ' test for wall
         ' *************
         If MAP(Int(_PLAYER_X+15)/16,Int(_PLAYER_Y/16))>=WALL_START or MAP(Int(_PLAYER_X+15)/16,Int((_PLAYER_Y+15)/16))>=WALL_START
            Add _PLAYER_X,-_PLAYER_SPEED
         End If 
      End If 
      ' **** 
      ' left 
      ' **** 
      If _PLAYER_DIRECTION=6 or _PLAYER_DIRECTION=5 or _PLAYER_DIRECTION=7
         ' ************** 
         ' animate player 
         ' ************** 
         ' ***********
         ' normal mode  
         ' ***********
         If _PLAYER_STATE=0 and _PLAYER_FRAME_DELAY=0
            Add _PLAYER_FRAME,1,5 To 8
         End If 
         ' ***********
         ' absorb mode
         ' ***********
         If _PLAYER_STATE=1 and _PLAYER_FRAME_DELAY=0
            Add _PLAYER_FRAME,1,26 To 29
         End If 
         ' ***********
         ' move player
         ' ***********
         Add _PLAYER_X,-_PLAYER_SPEED
         ' *************
         ' test for wall
         ' *************
         If MAP(Int(_PLAYER_X)/16,Int(_PLAYER_Y/16))>=WALL_START or MAP(Int(_PLAYER_X/16),Int((_PLAYER_Y+15)/16))>=WALL_START
            Add _PLAYER_X,_PLAYER_SPEED
         End If 
      End If 
      Add _PLAYER_FRAME_DELAY,1,0 To 1
      ' ************************************ 
      ' has player collided with a monster ? 
      ' ************************************ 
      If Bob Col(19,15 To 18)
         ' *****************************************  
         ' yes we have collided 
         ' so if we are holding a bomb get rid of it  
         ' *****************************************  
         If _PLAYER_STATE=1
            ' ********************************** 
            ' find out which bomb we are holding 
            ' ********************************** 
            For COUNT=0 To 4
               ' ****************************** 
               ' this is the one we are holding 
               ' ****************************** 
               If BOMB_STATE(COUNT)=3
                  ' ******************** 
                  ' make it non-existant 
                  ' ******************** 
                  BOMB_STATE(COUNT)=0
               End If 
            Next COUNT
            ' ****************************** 
            ' reduce number of bombs in maze 
            ' ****************************** 
            Dec BOMBS_ON
         End If 
         ' ************************ 
         ' set player mode to dying 
         ' ************************ 
         _PLAYER_STATE=2
         ' *********************
         ' and get correct frame
         ' *********************
         _PLAYER_FRAME=43
         ' *******************************
         ' aaaarrrrrrgggggghhhhhh!!!!!!!!!
         ' *******************************
         If SOUND=1
            Sam Raw 3,Start(10)+8212,5940,10000
         End If 
      End If 
      ' *************************************
      ' has player dropped bomb down portal ?
      ' *************************************
      If MAP(Int((_PLAYER_X+7)/16),Int((_PLAYER_Y+7)/16))=1 and _PLAYER_STATE=1
         ' ***********************************  
         ' yes so find the bomb we are holding  
         ' ***********************************  
         For COUNT=0 To 4
            ' ****************************** 
            ' this is the one we are holding 
            ' ****************************** 
            If BOMB_STATE(COUNT)=3
               ' ******************************** 
               ' so change it's state to indicate 
               ' it is dropping down portal 
               ' ******************************** 
               BOMB_STATE(COUNT)=4
               ' ****************************** 
               ' and get correct starting frame 
               ' ****************************** 
               BOMB_FRAME(COUNT)=88
               ' *****************************
               ' align bomb relative to portal
               ' *****************************
               BOMB_X(COUNT)=(Int(_PLAYER_X+7)/16)*16
               BOMB_Y(COUNT)=(Int(_PLAYER_Y+7)/16)*16
            End If 
         Next COUNT
         ' ******************************** 
         ' change player back 2 normal mode 
         ' ******************************** 
         _PLAYER_STATE=0
         ' ***************************************************
         ' noise to indicate bomb has been dropped into portal
         ' ***************************************************
         If SOUND=1
            Sam Raw 3,Start(10)+8212+5940,796,10000
         End If 
         ' *****************************************************
         ' reduce bombs needed to dispose of and show new amount
         ' *****************************************************
         Dec BOMBS_TO_COLLECT
         STATUS_BOMBS
      End If 
      ' *******************************************************  
      ' has player dropped bomb somewhere other than a portal ?
      ' *******************************************************  
      If _PLAYER_STATE=1 and(MAP(Int((_PLAYER_X+7)/16),Int((_PLAYER_Y+7)/16))>=FLOOR_START or MAP(Int((_PLAYER_X+7)/16),Int((_PLAYER_Y+7)/16))=0) and MAP(Int((_PLAYER_X+7)/16),Int((_PLAYER_Y+7)/16))<WALL_START and Not Fire(1)
         ' ********************************** 
         ' yes so find which bomb was dropped 
         ' ********************************** 
         For COUNT=0 To 4
            ' ********************************** 
            ' this is the one i.e bomb state = 3 
            ' ********************************** 
            If BOMB_STATE(COUNT)=3
               ' ********************** 
               ' align bomb within maze 
               ' ********************** 
               BOMB_X(COUNT)=(Int((_PLAYER_X+7))/16)*16
               BOMB_Y(COUNT)=(Int((_PLAYER_Y+7))/16)*16
               ' ************************************************** 
               ' update maze map so we know there is a bomb in this 
               ' part of maze 
               ' ************************************************** 
               MAP(Int(_PLAYER_X+7)/16,Int(_PLAYER_Y+7)/16)=-1
               ' ****************************** 
               ' put bomb state into decay mode 
               ' ****************************** 
               BOMB_STATE(COUNT)=1
               ' ******************** 
               ' restore bomb's timer 
               ' ******************** 
               BOMB_DECAY(COUNT)=BOMB_DECAY_RATE
               ' **************************** 
               ' return player to normal mode 
               ' **************************** 
               _PLAYER_STATE=0
            End If 
         Next COUNT
      End If 
   End If 
   ' *****************
   ' is player dying ?
   ' *****************
   If _PLAYER_STATE=2
      ' ************************ 
      ' does the dying animation 
      ' ************************ 
      If _PLAYER_FRAME_DELAY=0
         Add _PLAYER_FRAME,1
         Wait Vbl 
      End If 
      Add _PLAYER_FRAME_DELAY,1,0 To 4
      '
      ' *******************************************  
      ' come here when dying animation has finished
      ' *******************************************
      If _PLAYER_FRAME>50
         If LIVES>0
            Wait 50
            ' *************
            ' fade out maze
            ' *************
            Fade 5
            Wait 75
            ' *************************
            ' remove all bobs from maze
            ' *************************
            For A=4 To 14 : Bob Off A : Next A
            Screen Swap 
            Wait Vbl 
            For A=4 To 14 : Bob Off A : Next A
            Screen Swap 
            ' ******************** 
            ' restore player stuff 
            ' ******************** 
            _PLAYER_STATE=0
            _PLAYER_DIRECTION=8
            _PLAYER_X=_PLAYER_X_COPY
            _PLAYER_Y=_PLAYER_Y_COPY
            _PLAYER_FRAME=9
            ' *******************
            ' restore baddy stuff
            ' *******************
            For A=0 To 3
               BADDY_X(A)=BADDY_X_COPY(A)
               BADDY_Y(A)=BADDY_Y_COPY(A)
            Next A
            ' ****************************************** 
            ' remove bombs and clear map where they were 
            ' ****************************************** 
            For A=0 To 4
               BOMB_STATE(A)=0
               If MAP(Int(BOMB_X(A))/16,Int(BOMB_Y(A))/16)<>1 and MAP(Int(BOMB_X(A))/16,Int(BOMB_Y(A))/16)<WALL_START
                  MAP(Int(BOMB_X(A))/16,Int(BOMB_Y(A))/16)=0
               End If 
            Next A
            ' ************************ 
            ' no bombs are now in maze 
            ' ************************ 
            BOMBS_ON=0
            ' *******************************
            ' restore timer that decides when  
            ' to allow monster to drop bomb
            ' *******************************
            DROP_DELAY=DROP_DELAY_MAX
            Wait 10
         End If 
         ' *********************************
         ' reduce lives and print new amount
         ' *********************************
         Dec LIVES
         STATUS_LIVES
         ' ********************************** 
         ' reduce energy and print new amount 
         ' ********************************** 
         ENERGY=3
         STATUS_ENERGY
         ' ****************************************** 
         ' if we are still alive have another attempt 
         ' ****************************************** 
         If LIVES>-1
            Wait 50
            Bob Clear 
            ' ************************** 
            ' put baddies back into maze 
            ' ************************** 
            For A=0 To 3
               Bob A+15,BADDY_X(A),BADDY_Y(A),BADDY_FRAME(A)
            Next A
            ' *************************
            ' put player back into maze
            ' *************************
            Bob 19,_PLAYER_X,_PLAYER_Y,_PLAYER_FRAME
            ' ********************** 
            ' show message "lets go" 
            ' ********************** 
            Bob 20,136,64,163
            Bob 21,144,78,164
            Bob Draw 
            Screen Swap 
            Wait Vbl 
            ' *******************
            ' fade in maze screen
            ' *******************
            Fade 5 To -1,%1111111111111110
            Wait 100
            ' ************************ 
            ' remove message "lets go" 
            ' ************************ 
            Bob Off 20 : Bob Off 21
            '
            _PORTAL_COUNT=0
         End If 
      End If 
   End If 
   Bob 19,_PLAYER_X,_PLAYER_Y,_PLAYER_FRAME
End Proc
Procedure MOVE_BADDY
   For COUNT=0 To 3
      ' ** 
      ' up 
      ' ** 
      If BADDY_DIRECTION(COUNT)=0
         Add BADDY_Y(COUNT),-BADDY_SPEED
         ' ****************************************** 
         ' reduce baddy steps 
         ' when = 0 baddy will choose a new direction 
         ' ****************************************** 
         Dec BADDY_STEP(COUNT)
         ' *************************
         ' see if baddy has hit wall
         ' *************************
         If MAP(Int(BADDY_X(COUNT)/16),Int(BADDY_Y(COUNT)/16))>=WALL_START or MAP(Int(BADDY_X(COUNT)+15)/16,Int(BADDY_Y(COUNT)/16))>=WALL_START
            ' ***********************************************************
            ' if yes we reduce its steps to 0 and it gets a new direction
            ' ***********************************************************
            Add BADDY_Y(COUNT),BADDY_SPEED
            BADDY_STEP(COUNT)=0
         End If 
      End If 
      ' *****
      ' right
      ' *****
      If BADDY_DIRECTION(COUNT)=1
         Add BADDY_X(COUNT),BADDY_SPEED
         ' ****************************************** 
         ' reduce baddy steps 
         ' when = 0 baddy will choose a new direction 
         ' ****************************************** 
         Dec BADDY_STEP(COUNT)
         ' *************************
         ' see if baddy has hit wall
         ' *************************
         If MAP(Int(BADDY_X(COUNT)+15)/16,Int(BADDY_Y(COUNT)/16))>=WALL_START or MAP(Int(BADDY_X(COUNT)+15)/16,Int((BADDY_Y(COUNT)+15)/16))>=WALL_START
            ' ***********************************************************
            ' if yes we reduce its steps to 0 and it gets a new direction
            ' ***********************************************************
            Add BADDY_X(COUNT),-BADDY_SPEED
            BADDY_STEP(COUNT)=0
         End If 
      End If 
      ' **** 
      ' down 
      ' **** 
      If BADDY_DIRECTION(COUNT)=2
         Add BADDY_Y(COUNT),BADDY_SPEED
         ' ****************************************** 
         ' reduce baddy steps 
         ' when = 0 baddy will choose a new direction 
         ' ****************************************** 
         Dec BADDY_STEP(COUNT)
         ' *************************
         ' see if baddy has hit wall
         ' *************************
         If MAP(Int(BADDY_X(COUNT)/16),Int((BADDY_Y(COUNT)+15)/16))>=WALL_START or MAP(Int(BADDY_X(COUNT)+15)/16,Int((BADDY_Y(COUNT)+15)/16))>=WALL_START
            ' ***********************************************************
            ' if yes we reduce its steps to 0 and it gets a new direction
            ' ***********************************************************
            Add BADDY_Y(COUNT),-BADDY_SPEED
            BADDY_STEP(COUNT)=0
         End If 
      End If 
      ' **** 
      ' left 
      ' **** 
      If BADDY_DIRECTION(COUNT)=3
         Add BADDY_X(COUNT),-BADDY_SPEED
         ' ****************************************** 
         ' reduce baddy steps 
         ' when = 0 baddy will choose a new direction 
         ' ****************************************** 
         Dec BADDY_STEP(COUNT)
         ' *************************
         ' see if baddy has hit wall
         ' *************************
         If MAP(Int(BADDY_X(COUNT))/16,Int((BADDY_Y(COUNT)/16)))>=WALL_START or MAP(Int(BADDY_X(COUNT)/16),Int((BADDY_Y(COUNT)+15)/16))>=WALL_START
            ' ***********************************************************
            ' if yes we reduce its steps to 0 and it gets a new direction
            ' ***********************************************************
            Add BADDY_X(COUNT),BADDY_SPEED
            BADDY_STEP(COUNT)=0
         End If 
      End If 
      '
      ' ***************
      ' animate monster
      ' ***************
      Add BADDY_FRAME(COUNT),1,BADDY_FRAME_START(COUNT) To BADDY_FRAME_START(COUNT)+3
      '
      ' ***********************************************************
      ' get a new direction for monster if its "steps" have run out  
      ' ***********************************************************
      If BADDY_STEP(COUNT)=0
         BADDY_DIRECTION(COUNT)=Rnd(3)
         BADDY_STEP(COUNT)=(Rnd(3)+1)*16
      End If 
      '
      ' *******************************************************
      ' reduce timer that determines when monster can drop bomb
      ' *******************************************************
      Dec DROP_DELAY
      '
      ' *********************************
      ' is monster allowed to drop bomb ?
      ' *********************************
      If DROP_DELAY<=0 and BOMBS_ON<5 and((MAP(Int(BADDY_X(COUNT)/16),Int(BADDY_Y(COUNT)/16))=0 or MAP(Int(BADDY_X(COUNT)/16),Int(BADDY_Y(COUNT)/16))>=FLOOR_START) and MAP(Int(BADDY_X(COUNT)/16),Int(BADDY_Y(COUNT)/16))<WALL_START)
         If Rnd(3)=2
            ' ***************************  
            ' yes so put a bomb into maze  
            ' ***************************  
            CHOSEN=0
            ' ************************************** 
            ' find a bomb that isn't already in maze 
            ' state = 0
            ' ************************************** 
            For C=0 To 4
               ' ***********************************
               ' can use this one i.e bomb state = 0
               ' ***********************************
               If BOMB_STATE(C)=0 and CHOSEN=0
                  ' ***********************************************
                  ' change bomb state to indicate it is now in maze
                  ' ***********************************************
                  BOMB_STATE(C)=1
                  ' **************************************************** 
                  ' give bomb co-ords which are taken from baddy co-ords 
                  ' **************************************************** 
                  BOMB_X(C)=Int(BADDY_X(COUNT)/16)*16
                  BOMB_Y(C)=Int(BADDY_Y(COUNT)/16)*16
                  ' **************** 
                  ' set bomb's timer 
                  ' **************** 
                  BOMB_DECAY(C)=BOMB_DECAY_RATE
                  ' ***********************************************
                  ' update maze map so we know there is a bomb here
                  ' ***********************************************
                  MAP(Int(BADDY_X(COUNT)/16),Int(BADDY_Y(COUNT)/16))=-1
                  ' *************************************************
                  ' set this to 1 so we don't drop more than one bomb
                  ' *************************************************
                  CHOSEN=1
               End If 
            Next C
            ' ****************************************** 
            ' increase "number of bombs in maze" counter 
            ' ****************************************** 
            Inc BOMBS_ON
            ' **************************************************************** 
            ' restore timer that controls how fast bombs can be placed in maze 
            ' **************************************************************** 
            DROP_DELAY=DROP_DELAY_MAX
         End If 
      End If 
      ' ************************ 
      ' draw monster onto screen 
      ' ************************ 
      Bob 15+COUNT,BADDY_X(COUNT),BADDY_Y(COUNT),BADDY_FRAME(COUNT)
   Next COUNT
End Proc
Procedure BOMB
   For COUNT=0 To 4
      ' ************************************************************ 
      ' reduce bomb timer if it is in maze and has not been absorbed 
      ' ************************************************************ 
      If BOMB_STATE(COUNT)>0 and BOMB_STATE(COUNT)<3
         Dec BOMB_DECAY(COUNT)
         ' ***********************************************
         ' deals with bombs before they start to flash
         ' works out how far the timer has been reduced by
         ' and selects appropriate frame
         ' ***********************************************
         If BOMB_DECAY(COUNT)>BOMB_DECAY_RATE*0.5
            BOMB_STATE(COUNT)=1
            If BOMB_DECAY(COUNT)>=BOMB_DECAY_RATE*0.8
               Add BOMB_FRAME(COUNT),1,75 To 76
            End If 
            If BOMB_DECAY(COUNT)>=BOMB_DECAY_RATE*0.7 and BOMB_DECAY(COUNT)<BOMB_DECAY_RATE*0.8
               Add BOMB_FRAME(COUNT),1,81 To 82
            End If 
            If BOMB_DECAY(COUNT)>=BOMB_DECAY_RATE*0.5 and BOMB_DECAY(COUNT)<BOMB_DECAY_RATE*0.7
               Add BOMB_FRAME(COUNT),1,85 To 86
            End If 
         End If 
         ' ***************************************
         ' make bomb flash as its timer is =< half  
         ' ***************************************
         If BOMB_DECAY(COUNT)=<BOMB_DECAY_RATE*0.5
            BOMB_STATE(COUNT)=2
            Add BOMB_FRAME(COUNT),1,86 To 87
         End If 
         ' ***************************************
         ' timer has run out so blow the bugger up
         ' ***************************************
         If BOMB_DECAY(COUNT)=0
            ' *********************
            ' bomb no longer exists
            ' *********************
            BOMB_STATE(COUNT)=0
            ' ************************ 
            ' clear map where bomb was 
            ' ************************ 
            MAP(Int(BOMB_X(COUNT)/16),Int(BOMB_Y(COUNT)/16))=0
            ' *************************
            ' one less bomb in maze now
            ' *************************
            Dec BOMBS_ON
            ' ********************** 
            ' boooooommmmmmm!!!!!!!! 
            ' ********************** 
            If SOUND=1
               Sam Raw 3,Start(10),8000,10000
            End If 
            ' ********************** 
            ' this shakes the screen 
            ' ********************** 
            For NUMBER_OF_SHAKES=0 To 19
               For A=128 To 32 Step -16
                  Screen Display 0,A,45,,
               Next A
               For A=100 To 224 Step 16
                  Screen Display 0,A,45,,
               Next A
            Next NUMBER_OF_SHAKES
            ' ********************************** 
            ' put screen back to normal position 
            ' ********************************** 
            Screen Display 0,128,45,,
            ' ************************************ 
            ' lose some energy and show new amount 
            ' ************************************ 
            Dec ENERGY
            STATUS_ENERGY
         End If 
         ' *******************************************************  
         ' has player collided with bomb and pressed fire button ?  
         ' i.e can we absorb bomb ? 
         ' *******************************************************  
         If Bob Col(19,4+COUNT To 4+COUNT) and _PLAYER_STATE=0 and Fire(1) and Abs(_PLAYER_X-BOMB_X(COUNT))<7 and Abs(_PLAYER_Y-BOMB_Y(COUNT))<7
            ' ***
            ' yes
            ' ***
            ' ***************************************************
            ' clear map where bomb was as we have now absorbed it
            ' ***************************************************
            MAP(Int(BOMB_X(COUNT)/16),Int(BOMB_Y(COUNT)/16))=0
            ' ********************************** 
            ' change player state to absorb mode 
            ' ********************************** 
            _PLAYER_STATE=1
            ' ********************************** 
            ' change bomb state to absorbed mode 
            ' ********************************** 
            BOMB_STATE(COUNT)=3
            ' ************ 
            ' make a noise 
            ' ************ 
            If SOUND=1
               Sam Raw 3,Start(9),7600,40000
            End If 
         End If 
      End If 
      ' ***************
      ' down the portal
      ' ***************
      If BOMB_STATE(COUNT)=4
         If BOMB_FRAME_DELAY=0
            Add BOMB_FRAME(COUNT),1
         End If 
         Add BOMB_FRAME_DELAY,1,0 To 4
         ' ***********************************************************
         ' bomb has completed drop down portal so it now doesn't exist
         ' ***********************************************************
         If BOMB_FRAME(COUNT)=92
            BOMB_STATE(COUNT)=0
            ' *********************
            ' one less bomb in maze
            ' *********************
            Dec BOMBS_ON
            DROP_DELAY=DROP_DELAY_MAX
         End If 
      End If 
      ' *************************************************  
      ' print bomb if it exists and has not been absorbed
      ' *************************************************
      If BOMB_STATE(COUNT)>0 and BOMB_STATE(COUNT)<>3
         Bob 4+COUNT,BOMB_X(COUNT),BOMB_Y(COUNT),BOMB_FRAME(COUNT)
      Else 
         ' *******************************************************************************************************************
         ' if it doesn't exist we print it to the bottom part of screen which is not visible-this will keep speed of game same
         ' *******************************************************************************************************************
         Bob 4+COUNT,COUNT*16,209,BOMB_FRAME(COUNT)
      End If 
   Next COUNT
End Proc
Procedure STATUS_LIVES
   ' *********************
   ' print to panel screen
   ' ********************** 
   Screen 1
   If LIVES>9
      Paste Bob 75,16,151+Int(LIVES/10)
      Paste Bob 85,16,151+(LIVES-Int((LIVES/10)*10))
   End If 
   If LIVES<10 and LIVES>-1
      Paste Bob 75,16,151
      Paste Bob 85,16,151+LIVES
   End If 
   ' *******************************
   ' send output back to main screen
   ' *******************************
   Screen 0
End Proc
Procedure STATUS_BOMBS
   ' *********************
   ' print to panel screen
   ' *********************
   Screen 1
   If BOMBS_TO_COLLECT>9
      Paste Bob 209,16,151+Int(BOMBS_TO_COLLECT/10)
      Paste Bob 219,16,151+(BOMBS_TO_COLLECT-Int((BOMBS_TO_COLLECT/10)*10))
   End If 
   If BOMBS_TO_COLLECT<10
      Paste Bob 209,16,151
      Paste Bob 219,16,151+BOMBS_TO_COLLECT
   End If 
   ' ************************************************ 
   ' if all bombs disposed of we have completed level 
   ' ************************************************ 
   If BOMBS_TO_COLLECT=0
      _PLAYER_FRAME=9
      LEVEL_COMPLETE=1
   End If 
   ' *******************************
   ' send output back to main screen
   ' *******************************
   Screen 0
End Proc
Procedure STATUS_LEVEL
   ' *********************
   ' print to panel screen
   ' *********************
   Screen 1
   If LEVEL>9
      Paste Bob 266,16,151+Int(LEVEL/10)
      Paste Bob 276,16,151+(LEVEL-Int((LEVEL/10)*10))
   End If 
   If LEVEL<10
      Paste Bob 266,16,151
      Paste Bob 276,16,151+(LEVEL-Int((LEVEL/10)*10))
   End If 
   ' *******************************
   ' send output back to main screen
   ' *******************************
   Screen 0
End Proc
Procedure STATUS_SCORE
   I$="0123456789"
   SCORE_TO_ADD=(LEVEL+LIVES+1)*(100-(_MAX_LIVES*10))
   For _LOOP=1 To SCORE_TO_ADD
      Add SCORE,1
      SCORE$=Str$(SCORE)
      Screen 1
      X=180
      For COUNT=Len(SCORE$) To 1 Step -1
         IC$=Mid$(SCORE$,COUNT,1)
         I=Instr(I$,IC$)
         If I>0 Then Paste Bob X,19,I+150
         Add X,-10
      Next COUNT
   Next _LOOP
End Proc
Procedure STATUS_ENERGY
   ' *********************
   ' print to panel screen
   ' *********************
   Screen 1
   ' ****************** 
   ' remove energy bars 
   ' ****************** 
   Cls 5,39,15 To 63,30
   ' ************ 
   ' are we dying 
   ' ************ 
   If ENERGY<=0
      ' ***************************
      ' make all bombs non-existant
      ' ***************************
      For COUNT=0 To 4
         BOMB_STATE(COUNT)=0
      Next COUNT
      BOMBS_ON=0
      ' **************************** 
      ' change player state to dying 
      ' **************************** 
      _PLAYER_STATE=2
      _PLAYER_FRAME=43
      ' *******************
      ' aaaaarggghhhhh!!!!!
      ' *******************
      If SOUND=1
         Sam Raw 3,Start(10)+8212,5940,10000
      End If 
   End If 
   ' ****************************** 
   ' show new amount of energy bars 
   ' ****************************** 
   If ENERGY>0 and LIVES>-1
      X=39
      For COUNT=1 To ENERGY
         Paste Bob X,15,161
         Add X,7
      Next COUNT
   End If 
   ' ****************************** 
   ' put output back to main screen 
   ' ****************************** 
   Screen 0
End Proc
