home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / programm / 2121 < prev    next >
Encoding:
Text File  |  1992-07-28  |  3.2 KB  |  80 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!math.fu-berlin.de!informatik.tu-muenchen.de!stumpf
  3. From: stumpf@Informatik.TU-Muenchen.DE (Markus Stumpf)
  4. Subject: Re: MAZE
  5. References:  <1992Jul23.145751.29068@wuecl.wustl.edu>
  6. Originator: stumpf@hphalle0.informatik.tu-muenchen.de
  7. Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem)
  8. Organization: Technische Universitaet Muenchen, Germany
  9. Date: Tue, 28 Jul 1992 16:07:21 GMT
  10. Message-ID: <1992Jul28.160721.7575@Informatik.TU-Muenchen.DE>
  11. Lines: 67
  12.  
  13.  
  14. In article <1992Jul23.145751.29068@wuecl.wustl.edu>, ppc1@cec2.wustl.edu (Peter Pui Tak Chiu) writes:
  15. |> I am trying to write a 3D maze in which the player can move around as if
  16. |> he/she is "inside" the maze.  (something like the adventure game ULTIMA
  17. |> when you are inside a dungeon...)
  18. |> 
  19. |> I wrote a version but it is extremely slow.  First I transform the 2D maze
  20. |> into 3D coordinates.  Then for every move, I redraw the maze with appropriate
  21. |> transformation, rotations and hidden surface eliminations...  and as you can
  22. |> tell it takes a lot of TIME!!!
  23.  
  24. Hmmm, did this in BASIC on a TRS-80 Model I some years ago!
  25. Thats how I solved it:
  26.  
  27. asume maze is  m * n squares;
  28. the maze layout is saved as a m * n matrix
  29. the values of the single cells are bitwise OR of the following values:
  30.     1 = exit to east
  31.     2 = exit to north
  32.     4 = exit to west
  33.     8 = exit to south
  34.  
  35. (a way without corners or crossing would eg. have values of 5 (east-west
  36. passage or 10 north-south passage)
  37.  
  38. Calculate the next square that can be seen by adding/subtracting 1 to the
  39. row/column, depending on which is the current direction the player is looking.
  40.  
  41. Have some graphics for a way to the left in distance one/two/three/four/...
  42. same for right, wall left, wall right.
  43.  
  44. Draw the appropiate graphics for each distance.
  45. Stop as soon as row (resp. column) is < 0 or is > m (resp. n),
  46. as soon as you encounter a wall in the direction the player looks or as
  47. soon as you have reached the max distance the player can look (usually
  48. 5 cells in Ultima, if I can remember correctly)
  49.  
  50. Whether there is an exit or a wall to be drawn can be determined by bitwise
  51. ANDing the value of the matrix cell with EAST/NORTH/WEST, that is
  52. (draw exit for xxx if xxx_exit is TRUE, draw a wall for xxx otherwise)
  53.  
  54. (in C notation:)
  55. left_exit = maze[player_x + distance_x, player_y + distance_y] & EAST;
  56. ahead_exit = maze[player_x + distance_x, player_y + distance_y] & NORTH;
  57. right_exit = maze[player_x + distance_x, player_y + distance_y] & WEST;
  58. /* do not need backward_exit as it can't be seen */
  59.  
  60. where EAST, WEST, NORTH are set according to
  61.  
  62. player looks east:
  63.     EAST=8;  NORTH=1;  WEST=2;
  64. player looks north:
  65.     EAST=1;  NORTH=2;  WEST=4;
  66. player looks west:
  67.     EAST=2;  NORTH=4;  WEST=8;
  68. player looks south:
  69.     EAST=4;  NORTH=8;  WEST=1;
  70.  
  71. Hope that helps and was what you where looking for.
  72.  
  73.     \Maex
  74.  
  75. P.S. you can use the values 16, 32, 64 and 128 bitwise to the maxtrix cell
  76.      to indicated something special for that position (trapdoors, boxes ...)
  77. -- 
  78. ______________________________________________________________________________
  79.  Markus Stumpf                        Markus.Stumpf@Informatik.TU-Muenchen.DE 
  80.