sdh@joevax.UUCP (Steve Hawley) (07/16/85)
This is the source code for the maze display program. It was done in
Aztec C version 1.06D. Note: the tabs should be set to 4 spaces.
Steve Hawley
{joevax,mouton,alice}!sdh
Date: 16 July 1985 1131-EDT (Tuesday)
#include <quickdraw.h>
#include <window.h>
#include <inits.h>
#include <event.h>
#include <menu.h>
#include <osutil.h>
/* Program to display a 2D maze in 3D with hidden lines and limited shading */
/* Steve Hawley 7/15/85. Written in Aztec C, version 1.06D */
WindowRecord wRecord;
WindowPtr myWindow;
EventRecord myEvent;
static char maze[22][17] ={ {1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1},
{1,0,1,1,1,0,1,1,0,1,0,1,1,0,1,1,1},
{1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1},
{1,1,0,1,0,1,1,0,1,1,0,1,1,1,1,0,1},
{1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,1},
{1,0,0,1,0,1,0,1,0,0,0,1,0,0,0,0,1},
{1,1,0,0,0,1,1,1,0,1,0,1,1,1,0,1,1},
{1,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,1},
{1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1},
{1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,1},
{1,0,1,1,1,1,1,1,0,1,0,1,0,0,0,1,1},
{1,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,1},
{1,0,1,1,0,1,1,1,0,1,0,1,1,1,1,0,1},
{1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1},
{1,0,1,1,0,1,0,1,0,1,1,1,1,1,1,0,1},
{1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,1},
{1,0,1,1,0,1,0,1,1,1,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1},
{1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1},
{1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1}};
/* the maze. 1's = blocks, 0's = space */
sqre3d (col, row)
int col, row;
/* Displays a given block from the maze. Decides on which side of center the block is found, and */
/* draws the visible faces, which are defined as polygons. The faces are projected using the */
/* formulae: x' = x/z; y' = y/z; to achieve one point perspective. */
{
int x1,x2,y1,y2,z1,z2;
PolyHandle sideleft, siderite, top, front;
x1 = (col - 8) * 100;
x2 = x1 + 100;
z1 = (23 - row);
z2 = z1 -1;
y1 = 150;
y2 = 250;
sideleft = OpenPoly();
MoveTo( (x1/z1) + 200, (y1/z1) + 60);
LineTo( (x1/z1) + 200, (y2/z1) + 60);
LineTo( (x1/z2) + 200, (y2/z2) + 60);
LineTo( (x1/z2) + 200, (y1/z2) + 60);
LineTo( (x1/z1) + 200, (y1/z1) + 60);
ClosePoly();
siderite = OpenPoly();
MoveTo( (x2/z1) + 200, (y1/z1) + 60);
LineTo( (x2/z1) + 200, (y2/z1) + 60);
LineTo( (x2/z2) + 200, (y2/z2) + 60);
LineTo( (x2/z2) + 200, (y1/z2) + 60);
LineTo( (x2/z1) + 200, (y1/z1) + 60);
ClosePoly();
top = OpenPoly();
MoveTo( (x1/z1) + 200, (y1/z1) + 60);
LineTo( (x2/z1) + 200, (y1/z1) + 60);
LineTo( (x2/z2) + 200, (y1/z2) + 60);
LineTo( (x1/z2) + 200, (y1/z2) + 60);
LineTo( (x1/z1) + 200, (y1/z1) + 60);
ClosePoly();
front = OpenPoly();
MoveTo( (x1/z2) + 200, (y1/z2) + 60);
LineTo( (x2/z2) + 200, (y1/z2) + 60);
LineTo( (x2/z2) + 200, (y2/z2) + 60);
LineTo( (x1/z2) + 200, (y2/z2) + 60);
LineTo( (x1/z2) + 200, (y1/z2) + 60);
ClosePoly();
if (x2 < 0 && maze[row][col +1] != 1)/*decide to draw right side (dark gray)*/
{
PenPat(dkGray);
ErasePoly(siderite);
PaintPoly(siderite);
PenPat(black);
FramePoly(siderite);
}
if (x1 > 0 && maze[row][col-1] != 1) /*decide to draw left face (light gray)*/
{
PenPat(ltGray);
ErasePoly(sideleft);
PaintPoly(sideleft);
PenPat(black);
FramePoly(sideleft);
}
PenPat(white); /* Draw the top (white) */
ErasePoly(top);
PaintPoly(top);
PenPat(black);
FramePoly(top);
PenPat(gray); /*draw the front (gray) */
ErasePoly(front);
PaintPoly(front);
PenPat(black);
FramePoly(front);
PenNormal(); /*restore pen characteristics */
KillPoly(top); /* dispose of all the polygons to free up memory*/
KillPoly(front);
KillPoly(sideleft);
KillPoly(siderite);
}
display ()
/* Draws out all the blocks, starting from the back, moving left to center, then right to center */
{
Rect trect;
int row, col;
for (row = 0; row < 22; row++)
{
for (col = 0; col < 8; col++)
if (maze[row][col] == 1) sqre3d(col,row);
for (col = 16; col > 7; col--)
if (maze[row][col] == 1) sqre3d(col, row);
}
}
main ()
{
Rect screen;
InitGraf(&thePort); /* do inits */
InitFonts();
FlushEvents(everyEvent,0);
InitWindows();
SetCursor(&arrow);
ShowCursor();
SetRect(&screen, 4, 40, 508, 338); /*set up window */
myWindow = NewWindow(&wRecord, &screen, ctop("Something Amazing"),1,0,(char*)-1,1,(long)0);
SetPort(myWindow);
ShowWindow(myWindow);
display(); /*draw maze*/
while(!Button()) /*wait for button to be pressed and handle events like clover-shift-4 */
GetNextEvent(everyEvent, &myEvent);
}