home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!math.fu-berlin.de!informatik.tu-muenchen.de!stumpf
- From: stumpf@Informatik.TU-Muenchen.DE (Markus Stumpf)
- Subject: Re: MAZE
- References: <1992Jul23.145751.29068@wuecl.wustl.edu>
- Originator: stumpf@hphalle0.informatik.tu-muenchen.de
- Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem)
- Organization: Technische Universitaet Muenchen, Germany
- Date: Tue, 28 Jul 1992 16:07:21 GMT
- Message-ID: <1992Jul28.160721.7575@Informatik.TU-Muenchen.DE>
- Lines: 67
-
-
- In article <1992Jul23.145751.29068@wuecl.wustl.edu>, ppc1@cec2.wustl.edu (Peter Pui Tak Chiu) writes:
- |> I am trying to write a 3D maze in which the player can move around as if
- |> he/she is "inside" the maze. (something like the adventure game ULTIMA
- |> when you are inside a dungeon...)
- |>
- |> I wrote a version but it is extremely slow. First I transform the 2D maze
- |> into 3D coordinates. Then for every move, I redraw the maze with appropriate
- |> transformation, rotations and hidden surface eliminations... and as you can
- |> tell it takes a lot of TIME!!!
-
- Hmmm, did this in BASIC on a TRS-80 Model I some years ago!
- Thats how I solved it:
-
- asume maze is m * n squares;
- the maze layout is saved as a m * n matrix
- the values of the single cells are bitwise OR of the following values:
- 1 = exit to east
- 2 = exit to north
- 4 = exit to west
- 8 = exit to south
-
- (a way without corners or crossing would eg. have values of 5 (east-west
- passage or 10 north-south passage)
-
- Calculate the next square that can be seen by adding/subtracting 1 to the
- row/column, depending on which is the current direction the player is looking.
-
- Have some graphics for a way to the left in distance one/two/three/four/...
- same for right, wall left, wall right.
-
- Draw the appropiate graphics for each distance.
- Stop as soon as row (resp. column) is < 0 or is > m (resp. n),
- as soon as you encounter a wall in the direction the player looks or as
- soon as you have reached the max distance the player can look (usually
- 5 cells in Ultima, if I can remember correctly)
-
- Whether there is an exit or a wall to be drawn can be determined by bitwise
- ANDing the value of the matrix cell with EAST/NORTH/WEST, that is
- (draw exit for xxx if xxx_exit is TRUE, draw a wall for xxx otherwise)
-
- (in C notation:)
- left_exit = maze[player_x + distance_x, player_y + distance_y] & EAST;
- ahead_exit = maze[player_x + distance_x, player_y + distance_y] & NORTH;
- right_exit = maze[player_x + distance_x, player_y + distance_y] & WEST;
- /* do not need backward_exit as it can't be seen */
-
- where EAST, WEST, NORTH are set according to
-
- player looks east:
- EAST=8; NORTH=1; WEST=2;
- player looks north:
- EAST=1; NORTH=2; WEST=4;
- player looks west:
- EAST=2; NORTH=4; WEST=8;
- player looks south:
- EAST=4; NORTH=8; WEST=1;
-
- Hope that helps and was what you where looking for.
-
- \Maex
-
- P.S. you can use the values 16, 32, 64 and 128 bitwise to the maxtrix cell
- to indicated something special for that position (trapdoors, boxes ...)
- --
- ______________________________________________________________________________
- Markus Stumpf Markus.Stumpf@Informatik.TU-Muenchen.DE
-