home *** CD-ROM | disk | FTP | other *** search
- // Filnamn: RAYCAST.CPP
- // Datum: 1996-02-20
- // Info: Innehåller funktioner för raycasting.
- //=========================================================================
- //
- // INCLUDES
- //
- //=========================================================================
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include "raycast.h"
- #include "pcx.h"
- #include "dos.h"
- #include "ray.h"
- #include "trig.h"
- #include "fixpoint.h"
- #include "objdraw.h"
-
- //=========================================================================
- //
- // External variables:
- //
- //=========================================================================
- extern unsigned char far *texturelist[NUMTEXTURES];
- extern objtype obj[NUMOBJECTS];
- extern map_type objmap, walls, ceiling, flor;
-
- //=========================================================================
- //
- // GLOBAL CONSTANTS & VARIABLES.
- //
- //=========================================================================
- int VIEWPORT_LEFT=0; // Dimensions of viewport
- int VIEWPORT_RIGHT=319;
- int VIEWPORT_TOP=0;
- int VIEWPORT_BOT=169;
- int VIEWPORT_HEIGHT=VIEWPORT_BOT-VIEWPORT_TOP+1;
- int VERT_CENTER=VIEWPORT_TOP+VIEWPORT_HEIGHT/2;
- int VIEWPORT_WIDTH=VIEWPORT_RIGHT-VIEWPORT_LEFT+1;
- int HORIZ_CENTER=VIEWPORT_LEFT+VIEWPORT_WIDTH/2;
- unsigned char *screen_buffer; // Off screen buffer
- unsigned char bottoms[320],tops[320]; // Lookup table containing wall height
- extern int objptr[16][16]; // Array holding objects' positions
- unsigned int dist[320]; // Pre-calculated distances
- int visible[16][16]; // Visibility array
- int objlist[MAXOBJECTS]; // Array holding sorted objects
- unsigned char litetable[MAXLIGHT+1][PALETTESIZE]; // Color array
- float wallangle[320];
- int distance_table[MAXDISTANCE];
- int wheight[MAXDISTANCE];
- unsigned char *litelevel=new unsigned char[MAXDISTANCE];
- unsigned char *texturelist[15];
- int column_angle1, column_angle2;
- long viewing_angle=130;
- long ambient_level=10;
- long xview=6*64+32;
- long yview=6*64+32;
- long nextx;
- long nexty;
- door doors[10];
- int xmaze,ymaze; // Map location of ray collision
- char MAX_DOORS;
-
- // Coordinates for viewport size
- vp_size viewport_size[5] = {{0, 0, 319, 169},
- {20, 15, 299, 154},
- {45, 30, 270, 139},
- {75, 45, 244, 124},
- {110, 60, 209, 109}};
-
- /*
- ===================
- = getdistance()
- = Calculates distance from player
- = to wall intersection.
- = Uses inline function for maximum
- = speed.
- ===================
- */
- inline int getdistance(long degrees,int column_angle,long x,long y)
- {
- long trig,fix_ny,fix_nx;
- int distance;
-
- int c=degrees>>9;
- if (((c&3)==0)||((c&3)==3))
- distance=abs(fixdiv((y-((long)yview<<SHIFT))>>SHIFT,
- COS(degrees-((c<<10)<<1)))*cos_table[column_angle]>>SHIFT);
- else
- distance=abs(fixdiv((x-((long)xview<<SHIFT))>>SHIFT,
- SIN(degrees-((c<<10)<<1)))*cos_table[column_angle]>>SHIFT);
- return(distance);
- }
-
-
-
- /*
- =============================
- =
- = draw_maze()
- = Hjärnan i raycasting-motorn. Gör det
- = egentliga grovjobbet.
- =
- =============================
- */
- void draw_maze(unsigned char far **textmaps, unsigned char **objects)
-
- // Draws a raycast image in the viewport of the maze represented
- // in array MAP[], as seen from position XVIEW, YVIEW by a
- // viewer looking at angle VIEWING_ANGLE where angle 0 is due
- // north.
-
- {
- // Variable declarations:
- int sy,offset; // Pixel y position and offset
- long fix_xd,fix_yd; // Distance to next wall in x and y
- int grid_x,grid_y; // Coordinates of x and y grid lines
- long fix_xcross_x,fix_xcross_y; // Ray intersection coordinates
- long fix_ycross_x,fix_ycross_y;
- unsigned int xdist,ydist; // Distance to x and y grid lines
- int distance; // Distance to wall along ray
- int tmcolumn; // Column in texture map
- int top,bot;
- long fix_yratio;
- int degrees, viewer_height = 32;
- int column_angle;
- int index;
- long far *clock = (long far *)0x0000046CL; // Pointer to internal timer
-
- for (int ysquare=0; ysquare<16; ysquare++)
- for (int xsquare=0; xsquare<16; xsquare++)
- visible[xsquare][ysquare]=0;
-
- // Loop through all columns of pixels in viewport:
- for (int column=VIEWPORT_LEFT; column<=VIEWPORT_RIGHT; column++)
- {
- // Calculate horizontal angle of ray relative to
- // center ray:
- column_angle=wallangle[column];
- if (column_angle<0) column_angle+=NUMBER_OF_DEGREES;
- if (column_angle>NUMBER_OF_DEGREES-1) column_angle-=NUMBER_OF_DEGREES;
-
- // Calculate angle of ray relative to maze coordinates
- degrees=viewing_angle+column_angle;
- if (degrees>NUMBER_OF_DEGREES-1) degrees-=NUMBER_OF_DEGREES;
-
- // Rotate endpoint of ray to viewing angle:
- int x2 = fixmul(-256L<<SHIFT,SIN(degrees))>>SHIFT;
- int y2 = fixmul(256L<<SHIFT,COS(degrees))>>SHIFT;
-
- // Translate relative to viewer's position:
- x2+=xview;
- y2+=yview;
-
- // Initialize ray at viewer's position:
- long fix_x=(long)xview<<SHIFT;
- long fix_y=(long)yview<<SHIFT;
-
- // Find difference in x,y coordinates along ray:
- long xdiff=x2-xview;
- long ydiff=y2-yview;
-
- // Cheat to avoid divide-by-zero error:
- if (xdiff==0) xdiff=1;
- if (ydiff==0) ydiff=1;
-
- // Get slope of ray:
- long fix_slope = fixdiv((long)ydiff<<SHIFT,(long)xdiff<<SHIFT);
-
- // Cast ray from grid line to grid line:
- for (;;)
- {
-
- // If ray direction positive in x, get next x grid line:
- if (xdiff>0) grid_x=((fix_x>>SHIFT) & 0xffc0) + 64;
-
- // If ray direction negative in x, get last x grid line:
- else grid_x=((fix_x>>SHIFT) & 0xffc0) - 1;
-
- // If ray direction positive in y, get next y grid line:
- if (ydiff>0) grid_y=((fix_y>>SHIFT) & 0xffc0) + 64;
-
- // If ray direction negative in y, get last y grid line:
- else grid_y=((fix_y>>SHIFT) & 0xffc0) - 1;
-
- // Get x,y coordinates where ray crosses x grid line:
- fix_xcross_x = (long) grid_x << SHIFT;
- fix_xcross_y = fix_y + fixmul(fix_slope,((long)grid_x<<SHIFT)-fix_x);
-
- // Get x,y coordinates where ray crosses y grid line:
- fix_ycross_x=fix_x+fixdiv((((long)grid_y<<SHIFT)-fix_y),fix_slope);
- fix_ycross_y=(long)grid_y<<SHIFT;
-
- // Get distance to x grid line:
- distance=getdistance(degrees,column_angle,fix_xcross_x,fix_xcross_y);
- xdist=distance;
-
- // Get distance to y grid line:
- distance=getdistance(degrees,column_angle,fix_ycross_x,fix_ycross_y);
- ydist=distance;
-
- // If x grid line is closer...
- if (xdist<ydist)
- {
-
- // Calculate maze grid coordinates of square:
- xmaze=fix_xcross_x>>22;
- ymaze=fix_xcross_y>>22;
-
- // Set x and y to point of ray intersection:
- fix_x=fix_xcross_x;
- fix_y=fix_xcross_y;
-
- // Find relevant column of texture map:
- tmcolumn = (fix_y>>SHIFT) & 0x3f;
-
- // Is there a maze cube here? If so, stop looping:
- if (walls[xmaze][ymaze])
- {
- // Did the ray hit a door?
- if (walls[xmaze][ymaze] == 4)
- {
- // If so, find that door:
- index = GetDoorID(xmaze, ymaze);
-
- // Should this part of the door be rendered?
- tmcolumn -= doors[index].position;
-
- // If so, break out of the iteration...
- if ((tmcolumn << 6) < doors[index].position) break;
- }
- else break;
- }
- else visible[xmaze][ymaze] = -1;
- }
- else
- { // If y grid line is closer:
-
- // Calculate maze grid coordinates of square:
- xmaze=fix_ycross_x>>22;
- ymaze=fix_ycross_y>>22;
-
- // Set x and y to point of ray intersection:
- fix_x=fix_ycross_x;
- fix_y=fix_ycross_y;
-
- // Find relevant column of texture map:
- tmcolumn = (fix_x>>SHIFT) & 0x3f;
-
- // Is there a maze cube here? If so, stop looping:
- if (walls[xmaze][ymaze])
- {
- // Did the ray hit a door?
- if (walls[xmaze][ymaze] == 4)
- {
- // If so, find the door in the table
- index = GetDoorID(xmaze, ymaze);
-
- // Should this part of the door be rendered?
- tmcolumn -= doors[index].position;
-
- // If so, break out of the iteration...
- if ((tmcolumn << 6) < doors[index].position) break;
- }
- else
- break;
- }
- else visible[xmaze][ymaze] = -1;
- }
- }
-
- // Get distance from viewer to intersection point:
- distance=getdistance(degrees,column_angle,fix_x,fix_y);
-
- if (distance==0) distance=1;
- // if (walls[xmaze][ymaze] == 4) distance += 32;
-
- dist[column]=distance;
-
- // Calculate visible height of wall:
- int height = wheight[distance];
- if (!height) height=1;
-
- // Calculate bottom of wall on screen:
- bot = distance_table[distance];
-
- // Calculate top of wall on screen:
- top = bot - height + 1;
-
- // Initialize temporary offset into texture map:
- int t=(tmcolumn<<6)+IMAGE_HEIGHT;
-
- // If top of current vertical line is outside of
- // viewport, clip it:
- long dheight=height;
- long iheight=IMAGE_HEIGHT;
- long fix_yratio=fixdiv((long)WALL_HEIGHT<<SHIFT,(long)height<<SHIFT);
- if (top < VIEWPORT_TOP) {
- int diff=VIEWPORT_TOP-top;
- dheight-=diff;
- iheight -= (diff*fix_yratio)>>SHIFT;
- top=VIEWPORT_TOP;
- }
- if (bot >= VIEWPORT_BOT) {
- int diff=bot-VIEWPORT_BOT;
- dheight -= diff;
- iheight -= diff*fix_yratio>>SHIFT;
- t-=(diff*fix_yratio)>>SHIFT;
- bot=VIEWPORT_BOT + 1;
- }
-
- // Save top and bottom in arrays:
- tops[column]=top;
- bottoms[column]=bot;
-
- // Point to video memory offset for top of line:
- offset = (bot<<8)+(bot<<6) + column;
-
- // Which graphics tile are we using?
- int tile=walls[xmaze][ymaze]-1;
-
- long fix_increment=fixdiv(iheight<<SHIFT,dheight<<SHIFT);
- int level=litelevel[distance]+ambient_level;
- if (level>MAXLIGHT) level=MAXLIGHT;
- drawwall(&(screen_buffer[offset]),&(textmaps[tile][t]),dheight,
- fix_increment,&(litetable[level][0]));
-
- }
-
- // The whole door is now rendered, let's open it some more...
- if (doors[index].state == DOOR_OPENING) doors[index].position -= doors[index].speed;
-
- // If the door is closing, close it some more!
- if (doors[index].state == DOOR_CLOSING) doors[index].position += doors[index].speed;
-
- // If no part of the door is visible, then the door must be open, huh?
- if (doors[index].position <= 4032 && doors[index].state == DOOR_OPENING)
- {
- doors[index].state = DOOR_OPEN;
- doors[index].time = *clock; // Get current time
- }
-
- // If door is closed, then indicate this by setting door state properly...
- if (doors[index].position >= 4096 && doors[index].state == DOOR_CLOSING)
- doors[index].state = DOOR_CLOSED;
-
- // Check current time. If 60 clock ticks (about 40 seconds) has passed
- // since the door was entirely open, then start closing it...
- if (doors[index].state == DOOR_OPEN)
- if (*clock - doors[index].time > 60) doors[index].state = DOOR_CLOSING;
-
-
- // Step through floor pixels:
-
- for (int row=VERT_CENTER+5; row<=VIEWPORT_BOT; row++) {
-
- // Calculate horizontal angle of leftmost column relative to
- // center ray:
- column_angle = column_angle1;
- if (column_angle<0) column_angle+=NUMBER_OF_DEGREES;
- if (column_angle>NUMBER_OF_DEGREES-1) column_angle-=NUMBER_OF_DEGREES;
-
- // Calculate angle of ray relative to maze coordinates
- int degrees=viewing_angle+column_angle;
- if (degrees>NUMBER_OF_DEGREES-1) degrees-=NUMBER_OF_DEGREES;
-
- // Get ratio of viewer's height to pixel height:
- long fix_ratio=fixdiv((long)viewer_height<<SHIFT,(long)(row-VERT_CENTER)<<SHIFT);
-
- // Get distance to visible pixel:
- long fix_distance=fixdiv((fix_ratio<<7)+(fix_ratio<<6),COS(column_angle));
-
- // Rotate distance to ray angle:
- int left_x = - (fixmul(fix_distance,SIN(degrees))>>SHIFT);
- int left_y = fixmul(fix_distance,COS(degrees))>>SHIFT;
-
- // Translate relative to viewer coordinates:
- left_x+=xview;
- left_y+=yview;
-
- // Calculate horizontal angle of rightmost column relative to
- // center ray:
- column_angle = column_angle2;
- if (column_angle<0) column_angle+=NUMBER_OF_DEGREES;
- if (column_angle>NUMBER_OF_DEGREES-1) column_angle-=NUMBER_OF_DEGREES;
-
- // Calculate angle of ray relative to maze coordinates
- degrees=viewing_angle+column_angle;
- if (degrees>NUMBER_OF_DEGREES-1) degrees-=NUMBER_OF_DEGREES;
-
- // Get ratio of viewer's height to pixel height:
- // fix_ratio=fixdiv((long)viewer_height<<SHIFT,(long)(row-VERT_CENTER)<<SHIFT);
-
- // Get distance to visible pixel:
- // fix_distance=fixdiv((fix_ratio<<7)+(fix_ratio<<6),COS(column_angle));
-
- // Rotate distance to ray angle:
- int right_x = - (fixmul(fix_distance,SIN(degrees))>>SHIFT);
- int right_y = fixmul(fix_distance,COS(degrees))>>SHIFT;
-
- // Translate relative to viewer coordinates:
- right_x+=xview;
- right_y+=yview;
-
- // Calculate stepping increment:
- long fix_x_increment=fixdiv((long)(right_x-left_x)<<SHIFT,
- (long)(VIEWPORT_RIGHT-VIEWPORT_LEFT)<<SHIFT);
- long fix_y_increment=fixdiv((long)(right_y-left_y)<<SHIFT,
- (long)(VIEWPORT_RIGHT-VIEWPORT_LEFT)<<SHIFT);
- long fix_x=(long)left_x<<SHIFT;
- long fix_y=(long)left_y<<SHIFT;
-
- int level=litelevel[fix_distance>>SHIFT]+ambient_level;
- if (level>MAXLIGHT) level=MAXLIGHT;
-
- drawfloorrow(row,&(screen_buffer[(row<<8)+(row<<6)+VIEWPORT_LEFT]),
- &(texturelist[0]),&flor[0][0],
- &(litetable[level][0]),
- &(bottoms[VIEWPORT_LEFT]),fix_x_increment,
- fix_y_increment,fix_x,fix_y,VIEWPORT_WIDTH);
- }
-
- // Step through ceiling pixels:
-
- for (row=VERT_CENTER-5; row>=VIEWPORT_TOP; --row) {
-
- // Calculate horizontal angle of leftmost column relative to
- // center ray:
- int column_angle = column_angle1;
- if (column_angle<0) column_angle+=NUMBER_OF_DEGREES;
- if (column_angle>NUMBER_OF_DEGREES-1) column_angle-=NUMBER_OF_DEGREES;
-
- // Calculate angle of ray relative to maze coordinates
- int degrees=viewing_angle+column_angle;
- if (degrees>NUMBER_OF_DEGREES-1) degrees-=NUMBER_OF_DEGREES;
-
- // Get ratio of viewer's height to pixel height:
- long fix_ratio=fixdiv((long)(WALL_HEIGHT-viewer_height)<<SHIFT,
- (long)(VERT_CENTER-row)<<SHIFT);
-
- // Get distance to visible pixel:
- long fix_distance=fixdiv((fix_ratio<<7)+(fix_ratio<<6),COS(column_angle));
-
- // Rotate distance to ray angle:
- int left_x = - (fixmul(fix_distance,SIN(degrees))>>SHIFT);
- int left_y = fixmul(fix_distance,COS(degrees))>>SHIFT;
-
- // Translate relative to viewer coordinates:
- left_x+=xview;
- left_y+=yview;
-
- // Calculate horizontal angle of rightmost column relative to
- // center ray:
- column_angle= column_angle2;
- if (column_angle<0) column_angle+=NUMBER_OF_DEGREES;
- if (column_angle>NUMBER_OF_DEGREES-1) column_angle-=NUMBER_OF_DEGREES;
-
- // Calculate angle of ray relative to maze coordinates
- degrees=viewing_angle+column_angle;
- if (degrees>NUMBER_OF_DEGREES-1) degrees-=NUMBER_OF_DEGREES;
-
- // Get ratio of viewer's height to pixel height:
- // fix_ratio=fixdiv((long)(WALL_HEIGHT-viewer_height)<<SHIFT,(long)(VERT_CENTER-row)<<SHIFT);
-
- // Get distance to visible pixel:
- // fix_distance=fixdiv((fix_ratio<<7)+(fix_ratio<<6),COS(column_angle));
-
- // Rotate distance to ray angle:
- int right_x = - (fixmul(fix_distance,SIN(degrees))>>SHIFT);
- int right_y = fixmul(fix_distance,COS(degrees))>>SHIFT;
-
- // Translate relative to viewer coordinates:
- right_x+=xview;
- right_y+=yview;
-
- // Calculate stepping increment:
- long fix_x_increment=fixdiv((long)(right_x-left_x)<<SHIFT,
- (long)(VIEWPORT_RIGHT-VIEWPORT_LEFT)<<SHIFT);
- long fix_y_increment=fixdiv((long)(right_y-left_y)<<SHIFT,
- (long)(VIEWPORT_RIGHT-VIEWPORT_LEFT)<<SHIFT);
- long fix_x=(long)left_x<<SHIFT;
- long fix_y=(long)left_y<<SHIFT;
-
- int level=litelevel[fix_distance>>SHIFT]+ambient_level;
- if (level>MAXLIGHT) level=MAXLIGHT;
-
- drawceilrow(row,&(screen_buffer[(row<<8)+(row<<6)+VIEWPORT_LEFT]),
- &(texturelist[0]),&ceiling[0][0],
- &(litetable[level][0]),
- &(tops[VIEWPORT_LEFT]),fix_x_increment,
- fix_y_increment,fix_x,fix_y,VIEWPORT_WIDTH);
- }
-
- int numobjs=0;
- for (xsquare=0; xsquare<16; xsquare++) {
- for (ysquare=0; ysquare<16; ysquare++) {
- if (visible[xsquare][ysquare]) {
- int objnum=objmap[xsquare][ysquare];
- if (objnum) { // If fixed object
- --objnum;
- int x=obj[objnum].mazex-xview;
- int y=obj[objnum].mazey-yview;
- int alignx=(x*COS(-viewing_angle)
- - y*SIN(-viewing_angle))>>16;
- int aligny=(x*SIN(-viewing_angle)
- + y*COS(-viewing_angle))>>16;
- if (aligny>=0) {
- distance=sqrt((long)alignx*alignx+(long)aligny*aligny);
- int projx=-(long)alignx*VIEWER_DISTANCE/distance+HORIZ_CENTER;
- obj[objnum].wdraw=obj[objnum].wbit*VIEWER_DISTANCE/
- distance;
- obj[objnum].hdraw=obj[objnum].hbit*VIEWER_DISTANCE/
- distance;
- obj[objnum].screenx=projx-(obj[objnum].wdraw >> 1);
- obj[objnum].screeny=VERT_CENTER-(obj[objnum].hdraw >> 1);
- obj[objnum].distance=distance;
- objlist[numobjs++]=objnum;
- } // End if
- } // End if
- } // End if
- } // End for
- } // End for
- if (numobjs) {
- int swap=-1;
- while (swap) {
- swap=0;
- for (int i=0; i<(numobjs-1); i++) {
- if (obj[objlist[i]].distance<obj[objlist[i+1]].distance) {
- int temp=objlist[i];
- objlist[i]=objlist[i+1];
- objlist[i+1]=temp;
- swap=-1;
- } // End if
- } // End for
- } // End while
- } // End if
- for (int i=0; i<numobjs; i++) {
- int level=litelevel[distance]+ambient_level;
- if (level>MAXLIGHT) level=MAXLIGHT;
- drawobject(&(obj[objlist[i]]),distance,&(litetable[level][0]),
- &(objects[objlist[i]][0]));
- } // End for
- }
-
- /*
- =============================
- =
- = Init_Engine()
- = Initializes the raycasting engine
- = and sets up look up tables etc.
- =============================
- */
-
- void Init_Engine(unsigned char **textures, int num_textures)
- {
- FILE *handle;
-
- // Load lightsourcing tables:
- if ((handle=fopen("ltable.dat","rb"))==NULL) {
- perror("Error");
- exit;
- }
- fread(litetable,MAXLIGHT+1,PALETTESIZE,handle);
- fclose(handle);
-
- // Calculate light intensities for all possible
- // distances:
- for (int distance=1; distance<MAXDISTANCE; distance++) {
- float ratio=(float)MAXLIGHT/distance*3;
- if (ratio>1.0) ratio=1.0;
- litelevel[distance]=ratio*MAXLIGHT;
- }
-
- for (int i = 0; i < 320; i++)
- wallangle[i] = atan((float)(i-160)/VIEWER_DISTANCE)*652.2293;
-
- // Create texture list array:
- for (i=0; i < num_textures; i++)
- {
- texturelist[i]=&(textures[i][0]);
- }
-
- for (i = 0; i < MAXDISTANCE; i++)
- distance_table[i] = 6144 / (i + 1) + VERT_CENTER;
- for (i = 0; i < MAXDISTANCE; i++)
- wheight[i] = 12288 / (i + 1);
-
- CalcViewport(0);
-
- i = 0;
-
- // Create door info.
- for (int x = 0; x < GRIDSIZE; x++)
- for (int y = 0; y < GRIDSIZE; y++)
- {
- if (walls[x][y] == 4)
- {
- doors[i].xpos = x;
- doors[i].ypos = y;
- doors[i].position = 4096;
- doors[i].speed = 8;
- i++;
- }
- }
- MAX_DOORS = i;
- }
-
- /*
- =============================
- = CalcViewport(int num)
- = Calculates new screen coordinates
- = for viewport
- =============================
- */
- void CalcViewport(int num)
- {
- VIEWPORT_LEFT=viewport_size[num].x1; // Dimensions of viewport
- VIEWPORT_RIGHT=viewport_size[num].x2;
- VIEWPORT_TOP=viewport_size[num].y1;
- VIEWPORT_BOT=viewport_size[num].y2;
- VIEWPORT_HEIGHT=VIEWPORT_BOT-VIEWPORT_TOP+1;
- VERT_CENTER=VIEWPORT_TOP+(VIEWPORT_HEIGHT >> 1);
- VIEWPORT_WIDTH=VIEWPORT_RIGHT-VIEWPORT_LEFT + 1;
- HORIZ_CENTER=VIEWPORT_LEFT+(VIEWPORT_WIDTH >> 1);
- column_angle1 = atan((float)(VIEWPORT_LEFT-HORIZ_CENTER)
- / VIEWER_DISTANCE)*(NUMBER_OF_DEGREES / 6.28);
-
- column_angle2 = atan((float)(VIEWPORT_RIGHT-HORIZ_CENTER)
- / VIEWER_DISTANCE)*(NUMBER_OF_DEGREES / 6.28);
- }
-
- /*
- =============================
-
- int GetDoorID(void)
- Returns door index at coordinates xmaze,ymaze
-
- =============================
- */
- int GetDoorID(int xpos, int ypos)
- {
- for (char i = 0; i < MAX_DOORS; i++)
- if (doors[i].xpos == xpos && doors[i].ypos == ypos) return(i);
- }
-