home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
ST_USER
/
1990
/
USERDC90.MSA
/
TEXT_STOS.TXT
< prev
Wrap
Text File
|
1990-10-08
|
9KB
|
182 lines
STOS IN 3D
Phil Lawson boldy takes the STOS series
where no freelance writer has gone before,
into the third dimension.
If you haven't played Dungeon Master, or its equally impressive successor Chaos
Strikes Back, you haven't lived. What really makes these two games stand out
from the rest is the fantastic 3D graphics and the speed at which they're
drawn. However, would you believe that STOS can also be used to produce 3D maze
type games and draw a larger screen faster, all without the aid of the long
awaited for 3D graphics extension? If not, you'd better read on.
Drawing in three dimensions is all about working out what the world around you
looks like, translating this into graphics and drawing them on the screen.
Taking a look at Figure I will show all the graphics used in writing this
month's program.
MAZEPIC.PI1: <<SCREENSHOT>>
Before starting any programming, you'll need to define the maze. The data for
this starts at line 700 in my program, and is read into the array maze(x,y),
where 0 indicate a walkway and 1 a wall. We can now test any part of the maze
just by using the correct X and Y values in the array.
Notice that around the actual maze is a series of walls three deep, since my
game shows everything for three places in front of the current position.
Imagine if the player was currently at the outside edge of the maze, facing the
wall. It is much easier to have a dummy series of walls defined and just draw
them, rather than continually having to check where the player is and how much
to draw.
Using two variables, XP and YP, we can keep track of where the player is when
working out what the surrounding area looks like. However, knowing the players'
current location isn't enough. We must also know which direction he's facing.
Take a look at the example maze below:
direction 1
1 0 1 1 1 0 1
1 0 0 1 0 0 1
direction 4 1 1 0 0 0 1 1 direction 2
1 0 0 X 1 0 1
1 0 1 1 0 0 1
1 0 0 0 0 1 1
direction 3
If the player at position X was facing direction 1, would see:
P P W P P
W P P P W
P W
But facing direction 4 would change the view to:
P P P W P
P W P P W
W P
Where P is a path and W is a wall.
Therefore a variable, DI, is needed to store the current direction, which will
be updated whenever the player turns around. We'll also need some way of
reading the correct information from the MAZE array depending upon the value of
DI. This is best achieved with two other arrays, one each for the X and Y
coordinates, TX(DI,ROW,POS) and TY(DI,ROW,POS).
The data for these arrays, covering each of the four directions, can be found
starting at line 860 in my program. Some explanation of how these values were
obtained, together with how to use them, is essential. It's also quite a tricky
subject to describe, so you may need to read the following sections more than
once. (If you have a printer, use the PRINT option, otherwise try taking notes.
You'll find them invaluable when you start playing around with the program).
To draw the screen you need to read five positions from the back row, five from
the middle and three from the one the player is currently standing on, as shown
in the figures above. The coordinates of these are found by adding offset
values to both the X and Y coordinates. It is these offsets that are stored in
the TX and TY arrays.
1 2 3 4 5
A X-2,Y-2 X-1,Y-2 X,Y-2 X+1,Y-2 X+2,Y-2
B X-2,Y-1 X-1,Y-1 X,Y-1 X+1,Y-1 X+2,Y-1
C X-2,Y X-1,Y X,Y X+1,Y X+2,Y
D X-2,Y+1 X-1,Y+1 X,Y+1 X+1,Y+1 X+2,Y+1
E X-2,Y+2 X-1,Y+2 X,Y+2 X+1,Y+2 X+2,Y+2
Table I: The offset values.
For example, the offset values for direction 1 would be all of rows A and B,
and the three middle bits of row C. The values for direction 4 however, would
be all of columns 1 and 2, with the middle bits of column 3. Try matching the
offsets given in Table I with the data in the program.
When actually drawing the screen it's best to start at the back and work
forwards. This way there are no messy calculations trying to work out whether
something is going to be hidden by a wall.
If all that seemed a little complicated, the following description of how the
program works should help clear things up a bit. Don't be surprised if you have
to read this article more than once to fully understand the techniques I've
used, it gave me enough brain-ache working it out my self.
Since my game only has a perspective three places deep, it is necessary to draw
a very dark strip to make up the background. Otherwise, in certain parts of the
maze, it would appear that walls just ended in nothingness. Also, when you move
forward, new walls would seem to appear from nowhere.
Once this has been drawn, we can start drawing the walls. Note, there is no
need to draw pathways, since these are just empty spaces with nothing in them.
Because we want the new image to appear almost immediately, without appearing
to draw the various sections individually, I have defined a blank screen (7),
to which I copy the graphics to. When the image is complete, it is a simple
matter to draw a frame around it all and copy the whole thing to the physical
screen.
If you want to examine the program while it's running and see exactly what is
going on, try making the following changes:
245 GOSUB 10000
255 GOSUB 10000
305 GOSUB 10000
315 GOSUB 10000
330 GOSUB 10000 : RETURN
365 GOSUB 10000
375 GOSUB 10000
420 GOSUB 10000 : xx=xx+160 : NEXT c
465 GOSUB 10000
495 GOSUB 10000
505 GOSUB 10000
535 GOSUB 10000
10000 SCREEN COPY 7 TO PHYSIC : WAIT VBL : SCREEN COPY 7 TO BACK : WAIT VBL
10010 WAIT KEY
10020 RETURN
After drawing the dark strip, the back row is put in place. Take a look at line
290:
290 IF maze(xp+tx(di,3,c),yp+ty(di,3,c))=0 THEN 330
This uses the players coordinates, (XP and YP), and the two offset arrays. The
variable 'di' is the direction in which the player is facing, the number 3
means the third or back row, and 'c' is a number from 1 to 5. By combining this
lot with the 'maze' array, we'll obtain a value of either zero or one.
If the value is zero, the position being tested is a walkway, and therefore we
don't need to draw anything. On the other hand, if it's one we've found a wall.
Lines 300 to 320 will copy the correct graphics from screen 5 to screen 7. The
front face of a wall is done by 300 and the side pieces, used to give a feeling
of depth, are drawn with 310 and 320.
Once this routine has been done five times, once for each value of 'c', the
back row will be completed with the walls and pathways in the correct places.
We now do this all again for the second row with lines 340 to 460, except the
value of 'c' will be two instead of three. Lines 360 and 370 are used to draw
the edge pieces you'll see whenever your looking around a corner. To see
exaclty what I mean, try running the program as it is and then running it with
these two lines REMmed out.
Notice lines 430 to 460, which check the position directly in front of the
player and draw a block if neccessary.
The last two lines concerned with the graphics are 490 and 500. These put in
the side pieces immediately left and right of the player. All that is left to
do now is draw the border, by copying it from screen 6. Displaying the new
screen is a simple matter of copying the data from screen 7 to the physical and
background screens.
The remaining part of the program, lines 580 to 690, is concerned with reading
the keyboard. To actually move around use the four arrow keys, with the Insert
and Clr/Home keys being used to rotate the player on the spot.
Don't worry if the graphics seem a little rough, or even out of perspective in
places. The last thing I am is an artist, so it's up to you to take the
techniques and ideas discussed this month and produce your own mega 3D game.
I'm sure our friendly editor, (crawl crawl), will only be too happy to put the
best on the cover disc for the rest of the world to marvel at.