FLATMAN
by J.D. Rogers
from ZX Computing Apr/May.1984

There's been Zip, Zap and Pac-Man, now here's Flatman,
a race against grime by J Dave Rogers of Liverpool!


In this game you play the part of the harassed caretaker of
a rather badly situated block of flats. Your job is to
ensure that every window gets cleaned when dirty and
repaired when cracked, using the buckets of water and spare
panes of glass that are stored around the building. The
difficulties, however, are that you cannot carry both water
and glass at the same time, and that the windows keep
getting dirtied again (pollution and pigeons!) and cracked
again (aircraft vibrations and vandals). If you manage to
get the whole lot perfect (and don't fall off too many times
in the process) you can go on to harder levels of the game,
the object being to reach as high a level as possible.


How to play

Use keys Z and C to move left/right, keys N and J to move up
down. You must travel along the ladders and walkways marked
by inverse 'equals' signs, if you try to do otherwise you
will fall off and lose a life. To pick up water move towards
a 'W', or for glass go towards a '/', the man will then
flash with whatever has been picked up. When you are 'empty'
the man flashes white. Each 'W' you pick up lets you clean
four windows, and similarly each pane of glass lets you fix
four windows. You can pick up as many as you like at one
time but you cannot carry glass and water together (too
dangerous!) so if you already have water and then go to pick
up glass you will lose whatever water you had left, and vice
versa. Tactics are clearly needed to make the most of what
there is.

To clean or repair a window just move towards it from either
side or from underneath, using the same movement keys as
usual. Whenever you manage to get all the windows clean
together you are moved on to harder levels of the game,
where the ladder-pattern is more awkward and there is less
water available.


Program operation

Lines 20-70 are the man-move subroutine. Since this is by
far the most frequently used part of the program, it has
been placed right at the beginning of the listing, and the
variables used in it are defined before any others when the
program is first run, this making all access times as short
as possible. These considerations together with poking onto
the screen rather than 'PRINT AT' make for a fast game
compared to many ZX81 BASIC written programs.

Line 40 checks for move / can't move / fall off / pick up
water / glass / clean window / repair window. It does this
by looking at the next space to be moved to and if this is
not a 'ladder' (character 148) then the program is diverted
to lines 300-580 where, depending on what character is
found, different actions are taken. Eventually a return
command is hit which completes the original GOSUB to the
man-move subroutine. The man's previous known screen
position is still held unchanged in the variable PP so that
normal movement can resume next time around.

Lines 100 and 110 form a loop which constantly calls the
man-move subroutine, but the loop is occasionally broken out
of to allow the next set of lines to operate as follows:
lines 200-290 cause windows to be cracked or dirtied again
during the game. So as not to slow down movement during this
operation, the man-move subroutine is also called in between
lines.

Line 310 uses Boolean algebra to replace a long mess of
IF-THEN-GOTO comparison lines. Assume for example, that line
310 has found a 'dirty window' (grey character, code 8) and
that the man has 'water' (w>0) then line 500 is selected.
This reduces water points by one, then in line 540 the grey
is POKEd with a space character to 'clean' it. Line 550 then
looks to see if the next space is also a grey, if so POKEing
it, if not POKEing the space before it. This is so that any
window can be wiped from either side or even underneath and
still give the same result. A similar procedure is followed
for repairing cracked windows.

Lines 600-690 initialise variables. Lines 700-892 form a
subroutine to draw the screen, also used to redraw it full
of broken windows at each new level of the game. Line 705
starts the ZX81's random number sequence off at a fixed
place for each level of the game. Each screen therefore
follows a different pattern of window cracking, but it is
always the same for a given level. This is done so that
players can eventually learn what to expect and develop
tactics.

Line 830 causes the ladder pattern to vary between levels.
Lines 900-990. The 'fall off' routine. This replaces
characters behind the man as he falls.


Modifications

On-screen instructions have been omitted to keep program
length down, but readers may like to add their lines at the
end of the program to do this. A few sarcastic comments
might also be added at the end, depending what level the
player managed to reach.

If you find the game too difficult then change line 800 to
print 32 graphic 'equals' instead of blacks, thereby giving
the man extra access all along the bottom. If the game seems
too easy however, try slightly decreasing the value of 0.94
in line 110 as this determines how often windows are likely
to be re-cracked during play.


Variables

PP      Present position of man.
S       Next intended screen position.
X       Marks the start of the screen in the display file.
K       Character of man.
Y       Character of next space if user tries to move off a ladder.
        This is used to decide whether man picks up water, picks up
        glass, cleans window, repairs window or just falls off.
W       Water points.
GL      Glass points.
PW      Perfect windows (0 to 30).
E,F,H   Used to generate random cracking/dirtying of windows.
LE      Level of game.
N       FOR-NEXT loops.
P$      Printing string, used to print horizontal walkways.
LIFE,L$ Number of lives left; on screen indication of this.
JD      At the end of line 990 is just an undefined variable
	to stop the program at the end of the game.


A note or two

Graphics 'equals' are important characters in this program,
but these can often look like inverse spaces when printed on
paper, so please note the following very carefully when
typing-in:

Line 730 : 14 graphic shift F; 3 spaces, 3 graphic shift F.
Line 740 : 3 graphic spaces, eight various characters,
           5 graphics spaces, 2 spaces, 3 graphic 'equals'.
Line 760 : Graphic shift 'S' is used.
Lines 760, 770 and 780 must have graphic 'equals' at positions
           4,7,10,13,19 and 21.
Line 810 : 6 graphic 'equals'.
Line 830 : 2 graphic spaces, 3 graphic 'equals'.
Line 880 W, graphic 'equals', W.

Since the program contains 'pokes' it is liable to crash if
typed in wrongly, so it is a good idea at first to omit the
self-start line 1050 and 'save' a few copies of the program
onto a cassette before it is ever run.


Warning

This listing was not printed on a Sinclair printer and
graphic characters have been replaced by a simple code. This
consists of a number (no number means only one character)
which is the number of characters needed, followed by "g" to
indicate graphics mode, and finally a letter or number which
is the key of the character. The code "is" means inverse
space.

These codes are combined with a "+" as a separator, so the
code "2is+2ga" means two inverse spaces and two characters
obtained by graphics mode shift/key A. Lower case messages
are to be typed in inverse mode.

I hope you will find this easy to enter, I know it is less
than simple, but I think that you will agree with me that it
makes the rest of the program easier to read ...


--
Another Fine Product transcribed by:
Jim Grimwood (jimg@globalnet.co.uk), Weardale, England
--
