Home » Archimedes archive » Acorn User » AU 1997-10 B.adf » 3D » !AU_Attack/source/c/engine

!AU_Attack/source/c/engine

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1997-10 B.adf » 3D
Filename: !AU_Attack/source/c/engine
Read OK:
File size: C012 bytes
Load address: 0000
Exec address: 0000
File contents
/*
   engine.c : Written by Greg Scott   1997
   for Acorn User, as part of the "Virtual
   Worlds" series.

   Usage of the source code is done at the owners risk, and Acorn User or the   author hold no responsibility for damages.
*/

/* AUTHORS NOTE: A lot of the code in here is very complex, and can never be adequately explained. PLEASE PLEASE contact me for more assistance, it is much easier to address personal problems with the ideas than in general.

AUThreeD@aol.com

or contact the Acorn User offices and they will pass it on. Thank you. */

/* ANSI C includes */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
/* OTHER includes */

#include "our_lib.h"

/* DEFINES */

#define WORLD_WIDTH 64 /* This is the number of walls across in our world */
#define WORLD_HEIGHT 64 /* This is the number of walls down in our world */
#define WALL_WIDTH 64 /* This is the width of each wall in pixels */
#define WALL_HEIGHT 64 /* This is the height of each wall in pixels */
#define WALL_NUMBER 20 /* This defines the number of walls allowed */
#define CELL_X_SIZE 64 /* this is the size in units of each cell */
#define CELL_Y_SIZE 64 /* this is the size in units of each cell */
#define CELL_X_SIZE_FP 6 /* this is used in binary shifting */
#define CELL_Y_SIZE_FP 6 /* this is used in binary shifting */
#define FOUND_WALL 1 /* this flag is used to indicate when an intersection has be found */
#define MAX_DISTANCE 4000 /* this defines the largest distance a ray could travel in the world, used for look up tables */
#define MAX_SCALE 300 /* used for clipping */
#define CLOSEST 50 /* this stores the closest a player can walk into a wall */
/* NEW use of ANGLES variables, they are now not defines but are inputted by the command line at the beginning of main()*/

/* OLD defines have been converted to integers because we now load them in from the command line */
int ANGLE_0,ANGLE_6,ANGLE_30,ANGLE_90,ANGLE_180,ANGLE_270,ANGLE_360,STEP_LENGTH,VERTICAL_SCALE,VIEWVAR,VIEWVART,SCREEN_HEIGHT,SCREEN_WIDTH,DEMO_READ,DEMO_WRITE;

/* GLOBAL variables */

char world[WORLD_HEIGHT+1][WORLD_WIDTH+1];/* This holds our text data file */
char objects[WORLD_HEIGHT+1][WORLD_WIDTH+1]; /* NEW object array (as world)*/
char walls[WALL_NUMBER+1][(WALL_WIDTH*WALL_HEIGHT)+1];
char objgraphics[WALL_NUMBER+1][(WALL_WIDTH*WALL_HEIGHT)+1];
char bar_graphic[16001]; /* this holds the bottom bar on the screen */

/* This holds the wall graphics in a two dimensional array */
/* Note the usage of char and not "int" in both cases. This is because a char is 8 bytes, which gives 256 colours (used in our Mode 13 screen) and also an integer up to 256, when our text file doesn't go over 20 in number! Hence there is no need for an int array in either case. */

char *screen_address; /* this will hold the base of the screen memory which we will manipulate. By altering values in the screen memory, we alter what appears on the screen. Note that this is of type "char *" because it holds the memory address of a byte array - the 256 colour mode 13 screen (well it will do!) */
char *screen_address_bank; /* this is another pointer to the other area of screen memory which we will be using for SCREEN BANKING - avoiding flickering of the screen during animating graphics */
char *screen_address_temp; /* this is a spare pointer for use during the switching of the two above values */

/* these new FIXED POINT INTEGER pointers point to look-up tables used in the ray casting engine. These are explained of in the engine, but the look-ups are generated in aua_tables() */

int *tan_table,*inv_tan_table; /* pointers to tangent look_ups */
int *y_step,*x_step;           /* pointers to more complex look_ups */
int *inv_cos_table,            /* sin/cos tables (look_ups)    */
    *inv_sin_table;
int *cos_table;                /* cosinal look_up table    */
int *recip_table;              /* reciprocal table used instead of a */
                               /* division. See later */
int *coso_table,*sino_table;   /* these two tables are for objects */
int *dx_table,                 /* FIXED POINT tables for moving the */
    *dy_table;                 /* view point very quickly */
int scale_array[320];          /* NEW used to store scale values of each */
                               /* sliver,for objects later on */
int mirror_array[320];         /* used to flag if a mirror is in use */
/* FUNCTION definitions */

/* this function generates LOOK UP tables - arrays holding pre-calculated trigonometric variables used in the ray casting process */

void aua_tables(void)
{

int ang, /* this is used to hold values while making look-ups */
    angt; /* same */

float rad_angle; /* this holds the radians equivalent of the fixed point angle system (0-1920 = 0-360 degrees = 0-6.whatever radians. Next month I'll be changing the system so it becomes 0-1800 instead of 1920, this will allow a slightly smaller screen width, more like Wolfenstein, this will lead to an increase in frame rate. Yes! */

/* dynamically allocated adequate memory for the look-ups */
tan_table     = (int *)malloc(sizeof(int) * (ANGLE_360+1));
inv_tan_table = (int *)malloc(sizeof(int) * (ANGLE_360+1));

y_step        = (int *)malloc(sizeof(int) * (ANGLE_360+1));
x_step        = (int  *)malloc(sizeof(int) * (ANGLE_360+1));

cos_table     = (int  *)malloc(sizeof(int) * (ANGLE_360+1));
inv_cos_table = (int  *)malloc(sizeof(int) * (ANGLE_360+1));
inv_sin_table = (int  *)malloc(sizeof(int) * (ANGLE_360+1));
/* new table, for the engine, to avoid using a divide */
recip_table   = (int  *)malloc(sizeof(int) * (MAX_DISTANCE+1));
/* new tables for moving the view point */
dx_table      = (int  *)malloc(sizeof(int) * (ANGLE_360+1));
dy_table      = (int  *)malloc(sizeof(int) * (ANGLE_360+1));
/* generate them, their use is explained in the ray casting engine */
/* two new tables to use for object plotting */
coso_table     = (int  *)malloc(sizeof(int) * (ANGLE_360+1));
sino_table =     (int  *)malloc(sizeof(int) * (ANGLE_360+1));

printf("_tables: starting angle loop\n[.");
for(angt=ANGLE_0;angt<=ANGLE_360;angt++)
{
ang=angt;
/* this next line calculates the radian angle to pass to the trig. functions */
rad_angle=(float)((3.272e-4) + ang * 2*3.141592654/ANGLE_360);

tan_table[ang]=(int)(tan(rad_angle)*65536);
inv_tan_table[ang]=(int)((1/tan(rad_angle))*65536);
/* note tha above conversions to fixed point integers */

/* we do the same for these tables, but unfortunately at the asymptotes the numbers become awkwardly large to store in our fixed point representation. Instead of multiplying by 64 we do 8, to make sure that no overflow can occur at this stage. We only need to multiply by another 8 later in the engine, its okay */

if(ang>=ANGLE_0 && ang<ANGLE_180)
{
y_step[ang]=fabs( (8) * (tan_table[ang]) );
}
else
  y_step[ang]=-fabs( (8) * (tan_table[ang]) );

if(ang>=ANGLE_90 && ang<ANGLE_270)
{
x_step[ang]=-fabs( (8) * (inv_tan_table[ang]) );
}
else
{
x_step[ang]=fabs( (8) * (inv_tan_table[ang]) );
}

/* conversion to fixed point */
inv_cos_table[ang]=(int)((1/cos(rad_angle))*65536);
inv_sin_table[ang]=(int)((1/sin(rad_angle))*65536);
/* conversion to fixed point of object plotting sine and cosines */
sino_table[ang]=(int)(sin(rad_angle-1.570796327)*65536);
coso_table[ang]=(int)(cos(rad_angle-1.570796327)*65536);
/* work out tables for moving the viewpoint */
dx_table[ang]=(int)(cos(6.28*ang/ANGLE_360)*STEP_LENGTH)*65536;
dy_table[ang]=(int)(sin(6.28*ang/ANGLE_360)*STEP_LENGTH)*65536;
printf(".");
}

/* the cosine table is used to get rid of the "fish bowl effect", explained in the ray caster. Basically we work out cosines for our own span of vision, from -30 degrees to +30 degrees. This means that as we scan from left to right, or vice versa, our rays of light are actually cast out in a cartesian, circular way. Our world is however square, polar, so we have to acknowledge the distortion caused by mixing cartesian and polar coordinates. In this look up we also have a bit of scaling in it, yet more time saving !!! */

for(ang=-ANGLE_30;ang<=ANGLE_30;ang++)
{
/* work out radians to pass to cosine function */
rad_angle=(float)((3.272e-4)+ ang * 2*3.141592654/ANGLE_360);

/*fixed point conversion */
cos_table[ang+ANGLE_30]=(int)(VERTICAL_SCALE/(cos(rad_angle))*65536);
}
printf("......");
/* this creates a reciprocal table, so we don't have to use divides. Multiplying by the reciprocal of a number is the same as dividing by it: After all,

8 / 4 = 2 and 8 * 0.25 (1 over 4) = 2 - they produce the same result */

for(ang=1;ang<MAX_DISTANCE;ang++)
{
  /* it is still fixed point though */
  recip_table[ang]=(int)(1.0/(float)ang*65536);
}
printf(".]\n");
}

/* this function is the heart of the program, the engine, to generate the first person view */
void aua_raycaster(int view_x,int view_y,int view_angle)
{
/* remember that we are thinking in 2-D, not in 3D when we discuss ideas. Below does not mean "a floor below", it really means "behind", but we say below because we are imagining looking down on the view point to form a 2-D plan */

/* this function, for each column of the 320 pixel width Mode 13 screen, casts out two rays. One ray looks for X, horizontal intersections with walls, and the other tracks intersections with Y, vertical wall boundaries. After all, the only time a collision could occur is on a boundary of a cell, as the wall fills up the entire cell. Expect to see lots of 64's, though remember that this ray caster is very routine, and has not at all been put through my "box of magic". The engine will become much more personalised very soon! */



int cell_x, /* used to store which cell of the walls data the ray is in */
cell_y, /* " */
casting=2, /* used to store if ray casting has finished */
x_hit_type, /* this stores the wall type hit by the x casting ray */
y_hit_type, /* this sotres the wall type (number) hit by the y ray */
x_bound, /* this holds the next x boundary for a possible intersection */
y_bound, /* this holds the next y boundary for a possible intersection */
next_y_cell, /* this is used to figure out the quadrant of the ray (+/-)*/
next_x_cell, /* " */
x_delta, /* this is +'d to the x_bound var. to move to the next boundary */
y_delta, /* this is +'d to the y_bound var. to move to the next boundary */
xi_save, /* this stores where the x casting ray made its intersection */
yi_save, /* this stores where the y casting ray made its intersection */
scale,   /* this stores the scale of the sliver to be drawn in each column */
ray, /* this stores the ray number being cast out (0-320)*/
xray, /* this flag is used to show if casting is over */
yray, /* " */
dist_x, /* this holds the distance to the x intersection */
dist_y; /* this holds the distance to the y intersection */

int   xi,
      yi,
      xadd,
      yadd; /* these are used to accurately trace and move each ray      */

int variables[6], /* this is used to pass variables to a sliver renderer  */
    clip;      /* this could be used later for clipping */
int xtrans_dist, /* these NEW TRANSPARENT variables are used for windows  */
    ytrans_dist, /* each one will be used later to draw transparent walls */
    xtrans_col,
    ytrans_col,
    xtrans_type,
    ytrans_type,
    xtrans_done,/* these last two are used as flags to mark if a transpar-*/
    ytrans_done;/*ency has been found or not */

int counter=0;
/* firstly, we set up the variables[] we already know, such as screen_address, walls and the screen height we are using. These are all things which our sliver renderer needs to know to plot its column */

variables[0]=(int)screen_address;


/* now we get down to the nitty gritty. Here we subtract 30 degrees from the viewing angle remember that our FOV is 60 degrees which means that we cast from -30 to +30 */

if ( (view_angle-=ANGLE_30) < 0)
   {
   /* this ensures that we don't go over or under 0/360 degrees! */
   view_angle=ANGLE_360 + view_angle;
   }
/* now we start the main loop, start at the right of the screen (319), and cast each column one by one to the left */

for (ray=SCREEN_WIDTH-1; ray>=0; ray--)
    {
/* for each ray to be cast we actually cast out two rays : one to check for vertical boundary collisions and the other to check for horizontal boundary collisions. Considering that walls fill up each cell, we need only look for intersections on the boundaries. We have to perform seperate cast because just casting one ray complicates the matter and it doesn't give much speed increase, if any. */

/* NEW LINE : We have to check to see if the viewing angle is at the asymptotes, unfortunately the fixed point system cannot store the values held at these angles, so we have to avoid their use. This is not very elegant I know, but it saves a lot of head aches and no one can tell we've done it! */

if(view_angle==ANGLE_0 || view_angle==ANGLE_90 || view_angle ==ANGLE_180 || view_angle==ANGLE_270)view_angle++;
/* SECTION 1 : CALCULATING THE FIRST X and Y INTERSECTIONS*/
/* Once we have done this the following intersections are easy*/


/* The X CASTING RAY : here we test to see if the angle of the ray is facing upwards. We need to know which halfplane we're casting from relative to the y-axis. */


 if (view_angle >= ANGLE_0 && view_angle < ANGLE_180)
       {
/* if so then we assign variables to that effect. We must compute the first horizontal line that could be intersected with the ray. Note : it will be above the viewer.*/

y_bound = (CELL_Y_SIZE + (view_y & 0xffc0)); /* this line is merely an optimized version of CELL_Y_SIZE + (view_y % 64). I use it many times in this engine. */

y_delta = CELL_Y_SIZE; /* this means that for every movement of the ray, the y boundary moves up one cell, which it would. It is the delta to get to the next horizontal line */

/* next we use the inverse tan function to calculate the initial position of the x boundary searching ray on its first intersection. We have to use tan because it is related to slopes */

/* NEW FIXED POINT CALCULATION of
xi = (float)(inv_tan_table[view_angle] * (y_bound - view_y)) +view_x; */

xi=((y_bound-view_y))*(inv_tan_table[view_angle]);
xi+=(view_x<<16);

/* this means that the quadrant of the ray is not negative, that is the next y boundary will appear above the view point and not below (in terms of looking down on the viewer). This is the cell delta */
next_y_cell = 0;

       }
/* if the viewing angle is greater than 180 degrees and less than 270 degrees then we have to do other calculations (lower half plane) */
    else
       {
/* we know that because the viewing angle is downwards, so then the horizontal intersection has to be BELOW the viewer */
y_bound = (int)(view_y & 0xffc0);

/* because of this we also know that the next Y intersections will be a cell below each other. So the delta for each horizontal intersection will be a cell below  the last */
y_delta = -CELL_Y_SIZE;

/* we again use the tangent function, just as before, to calculate the first x intersection with a boundary. */

/* NEW FIXED POINT, I won't show the old lines any more */

xi=((y_bound-view_y))*(inv_tan_table[view_angle]);
xi+=(view_x<<16);

/* and we know also that the quadrant is below the player, so the cell y delta will be negative */

next_y_cell = -1;

       }
/* Y RAY : we do similar calculations but this time to calculate the first y intersections */

/* we test to see if the view angle is within the vertical asymptotes of 360 degrees. We need to know which halfplane we're casting from relative to the x-axis. */

if (view_angle < ANGLE_90 || view_angle >= ANGLE_270)
       {
/* we can deduce certain things, just as with the x ray. We know that because the view angle is to the right, the next X boundary (which is constant) will be to the RIGHT of the viewer. */
x_bound = (int)(CELL_X_SIZE + (view_x & 0xffc0));

/* notice this recurring optimization of view_x % 64 */

/* and we also know that each vertical cell boundary after the first will be a cell's width away */

x_delta = CELL_X_SIZE;
/* this time we use the tangent function (not the inverse tan) to calculate where the first y boundary intersection will occur). */

/* NEW FIXED POINT */

yi=((x_bound - view_x))*(tan_table[view_angle]);
yi+=(view_y<<16);
/* and we know also that because the view is positive, the next_x_cell delta does not need to be negative */

next_x_cell = 0;

       }
/* otherwise, if the viewing angle is towards the other direction...*/
    else
       {
/* we know that the first x boundary can occur only to the left of the viewer because the ray angle is facing left. So we can do view_x % 64 to calculate the first vertical boundary, this should be becoming obvious */
x_bound = (int)(view_x & 0xffc0);

/* we also know that the delta for the cell will be to the left, each time the ray moves to the next boundary the next vertical intersection will be a cell to the left than the last. */
x_delta = -CELL_X_SIZE;

/* we use the tangental function again to calculate the position on the horizontal intersections */

/* NEW FIXED POINT */

yi=((x_bound - view_x))*(tan_table[view_angle]);
yi+=(view_y<<16);
/* and we also know that the x cell value will be minus, because as the ray moves to another cell, because the ray is going left, the value must be minus. */
next_x_cell = -1;

       }

/* Now we have performed the slightly tricky task of the first intersections, we can move on to calculating the next ones. This is more simple, as we know that the intersections can only occur at cell boundaries.*/

/* SECTION 2 : Testing for further intersections */

/* these flags store if casting of both rays is complete */
xray=yray=xtrans_done=ytrans_done=0;

/* X Ray is first */
/* because we are testing for each next intersection, we can figure out more easily the following intersections. */
/* this is a look up table holding the next y intercepts, based on the tangental function and the size of cells. Basically we add this to the ray each time we move it a bit more, searching for a wall at a cell boundary */

/* NEW FIXED POINT, note the shift 3 times to the left, the equivalent of a multiply by 8, this takes no time, and really I don't know why I've done it like this! It works. */

xadd=y_step[view_angle]<<3;

/* start casting the x ray */
while(!xray)
{
/* compute current cell position of the ray to inspect*/

cell_x = ( (x_bound+next_x_cell) >> CELL_X_SIZE_FP);
/* Note we have to shift not only by 6, but also by 16 to convert BACK to normal maths */
cell_y = (int)yi>>22;

/* both of the above examples use binary shifting to achieve a divide by 64. Cell_y computation uses identical techniques to those covered in the magazine. Cell_x is calculated by using the x_bound and next_x_cell values calculated beforehand. */

if(cell_x<0)cell_x=0;if(cell_x>63)cell_x=63;
if(cell_y<0)cell_y=0;if(cell_y>63)cell_y=63;
/* these simple lines ensure that the ray doesn't go out of the world, though they aren't really needed. */

/* we look up in the world file to see if there is a wall at the intersection of our ray */

if ((x_hit_type =world[cell_y][cell_x])!=0)
{
 /* or any (extra or different) tile value you wish */
if(x_hit_type==9 || x_hit_type==7 || x_hit_type==10){
  /*THEN THE WALL IS TRANSPARENT!!!*/
 xtrans_dist=((yi-(view_y<<16))>>8)*(inv_sin_table[view_angle]>>8);
 xtrans_type=x_hit_type;
 xtrans_col=((int)(yi>>16) & 0x003f);
 xtrans_done=FOUND_WALL;
/* we record all required details then continue */
                 }

else
{
/* if so we calculate the distance to it using the old O-Level technique of using sine and cosine instead of doing the standard PYTHAGORAS technique.*/

/* NEW FIXED POINT calculation, notice that in this next line we have both a conversion TO fixed point (view_y) and also the check against over flow is very apparent, we share the accuracy. See the article for more details */

dist_x  = ( (yi - (view_y<<16))>>8) * (inv_sin_table[view_angle]>>8);
/* we also save the exact position of the intersection because we will need it later to add texture mapping. */

/* We save yi after converting it back to normal maths */

yi_save = (int)yi>>16;

/* because the x ray has found a wall, we can stop casting */
xray=FOUND_WALL;

}
}


/* if not, we compute the next possible intersection */
yi +=xadd; /* FIXED POINT ADDITION requires no extra work */
x_bound += x_delta; /* and we also calculate the next horizontal boundary, which we know will be x_delta away, no need for complex workings. */

}
/* SECTION 3 */
/* WE NOW do exactly the same but for the yray, we cast it out, check for a wall, if there is one we take the distance to it etc, if not, we move  the ray until a wall it found. */

/* look up the value to add to the ray each time we move it */

/* See above for more information, this is FIXED POINT remember */
yadd=x_step[view_angle]<<3;

/* start casting the ray */
while(!yray)
{

/* compute current cell to inspect */

/* Because XI IS IN FIXED POINT we have to not only divide by 64 but also we have to convert BACK to normal maths */

cell_x = (int)xi>>22;
cell_y = ( (y_bound + next_y_cell) >> CELL_Y_SIZE_FP);
/* these calculations work out which cells the ray is in, ready to check for walls in the world[][] array. They both use binary shifting to perform divide by 64's. */

/* check that the ray has not gone out of the world, though this isn't really necessary */
if(cell_x<0)cell_x=0;if(cell_x>63)cell_x=63;
if(cell_y<0)cell_y=0;if(cell_y>63)cell_y=63;

/* look and see if there is a wall at the current point of intersection */

if ((y_hit_type = world[cell_y][cell_x])!=0)
{
if(y_hit_type==9 || y_hit_type==7 || y_hit_type==10){
  /*THEN THE WALL IS TRANSPARENT!!!*/
ytrans_dist=((xi-(view_x<<16))>>8)*(inv_cos_table[view_angle]>>8);
ytrans_type=y_hit_type;
ytrans_col=((int)(xi>>16) & 0x003f);
ytrans_done=FOUND_WALL;
}
/* we record all required details then continue */

else
{



/* Use the old O-Level triangle method of calulating distance using cos, rather than using PYTHAGORAS, which is slower because it uses a square root! */
/* FIXED POINT calculation, just the same as the inv_sin calculation see above. */
dist_y  = ( (xi - (view_x<<16))>>8) * (inv_cos_table[view_angle]>>8);

/* save the exact intersection point, we will need it later */
/* Same as aobve, very simple conversion back from FIXED POINT to normal maths */
xi_save = (int)xi>>16;
/* STOP y casting in that case, a wall has been found. */
yray=FOUND_WALL;
}
}


/* if not, move the ray on */
xi+=yadd; /* AGAIN, no extra work is required for FIXED POINT ADDITION */
y_bound += y_delta; /* and move to the next vertical boundary position */



}

/* SECTION 4*/
/* Both rays have been cast, both rays have met a wall, we now need to see which is closer, and then plot it correctly. */

/* find out which wall (x or y) is nearer the viewer. */

/* we have altered this distance checking line to avoid minus distances being selected to draw, which produces large spikes on the screen! Again this is because of fixed point */

    if (dist_x < dist_y && dist_x>0 || dist_y<0)

       {


/* we need to take into account here, when computing the scale of the vertical strip (sliver) to be drawn, a phenemenon (of sorts) known as the "fish bowl effect". This is caused by mizing of cartesian and polar coordinates. To get rid of it we use the cosine function. I have combined other multiplies of a vertical scaling factor with the cosine transformation to save time. All we eventually be explained. You could replace the line with scale=13312/dist_x++ and see what weird results you get! */

/* NEW NEW NEW : We have fixed point here, and using the reciprocal table (see around) we don't have to do a lengthy divide! Notice how we convert dist_x back to normal to index the recip_table array, and that all accuracy is lost with the cos_table, because all its figures are above zero (see aua_tables) and also that we actually convert the whole answer back to normal maths for scale */

scale = (int)( (cos_table[ray]>>16) * (recip_table[dist_x>>16]) >>16);

/* assign the variables we need to the variables to be passed to the ASM sliver renderer (super fast!) */
if(scale>SCREEN_HEIGHT)
{

  scale=SCREEN_HEIGHT-1;
}

variables[2]=scale; /*stores the scale of the strip (height of it)*/
variables[3]=ray; /* we use ray as the x position to plot to (0-319)*/
variables[1]=(int)&walls[x_hit_type][(yi_save & 0x003f)];
variables[4]=(recip_table[scale]<<6);
/* and we call the assembler function (explained at a later date)*/
ourlib_new(&variables[0]);
scale_array[ray]=scale;
       }
/* else the dist_y was nearer, everything from above applies */
    else
       {

/* avoid fish bowl effect and scale properly with FIXED POINT clever bits!, see above */
scale = (int)( (cos_table[ray]>>16) * (recip_table[dist_y>>16]) >> 16);


/* set up variables for our sliver engine, see above */
if(scale>SCREEN_HEIGHT)
{

  scale=SCREEN_HEIGHT-1;
}

variables[2]=scale; /*stores the scale of the strip (height of it)*/
variables[3]=ray; /* we use ray as the x position to plot to (0-319)*/
variables[1]=(int)&walls[y_hit_type+1][(xi_save & 0x003f)];
variables[4]=(recip_table[scale]<<6);
/* notice we add one to the wall graphic selection, so the darker tile is used for added variation. See the article for more details of this sort of shading, if you want to call it that! */

/* call our sliver engine */
ourlib_new(&variables[0]);
scale_array[ray]=scale;
       }
/* it is here that we draw the overlaying transparent wall */
if(xtrans_done && xtrans_dist<dist_y)
{
  scale=(int)((cos_table[ray]>>16) * (recip_table[xtrans_dist>>16])>>16);
  if(scale>SCREEN_HEIGHT)scale=SCREEN_HEIGHT-1;
  variables[2]=scale;
  variables[3]=ray;
  variables[4]=(recip_table[scale]<<6);
  variables[1]=(int)&walls[xtrans_type][xtrans_col];

/* now call our special function which treats color 0 as a mask */

ourlib_new_mask(variables);
mirror_array[ray]=0;
if(xtrans_type==10)mirror_array[ray]=255;
else scale_array[ray]=scale;
}
else if(ytrans_done && ytrans_dist<dist_x)
{
  scale=(int)((cos_table[ray]>>16) * (recip_table[ytrans_dist>>16])>>16);
  if(scale>SCREEN_HEIGHT)scale=SCREEN_HEIGHT-1;
  variables[2]=scale;
  variables[3]=ray;
  variables[4]=(recip_table[scale]<<6);
  variables[1]=(int)&walls[ytrans_type][ytrans_col];

/* now call our special function which treats color 0 as a mask */

ourlib_new_mask(variables);

mirror_array[ray]=0;
if(ytrans_type==10)mirror_array[ray]=255;
else scale_array[ray]=scale;
}




/* this ray has been finished. Increase the angle of the next ray and start again! */

    if (++view_angle>=ANGLE_360)
       {
       /* this ensures that the ray angle doesn't go over 360 degrees! */
       view_angle=0;

       }
/* ray loop */
    }
/* end ray caster engine */
/* objects*/


}



/* this function grabs all the different walls from a single file */

void aua_graphics(void)
{
int x, /* this is used to store the x coordinate of a point on the screen */
    y, /* this is used to store the y coordinate of a point on the screen */
    wall_number; /* this will be used to index the walls[x][] char array */

/* first of all we get the graphics file <AUARay$Dir>.graphics onto the screen */

system("*ScreenLoad <AUARay$Dir>.graphics");

/* next we start grabbing each tile, 64 x 64 pixels, into the walls[][] array */

/* we use this large for loop at the ourlib_bitmap_grab function to invidually grab each tile into its own walls[x][] array slot, note that we CAN'T HAVE WALL 0 as this represents a gap in the world! */

ourlib_killcursor(); /* get rid of cursor first */

for(wall_number=1,y=0;y<256;y+=WALL_HEIGHT)for(x=0;x<320;x+=WALL_WIDTH,wall_number++)
{
/* this calls the function ourlib_bitmap_grab (I said it would be handy!) which grabs the area of screen memory marked by the first four parameters, stores it in the byte array pointer in parameter five, reading it all from the screen pointed to by screen_address */

ourlib_bitmap_grab(x,y,x+WALL_WIDTH-1,y+WALL_HEIGHT-1,&walls[wall_number][0],screen_address);

/* this makes sure we don't go over our number of walls limit */

if(wall_number>=WALL_NUMBER)break;
}

/* new stuff load in objects separately */
/* see above for comments (its identical) */
system("*ScreenLoad <AUARay$Dir>.Objgraphic");
ourlib_killcursor();

for(wall_number=1,y=0;y<256;y+=WALL_HEIGHT)for(x=0;x<320;x+=WALL_WIDTH,wall_number++)
{
ourlib_bitmap_grab(x,y,x+63,y+63,&objgraphics[wall_number][0],screen_address);
if(wall_number>WALL_NUMBER)break;
}

/* NEW bottom bar graphics code, here we grab the sprite */
system("*screenload <AUARay$Dir>.Bottombar");
ourlib_bitmap_grab(0,206,319,255,bar_graphic,screen_address);


}

/* this function loads in the data from our world text file and stores it in the world[][] array */

void aua_world(void)
{

FILE *world_file; /* we need a file pointer as we will be loading in text */

int row, /* this will be used to index the world[][] array */
    column,counter=0; /* this will be used to index the world[][] array */

char ch; /* this is used to store each number as it is loaded in */

/* open the world file, if it is not there then exit the program */

if(!(world_file=fopen("<AUARay$Dir>.world","r")))exit(1);

/* this program loads in the data from the world file, row by row, column by column using the getc() ANSI function */

for(row=0;row<WORLD_HEIGHT;row++)
{
for(column=0;column<WORLD_WIDTH;column++)
{
while((ch=getc(world_file))==10){} /* this filters out any mess, though not often used! */

if(ch==' ')ch=0; /*this ensures the correct value is stored, if there is a gap in the file, this means a space in the world, a zero */
else ch=ch-'0';

/* this new line will (should!) convert letters into their appropriate number */

if(ch>15)ch-=7;

world[(WORLD_HEIGHT-1)-row][column]=ch; /* this finally stores the value in the correct position */

/*printf("%d",ch); uncomment this line to see the world data loaded in */
}
/*printf("\n"); uncomment this line to see the world data loaded in */
}

/* when all is done, close the file */
fclose(world_file);

/* new part to load in object data, see above for comments */

if(!(world_file=fopen("<AUARay$Dir>.objworld","r"))) exit(1);
for(row=0;row<WORLD_HEIGHT;row++)
{
  for(column=0;column<WORLD_WIDTH;column++)
  {
  while((ch=getc(world_file))==10){}
  if(ch==' ')ch=0;
  else ch=ch-'0';
  if(ch>16)ch-=7;

objects[(WORLD_HEIGHT-1)-row][column]=ch;

  }
}

fclose(world_file);

}


/* NEWER MAIN function .

All changes are commented */

void main(int argc,char *argv[])
{
  int view_x, /* this holds the viewing x coordinate */
      view_y, /* this holds the viewing y coordinate */
      view_angle; /* this holds the viewing angle in fixed units 0-1920 */

  int
      done=0,    /* flag to indicate if the user wants to quit */
      dx,        /* movement variables for the viewer */
      dy,
      y_cell,    /* these NEW variables are used to store the player/viewer*/
      x_cell,    /* world positions, for calculating viewer hitting walls */
      y_sub_cell,
      x_sub_cell,
      time_start,
      time_finish, /* These last few variables are used to work out */
      frames=0,    /* the frames per sec. of the system, slow for now! */
      door_x,
      door_y,      /* These new variables will be used for door things */
      screen_limit;

/* New Object Code ***************** Added Article 5 - good stuff ! */
int object_x,object_y,trans_x,trans_z,screen_x,screen_y1,screen_y2,temp_1,counter,scale,variables[7],index,increment,grid_x,grid_y,object_type,start_x,start_y,stop_x,stop_y,move_x,move_y,tview_x,tview_y,tview_angle;
/* New Object Code Variables Over *************** See Later in Main() */
/* NEW object MOVING code and arrays are now in this function */

 /* pattern of movements */
float object_move_increment=0.0000;               /* amount to add to index each frame */
float object_move_index=0.0000;
int object_temp_move_index=0;
int object_move_found=0;            /* flag to say if moving object found */
   /* values to hold moving object */
int object_move_new_x,object_move_new_y; /* new values of object */

/* NEW demo file which can load/store demo information for a walkthrough*/

FILE *demo_file;

/* NEW system of passing, we use the standard argc and argv to supply parameters to the engine. FIRST we must extract them:*/

/* check that correct number of parameters have been passed */

if(argc!=15)
{
/* quit if not */
printf("Error: Incorrect number of parameters passed. _Exiting\n"); exit(1);
/* "beep" (on most machines)*/ putchar('\a');
}
/* use atoi to get it right */
/* INPUT ALL VALUES FROM COMMAND LINE using ATOI and then work out needed*/
/* angle values for the ray casting engine. */
view_x=atoi(argv[1]);
view_y=atoi(argv[2]);
view_angle=atoi(argv[3]);
SCREEN_WIDTH=atoi(argv[4]);
SCREEN_HEIGHT=atoi(argv[5]);
ANGLE_360=atoi(argv[6]);
ANGLE_180=ANGLE_360/2;ANGLE_90=ANGLE_180/2;
ANGLE_6=atoi(argv[9]);
ANGLE_30=(int)ANGLE_90/3;
ANGLE_0=0;
ANGLE_270=ANGLE_90*3;
VERTICAL_SCALE=atoi(argv[7]);
STEP_LENGTH=atoi(argv[8]);
VIEWVAR=atoi(argv[10]);
VIEWVART=atoi(argv[11]);
DEMO_READ=atoi(argv[12]);
DEMO_WRITE=atoi(argv[13]);
object_move_increment=atoi(argv[14]);
/* convert object_inrement properly */
if(object_move_increment==0)object_move_increment=1;
object_move_increment=(float)1/object_move_increment;

screen_limit=(320-SCREEN_WIDTH)>>2;
/* Now we print the information just for the information of the user */
printf("_pre-start: switching to Mode (15) - high res for text.\n");
ourlib_changemode(15);
printf("############## SYSTEM START-UP ###################\n");
printf("_system variables: view_x: %d view_y: %d view_angle: %d\nscreen_width: %d screen_height: %d\nangle_360: %d vertical_scale: %d step_length: %d\nviewvars: %d %d\ndemo_read: %d demo_write: %d object_move_increment: %f\n\n",view_x,view_y,view_angle,SCREEN_WIDTH,SCREEN_HEIGHT,ANGLE_360,VERTICAL_SCALE,STEP_LENGTH,VIEWVAR,VIEWVART,DEMO_READ,DEMO_WRITE,object_move_increment);


if(DEMO_WRITE==1){
if(!(demo_file=fopen("<AUARay$Dir>.demo","w")))exit(1);
printf("_file access: writing to file\n");
}
else if(DEMO_READ==1)
{
  if(!(demo_file=fopen("<AUARay$Dir>.demo","r")))exit(1);
  printf("_file access: reading demo file\n\n");
}

/* DONE. Now continue as normal with the program */
/* It is here that we see if the DEMOFLAG is set to read/write demos */



/* now we call aua_world to load in the text world file which defines our walls type and layout */

printf("\n_file access: loading in text file <AUARay$Dir>.world\n\n");
aua_world();

/* check to see if the viewer is inside a game cell WALL, which would be bad news! */

if(world[view_y>>6][view_x>>6])
{
  printf("\n_error: Bad coordinates given, viewer is IN a WALL!, exiting\n");
  exit(1);
}

/* now we call aua_tables to generate some look-up tables for the engine to use, look-ups are explained up at the top of the file next to the global variables */

printf("_main: call aua_tables() (long time on slower machines)\n\n");
/* newer fixed point version */
aua_tables();

/* all is done in terms of input for now. We need to switch to Mode 13 */

printf("_screen: switching to Mode 13\n\n");

/* call ourlib_changemode to switch to mode 13 */

ourlib_changemode(13);

/* call ourlib_findscreen to get the screen base address of mode 13,  without the correct address we can't draw anything and the computer could crash */

screen_address=(char *)ourlib_findscreen();
/* NEW LOAD TITLE SCREEN */
system("*ScreenLoad <AUARay$Dir>.title");ourlib_killcursor();
ourlib_wait(200);
/*ourlib_screen_dissolve(screen_address,81920); USE IF WANTED */

/* THEN WAIT THEN SCREENDISSOLVE OUT, see above */

/* now we need to *screenload our graphics file, and grab each individual wall graphic one by one, the function aua_graphics does this */

aua_graphics();


/* NOW we call setup_screens, a small function which helps with banking */
/* With all the data loaded in we shall try and initiate SCREEN BANKS. First we change to MODE 15, so that screen memory becomes available for two times MODE 13 */

ourlib_setup_screens();
ourlib_changemode(15);

/* Now we switch to MODE 13, and get the first screen address */

ourlib_changemode(13);
ourlib_killcursor();

screen_address=(char *)ourlib_findscreen();

/* NEW code to plot the bottom bar on the screen */
ourlib_bitmap_plot(0,206,319,255,bar_graphic,screen_address);

/* Now we switch to the other screen bank and get the other screen address */

ourlib_simpleswitch();

screen_address_bank=(char *)ourlib_findscreen();
ourlib_slowclear(screen_address_bank,81920,0);
ourlib_bitmap_plot(0,206,319,255,bar_graphic,screen_address_bank);


ourlib_killcursor();
/* Switch back to the other screen */

ourlib_simpleswitch();

/* NOW we can call setup background, to tell the screen clearer the colour of the floor and ceilings we want.*/

ourlib_setup_background(208,45);

/* NOW we can start the main loop, exitable only by pressing the Q key. Use the Cursors to move the viewpoint around */
/* We shall also take a reading to work out the frame rate of the system, slow for now */

/* NEW ADJUSTING LINES : we add an offset to both screen memory areas in order to centre the image in the middle of the screen no matter what size */

screen_address+=(320-SCREEN_WIDTH)>>1;
screen_address_bank+=(320-SCREEN_WIDTH)>>1;

ourlib_killcursor(); /* get rid of the cursor flashing away */
time_start=ourlib_gettime();

while(!done) /* the loop will continue until done */
{

 ourlib_fastclg_two(screen_address,SCREEN_WIDTH,SCREEN_HEIGHT); /* we call the floor/ceiling function to colour the whole screen */
/* then we call the ray caster to draw over it */
 aua_raycaster(view_x,view_y,view_angle);

dx=dy=0;

/* now we test for different key presses and take action accordingly */

if(ourlib_keydown(16)==255)done=1; /* if Q is pressed then quit */

/* LEFT */
if(ourlib_keydown(121)==255)
{
  if((view_angle-=ANGLE_6)<ANGLE_0)
  view_angle=ANGLE_360;
}

/*RIGHT */
if(ourlib_keydown(25)==255)
{
  if((view_angle+=ANGLE_6)>ANGLE_360)
  view_angle=ANGLE_0;
}
/* UP and DOWN */
if(ourlib_keydown(57)==255)
{
  dx=dx_table[view_angle];
  dy=dy_table[view_angle];
}

if(ourlib_keydown(41)==255)
{

  dx=-dx_table[view_angle];
  dy=-dy_table[view_angle];
}

/* NOW we need to move the player and recalculate the cell the viewer is in, and ALSO check to see if the player has hit a wall */

/* Watch for the conversions of fixed point and things */

/* Player X actually is in normal maths */
 view_x= (int)((view_x<<16)+dx)>>16;
 view_y= (int)((view_y<<16)+dy)>>16;

/* DEMO HANDLING CODE COMES HERE */
/* Note that this is described briefly in article 5 */

if(DEMO_WRITE || DEMO_READ)
{
tview_x=view_x;
tview_y=view_y;
tview_angle=view_angle;
if(DEMO_WRITE)
{
  /* These lines can be used to record the direction of a moving object*/
  /*tview_angle=19;
  if(view_angle>ANGLE_0 && view_angle<ANGLE_90)tview_angle=19;
  if(view_angle>=ANGLE_90 && view_angle<ANGLE_180)tview_angle=17;
  if(view_angle>=ANGLE_180 && view_angle<ANGLE_270)tview_angle=15;
  if(view_angle>=ANGLE_270 && view_angle<ANGLE_360)tview_angle=10;*/

  fprintf(demo_file,"%d %d %d ",tview_x,tview_y,tview_angle);

}
if(DEMO_READ)if((fscanf(demo_file,"%d %d %d ",&tview_x,&tview_y,&tview_angle))==EOF)rewind(demo_file);
view_x=tview_x;
view_y=tview_y;
view_angle=tview_angle;
}
/* NEW OPTIMIZED VERSIONS OF MOVING THE PLAYER */

 x_cell = view_x>>6;
 y_cell = view_y>>6;

 x_sub_cell = view_x & 0x003f;
 y_sub_cell = view_y & 0x003f;

/* CHECK to see if player has walked into walls */
 if ((dx>>8)>0 ){
 if ((world[y_cell][x_cell+1] != 0)  && (x_sub_cell>(CELL_X_SIZE-CLOSEST)))
                {
                view_x-= (x_sub_cell-(CELL_X_SIZE-CLOSEST ));
                }
                }
 else
 {
 if ( (world[y_cell][x_cell-1] != 0)  && (x_sub_cell < (CLOSEST) ) )
                {
                view_x+= (CLOSEST-x_sub_cell) ;
                }
 }

 if ((dy>>8)>0 ){
 if ( (world[(y_cell+1)][x_cell] != 0)  &&
                (y_sub_cell > (CELL_Y_SIZE-CLOSEST ) ) )
                {
                view_y-= (y_sub_cell-(CELL_Y_SIZE-CLOSEST ));
                }
                }
 else
 {
 if ( (world[(y_cell-1)][x_cell] != 0)  && (y_sub_cell < (CLOSEST) ) )
                {
                view_y+= (CLOSEST-y_sub_cell);
                }
 }



/* NEW DOOR code. A "probe" is sent out in front of the player, if a door tile is found near it then the block is destroyed. */

if(ourlib_keydown(98)==255)
{
/* Use similar techniques to above to find door */

dx=dx_table[view_angle];
dy=dy_table[view_angle];

/* Calculate door x and y, it is in normal maths */
 door_x= (int)((view_x<<16)+(dx<<3))>>16;
 door_y= (int)((view_y<<16)+(dy<<3))>>16;

/* NEW OPTIMIZED VERSIONS OF FINDIN DOORS */
/* now find the cell we are looking in with the standard equation */

 x_cell = (int)door_x>>6;
 y_cell = (int)door_y>>6;

/* Check if a doors is present */

if(world[y_cell][x_cell]==7 /* OR WHATEVER YOU LIKE */)
{
world[y_cell][x_cell]=0; /* or alternatively do what you like */
}
}


/* NEW SIMPLE SHOOTER code. You can add as many further tests as you like */
/* Like many additions this month, this is just a simple starter for you all */

if(ourlib_keydown(7)==255)
{
/* Use similar techniques to above to find door */
putchar('\a');
dx=dx_table[view_angle];
dy=dy_table[view_angle];


 door_x= (int)((view_x<<16)+(dx<<1))>>16;
 door_y= (int)((view_y<<16)+(dy<<1))>>16;



 x_cell = (int)door_x>>6;
 y_cell = (int)door_y>>6;
/* Check if a object is present */
if(objects[y_cell][x_cell]/* OR WHATEVER YOU LIKE */)
{
objects[y_cell][x_cell]=0; /* or alternatively do what you like */
}
else
{


 door_x= (int)((view_x<<16)+(dx<<2))>>16;
 door_y= (int)((view_y<<16)+(dy<<2))>>16;

 x_cell = (int)door_x>>6;
 y_cell = (int)door_y>>6;
/* Check if a object is present */
if(objects[y_cell][x_cell]/* OR WHATEVER YOU LIKE */)
{
objects[y_cell][x_cell]=0; /* or alternatively do what you like */
}
else
{

/* Calculate bullets x and y, it is in normal maths */
 door_x= (int)((view_x<<16)+(dx<<3))>>16;
 door_y= (int)((view_y<<16)+(dy<<3))>>16;

 x_cell = (int)door_x>>6;
 y_cell = (int)door_y>>6;
/* Check if a doors is present */
if(objects[y_cell][x_cell]/* OR WHATEVER YOU LIKE */)
{
objects[y_cell][x_cell]=0; /* or alternatively do what you like */
}

}

}





}



/* New Object Code ****************** Added Article 5, good stuff!   */
/* This code cycles through the objects and plots them appropriately
   if they are visible by the viewer. See ARTICLE 5 for more details.*/

/* Firstly, set up variables we know are going to be used */
variables[0]=(int)screen_address;
variables[2]=SCREEN_HEIGHT;
/* Next we loop through all the visible squares to see if an object has been found */

if(view_angle>ANGLE_0 && view_angle<ANGLE_90)
{
start_x=(view_x>>6)+15;
start_y=(view_y>>6)+15;
stop_x=(view_x>>6)-5;
stop_y=(view_y>>6)-5;
move_x=-1;
move_y=-1;
if(stop_x<0)stop_x=0;if(stop_x>63)stop_x=63;
if(start_x<0)start_x=0;if(start_x>63)start_x=63;
if(stop_y<0)stop_y=0;if(stop_y>63)stop_y=63;
if(start_y<0)start_y=0;if(start_y>63)start_y=63;


}
else if(view_angle>=ANGLE_90 && view_angle<ANGLE_180)
{
  start_x=(view_x>>6)-15;
  start_y=(view_y>>6)+15;
  stop_x=(view_x>>6)+5;
  stop_y=(view_y>>6)-5;
move_x=1;
move_y=-1;
if(stop_x<0)stop_x=0;if(stop_x>63)stop_x=63;
if(start_x<0)start_x=0;if(start_x>63)start_x=63;
if(stop_y<0)stop_y=0;if(stop_y>63)stop_y=63;
if(start_y<0)start_y=0;if(start_y>63)start_y=63;
}
else if(view_angle>=ANGLE_180 && view_angle<ANGLE_270)
{
  start_x=(view_x>>6)-15;
  start_y=(view_y>>6)-15;
  stop_x=(view_x>>6)+5;
  stop_y=(view_y>>6)+5;
move_x=1;
move_y=1;
if(stop_x<0)stop_x=0;if(stop_x>63)stop_x=63;
if(start_x<0)start_x=0;if(start_x>63)start_x=63;
if(stop_y<0)stop_y=0;if(stop_y>63)stop_y=63;
if(start_y<0)start_y=0;if(start_y>63)start_y=63;
}
else
{

  start_x=(view_x>>6)+15;
  start_y=(view_y>>6)-15;
  stop_x=(view_x>>6)-5;
  stop_y=(view_y>>6)+5;
  move_x=-1;
  move_y=1;
if(stop_x<0)stop_x=0;if(stop_x>63)stop_x=63;
if(start_x<0)start_x=0;if(start_x>63)start_x=63;
if(stop_y<0)stop_y=0;if(stop_y>63)stop_y=63;
if(start_y<0)start_y=0;if(start_y>63)start_y=63;
}



for(grid_x=start_x;grid_x!=stop_x;grid_x+=move_x)for(grid_y=start_y;grid_y!=stop_y;grid_y+=move_y)
{


  if(!(object_type=objects[grid_y][grid_x]))continue;


  /* An object has been found in this grid square, good!*/
  /* in that case we process and plot the object */

/* NEW MOVING OBJECT code. This is actually very simple and can be done in */
/* a _variety_ of ways. This is just one of them, and not the best ;-) */
/*
if(object_type==10 || object_type==15 || object_type==17 || object_type==19)
{
 object_x=object_move_x;
 object_y=object_move_y;
}
else*/
{
      object_x=(grid_x<<6)+32;
      object_y=(grid_y<<6)+32;
}
 /* now we have to rotate the objects coordinates around the viewer */
      /* to establish where it is on the view plane ,using standard rots.*/

      trans_x=( (object_x-view_x)*coso_table[view_angle]+(object_y-view_y)*
      sino_table[view_angle])>>16;
      trans_z=(-(object_x-view_x)*sino_table[view_angle]+(object_y-view_y)*
      coso_table[view_angle])>>16;
      /* now if the object is infront of the viewer we go further */
      if(trans_z<0)continue; /* else we move to next object */

        /* we have to work out screen positions now (above and below!) */
         temp_1=(((VIEWVART<<5) * recip_table[trans_z]))>>16;
        screen_y1=100-temp_1; /* 128 and 160 here indicate origins at the*/
        screen_y2=100+temp_1; /* center of the screen ofcourse */
        /* the above lines works out the top and bottom of the object */
if((scale=screen_y2-screen_y1)>MAX_SCALE)continue;

        screen_x=160 + ( ( VIEWVAR*trans_x * recip_table[trans_z])>>16);

        if(scale>(SCREEN_HEIGHT))
        {

          scale=SCREEN_HEIGHT;

        }
        variables[5]=screen_y1;
        /* above line works out scale from y1 and y2 ready for drawing */
        screen_x-=scale>>1;
        /* we offset screen_x so then we are at the left of the object */            increment=(int)(recip_table[scale]<<6);
        variables[3]=scale;



/* NEW moving object detector checks to see if object is of moving sort */


        /* above line prepares more variables for the ourlib function    */
        /* next we set up fixed point systems to index the object graphic */
        /* while we draw it. Instead of floating point this is of course  */
        index=0;
        /* next we use a counter to count if we have finished drawing it. */
        counter=scale;
        /* initialise a loop to render each sliver one by one */
        /* keep going until off the screen or just finished! */


 while(screen_x>-64 && screen_x<SCREEN_WIDTH && counter>0)
           {
/* NEW mirror code, we have to be careful to make it look good */
if(mirror_array[screen_x]==255 && scale>scale_array[screen_x])
{
  variables[1]=(int)&objgraphics[object_type][(int)index>>16];

                  variables[4]=screen_x;

                 ourlib_sliver_mask_mirror(variables);
}
else{
              /* check to see if object is infront of wall, important! */
              if(scale>scale_array[screen_x] && screen_x>screen_limit)
                  {
                  /* if so draw this sliver! */
                 variables[1]=(int)&objgraphics[object_type][(int)index>>16];

                  variables[4]=screen_x;

                 ourlib_sliver_mask(variables);
                  }

} /* add on graphic increment, decrease counter and move to next column */     index+=increment;
  counter--;
  screen_x++;
           }


}
/* Object Code OVER ************* Continue as normal */
/* *************** See Article 5 for more details */

/* NEW moving object : We add a small bit of code to move the object */
/*objects[object_move_y>>6][object_move_x>>6]=0;
object_move_x=object_move[(int)object_move_index];
object_move_y=object_move[(int)object_move_index+1];
objects[object_move_y>>6][object_move_x>>6]=object_move[object_move_index+2];
object_move_index+=3;if(object_move_index>100)object_move_index=0;*/
/* PHEW! Now we can wait for a vysnc and then switch the views/banks over ot  produce flicker-free animation */

ourlib_waitvsync();
ourlib_simpleswitch();

/* We also have to switch the memory addresses around so our functions draw to the correct memory */

screen_address_temp=screen_address_bank;
screen_address_bank=screen_address;
screen_address=screen_address_temp;

/* add one to the frames count, we are counting the number of frames generated  */
frames++;

}
/* record the time stopped */

time_finish=ourlib_gettime();

/* take a screenshot, using *screen save, and save it inside the directory */

system("*ScreenSave <AUARay$Dir>.scrshot");
if(DEMO_READ || DEMO_WRITE)fclose(demo_file);
/* close down the screens using an ourlib function */

ourlib_closedown_screens();

/* change to mode 15 and bring back the cursor just in case */

ourlib_changemode(15);
ourlib_revivecursor();

/* print the calculation and other info. */
printf("******* FRAMES PER SECOND ********\n%f",(float)frames/(float)((time_finish-time_start)/100));

}

00000000  2f 2a 0a 20 20 20 65 6e  67 69 6e 65 2e 63 20 3a  |/*.   engine.c :|
00000010  20 57 72 69 74 74 65 6e  20 62 79 20 47 72 65 67  | Written by Greg|
00000020  20 53 63 6f 74 74 20 20  20 31 39 39 37 0a 20 20  | Scott   1997.  |
00000030  20 66 6f 72 20 41 63 6f  72 6e 20 55 73 65 72 2c  | for Acorn User,|
00000040  20 61 73 20 70 61 72 74  20 6f 66 20 74 68 65 20  | as part of the |
00000050  22 56 69 72 74 75 61 6c  0a 20 20 20 57 6f 72 6c  |"Virtual.   Worl|
00000060  64 73 22 20 73 65 72 69  65 73 2e 0a 0a 20 20 20  |ds" series...   |
00000070  55 73 61 67 65 20 6f 66  20 74 68 65 20 73 6f 75  |Usage of the sou|
00000080  72 63 65 20 63 6f 64 65  20 69 73 20 64 6f 6e 65  |rce code is done|
00000090  20 61 74 20 74 68 65 20  6f 77 6e 65 72 73 20 72  | at the owners r|
000000a0  69 73 6b 2c 20 61 6e 64  20 41 63 6f 72 6e 20 55  |isk, and Acorn U|
000000b0  73 65 72 20 6f 72 20 74  68 65 20 20 20 61 75 74  |ser or the   aut|
000000c0  68 6f 72 20 68 6f 6c 64  20 6e 6f 20 72 65 73 70  |hor hold no resp|
000000d0  6f 6e 73 69 62 69 6c 69  74 79 20 66 6f 72 20 64  |onsibility for d|
000000e0  61 6d 61 67 65 73 2e 0a  2a 2f 0a 0a 2f 2a 20 41  |amages..*/../* A|
000000f0  55 54 48 4f 52 53 20 4e  4f 54 45 3a 20 41 20 6c  |UTHORS NOTE: A l|
00000100  6f 74 20 6f 66 20 74 68  65 20 63 6f 64 65 20 69  |ot of the code i|
00000110  6e 20 68 65 72 65 20 69  73 20 76 65 72 79 20 63  |n here is very c|
00000120  6f 6d 70 6c 65 78 2c 20  61 6e 64 20 63 61 6e 20  |omplex, and can |
00000130  6e 65 76 65 72 20 62 65  20 61 64 65 71 75 61 74  |never be adequat|
00000140  65 6c 79 20 65 78 70 6c  61 69 6e 65 64 2e 20 50  |ely explained. P|
00000150  4c 45 41 53 45 20 50 4c  45 41 53 45 20 63 6f 6e  |LEASE PLEASE con|
00000160  74 61 63 74 20 6d 65 20  66 6f 72 20 6d 6f 72 65  |tact me for more|
00000170  20 61 73 73 69 73 74 61  6e 63 65 2c 20 69 74 20  | assistance, it |
00000180  69 73 20 6d 75 63 68 20  65 61 73 69 65 72 20 74  |is much easier t|
00000190  6f 20 61 64 64 72 65 73  73 20 70 65 72 73 6f 6e  |o address person|
000001a0  61 6c 20 70 72 6f 62 6c  65 6d 73 20 77 69 74 68  |al problems with|
000001b0  20 74 68 65 20 69 64 65  61 73 20 74 68 61 6e 20  | the ideas than |
000001c0  69 6e 20 67 65 6e 65 72  61 6c 2e 0a 0a 41 55 54  |in general...AUT|
000001d0  68 72 65 65 44 40 61 6f  6c 2e 63 6f 6d 0a 0a 6f  |hreeD@aol.com..o|
000001e0  72 20 63 6f 6e 74 61 63  74 20 74 68 65 20 41 63  |r contact the Ac|
000001f0  6f 72 6e 20 55 73 65 72  20 6f 66 66 69 63 65 73  |orn User offices|
00000200  20 61 6e 64 20 74 68 65  79 20 77 69 6c 6c 20 70  | and they will p|
00000210  61 73 73 20 69 74 20 6f  6e 2e 20 54 68 61 6e 6b  |ass it on. Thank|
00000220  20 79 6f 75 2e 20 2a 2f  0a 0a 2f 2a 20 41 4e 53  | you. */../* ANS|
00000230  49 20 43 20 69 6e 63 6c  75 64 65 73 20 2a 2f 0a  |I C includes */.|
00000240  0a 23 69 6e 63 6c 75 64  65 20 3c 73 74 64 69 6f  |.#include <stdio|
00000250  2e 68 3e 0a 23 69 6e 63  6c 75 64 65 20 3c 73 74  |.h>.#include <st|
00000260  64 6c 69 62 2e 68 3e 0a  23 69 6e 63 6c 75 64 65  |dlib.h>.#include|
00000270  20 3c 6d 61 74 68 2e 68  3e 0a 23 69 6e 63 6c 75  | <math.h>.#inclu|
00000280  64 65 20 3c 73 74 72 69  6e 67 2e 68 3e 0a 2f 2a  |de <string.h>./*|
00000290  20 4f 54 48 45 52 20 69  6e 63 6c 75 64 65 73 20  | OTHER includes |
000002a0  2a 2f 0a 0a 23 69 6e 63  6c 75 64 65 20 22 6f 75  |*/..#include "ou|
000002b0  72 5f 6c 69 62 2e 68 22  0a 0a 2f 2a 20 44 45 46  |r_lib.h"../* DEF|
000002c0  49 4e 45 53 20 2a 2f 0a  0a 23 64 65 66 69 6e 65  |INES */..#define|
000002d0  20 57 4f 52 4c 44 5f 57  49 44 54 48 20 36 34 20  | WORLD_WIDTH 64 |
000002e0  2f 2a 20 54 68 69 73 20  69 73 20 74 68 65 20 6e  |/* This is the n|
000002f0  75 6d 62 65 72 20 6f 66  20 77 61 6c 6c 73 20 61  |umber of walls a|
00000300  63 72 6f 73 73 20 69 6e  20 6f 75 72 20 77 6f 72  |cross in our wor|
00000310  6c 64 20 2a 2f 0a 23 64  65 66 69 6e 65 20 57 4f  |ld */.#define WO|
00000320  52 4c 44 5f 48 45 49 47  48 54 20 36 34 20 2f 2a  |RLD_HEIGHT 64 /*|
00000330  20 54 68 69 73 20 69 73  20 74 68 65 20 6e 75 6d  | This is the num|
00000340  62 65 72 20 6f 66 20 77  61 6c 6c 73 20 64 6f 77  |ber of walls dow|
00000350  6e 20 69 6e 20 6f 75 72  20 77 6f 72 6c 64 20 2a  |n in our world *|
00000360  2f 0a 23 64 65 66 69 6e  65 20 57 41 4c 4c 5f 57  |/.#define WALL_W|
00000370  49 44 54 48 20 36 34 20  2f 2a 20 54 68 69 73 20  |IDTH 64 /* This |
00000380  69 73 20 74 68 65 20 77  69 64 74 68 20 6f 66 20  |is the width of |
00000390  65 61 63 68 20 77 61 6c  6c 20 69 6e 20 70 69 78  |each wall in pix|
000003a0  65 6c 73 20 2a 2f 0a 23  64 65 66 69 6e 65 20 57  |els */.#define W|
000003b0  41 4c 4c 5f 48 45 49 47  48 54 20 36 34 20 2f 2a  |ALL_HEIGHT 64 /*|
000003c0  20 54 68 69 73 20 69 73  20 74 68 65 20 68 65 69  | This is the hei|
000003d0  67 68 74 20 6f 66 20 65  61 63 68 20 77 61 6c 6c  |ght of each wall|
000003e0  20 69 6e 20 70 69 78 65  6c 73 20 2a 2f 0a 23 64  | in pixels */.#d|
000003f0  65 66 69 6e 65 20 57 41  4c 4c 5f 4e 55 4d 42 45  |efine WALL_NUMBE|
00000400  52 20 32 30 20 2f 2a 20  54 68 69 73 20 64 65 66  |R 20 /* This def|
00000410  69 6e 65 73 20 74 68 65  20 6e 75 6d 62 65 72 20  |ines the number |
00000420  6f 66 20 77 61 6c 6c 73  20 61 6c 6c 6f 77 65 64  |of walls allowed|
00000430  20 2a 2f 0a 23 64 65 66  69 6e 65 20 43 45 4c 4c  | */.#define CELL|
00000440  5f 58 5f 53 49 5a 45 20  36 34 20 2f 2a 20 74 68  |_X_SIZE 64 /* th|
00000450  69 73 20 69 73 20 74 68  65 20 73 69 7a 65 20 69  |is is the size i|
00000460  6e 20 75 6e 69 74 73 20  6f 66 20 65 61 63 68 20  |n units of each |
00000470  63 65 6c 6c 20 2a 2f 0a  23 64 65 66 69 6e 65 20  |cell */.#define |
00000480  43 45 4c 4c 5f 59 5f 53  49 5a 45 20 36 34 20 2f  |CELL_Y_SIZE 64 /|
00000490  2a 20 74 68 69 73 20 69  73 20 74 68 65 20 73 69  |* this is the si|
000004a0  7a 65 20 69 6e 20 75 6e  69 74 73 20 6f 66 20 65  |ze in units of e|
000004b0  61 63 68 20 63 65 6c 6c  20 2a 2f 0a 23 64 65 66  |ach cell */.#def|
000004c0  69 6e 65 20 43 45 4c 4c  5f 58 5f 53 49 5a 45 5f  |ine CELL_X_SIZE_|
000004d0  46 50 20 36 20 2f 2a 20  74 68 69 73 20 69 73 20  |FP 6 /* this is |
000004e0  75 73 65 64 20 69 6e 20  62 69 6e 61 72 79 20 73  |used in binary s|
000004f0  68 69 66 74 69 6e 67 20  2a 2f 0a 23 64 65 66 69  |hifting */.#defi|
00000500  6e 65 20 43 45 4c 4c 5f  59 5f 53 49 5a 45 5f 46  |ne CELL_Y_SIZE_F|
00000510  50 20 36 20 2f 2a 20 74  68 69 73 20 69 73 20 75  |P 6 /* this is u|
00000520  73 65 64 20 69 6e 20 62  69 6e 61 72 79 20 73 68  |sed in binary sh|
00000530  69 66 74 69 6e 67 20 2a  2f 0a 23 64 65 66 69 6e  |ifting */.#defin|
00000540  65 20 46 4f 55 4e 44 5f  57 41 4c 4c 20 31 20 2f  |e FOUND_WALL 1 /|
00000550  2a 20 74 68 69 73 20 66  6c 61 67 20 69 73 20 75  |* this flag is u|
00000560  73 65 64 20 74 6f 20 69  6e 64 69 63 61 74 65 20  |sed to indicate |
00000570  77 68 65 6e 20 61 6e 20  69 6e 74 65 72 73 65 63  |when an intersec|
00000580  74 69 6f 6e 20 68 61 73  20 62 65 20 66 6f 75 6e  |tion has be foun|
00000590  64 20 2a 2f 0a 23 64 65  66 69 6e 65 20 4d 41 58  |d */.#define MAX|
000005a0  5f 44 49 53 54 41 4e 43  45 20 34 30 30 30 20 2f  |_DISTANCE 4000 /|
000005b0  2a 20 74 68 69 73 20 64  65 66 69 6e 65 73 20 74  |* this defines t|
000005c0  68 65 20 6c 61 72 67 65  73 74 20 64 69 73 74 61  |he largest dista|
000005d0  6e 63 65 20 61 20 72 61  79 20 63 6f 75 6c 64 20  |nce a ray could |
000005e0  74 72 61 76 65 6c 20 69  6e 20 74 68 65 20 77 6f  |travel in the wo|
000005f0  72 6c 64 2c 20 75 73 65  64 20 66 6f 72 20 6c 6f  |rld, used for lo|
00000600  6f 6b 20 75 70 20 74 61  62 6c 65 73 20 2a 2f 0a  |ok up tables */.|
00000610  23 64 65 66 69 6e 65 20  4d 41 58 5f 53 43 41 4c  |#define MAX_SCAL|
00000620  45 20 33 30 30 20 2f 2a  20 75 73 65 64 20 66 6f  |E 300 /* used fo|
00000630  72 20 63 6c 69 70 70 69  6e 67 20 2a 2f 0a 23 64  |r clipping */.#d|
00000640  65 66 69 6e 65 20 43 4c  4f 53 45 53 54 20 35 30  |efine CLOSEST 50|
00000650  20 2f 2a 20 74 68 69 73  20 73 74 6f 72 65 73 20  | /* this stores |
00000660  74 68 65 20 63 6c 6f 73  65 73 74 20 61 20 70 6c  |the closest a pl|
00000670  61 79 65 72 20 63 61 6e  20 77 61 6c 6b 20 69 6e  |ayer can walk in|
00000680  74 6f 20 61 20 77 61 6c  6c 20 2a 2f 0a 2f 2a 20  |to a wall */./* |
00000690  4e 45 57 20 75 73 65 20  6f 66 20 41 4e 47 4c 45  |NEW use of ANGLE|
000006a0  53 20 76 61 72 69 61 62  6c 65 73 2c 20 74 68 65  |S variables, the|
000006b0  79 20 61 72 65 20 6e 6f  77 20 6e 6f 74 20 64 65  |y are now not de|
000006c0  66 69 6e 65 73 20 62 75  74 20 61 72 65 20 69 6e  |fines but are in|
000006d0  70 75 74 74 65 64 20 62  79 20 74 68 65 20 63 6f  |putted by the co|
000006e0  6d 6d 61 6e 64 20 6c 69  6e 65 20 61 74 20 74 68  |mmand line at th|
000006f0  65 20 62 65 67 69 6e 6e  69 6e 67 20 6f 66 20 6d  |e beginning of m|
00000700  61 69 6e 28 29 2a 2f 0a  0a 2f 2a 20 4f 4c 44 20  |ain()*/../* OLD |
00000710  64 65 66 69 6e 65 73 20  68 61 76 65 20 62 65 65  |defines have bee|
00000720  6e 20 63 6f 6e 76 65 72  74 65 64 20 74 6f 20 69  |n converted to i|
00000730  6e 74 65 67 65 72 73 20  62 65 63 61 75 73 65 20  |ntegers because |
00000740  77 65 20 6e 6f 77 20 6c  6f 61 64 20 74 68 65 6d  |we now load them|
00000750  20 69 6e 20 66 72 6f 6d  20 74 68 65 20 63 6f 6d  | in from the com|
00000760  6d 61 6e 64 20 6c 69 6e  65 20 2a 2f 0a 69 6e 74  |mand line */.int|
00000770  20 41 4e 47 4c 45 5f 30  2c 41 4e 47 4c 45 5f 36  | ANGLE_0,ANGLE_6|
00000780  2c 41 4e 47 4c 45 5f 33  30 2c 41 4e 47 4c 45 5f  |,ANGLE_30,ANGLE_|
00000790  39 30 2c 41 4e 47 4c 45  5f 31 38 30 2c 41 4e 47  |90,ANGLE_180,ANG|
000007a0  4c 45 5f 32 37 30 2c 41  4e 47 4c 45 5f 33 36 30  |LE_270,ANGLE_360|
000007b0  2c 53 54 45 50 5f 4c 45  4e 47 54 48 2c 56 45 52  |,STEP_LENGTH,VER|
000007c0  54 49 43 41 4c 5f 53 43  41 4c 45 2c 56 49 45 57  |TICAL_SCALE,VIEW|
000007d0  56 41 52 2c 56 49 45 57  56 41 52 54 2c 53 43 52  |VAR,VIEWVART,SCR|
000007e0  45 45 4e 5f 48 45 49 47  48 54 2c 53 43 52 45 45  |EEN_HEIGHT,SCREE|
000007f0  4e 5f 57 49 44 54 48 2c  44 45 4d 4f 5f 52 45 41  |N_WIDTH,DEMO_REA|
00000800  44 2c 44 45 4d 4f 5f 57  52 49 54 45 3b 0a 0a 2f  |D,DEMO_WRITE;../|
00000810  2a 20 47 4c 4f 42 41 4c  20 76 61 72 69 61 62 6c  |* GLOBAL variabl|
00000820  65 73 20 2a 2f 0a 0a 63  68 61 72 20 77 6f 72 6c  |es */..char worl|
00000830  64 5b 57 4f 52 4c 44 5f  48 45 49 47 48 54 2b 31  |d[WORLD_HEIGHT+1|
00000840  5d 5b 57 4f 52 4c 44 5f  57 49 44 54 48 2b 31 5d  |][WORLD_WIDTH+1]|
00000850  3b 2f 2a 20 54 68 69 73  20 68 6f 6c 64 73 20 6f  |;/* This holds o|
00000860  75 72 20 74 65 78 74 20  64 61 74 61 20 66 69 6c  |ur text data fil|
00000870  65 20 2a 2f 0a 63 68 61  72 20 6f 62 6a 65 63 74  |e */.char object|
00000880  73 5b 57 4f 52 4c 44 5f  48 45 49 47 48 54 2b 31  |s[WORLD_HEIGHT+1|
00000890  5d 5b 57 4f 52 4c 44 5f  57 49 44 54 48 2b 31 5d  |][WORLD_WIDTH+1]|
000008a0  3b 20 2f 2a 20 4e 45 57  20 6f 62 6a 65 63 74 20  |; /* NEW object |
000008b0  61 72 72 61 79 20 28 61  73 20 77 6f 72 6c 64 29  |array (as world)|
000008c0  2a 2f 0a 63 68 61 72 20  77 61 6c 6c 73 5b 57 41  |*/.char walls[WA|
000008d0  4c 4c 5f 4e 55 4d 42 45  52 2b 31 5d 5b 28 57 41  |LL_NUMBER+1][(WA|
000008e0  4c 4c 5f 57 49 44 54 48  2a 57 41 4c 4c 5f 48 45  |LL_WIDTH*WALL_HE|
000008f0  49 47 48 54 29 2b 31 5d  3b 0a 63 68 61 72 20 6f  |IGHT)+1];.char o|
00000900  62 6a 67 72 61 70 68 69  63 73 5b 57 41 4c 4c 5f  |bjgraphics[WALL_|
00000910  4e 55 4d 42 45 52 2b 31  5d 5b 28 57 41 4c 4c 5f  |NUMBER+1][(WALL_|
00000920  57 49 44 54 48 2a 57 41  4c 4c 5f 48 45 49 47 48  |WIDTH*WALL_HEIGH|
00000930  54 29 2b 31 5d 3b 0a 63  68 61 72 20 62 61 72 5f  |T)+1];.char bar_|
00000940  67 72 61 70 68 69 63 5b  31 36 30 30 31 5d 3b 20  |graphic[16001]; |
00000950  2f 2a 20 74 68 69 73 20  68 6f 6c 64 73 20 74 68  |/* this holds th|
00000960  65 20 62 6f 74 74 6f 6d  20 62 61 72 20 6f 6e 20  |e bottom bar on |
00000970  74 68 65 20 73 63 72 65  65 6e 20 2a 2f 0a 0a 2f  |the screen */../|
00000980  2a 20 54 68 69 73 20 68  6f 6c 64 73 20 74 68 65  |* This holds the|
00000990  20 77 61 6c 6c 20 67 72  61 70 68 69 63 73 20 69  | wall graphics i|
000009a0  6e 20 61 20 74 77 6f 20  64 69 6d 65 6e 73 69 6f  |n a two dimensio|
000009b0  6e 61 6c 20 61 72 72 61  79 20 2a 2f 0a 2f 2a 20  |nal array */./* |
000009c0  4e 6f 74 65 20 74 68 65  20 75 73 61 67 65 20 6f  |Note the usage o|
000009d0  66 20 63 68 61 72 20 61  6e 64 20 6e 6f 74 20 22  |f char and not "|
000009e0  69 6e 74 22 20 69 6e 20  62 6f 74 68 20 63 61 73  |int" in both cas|
000009f0  65 73 2e 20 54 68 69 73  20 69 73 20 62 65 63 61  |es. This is beca|
00000a00  75 73 65 20 61 20 63 68  61 72 20 69 73 20 38 20  |use a char is 8 |
00000a10  62 79 74 65 73 2c 20 77  68 69 63 68 20 67 69 76  |bytes, which giv|
00000a20  65 73 20 32 35 36 20 63  6f 6c 6f 75 72 73 20 28  |es 256 colours (|
00000a30  75 73 65 64 20 69 6e 20  6f 75 72 20 4d 6f 64 65  |used in our Mode|
00000a40  20 31 33 20 73 63 72 65  65 6e 29 20 61 6e 64 20  | 13 screen) and |
00000a50  61 6c 73 6f 20 61 6e 20  69 6e 74 65 67 65 72 20  |also an integer |
00000a60  75 70 20 74 6f 20 32 35  36 2c 20 77 68 65 6e 20  |up to 256, when |
00000a70  6f 75 72 20 74 65 78 74  20 66 69 6c 65 20 64 6f  |our text file do|
00000a80  65 73 6e 27 74 20 67 6f  20 6f 76 65 72 20 32 30  |esn't go over 20|
00000a90  20 69 6e 20 6e 75 6d 62  65 72 21 20 48 65 6e 63  | in number! Henc|
00000aa0  65 20 74 68 65 72 65 20  69 73 20 6e 6f 20 6e 65  |e there is no ne|
00000ab0  65 64 20 66 6f 72 20 61  6e 20 69 6e 74 20 61 72  |ed for an int ar|
00000ac0  72 61 79 20 69 6e 20 65  69 74 68 65 72 20 63 61  |ray in either ca|
00000ad0  73 65 2e 20 2a 2f 0a 0a  63 68 61 72 20 2a 73 63  |se. */..char *sc|
00000ae0  72 65 65 6e 5f 61 64 64  72 65 73 73 3b 20 2f 2a  |reen_address; /*|
00000af0  20 74 68 69 73 20 77 69  6c 6c 20 68 6f 6c 64 20  | this will hold |
00000b00  74 68 65 20 62 61 73 65  20 6f 66 20 74 68 65 20  |the base of the |
00000b10  73 63 72 65 65 6e 20 6d  65 6d 6f 72 79 20 77 68  |screen memory wh|
00000b20  69 63 68 20 77 65 20 77  69 6c 6c 20 6d 61 6e 69  |ich we will mani|
00000b30  70 75 6c 61 74 65 2e 20  42 79 20 61 6c 74 65 72  |pulate. By alter|
00000b40  69 6e 67 20 76 61 6c 75  65 73 20 69 6e 20 74 68  |ing values in th|
00000b50  65 20 73 63 72 65 65 6e  20 6d 65 6d 6f 72 79 2c  |e screen memory,|
00000b60  20 77 65 20 61 6c 74 65  72 20 77 68 61 74 20 61  | we alter what a|
00000b70  70 70 65 61 72 73 20 6f  6e 20 74 68 65 20 73 63  |ppears on the sc|
00000b80  72 65 65 6e 2e 20 4e 6f  74 65 20 74 68 61 74 20  |reen. Note that |
00000b90  74 68 69 73 20 69 73 20  6f 66 20 74 79 70 65 20  |this is of type |
00000ba0  22 63 68 61 72 20 2a 22  20 62 65 63 61 75 73 65  |"char *" because|
00000bb0  20 69 74 20 68 6f 6c 64  73 20 74 68 65 20 6d 65  | it holds the me|
00000bc0  6d 6f 72 79 20 61 64 64  72 65 73 73 20 6f 66 20  |mory address of |
00000bd0  61 20 62 79 74 65 20 61  72 72 61 79 20 2d 20 74  |a byte array - t|
00000be0  68 65 20 32 35 36 20 63  6f 6c 6f 75 72 20 6d 6f  |he 256 colour mo|
00000bf0  64 65 20 31 33 20 73 63  72 65 65 6e 20 28 77 65  |de 13 screen (we|
00000c00  6c 6c 20 69 74 20 77 69  6c 6c 20 64 6f 21 29 20  |ll it will do!) |
00000c10  2a 2f 0a 63 68 61 72 20  2a 73 63 72 65 65 6e 5f  |*/.char *screen_|
00000c20  61 64 64 72 65 73 73 5f  62 61 6e 6b 3b 20 2f 2a  |address_bank; /*|
00000c30  20 74 68 69 73 20 69 73  20 61 6e 6f 74 68 65 72  | this is another|
00000c40  20 70 6f 69 6e 74 65 72  20 74 6f 20 74 68 65 20  | pointer to the |
00000c50  6f 74 68 65 72 20 61 72  65 61 20 6f 66 20 73 63  |other area of sc|
00000c60  72 65 65 6e 20 6d 65 6d  6f 72 79 20 77 68 69 63  |reen memory whic|
00000c70  68 20 77 65 20 77 69 6c  6c 20 62 65 20 75 73 69  |h we will be usi|
00000c80  6e 67 20 66 6f 72 20 53  43 52 45 45 4e 20 42 41  |ng for SCREEN BA|
00000c90  4e 4b 49 4e 47 20 2d 20  61 76 6f 69 64 69 6e 67  |NKING - avoiding|
00000ca0  20 66 6c 69 63 6b 65 72  69 6e 67 20 6f 66 20 74  | flickering of t|
00000cb0  68 65 20 73 63 72 65 65  6e 20 64 75 72 69 6e 67  |he screen during|
00000cc0  20 61 6e 69 6d 61 74 69  6e 67 20 67 72 61 70 68  | animating graph|
00000cd0  69 63 73 20 2a 2f 0a 63  68 61 72 20 2a 73 63 72  |ics */.char *scr|
00000ce0  65 65 6e 5f 61 64 64 72  65 73 73 5f 74 65 6d 70  |een_address_temp|
00000cf0  3b 20 2f 2a 20 74 68 69  73 20 69 73 20 61 20 73  |; /* this is a s|
00000d00  70 61 72 65 20 70 6f 69  6e 74 65 72 20 66 6f 72  |pare pointer for|
00000d10  20 75 73 65 20 64 75 72  69 6e 67 20 74 68 65 20  | use during the |
00000d20  73 77 69 74 63 68 69 6e  67 20 6f 66 20 74 68 65  |switching of the|
00000d30  20 74 77 6f 20 61 62 6f  76 65 20 76 61 6c 75 65  | two above value|
00000d40  73 20 2a 2f 0a 0a 2f 2a  20 74 68 65 73 65 20 6e  |s */../* these n|
00000d50  65 77 20 46 49 58 45 44  20 50 4f 49 4e 54 20 49  |ew FIXED POINT I|
00000d60  4e 54 45 47 45 52 20 70  6f 69 6e 74 65 72 73 20  |NTEGER pointers |
00000d70  70 6f 69 6e 74 20 74 6f  20 6c 6f 6f 6b 2d 75 70  |point to look-up|
00000d80  20 74 61 62 6c 65 73 20  75 73 65 64 20 69 6e 20  | tables used in |
00000d90  74 68 65 20 72 61 79 20  63 61 73 74 69 6e 67 20  |the ray casting |
00000da0  65 6e 67 69 6e 65 2e 20  54 68 65 73 65 20 61 72  |engine. These ar|
00000db0  65 20 65 78 70 6c 61 69  6e 65 64 20 6f 66 20 69  |e explained of i|
00000dc0  6e 20 74 68 65 20 65 6e  67 69 6e 65 2c 20 62 75  |n the engine, bu|
00000dd0  74 20 74 68 65 20 6c 6f  6f 6b 2d 75 70 73 20 61  |t the look-ups a|
00000de0  72 65 20 67 65 6e 65 72  61 74 65 64 20 69 6e 20  |re generated in |
00000df0  61 75 61 5f 74 61 62 6c  65 73 28 29 20 2a 2f 0a  |aua_tables() */.|
00000e00  0a 69 6e 74 20 2a 74 61  6e 5f 74 61 62 6c 65 2c  |.int *tan_table,|
00000e10  2a 69 6e 76 5f 74 61 6e  5f 74 61 62 6c 65 3b 20  |*inv_tan_table; |
00000e20  2f 2a 20 70 6f 69 6e 74  65 72 73 20 74 6f 20 74  |/* pointers to t|
00000e30  61 6e 67 65 6e 74 20 6c  6f 6f 6b 5f 75 70 73 20  |angent look_ups |
00000e40  2a 2f 0a 69 6e 74 20 2a  79 5f 73 74 65 70 2c 2a  |*/.int *y_step,*|
00000e50  78 5f 73 74 65 70 3b 20  20 20 20 20 20 20 20 20  |x_step;         |
00000e60  20 20 2f 2a 20 70 6f 69  6e 74 65 72 73 20 74 6f  |  /* pointers to|
00000e70  20 6d 6f 72 65 20 63 6f  6d 70 6c 65 78 20 6c 6f  | more complex lo|
00000e80  6f 6b 5f 75 70 73 20 2a  2f 0a 69 6e 74 20 2a 69  |ok_ups */.int *i|
00000e90  6e 76 5f 63 6f 73 5f 74  61 62 6c 65 2c 20 20 20  |nv_cos_table,   |
00000ea0  20 20 20 20 20 20 20 20  20 2f 2a 20 73 69 6e 2f  |         /* sin/|
00000eb0  63 6f 73 20 74 61 62 6c  65 73 20 28 6c 6f 6f 6b  |cos tables (look|
00000ec0  5f 75 70 73 29 20 20 20  20 2a 2f 0a 20 20 20 20  |_ups)    */.    |
00000ed0  2a 69 6e 76 5f 73 69 6e  5f 74 61 62 6c 65 3b 0a  |*inv_sin_table;.|
00000ee0  69 6e 74 20 2a 63 6f 73  5f 74 61 62 6c 65 3b 20  |int *cos_table; |
00000ef0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2f  |               /|
00000f00  2a 20 63 6f 73 69 6e 61  6c 20 6c 6f 6f 6b 5f 75  |* cosinal look_u|
00000f10  70 20 74 61 62 6c 65 20  20 20 20 2a 2f 0a 69 6e  |p table    */.in|
00000f20  74 20 2a 72 65 63 69 70  5f 74 61 62 6c 65 3b 20  |t *recip_table; |
00000f30  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
00000f40  72 65 63 69 70 72 6f 63  61 6c 20 74 61 62 6c 65  |reciprocal table|
00000f50  20 75 73 65 64 20 69 6e  73 74 65 61 64 20 6f 66  | used instead of|
00000f60  20 61 20 2a 2f 0a 20 20  20 20 20 20 20 20 20 20  | a */.          |
00000f70  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000f80  20 20 20 20 20 2f 2a 20  64 69 76 69 73 69 6f 6e  |     /* division|
00000f90  2e 20 53 65 65 20 6c 61  74 65 72 20 2a 2f 0a 69  |. See later */.i|
00000fa0  6e 74 20 2a 63 6f 73 6f  5f 74 61 62 6c 65 2c 2a  |nt *coso_table,*|
00000fb0  73 69 6e 6f 5f 74 61 62  6c 65 3b 20 20 20 2f 2a  |sino_table;   /*|
00000fc0  20 74 68 65 73 65 20 74  77 6f 20 74 61 62 6c 65  | these two table|
00000fd0  73 20 61 72 65 20 66 6f  72 20 6f 62 6a 65 63 74  |s are for object|
00000fe0  73 20 2a 2f 0a 69 6e 74  20 2a 64 78 5f 74 61 62  |s */.int *dx_tab|
00000ff0  6c 65 2c 20 20 20 20 20  20 20 20 20 20 20 20 20  |le,             |
00001000  20 20 20 20 2f 2a 20 46  49 58 45 44 20 50 4f 49  |    /* FIXED POI|
00001010  4e 54 20 74 61 62 6c 65  73 20 66 6f 72 20 6d 6f  |NT tables for mo|
00001020  76 69 6e 67 20 74 68 65  20 2a 2f 0a 20 20 20 20  |ving the */.    |
00001030  2a 64 79 5f 74 61 62 6c  65 3b 20 20 20 20 20 20  |*dy_table;      |
00001040  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 76 69  |           /* vi|
00001050  65 77 20 70 6f 69 6e 74  20 76 65 72 79 20 71 75  |ew point very qu|
00001060  69 63 6b 6c 79 20 2a 2f  0a 69 6e 74 20 73 63 61  |ickly */.int sca|
00001070  6c 65 5f 61 72 72 61 79  5b 33 32 30 5d 3b 20 20  |le_array[320];  |
00001080  20 20 20 20 20 20 20 20  2f 2a 20 4e 45 57 20 75  |        /* NEW u|
00001090  73 65 64 20 74 6f 20 73  74 6f 72 65 20 73 63 61  |sed to store sca|
000010a0  6c 65 20 76 61 6c 75 65  73 20 6f 66 20 65 61 63  |le values of eac|
000010b0  68 20 2a 2f 0a 20 20 20  20 20 20 20 20 20 20 20  |h */.           |
000010c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000010d0  20 20 20 20 2f 2a 20 73  6c 69 76 65 72 2c 66 6f  |    /* sliver,fo|
000010e0  72 20 6f 62 6a 65 63 74  73 20 6c 61 74 65 72 20  |r objects later |
000010f0  6f 6e 20 2a 2f 0a 69 6e  74 20 6d 69 72 72 6f 72  |on */.int mirror|
00001100  5f 61 72 72 61 79 5b 33  32 30 5d 3b 20 20 20 20  |_array[320];    |
00001110  20 20 20 20 20 2f 2a 20  75 73 65 64 20 74 6f 20  |     /* used to |
00001120  66 6c 61 67 20 69 66 20  61 20 6d 69 72 72 6f 72  |flag if a mirror|
00001130  20 69 73 20 69 6e 20 75  73 65 20 2a 2f 0a 2f 2a  | is in use */./*|
00001140  20 46 55 4e 43 54 49 4f  4e 20 64 65 66 69 6e 69  | FUNCTION defini|
00001150  74 69 6f 6e 73 20 2a 2f  0a 0a 2f 2a 20 74 68 69  |tions */../* thi|
00001160  73 20 66 75 6e 63 74 69  6f 6e 20 67 65 6e 65 72  |s function gener|
00001170  61 74 65 73 20 4c 4f 4f  4b 20 55 50 20 74 61 62  |ates LOOK UP tab|
00001180  6c 65 73 20 2d 20 61 72  72 61 79 73 20 68 6f 6c  |les - arrays hol|
00001190  64 69 6e 67 20 70 72 65  2d 63 61 6c 63 75 6c 61  |ding pre-calcula|
000011a0  74 65 64 20 74 72 69 67  6f 6e 6f 6d 65 74 72 69  |ted trigonometri|
000011b0  63 20 76 61 72 69 61 62  6c 65 73 20 75 73 65 64  |c variables used|
000011c0  20 69 6e 20 74 68 65 20  72 61 79 20 63 61 73 74  | in the ray cast|
000011d0  69 6e 67 20 70 72 6f 63  65 73 73 20 2a 2f 0a 0a  |ing process */..|
000011e0  76 6f 69 64 20 61 75 61  5f 74 61 62 6c 65 73 28  |void aua_tables(|
000011f0  76 6f 69 64 29 0a 7b 0a  0a 69 6e 74 20 61 6e 67  |void).{..int ang|
00001200  2c 20 2f 2a 20 74 68 69  73 20 69 73 20 75 73 65  |, /* this is use|
00001210  64 20 74 6f 20 68 6f 6c  64 20 76 61 6c 75 65 73  |d to hold values|
00001220  20 77 68 69 6c 65 20 6d  61 6b 69 6e 67 20 6c 6f  | while making lo|
00001230  6f 6b 2d 75 70 73 20 2a  2f 0a 20 20 20 20 61 6e  |ok-ups */.    an|
00001240  67 74 3b 20 2f 2a 20 73  61 6d 65 20 2a 2f 0a 0a  |gt; /* same */..|
00001250  66 6c 6f 61 74 20 72 61  64 5f 61 6e 67 6c 65 3b  |float rad_angle;|
00001260  20 2f 2a 20 74 68 69 73  20 68 6f 6c 64 73 20 74  | /* this holds t|
00001270  68 65 20 72 61 64 69 61  6e 73 20 65 71 75 69 76  |he radians equiv|
00001280  61 6c 65 6e 74 20 6f 66  20 74 68 65 20 66 69 78  |alent of the fix|
00001290  65 64 20 70 6f 69 6e 74  20 61 6e 67 6c 65 20 73  |ed point angle s|
000012a0  79 73 74 65 6d 20 28 30  2d 31 39 32 30 20 3d 20  |ystem (0-1920 = |
000012b0  30 2d 33 36 30 20 64 65  67 72 65 65 73 20 3d 20  |0-360 degrees = |
000012c0  30 2d 36 2e 77 68 61 74  65 76 65 72 20 72 61 64  |0-6.whatever rad|
000012d0  69 61 6e 73 2e 20 4e 65  78 74 20 6d 6f 6e 74 68  |ians. Next month|
000012e0  20 49 27 6c 6c 20 62 65  20 63 68 61 6e 67 69 6e  | I'll be changin|
000012f0  67 20 74 68 65 20 73 79  73 74 65 6d 20 73 6f 20  |g the system so |
00001300  69 74 20 62 65 63 6f 6d  65 73 20 30 2d 31 38 30  |it becomes 0-180|
00001310  30 20 69 6e 73 74 65 61  64 20 6f 66 20 31 39 32  |0 instead of 192|
00001320  30 2c 20 74 68 69 73 20  77 69 6c 6c 20 61 6c 6c  |0, this will all|
00001330  6f 77 20 61 20 73 6c 69  67 68 74 6c 79 20 73 6d  |ow a slightly sm|
00001340  61 6c 6c 65 72 20 73 63  72 65 65 6e 20 77 69 64  |aller screen wid|
00001350  74 68 2c 20 6d 6f 72 65  20 6c 69 6b 65 20 57 6f  |th, more like Wo|
00001360  6c 66 65 6e 73 74 65 69  6e 2c 20 74 68 69 73 20  |lfenstein, this |
00001370  77 69 6c 6c 20 6c 65 61  64 20 74 6f 20 61 6e 20  |will lead to an |
00001380  69 6e 63 72 65 61 73 65  20 69 6e 20 66 72 61 6d  |increase in fram|
00001390  65 20 72 61 74 65 2e 20  59 65 73 21 20 2a 2f 0a  |e rate. Yes! */.|
000013a0  0a 2f 2a 20 64 79 6e 61  6d 69 63 61 6c 6c 79 20  |./* dynamically |
000013b0  61 6c 6c 6f 63 61 74 65  64 20 61 64 65 71 75 61  |allocated adequa|
000013c0  74 65 20 6d 65 6d 6f 72  79 20 66 6f 72 20 74 68  |te memory for th|
000013d0  65 20 6c 6f 6f 6b 2d 75  70 73 20 2a 2f 0a 74 61  |e look-ups */.ta|
000013e0  6e 5f 74 61 62 6c 65 20  20 20 20 20 3d 20 28 69  |n_table     = (i|
000013f0  6e 74 20 2a 29 6d 61 6c  6c 6f 63 28 73 69 7a 65  |nt *)malloc(size|
00001400  6f 66 28 69 6e 74 29 20  2a 20 28 41 4e 47 4c 45  |of(int) * (ANGLE|
00001410  5f 33 36 30 2b 31 29 29  3b 0a 69 6e 76 5f 74 61  |_360+1));.inv_ta|
00001420  6e 5f 74 61 62 6c 65 20  3d 20 28 69 6e 74 20 2a  |n_table = (int *|
00001430  29 6d 61 6c 6c 6f 63 28  73 69 7a 65 6f 66 28 69  |)malloc(sizeof(i|
00001440  6e 74 29 20 2a 20 28 41  4e 47 4c 45 5f 33 36 30  |nt) * (ANGLE_360|
00001450  2b 31 29 29 3b 0a 0a 79  5f 73 74 65 70 20 20 20  |+1));..y_step   |
00001460  20 20 20 20 20 3d 20 28  69 6e 74 20 2a 29 6d 61  |     = (int *)ma|
00001470  6c 6c 6f 63 28 73 69 7a  65 6f 66 28 69 6e 74 29  |lloc(sizeof(int)|
00001480  20 2a 20 28 41 4e 47 4c  45 5f 33 36 30 2b 31 29  | * (ANGLE_360+1)|
00001490  29 3b 0a 78 5f 73 74 65  70 20 20 20 20 20 20 20  |);.x_step       |
000014a0  20 3d 20 28 69 6e 74 20  20 2a 29 6d 61 6c 6c 6f  | = (int  *)mallo|
000014b0  63 28 73 69 7a 65 6f 66  28 69 6e 74 29 20 2a 20  |c(sizeof(int) * |
000014c0  28 41 4e 47 4c 45 5f 33  36 30 2b 31 29 29 3b 0a  |(ANGLE_360+1));.|
000014d0  0a 63 6f 73 5f 74 61 62  6c 65 20 20 20 20 20 3d  |.cos_table     =|
000014e0  20 28 69 6e 74 20 20 2a  29 6d 61 6c 6c 6f 63 28  | (int  *)malloc(|
000014f0  73 69 7a 65 6f 66 28 69  6e 74 29 20 2a 20 28 41  |sizeof(int) * (A|
00001500  4e 47 4c 45 5f 33 36 30  2b 31 29 29 3b 0a 69 6e  |NGLE_360+1));.in|
00001510  76 5f 63 6f 73 5f 74 61  62 6c 65 20 3d 20 28 69  |v_cos_table = (i|
00001520  6e 74 20 20 2a 29 6d 61  6c 6c 6f 63 28 73 69 7a  |nt  *)malloc(siz|
00001530  65 6f 66 28 69 6e 74 29  20 2a 20 28 41 4e 47 4c  |eof(int) * (ANGL|
00001540  45 5f 33 36 30 2b 31 29  29 3b 0a 69 6e 76 5f 73  |E_360+1));.inv_s|
00001550  69 6e 5f 74 61 62 6c 65  20 3d 20 28 69 6e 74 20  |in_table = (int |
00001560  20 2a 29 6d 61 6c 6c 6f  63 28 73 69 7a 65 6f 66  | *)malloc(sizeof|
00001570  28 69 6e 74 29 20 2a 20  28 41 4e 47 4c 45 5f 33  |(int) * (ANGLE_3|
00001580  36 30 2b 31 29 29 3b 0a  2f 2a 20 6e 65 77 20 74  |60+1));./* new t|
00001590  61 62 6c 65 2c 20 66 6f  72 20 74 68 65 20 65 6e  |able, for the en|
000015a0  67 69 6e 65 2c 20 74 6f  20 61 76 6f 69 64 20 75  |gine, to avoid u|
000015b0  73 69 6e 67 20 61 20 64  69 76 69 64 65 20 2a 2f  |sing a divide */|
000015c0  0a 72 65 63 69 70 5f 74  61 62 6c 65 20 20 20 3d  |.recip_table   =|
000015d0  20 28 69 6e 74 20 20 2a  29 6d 61 6c 6c 6f 63 28  | (int  *)malloc(|
000015e0  73 69 7a 65 6f 66 28 69  6e 74 29 20 2a 20 28 4d  |sizeof(int) * (M|
000015f0  41 58 5f 44 49 53 54 41  4e 43 45 2b 31 29 29 3b  |AX_DISTANCE+1));|
00001600  0a 2f 2a 20 6e 65 77 20  74 61 62 6c 65 73 20 66  |./* new tables f|
00001610  6f 72 20 6d 6f 76 69 6e  67 20 74 68 65 20 76 69  |or moving the vi|
00001620  65 77 20 70 6f 69 6e 74  20 2a 2f 0a 64 78 5f 74  |ew point */.dx_t|
00001630  61 62 6c 65 20 20 20 20  20 20 3d 20 28 69 6e 74  |able      = (int|
00001640  20 20 2a 29 6d 61 6c 6c  6f 63 28 73 69 7a 65 6f  |  *)malloc(sizeo|
00001650  66 28 69 6e 74 29 20 2a  20 28 41 4e 47 4c 45 5f  |f(int) * (ANGLE_|
00001660  33 36 30 2b 31 29 29 3b  0a 64 79 5f 74 61 62 6c  |360+1));.dy_tabl|
00001670  65 20 20 20 20 20 20 3d  20 28 69 6e 74 20 20 2a  |e      = (int  *|
00001680  29 6d 61 6c 6c 6f 63 28  73 69 7a 65 6f 66 28 69  |)malloc(sizeof(i|
00001690  6e 74 29 20 2a 20 28 41  4e 47 4c 45 5f 33 36 30  |nt) * (ANGLE_360|
000016a0  2b 31 29 29 3b 0a 2f 2a  20 67 65 6e 65 72 61 74  |+1));./* generat|
000016b0  65 20 74 68 65 6d 2c 20  74 68 65 69 72 20 75 73  |e them, their us|
000016c0  65 20 69 73 20 65 78 70  6c 61 69 6e 65 64 20 69  |e is explained i|
000016d0  6e 20 74 68 65 20 72 61  79 20 63 61 73 74 69 6e  |n the ray castin|
000016e0  67 20 65 6e 67 69 6e 65  20 2a 2f 0a 2f 2a 20 74  |g engine */./* t|
000016f0  77 6f 20 6e 65 77 20 74  61 62 6c 65 73 20 74 6f  |wo new tables to|
00001700  20 75 73 65 20 66 6f 72  20 6f 62 6a 65 63 74 20  | use for object |
00001710  70 6c 6f 74 74 69 6e 67  20 2a 2f 0a 63 6f 73 6f  |plotting */.coso|
00001720  5f 74 61 62 6c 65 20 20  20 20 20 3d 20 28 69 6e  |_table     = (in|
00001730  74 20 20 2a 29 6d 61 6c  6c 6f 63 28 73 69 7a 65  |t  *)malloc(size|
00001740  6f 66 28 69 6e 74 29 20  2a 20 28 41 4e 47 4c 45  |of(int) * (ANGLE|
00001750  5f 33 36 30 2b 31 29 29  3b 0a 73 69 6e 6f 5f 74  |_360+1));.sino_t|
00001760  61 62 6c 65 20 3d 20 20  20 20 20 28 69 6e 74 20  |able =     (int |
00001770  20 2a 29 6d 61 6c 6c 6f  63 28 73 69 7a 65 6f 66  | *)malloc(sizeof|
00001780  28 69 6e 74 29 20 2a 20  28 41 4e 47 4c 45 5f 33  |(int) * (ANGLE_3|
00001790  36 30 2b 31 29 29 3b 0a  0a 70 72 69 6e 74 66 28  |60+1));..printf(|
000017a0  22 5f 74 61 62 6c 65 73  3a 20 73 74 61 72 74 69  |"_tables: starti|
000017b0  6e 67 20 61 6e 67 6c 65  20 6c 6f 6f 70 5c 6e 5b  |ng angle loop\n[|
000017c0  2e 22 29 3b 0a 66 6f 72  28 61 6e 67 74 3d 41 4e  |.");.for(angt=AN|
000017d0  47 4c 45 5f 30 3b 61 6e  67 74 3c 3d 41 4e 47 4c  |GLE_0;angt<=ANGL|
000017e0  45 5f 33 36 30 3b 61 6e  67 74 2b 2b 29 0a 7b 0a  |E_360;angt++).{.|
000017f0  61 6e 67 3d 61 6e 67 74  3b 0a 2f 2a 20 74 68 69  |ang=angt;./* thi|
00001800  73 20 6e 65 78 74 20 6c  69 6e 65 20 63 61 6c 63  |s next line calc|
00001810  75 6c 61 74 65 73 20 74  68 65 20 72 61 64 69 61  |ulates the radia|
00001820  6e 20 61 6e 67 6c 65 20  74 6f 20 70 61 73 73 20  |n angle to pass |
00001830  74 6f 20 74 68 65 20 74  72 69 67 2e 20 66 75 6e  |to the trig. fun|
00001840  63 74 69 6f 6e 73 20 2a  2f 0a 72 61 64 5f 61 6e  |ctions */.rad_an|
00001850  67 6c 65 3d 28 66 6c 6f  61 74 29 28 28 33 2e 32  |gle=(float)((3.2|
00001860  37 32 65 2d 34 29 20 2b  20 61 6e 67 20 2a 20 32  |72e-4) + ang * 2|
00001870  2a 33 2e 31 34 31 35 39  32 36 35 34 2f 41 4e 47  |*3.141592654/ANG|
00001880  4c 45 5f 33 36 30 29 3b  0a 0a 74 61 6e 5f 74 61  |LE_360);..tan_ta|
00001890  62 6c 65 5b 61 6e 67 5d  3d 28 69 6e 74 29 28 74  |ble[ang]=(int)(t|
000018a0  61 6e 28 72 61 64 5f 61  6e 67 6c 65 29 2a 36 35  |an(rad_angle)*65|
000018b0  35 33 36 29 3b 0a 69 6e  76 5f 74 61 6e 5f 74 61  |536);.inv_tan_ta|
000018c0  62 6c 65 5b 61 6e 67 5d  3d 28 69 6e 74 29 28 28  |ble[ang]=(int)((|
000018d0  31 2f 74 61 6e 28 72 61  64 5f 61 6e 67 6c 65 29  |1/tan(rad_angle)|
000018e0  29 2a 36 35 35 33 36 29  3b 0a 2f 2a 20 6e 6f 74  |)*65536);./* not|
000018f0  65 20 74 68 61 20 61 62  6f 76 65 20 63 6f 6e 76  |e tha above conv|
00001900  65 72 73 69 6f 6e 73 20  74 6f 20 66 69 78 65 64  |ersions to fixed|
00001910  20 70 6f 69 6e 74 20 69  6e 74 65 67 65 72 73 20  | point integers |
00001920  2a 2f 0a 0a 2f 2a 20 77  65 20 64 6f 20 74 68 65  |*/../* we do the|
00001930  20 73 61 6d 65 20 66 6f  72 20 74 68 65 73 65 20  | same for these |
00001940  74 61 62 6c 65 73 2c 20  62 75 74 20 75 6e 66 6f  |tables, but unfo|
00001950  72 74 75 6e 61 74 65 6c  79 20 61 74 20 74 68 65  |rtunately at the|
00001960  20 61 73 79 6d 70 74 6f  74 65 73 20 74 68 65 20  | asymptotes the |
00001970  6e 75 6d 62 65 72 73 20  62 65 63 6f 6d 65 20 61  |numbers become a|
00001980  77 6b 77 61 72 64 6c 79  20 6c 61 72 67 65 20 74  |wkwardly large t|
00001990  6f 20 73 74 6f 72 65 20  69 6e 20 6f 75 72 20 66  |o store in our f|
000019a0  69 78 65 64 20 70 6f 69  6e 74 20 72 65 70 72 65  |ixed point repre|
000019b0  73 65 6e 74 61 74 69 6f  6e 2e 20 49 6e 73 74 65  |sentation. Inste|
000019c0  61 64 20 6f 66 20 6d 75  6c 74 69 70 6c 79 69 6e  |ad of multiplyin|
000019d0  67 20 62 79 20 36 34 20  77 65 20 64 6f 20 38 2c  |g by 64 we do 8,|
000019e0  20 74 6f 20 6d 61 6b 65  20 73 75 72 65 20 74 68  | to make sure th|
000019f0  61 74 20 6e 6f 20 6f 76  65 72 66 6c 6f 77 20 63  |at no overflow c|
00001a00  61 6e 20 6f 63 63 75 72  20 61 74 20 74 68 69 73  |an occur at this|
00001a10  20 73 74 61 67 65 2e 20  57 65 20 6f 6e 6c 79 20  | stage. We only |
00001a20  6e 65 65 64 20 74 6f 20  6d 75 6c 74 69 70 6c 79  |need to multiply|
00001a30  20 62 79 20 61 6e 6f 74  68 65 72 20 38 20 6c 61  | by another 8 la|
00001a40  74 65 72 20 69 6e 20 74  68 65 20 65 6e 67 69 6e  |ter in the engin|
00001a50  65 2c 20 69 74 73 20 6f  6b 61 79 20 2a 2f 0a 0a  |e, its okay */..|
00001a60  69 66 28 61 6e 67 3e 3d  41 4e 47 4c 45 5f 30 20  |if(ang>=ANGLE_0 |
00001a70  26 26 20 61 6e 67 3c 41  4e 47 4c 45 5f 31 38 30  |&& ang<ANGLE_180|
00001a80  29 0a 7b 0a 79 5f 73 74  65 70 5b 61 6e 67 5d 3d  |).{.y_step[ang]=|
00001a90  66 61 62 73 28 20 28 38  29 20 2a 20 28 74 61 6e  |fabs( (8) * (tan|
00001aa0  5f 74 61 62 6c 65 5b 61  6e 67 5d 29 20 29 3b 0a  |_table[ang]) );.|
00001ab0  7d 0a 65 6c 73 65 0a 20  20 79 5f 73 74 65 70 5b  |}.else.  y_step[|
00001ac0  61 6e 67 5d 3d 2d 66 61  62 73 28 20 28 38 29 20  |ang]=-fabs( (8) |
00001ad0  2a 20 28 74 61 6e 5f 74  61 62 6c 65 5b 61 6e 67  |* (tan_table[ang|
00001ae0  5d 29 20 29 3b 0a 0a 69  66 28 61 6e 67 3e 3d 41  |]) );..if(ang>=A|
00001af0  4e 47 4c 45 5f 39 30 20  26 26 20 61 6e 67 3c 41  |NGLE_90 && ang<A|
00001b00  4e 47 4c 45 5f 32 37 30  29 0a 7b 0a 78 5f 73 74  |NGLE_270).{.x_st|
00001b10  65 70 5b 61 6e 67 5d 3d  2d 66 61 62 73 28 20 28  |ep[ang]=-fabs( (|
00001b20  38 29 20 2a 20 28 69 6e  76 5f 74 61 6e 5f 74 61  |8) * (inv_tan_ta|
00001b30  62 6c 65 5b 61 6e 67 5d  29 20 29 3b 0a 7d 0a 65  |ble[ang]) );.}.e|
00001b40  6c 73 65 0a 7b 0a 78 5f  73 74 65 70 5b 61 6e 67  |lse.{.x_step[ang|
00001b50  5d 3d 66 61 62 73 28 20  28 38 29 20 2a 20 28 69  |]=fabs( (8) * (i|
00001b60  6e 76 5f 74 61 6e 5f 74  61 62 6c 65 5b 61 6e 67  |nv_tan_table[ang|
00001b70  5d 29 20 29 3b 0a 7d 0a  0a 2f 2a 20 63 6f 6e 76  |]) );.}../* conv|
00001b80  65 72 73 69 6f 6e 20 74  6f 20 66 69 78 65 64 20  |ersion to fixed |
00001b90  70 6f 69 6e 74 20 2a 2f  0a 69 6e 76 5f 63 6f 73  |point */.inv_cos|
00001ba0  5f 74 61 62 6c 65 5b 61  6e 67 5d 3d 28 69 6e 74  |_table[ang]=(int|
00001bb0  29 28 28 31 2f 63 6f 73  28 72 61 64 5f 61 6e 67  |)((1/cos(rad_ang|
00001bc0  6c 65 29 29 2a 36 35 35  33 36 29 3b 0a 69 6e 76  |le))*65536);.inv|
00001bd0  5f 73 69 6e 5f 74 61 62  6c 65 5b 61 6e 67 5d 3d  |_sin_table[ang]=|
00001be0  28 69 6e 74 29 28 28 31  2f 73 69 6e 28 72 61 64  |(int)((1/sin(rad|
00001bf0  5f 61 6e 67 6c 65 29 29  2a 36 35 35 33 36 29 3b  |_angle))*65536);|
00001c00  0a 2f 2a 20 63 6f 6e 76  65 72 73 69 6f 6e 20 74  |./* conversion t|
00001c10  6f 20 66 69 78 65 64 20  70 6f 69 6e 74 20 6f 66  |o fixed point of|
00001c20  20 6f 62 6a 65 63 74 20  70 6c 6f 74 74 69 6e 67  | object plotting|
00001c30  20 73 69 6e 65 20 61 6e  64 20 63 6f 73 69 6e 65  | sine and cosine|
00001c40  73 20 2a 2f 0a 73 69 6e  6f 5f 74 61 62 6c 65 5b  |s */.sino_table[|
00001c50  61 6e 67 5d 3d 28 69 6e  74 29 28 73 69 6e 28 72  |ang]=(int)(sin(r|
00001c60  61 64 5f 61 6e 67 6c 65  2d 31 2e 35 37 30 37 39  |ad_angle-1.57079|
00001c70  36 33 32 37 29 2a 36 35  35 33 36 29 3b 0a 63 6f  |6327)*65536);.co|
00001c80  73 6f 5f 74 61 62 6c 65  5b 61 6e 67 5d 3d 28 69  |so_table[ang]=(i|
00001c90  6e 74 29 28 63 6f 73 28  72 61 64 5f 61 6e 67 6c  |nt)(cos(rad_angl|
00001ca0  65 2d 31 2e 35 37 30 37  39 36 33 32 37 29 2a 36  |e-1.570796327)*6|
00001cb0  35 35 33 36 29 3b 0a 2f  2a 20 77 6f 72 6b 20 6f  |5536);./* work o|
00001cc0  75 74 20 74 61 62 6c 65  73 20 66 6f 72 20 6d 6f  |ut tables for mo|
00001cd0  76 69 6e 67 20 74 68 65  20 76 69 65 77 70 6f 69  |ving the viewpoi|
00001ce0  6e 74 20 2a 2f 0a 64 78  5f 74 61 62 6c 65 5b 61  |nt */.dx_table[a|
00001cf0  6e 67 5d 3d 28 69 6e 74  29 28 63 6f 73 28 36 2e  |ng]=(int)(cos(6.|
00001d00  32 38 2a 61 6e 67 2f 41  4e 47 4c 45 5f 33 36 30  |28*ang/ANGLE_360|
00001d10  29 2a 53 54 45 50 5f 4c  45 4e 47 54 48 29 2a 36  |)*STEP_LENGTH)*6|
00001d20  35 35 33 36 3b 0a 64 79  5f 74 61 62 6c 65 5b 61  |5536;.dy_table[a|
00001d30  6e 67 5d 3d 28 69 6e 74  29 28 73 69 6e 28 36 2e  |ng]=(int)(sin(6.|
00001d40  32 38 2a 61 6e 67 2f 41  4e 47 4c 45 5f 33 36 30  |28*ang/ANGLE_360|
00001d50  29 2a 53 54 45 50 5f 4c  45 4e 47 54 48 29 2a 36  |)*STEP_LENGTH)*6|
00001d60  35 35 33 36 3b 0a 70 72  69 6e 74 66 28 22 2e 22  |5536;.printf("."|
00001d70  29 3b 0a 7d 0a 0a 2f 2a  20 74 68 65 20 63 6f 73  |);.}../* the cos|
00001d80  69 6e 65 20 74 61 62 6c  65 20 69 73 20 75 73 65  |ine table is use|
00001d90  64 20 74 6f 20 67 65 74  20 72 69 64 20 6f 66 20  |d to get rid of |
00001da0  74 68 65 20 22 66 69 73  68 20 62 6f 77 6c 20 65  |the "fish bowl e|
00001db0  66 66 65 63 74 22 2c 20  65 78 70 6c 61 69 6e 65  |ffect", explaine|
00001dc0  64 20 69 6e 20 74 68 65  20 72 61 79 20 63 61 73  |d in the ray cas|
00001dd0  74 65 72 2e 20 42 61 73  69 63 61 6c 6c 79 20 77  |ter. Basically w|
00001de0  65 20 77 6f 72 6b 20 6f  75 74 20 63 6f 73 69 6e  |e work out cosin|
00001df0  65 73 20 66 6f 72 20 6f  75 72 20 6f 77 6e 20 73  |es for our own s|
00001e00  70 61 6e 20 6f 66 20 76  69 73 69 6f 6e 2c 20 66  |pan of vision, f|
00001e10  72 6f 6d 20 2d 33 30 20  64 65 67 72 65 65 73 20  |rom -30 degrees |
00001e20  74 6f 20 2b 33 30 20 64  65 67 72 65 65 73 2e 20  |to +30 degrees. |
00001e30  54 68 69 73 20 6d 65 61  6e 73 20 74 68 61 74 20  |This means that |
00001e40  61 73 20 77 65 20 73 63  61 6e 20 66 72 6f 6d 20  |as we scan from |
00001e50  6c 65 66 74 20 74 6f 20  72 69 67 68 74 2c 20 6f  |left to right, o|
00001e60  72 20 76 69 63 65 20 76  65 72 73 61 2c 20 6f 75  |r vice versa, ou|
00001e70  72 20 72 61 79 73 20 6f  66 20 6c 69 67 68 74 20  |r rays of light |
00001e80  61 72 65 20 61 63 74 75  61 6c 6c 79 20 63 61 73  |are actually cas|
00001e90  74 20 6f 75 74 20 69 6e  20 61 20 63 61 72 74 65  |t out in a carte|
00001ea0  73 69 61 6e 2c 20 63 69  72 63 75 6c 61 72 20 77  |sian, circular w|
00001eb0  61 79 2e 20 4f 75 72 20  77 6f 72 6c 64 20 69 73  |ay. Our world is|
00001ec0  20 68 6f 77 65 76 65 72  20 73 71 75 61 72 65 2c  | however square,|
00001ed0  20 70 6f 6c 61 72 2c 20  73 6f 20 77 65 20 68 61  | polar, so we ha|
00001ee0  76 65 20 74 6f 20 61 63  6b 6e 6f 77 6c 65 64 67  |ve to acknowledg|
00001ef0  65 20 74 68 65 20 64 69  73 74 6f 72 74 69 6f 6e  |e the distortion|
00001f00  20 63 61 75 73 65 64 20  62 79 20 6d 69 78 69 6e  | caused by mixin|
00001f10  67 20 63 61 72 74 65 73  69 61 6e 20 61 6e 64 20  |g cartesian and |
00001f20  70 6f 6c 61 72 20 63 6f  6f 72 64 69 6e 61 74 65  |polar coordinate|
00001f30  73 2e 20 49 6e 20 74 68  69 73 20 6c 6f 6f 6b 20  |s. In this look |
00001f40  75 70 20 77 65 20 61 6c  73 6f 20 68 61 76 65 20  |up we also have |
00001f50  61 20 62 69 74 20 6f 66  20 73 63 61 6c 69 6e 67  |a bit of scaling|
00001f60  20 69 6e 20 69 74 2c 20  79 65 74 20 6d 6f 72 65  | in it, yet more|
00001f70  20 74 69 6d 65 20 73 61  76 69 6e 67 20 21 21 21  | time saving !!!|
00001f80  20 2a 2f 0a 0a 66 6f 72  28 61 6e 67 3d 2d 41 4e  | */..for(ang=-AN|
00001f90  47 4c 45 5f 33 30 3b 61  6e 67 3c 3d 41 4e 47 4c  |GLE_30;ang<=ANGL|
00001fa0  45 5f 33 30 3b 61 6e 67  2b 2b 29 0a 7b 0a 2f 2a  |E_30;ang++).{./*|
00001fb0  20 77 6f 72 6b 20 6f 75  74 20 72 61 64 69 61 6e  | work out radian|
00001fc0  73 20 74 6f 20 70 61 73  73 20 74 6f 20 63 6f 73  |s to pass to cos|
00001fd0  69 6e 65 20 66 75 6e 63  74 69 6f 6e 20 2a 2f 0a  |ine function */.|
00001fe0  72 61 64 5f 61 6e 67 6c  65 3d 28 66 6c 6f 61 74  |rad_angle=(float|
00001ff0  29 28 28 33 2e 32 37 32  65 2d 34 29 2b 20 61 6e  |)((3.272e-4)+ an|
00002000  67 20 2a 20 32 2a 33 2e  31 34 31 35 39 32 36 35  |g * 2*3.14159265|
00002010  34 2f 41 4e 47 4c 45 5f  33 36 30 29 3b 0a 0a 2f  |4/ANGLE_360);../|
00002020  2a 66 69 78 65 64 20 70  6f 69 6e 74 20 63 6f 6e  |*fixed point con|
00002030  76 65 72 73 69 6f 6e 20  2a 2f 0a 63 6f 73 5f 74  |version */.cos_t|
00002040  61 62 6c 65 5b 61 6e 67  2b 41 4e 47 4c 45 5f 33  |able[ang+ANGLE_3|
00002050  30 5d 3d 28 69 6e 74 29  28 56 45 52 54 49 43 41  |0]=(int)(VERTICA|
00002060  4c 5f 53 43 41 4c 45 2f  28 63 6f 73 28 72 61 64  |L_SCALE/(cos(rad|
00002070  5f 61 6e 67 6c 65 29 29  2a 36 35 35 33 36 29 3b  |_angle))*65536);|
00002080  0a 7d 0a 70 72 69 6e 74  66 28 22 2e 2e 2e 2e 2e  |.}.printf(".....|
00002090  2e 22 29 3b 0a 2f 2a 20  74 68 69 73 20 63 72 65  |.");./* this cre|
000020a0  61 74 65 73 20 61 20 72  65 63 69 70 72 6f 63 61  |ates a reciproca|
000020b0  6c 20 74 61 62 6c 65 2c  20 73 6f 20 77 65 20 64  |l table, so we d|
000020c0  6f 6e 27 74 20 68 61 76  65 20 74 6f 20 75 73 65  |on't have to use|
000020d0  20 64 69 76 69 64 65 73  2e 20 4d 75 6c 74 69 70  | divides. Multip|
000020e0  6c 79 69 6e 67 20 62 79  20 74 68 65 20 72 65 63  |lying by the rec|
000020f0  69 70 72 6f 63 61 6c 20  6f 66 20 61 20 6e 75 6d  |iprocal of a num|
00002100  62 65 72 20 69 73 20 74  68 65 20 73 61 6d 65 20  |ber is the same |
00002110  61 73 20 64 69 76 69 64  69 6e 67 20 62 79 20 69  |as dividing by i|
00002120  74 3a 20 41 66 74 65 72  20 61 6c 6c 2c 0a 0a 38  |t: After all,..8|
00002130  20 2f 20 34 20 3d 20 32  20 61 6e 64 20 38 20 2a  | / 4 = 2 and 8 *|
00002140  20 30 2e 32 35 20 28 31  20 6f 76 65 72 20 34 29  | 0.25 (1 over 4)|
00002150  20 3d 20 32 20 2d 20 74  68 65 79 20 70 72 6f 64  | = 2 - they prod|
00002160  75 63 65 20 74 68 65 20  73 61 6d 65 20 72 65 73  |uce the same res|
00002170  75 6c 74 20 2a 2f 0a 0a  66 6f 72 28 61 6e 67 3d  |ult */..for(ang=|
00002180  31 3b 61 6e 67 3c 4d 41  58 5f 44 49 53 54 41 4e  |1;ang<MAX_DISTAN|
00002190  43 45 3b 61 6e 67 2b 2b  29 0a 7b 0a 20 20 2f 2a  |CE;ang++).{.  /*|
000021a0  20 69 74 20 69 73 20 73  74 69 6c 6c 20 66 69 78  | it is still fix|
000021b0  65 64 20 70 6f 69 6e 74  20 74 68 6f 75 67 68 20  |ed point though |
000021c0  2a 2f 0a 20 20 72 65 63  69 70 5f 74 61 62 6c 65  |*/.  recip_table|
000021d0  5b 61 6e 67 5d 3d 28 69  6e 74 29 28 31 2e 30 2f  |[ang]=(int)(1.0/|
000021e0  28 66 6c 6f 61 74 29 61  6e 67 2a 36 35 35 33 36  |(float)ang*65536|
000021f0  29 3b 0a 7d 0a 70 72 69  6e 74 66 28 22 2e 5d 5c  |);.}.printf(".]\|
00002200  6e 22 29 3b 0a 7d 0a 0a  2f 2a 20 74 68 69 73 20  |n");.}../* this |
00002210  66 75 6e 63 74 69 6f 6e  20 69 73 20 74 68 65 20  |function is the |
00002220  68 65 61 72 74 20 6f 66  20 74 68 65 20 70 72 6f  |heart of the pro|
00002230  67 72 61 6d 2c 20 74 68  65 20 65 6e 67 69 6e 65  |gram, the engine|
00002240  2c 20 74 6f 20 67 65 6e  65 72 61 74 65 20 74 68  |, to generate th|
00002250  65 20 66 69 72 73 74 20  70 65 72 73 6f 6e 20 76  |e first person v|
00002260  69 65 77 20 2a 2f 0a 76  6f 69 64 20 61 75 61 5f  |iew */.void aua_|
00002270  72 61 79 63 61 73 74 65  72 28 69 6e 74 20 76 69  |raycaster(int vi|
00002280  65 77 5f 78 2c 69 6e 74  20 76 69 65 77 5f 79 2c  |ew_x,int view_y,|
00002290  69 6e 74 20 76 69 65 77  5f 61 6e 67 6c 65 29 0a  |int view_angle).|
000022a0  7b 0a 2f 2a 20 72 65 6d  65 6d 62 65 72 20 74 68  |{./* remember th|
000022b0  61 74 20 77 65 20 61 72  65 20 74 68 69 6e 6b 69  |at we are thinki|
000022c0  6e 67 20 69 6e 20 32 2d  44 2c 20 6e 6f 74 20 69  |ng in 2-D, not i|
000022d0  6e 20 33 44 20 77 68 65  6e 20 77 65 20 64 69 73  |n 3D when we dis|
000022e0  63 75 73 73 20 69 64 65  61 73 2e 20 42 65 6c 6f  |cuss ideas. Belo|
000022f0  77 20 64 6f 65 73 20 6e  6f 74 20 6d 65 61 6e 20  |w does not mean |
00002300  22 61 20 66 6c 6f 6f 72  20 62 65 6c 6f 77 22 2c  |"a floor below",|
00002310  20 69 74 20 72 65 61 6c  6c 79 20 6d 65 61 6e 73  | it really means|
00002320  20 22 62 65 68 69 6e 64  22 2c 20 62 75 74 20 77  | "behind", but w|
00002330  65 20 73 61 79 20 62 65  6c 6f 77 20 62 65 63 61  |e say below beca|
00002340  75 73 65 20 77 65 20 61  72 65 20 69 6d 61 67 69  |use we are imagi|
00002350  6e 69 6e 67 20 6c 6f 6f  6b 69 6e 67 20 64 6f 77  |ning looking dow|
00002360  6e 20 6f 6e 20 74 68 65  20 76 69 65 77 20 70 6f  |n on the view po|
00002370  69 6e 74 20 74 6f 20 66  6f 72 6d 20 61 20 32 2d  |int to form a 2-|
00002380  44 20 70 6c 61 6e 20 2a  2f 0a 0a 2f 2a 20 74 68  |D plan */../* th|
00002390  69 73 20 66 75 6e 63 74  69 6f 6e 2c 20 66 6f 72  |is function, for|
000023a0  20 65 61 63 68 20 63 6f  6c 75 6d 6e 20 6f 66 20  | each column of |
000023b0  74 68 65 20 33 32 30 20  70 69 78 65 6c 20 77 69  |the 320 pixel wi|
000023c0  64 74 68 20 4d 6f 64 65  20 31 33 20 73 63 72 65  |dth Mode 13 scre|
000023d0  65 6e 2c 20 63 61 73 74  73 20 6f 75 74 20 74 77  |en, casts out tw|
000023e0  6f 20 72 61 79 73 2e 20  4f 6e 65 20 72 61 79 20  |o rays. One ray |
000023f0  6c 6f 6f 6b 73 20 66 6f  72 20 58 2c 20 68 6f 72  |looks for X, hor|
00002400  69 7a 6f 6e 74 61 6c 20  69 6e 74 65 72 73 65 63  |izontal intersec|
00002410  74 69 6f 6e 73 20 77 69  74 68 20 77 61 6c 6c 73  |tions with walls|
00002420  2c 20 61 6e 64 20 74 68  65 20 6f 74 68 65 72 20  |, and the other |
00002430  74 72 61 63 6b 73 20 69  6e 74 65 72 73 65 63 74  |tracks intersect|
00002440  69 6f 6e 73 20 77 69 74  68 20 59 2c 20 76 65 72  |ions with Y, ver|
00002450  74 69 63 61 6c 20 77 61  6c 6c 20 62 6f 75 6e 64  |tical wall bound|
00002460  61 72 69 65 73 2e 20 41  66 74 65 72 20 61 6c 6c  |aries. After all|
00002470  2c 20 74 68 65 20 6f 6e  6c 79 20 74 69 6d 65 20  |, the only time |
00002480  61 20 63 6f 6c 6c 69 73  69 6f 6e 20 63 6f 75 6c  |a collision coul|
00002490  64 20 6f 63 63 75 72 20  69 73 20 6f 6e 20 61 20  |d occur is on a |
000024a0  62 6f 75 6e 64 61 72 79  20 6f 66 20 61 20 63 65  |boundary of a ce|
000024b0  6c 6c 2c 20 61 73 20 74  68 65 20 77 61 6c 6c 20  |ll, as the wall |
000024c0  66 69 6c 6c 73 20 75 70  20 74 68 65 20 65 6e 74  |fills up the ent|
000024d0  69 72 65 20 63 65 6c 6c  2e 20 45 78 70 65 63 74  |ire cell. Expect|
000024e0  20 74 6f 20 73 65 65 20  6c 6f 74 73 20 6f 66 20  | to see lots of |
000024f0  36 34 27 73 2c 20 74 68  6f 75 67 68 20 72 65 6d  |64's, though rem|
00002500  65 6d 62 65 72 20 74 68  61 74 20 74 68 69 73 20  |ember that this |
00002510  72 61 79 20 63 61 73 74  65 72 20 69 73 20 76 65  |ray caster is ve|
00002520  72 79 20 72 6f 75 74 69  6e 65 2c 20 61 6e 64 20  |ry routine, and |
00002530  68 61 73 20 6e 6f 74 20  61 74 20 61 6c 6c 20 62  |has not at all b|
00002540  65 65 6e 20 70 75 74 20  74 68 72 6f 75 67 68 20  |een put through |
00002550  6d 79 20 22 62 6f 78 20  6f 66 20 6d 61 67 69 63  |my "box of magic|
00002560  22 2e 20 54 68 65 20 65  6e 67 69 6e 65 20 77 69  |". The engine wi|
00002570  6c 6c 20 62 65 63 6f 6d  65 20 6d 75 63 68 20 6d  |ll become much m|
00002580  6f 72 65 20 70 65 72 73  6f 6e 61 6c 69 73 65 64  |ore personalised|
00002590  20 76 65 72 79 20 73 6f  6f 6e 21 20 2a 2f 0a 0a  | very soon! */..|
000025a0  0a 0a 69 6e 74 20 63 65  6c 6c 5f 78 2c 20 2f 2a  |..int cell_x, /*|
000025b0  20 75 73 65 64 20 74 6f  20 73 74 6f 72 65 20 77  | used to store w|
000025c0  68 69 63 68 20 63 65 6c  6c 20 6f 66 20 74 68 65  |hich cell of the|
000025d0  20 77 61 6c 6c 73 20 64  61 74 61 20 74 68 65 20  | walls data the |
000025e0  72 61 79 20 69 73 20 69  6e 20 2a 2f 0a 63 65 6c  |ray is in */.cel|
000025f0  6c 5f 79 2c 20 2f 2a 20  22 20 2a 2f 0a 63 61 73  |l_y, /* " */.cas|
00002600  74 69 6e 67 3d 32 2c 20  2f 2a 20 75 73 65 64 20  |ting=2, /* used |
00002610  74 6f 20 73 74 6f 72 65  20 69 66 20 72 61 79 20  |to store if ray |
00002620  63 61 73 74 69 6e 67 20  68 61 73 20 66 69 6e 69  |casting has fini|
00002630  73 68 65 64 20 2a 2f 0a  78 5f 68 69 74 5f 74 79  |shed */.x_hit_ty|
00002640  70 65 2c 20 2f 2a 20 74  68 69 73 20 73 74 6f 72  |pe, /* this stor|
00002650  65 73 20 74 68 65 20 77  61 6c 6c 20 74 79 70 65  |es the wall type|
00002660  20 68 69 74 20 62 79 20  74 68 65 20 78 20 63 61  | hit by the x ca|
00002670  73 74 69 6e 67 20 72 61  79 20 2a 2f 0a 79 5f 68  |sting ray */.y_h|
00002680  69 74 5f 74 79 70 65 2c  20 2f 2a 20 74 68 69 73  |it_type, /* this|
00002690  20 73 6f 74 72 65 73 20  74 68 65 20 77 61 6c 6c  | sotres the wall|
000026a0  20 74 79 70 65 20 28 6e  75 6d 62 65 72 29 20 68  | type (number) h|
000026b0  69 74 20 62 79 20 74 68  65 20 79 20 72 61 79 20  |it by the y ray |
000026c0  2a 2f 0a 78 5f 62 6f 75  6e 64 2c 20 2f 2a 20 74  |*/.x_bound, /* t|
000026d0  68 69 73 20 68 6f 6c 64  73 20 74 68 65 20 6e 65  |his holds the ne|
000026e0  78 74 20 78 20 62 6f 75  6e 64 61 72 79 20 66 6f  |xt x boundary fo|
000026f0  72 20 61 20 70 6f 73 73  69 62 6c 65 20 69 6e 74  |r a possible int|
00002700  65 72 73 65 63 74 69 6f  6e 20 2a 2f 0a 79 5f 62  |ersection */.y_b|
00002710  6f 75 6e 64 2c 20 2f 2a  20 74 68 69 73 20 68 6f  |ound, /* this ho|
00002720  6c 64 73 20 74 68 65 20  6e 65 78 74 20 79 20 62  |lds the next y b|
00002730  6f 75 6e 64 61 72 79 20  66 6f 72 20 61 20 70 6f  |oundary for a po|
00002740  73 73 69 62 6c 65 20 69  6e 74 65 72 73 65 63 74  |ssible intersect|
00002750  69 6f 6e 20 2a 2f 0a 6e  65 78 74 5f 79 5f 63 65  |ion */.next_y_ce|
00002760  6c 6c 2c 20 2f 2a 20 74  68 69 73 20 69 73 20 75  |ll, /* this is u|
00002770  73 65 64 20 74 6f 20 66  69 67 75 72 65 20 6f 75  |sed to figure ou|
00002780  74 20 74 68 65 20 71 75  61 64 72 61 6e 74 20 6f  |t the quadrant o|
00002790  66 20 74 68 65 20 72 61  79 20 28 2b 2f 2d 29 2a  |f the ray (+/-)*|
000027a0  2f 0a 6e 65 78 74 5f 78  5f 63 65 6c 6c 2c 20 2f  |/.next_x_cell, /|
000027b0  2a 20 22 20 2a 2f 0a 78  5f 64 65 6c 74 61 2c 20  |* " */.x_delta, |
000027c0  2f 2a 20 74 68 69 73 20  69 73 20 2b 27 64 20 74  |/* this is +'d t|
000027d0  6f 20 74 68 65 20 78 5f  62 6f 75 6e 64 20 76 61  |o the x_bound va|
000027e0  72 2e 20 74 6f 20 6d 6f  76 65 20 74 6f 20 74 68  |r. to move to th|
000027f0  65 20 6e 65 78 74 20 62  6f 75 6e 64 61 72 79 20  |e next boundary |
00002800  2a 2f 0a 79 5f 64 65 6c  74 61 2c 20 2f 2a 20 74  |*/.y_delta, /* t|
00002810  68 69 73 20 69 73 20 2b  27 64 20 74 6f 20 74 68  |his is +'d to th|
00002820  65 20 79 5f 62 6f 75 6e  64 20 76 61 72 2e 20 74  |e y_bound var. t|
00002830  6f 20 6d 6f 76 65 20 74  6f 20 74 68 65 20 6e 65  |o move to the ne|
00002840  78 74 20 62 6f 75 6e 64  61 72 79 20 2a 2f 0a 78  |xt boundary */.x|
00002850  69 5f 73 61 76 65 2c 20  2f 2a 20 74 68 69 73 20  |i_save, /* this |
00002860  73 74 6f 72 65 73 20 77  68 65 72 65 20 74 68 65  |stores where the|
00002870  20 78 20 63 61 73 74 69  6e 67 20 72 61 79 20 6d  | x casting ray m|
00002880  61 64 65 20 69 74 73 20  69 6e 74 65 72 73 65 63  |ade its intersec|
00002890  74 69 6f 6e 20 2a 2f 0a  79 69 5f 73 61 76 65 2c  |tion */.yi_save,|
000028a0  20 2f 2a 20 74 68 69 73  20 73 74 6f 72 65 73 20  | /* this stores |
000028b0  77 68 65 72 65 20 74 68  65 20 79 20 63 61 73 74  |where the y cast|
000028c0  69 6e 67 20 72 61 79 20  6d 61 64 65 20 69 74 73  |ing ray made its|
000028d0  20 69 6e 74 65 72 73 65  63 74 69 6f 6e 20 2a 2f  | intersection */|
000028e0  0a 73 63 61 6c 65 2c 20  20 20 2f 2a 20 74 68 69  |.scale,   /* thi|
000028f0  73 20 73 74 6f 72 65 73  20 74 68 65 20 73 63 61  |s stores the sca|
00002900  6c 65 20 6f 66 20 74 68  65 20 73 6c 69 76 65 72  |le of the sliver|
00002910  20 74 6f 20 62 65 20 64  72 61 77 6e 20 69 6e 20  | to be drawn in |
00002920  65 61 63 68 20 63 6f 6c  75 6d 6e 20 2a 2f 0a 72  |each column */.r|
00002930  61 79 2c 20 2f 2a 20 74  68 69 73 20 73 74 6f 72  |ay, /* this stor|
00002940  65 73 20 74 68 65 20 72  61 79 20 6e 75 6d 62 65  |es the ray numbe|
00002950  72 20 62 65 69 6e 67 20  63 61 73 74 20 6f 75 74  |r being cast out|
00002960  20 28 30 2d 33 32 30 29  2a 2f 0a 78 72 61 79 2c  | (0-320)*/.xray,|
00002970  20 2f 2a 20 74 68 69 73  20 66 6c 61 67 20 69 73  | /* this flag is|
00002980  20 75 73 65 64 20 74 6f  20 73 68 6f 77 20 69 66  | used to show if|
00002990  20 63 61 73 74 69 6e 67  20 69 73 20 6f 76 65 72  | casting is over|
000029a0  20 2a 2f 0a 79 72 61 79  2c 20 2f 2a 20 22 20 2a  | */.yray, /* " *|
000029b0  2f 0a 64 69 73 74 5f 78  2c 20 2f 2a 20 74 68 69  |/.dist_x, /* thi|
000029c0  73 20 68 6f 6c 64 73 20  74 68 65 20 64 69 73 74  |s holds the dist|
000029d0  61 6e 63 65 20 74 6f 20  74 68 65 20 78 20 69 6e  |ance to the x in|
000029e0  74 65 72 73 65 63 74 69  6f 6e 20 2a 2f 0a 64 69  |tersection */.di|
000029f0  73 74 5f 79 3b 20 2f 2a  20 74 68 69 73 20 68 6f  |st_y; /* this ho|
00002a00  6c 64 73 20 74 68 65 20  64 69 73 74 61 6e 63 65  |lds the distance|
00002a10  20 74 6f 20 74 68 65 20  79 20 69 6e 74 65 72 73  | to the y inters|
00002a20  65 63 74 69 6f 6e 20 2a  2f 0a 0a 69 6e 74 20 20  |ection */..int  |
00002a30  20 78 69 2c 0a 20 20 20  20 20 20 79 69 2c 0a 20  | xi,.      yi,. |
00002a40  20 20 20 20 20 78 61 64  64 2c 0a 20 20 20 20 20  |     xadd,.     |
00002a50  20 79 61 64 64 3b 20 2f  2a 20 74 68 65 73 65 20  | yadd; /* these |
00002a60  61 72 65 20 75 73 65 64  20 74 6f 20 61 63 63 75  |are used to accu|
00002a70  72 61 74 65 6c 79 20 74  72 61 63 65 20 61 6e 64  |rately trace and|
00002a80  20 6d 6f 76 65 20 65 61  63 68 20 72 61 79 20 20  | move each ray  |
00002a90  20 20 20 20 2a 2f 0a 0a  69 6e 74 20 76 61 72 69  |    */..int vari|
00002aa0  61 62 6c 65 73 5b 36 5d  2c 20 2f 2a 20 74 68 69  |ables[6], /* thi|
00002ab0  73 20 69 73 20 75 73 65  64 20 74 6f 20 70 61 73  |s is used to pas|
00002ac0  73 20 76 61 72 69 61 62  6c 65 73 20 74 6f 20 61  |s variables to a|
00002ad0  20 73 6c 69 76 65 72 20  72 65 6e 64 65 72 65 72  | sliver renderer|
00002ae0  20 20 2a 2f 0a 20 20 20  20 63 6c 69 70 3b 20 20  |  */.    clip;  |
00002af0  20 20 20 20 2f 2a 20 74  68 69 73 20 63 6f 75 6c  |    /* this coul|
00002b00  64 20 62 65 20 75 73 65  64 20 6c 61 74 65 72 20  |d be used later |
00002b10  66 6f 72 20 63 6c 69 70  70 69 6e 67 20 2a 2f 0a  |for clipping */.|
00002b20  69 6e 74 20 78 74 72 61  6e 73 5f 64 69 73 74 2c  |int xtrans_dist,|
00002b30  20 2f 2a 20 74 68 65 73  65 20 4e 45 57 20 54 52  | /* these NEW TR|
00002b40  41 4e 53 50 41 52 45 4e  54 20 76 61 72 69 61 62  |ANSPARENT variab|
00002b50  6c 65 73 20 61 72 65 20  75 73 65 64 20 66 6f 72  |les are used for|
00002b60  20 77 69 6e 64 6f 77 73  20 20 2a 2f 0a 20 20 20  | windows  */.   |
00002b70  20 79 74 72 61 6e 73 5f  64 69 73 74 2c 20 2f 2a  | ytrans_dist, /*|
00002b80  20 65 61 63 68 20 6f 6e  65 20 77 69 6c 6c 20 62  | each one will b|
00002b90  65 20 75 73 65 64 20 6c  61 74 65 72 20 74 6f 20  |e used later to |
00002ba0  64 72 61 77 20 74 72 61  6e 73 70 61 72 65 6e 74  |draw transparent|
00002bb0  20 77 61 6c 6c 73 20 2a  2f 0a 20 20 20 20 78 74  | walls */.    xt|
00002bc0  72 61 6e 73 5f 63 6f 6c  2c 0a 20 20 20 20 79 74  |rans_col,.    yt|
00002bd0  72 61 6e 73 5f 63 6f 6c  2c 0a 20 20 20 20 78 74  |rans_col,.    xt|
00002be0  72 61 6e 73 5f 74 79 70  65 2c 0a 20 20 20 20 79  |rans_type,.    y|
00002bf0  74 72 61 6e 73 5f 74 79  70 65 2c 0a 20 20 20 20  |trans_type,.    |
00002c00  78 74 72 61 6e 73 5f 64  6f 6e 65 2c 2f 2a 20 74  |xtrans_done,/* t|
00002c10  68 65 73 65 20 6c 61 73  74 20 74 77 6f 20 61 72  |hese last two ar|
00002c20  65 20 75 73 65 64 20 61  73 20 66 6c 61 67 73 20  |e used as flags |
00002c30  74 6f 20 6d 61 72 6b 20  69 66 20 61 20 74 72 61  |to mark if a tra|
00002c40  6e 73 70 61 72 2d 2a 2f  0a 20 20 20 20 79 74 72  |nspar-*/.    ytr|
00002c50  61 6e 73 5f 64 6f 6e 65  3b 2f 2a 65 6e 63 79 20  |ans_done;/*ency |
00002c60  68 61 73 20 62 65 65 6e  20 66 6f 75 6e 64 20 6f  |has been found o|
00002c70  72 20 6e 6f 74 20 2a 2f  0a 0a 69 6e 74 20 63 6f  |r not */..int co|
00002c80  75 6e 74 65 72 3d 30 3b  0a 2f 2a 20 66 69 72 73  |unter=0;./* firs|
00002c90  74 6c 79 2c 20 77 65 20  73 65 74 20 75 70 20 74  |tly, we set up t|
00002ca0  68 65 20 76 61 72 69 61  62 6c 65 73 5b 5d 20 77  |he variables[] w|
00002cb0  65 20 61 6c 72 65 61 64  79 20 6b 6e 6f 77 2c 20  |e already know, |
00002cc0  73 75 63 68 20 61 73 20  73 63 72 65 65 6e 5f 61  |such as screen_a|
00002cd0  64 64 72 65 73 73 2c 20  77 61 6c 6c 73 20 61 6e  |ddress, walls an|
00002ce0  64 20 74 68 65 20 73 63  72 65 65 6e 20 68 65 69  |d the screen hei|
00002cf0  67 68 74 20 77 65 20 61  72 65 20 75 73 69 6e 67  |ght we are using|
00002d00  2e 20 54 68 65 73 65 20  61 72 65 20 61 6c 6c 20  |. These are all |
00002d10  74 68 69 6e 67 73 20 77  68 69 63 68 20 6f 75 72  |things which our|
00002d20  20 73 6c 69 76 65 72 20  72 65 6e 64 65 72 65 72  | sliver renderer|
00002d30  20 6e 65 65 64 73 20 74  6f 20 6b 6e 6f 77 20 74  | needs to know t|
00002d40  6f 20 70 6c 6f 74 20 69  74 73 20 63 6f 6c 75 6d  |o plot its colum|
00002d50  6e 20 2a 2f 0a 0a 76 61  72 69 61 62 6c 65 73 5b  |n */..variables[|
00002d60  30 5d 3d 28 69 6e 74 29  73 63 72 65 65 6e 5f 61  |0]=(int)screen_a|
00002d70  64 64 72 65 73 73 3b 0a  0a 0a 2f 2a 20 6e 6f 77  |ddress;.../* now|
00002d80  20 77 65 20 67 65 74 20  64 6f 77 6e 20 74 6f 20  | we get down to |
00002d90  74 68 65 20 6e 69 74 74  79 20 67 72 69 74 74 79  |the nitty gritty|
00002da0  2e 20 48 65 72 65 20 77  65 20 73 75 62 74 72 61  |. Here we subtra|
00002db0  63 74 20 33 30 20 64 65  67 72 65 65 73 20 66 72  |ct 30 degrees fr|
00002dc0  6f 6d 20 74 68 65 20 76  69 65 77 69 6e 67 20 61  |om the viewing a|
00002dd0  6e 67 6c 65 20 72 65 6d  65 6d 62 65 72 20 74 68  |ngle remember th|
00002de0  61 74 20 6f 75 72 20 46  4f 56 20 69 73 20 36 30  |at our FOV is 60|
00002df0  20 64 65 67 72 65 65 73  20 77 68 69 63 68 20 6d  | degrees which m|
00002e00  65 61 6e 73 20 74 68 61  74 20 77 65 20 63 61 73  |eans that we cas|
00002e10  74 20 66 72 6f 6d 20 2d  33 30 20 74 6f 20 2b 33  |t from -30 to +3|
00002e20  30 20 2a 2f 0a 0a 69 66  20 28 20 28 76 69 65 77  |0 */..if ( (view|
00002e30  5f 61 6e 67 6c 65 2d 3d  41 4e 47 4c 45 5f 33 30  |_angle-=ANGLE_30|
00002e40  29 20 3c 20 30 29 0a 20  20 20 7b 0a 20 20 20 2f  |) < 0).   {.   /|
00002e50  2a 20 74 68 69 73 20 65  6e 73 75 72 65 73 20 74  |* this ensures t|
00002e60  68 61 74 20 77 65 20 64  6f 6e 27 74 20 67 6f 20  |hat we don't go |
00002e70  6f 76 65 72 20 6f 72 20  75 6e 64 65 72 20 30 2f  |over or under 0/|
00002e80  33 36 30 20 64 65 67 72  65 65 73 21 20 2a 2f 0a  |360 degrees! */.|
00002e90  20 20 20 76 69 65 77 5f  61 6e 67 6c 65 3d 41 4e  |   view_angle=AN|
00002ea0  47 4c 45 5f 33 36 30 20  2b 20 76 69 65 77 5f 61  |GLE_360 + view_a|
00002eb0  6e 67 6c 65 3b 0a 20 20  20 7d 0a 2f 2a 20 6e 6f  |ngle;.   }./* no|
00002ec0  77 20 77 65 20 73 74 61  72 74 20 74 68 65 20 6d  |w we start the m|
00002ed0  61 69 6e 20 6c 6f 6f 70  2c 20 73 74 61 72 74 20  |ain loop, start |
00002ee0  61 74 20 74 68 65 20 72  69 67 68 74 20 6f 66 20  |at the right of |
00002ef0  74 68 65 20 73 63 72 65  65 6e 20 28 33 31 39 29  |the screen (319)|
00002f00  2c 20 61 6e 64 20 63 61  73 74 20 65 61 63 68 20  |, and cast each |
00002f10  63 6f 6c 75 6d 6e 20 6f  6e 65 20 62 79 20 6f 6e  |column one by on|
00002f20  65 20 74 6f 20 74 68 65  20 6c 65 66 74 20 2a 2f  |e to the left */|
00002f30  0a 0a 66 6f 72 20 28 72  61 79 3d 53 43 52 45 45  |..for (ray=SCREE|
00002f40  4e 5f 57 49 44 54 48 2d  31 3b 20 72 61 79 3e 3d  |N_WIDTH-1; ray>=|
00002f50  30 3b 20 72 61 79 2d 2d  29 0a 20 20 20 20 7b 0a  |0; ray--).    {.|
00002f60  2f 2a 20 66 6f 72 20 65  61 63 68 20 72 61 79 20  |/* for each ray |
00002f70  74 6f 20 62 65 20 63 61  73 74 20 77 65 20 61 63  |to be cast we ac|
00002f80  74 75 61 6c 6c 79 20 63  61 73 74 20 6f 75 74 20  |tually cast out |
00002f90  74 77 6f 20 72 61 79 73  20 3a 20 6f 6e 65 20 74  |two rays : one t|
00002fa0  6f 20 63 68 65 63 6b 20  66 6f 72 20 76 65 72 74  |o check for vert|
00002fb0  69 63 61 6c 20 62 6f 75  6e 64 61 72 79 20 63 6f  |ical boundary co|
00002fc0  6c 6c 69 73 69 6f 6e 73  20 61 6e 64 20 74 68 65  |llisions and the|
00002fd0  20 6f 74 68 65 72 20 74  6f 20 63 68 65 63 6b 20  | other to check |
00002fe0  66 6f 72 20 68 6f 72 69  7a 6f 6e 74 61 6c 20 62  |for horizontal b|
00002ff0  6f 75 6e 64 61 72 79 20  63 6f 6c 6c 69 73 69 6f  |oundary collisio|
00003000  6e 73 2e 20 43 6f 6e 73  69 64 65 72 69 6e 67 20  |ns. Considering |
00003010  74 68 61 74 20 77 61 6c  6c 73 20 66 69 6c 6c 20  |that walls fill |
00003020  75 70 20 65 61 63 68 20  63 65 6c 6c 2c 20 77 65  |up each cell, we|
00003030  20 6e 65 65 64 20 6f 6e  6c 79 20 6c 6f 6f 6b 20  | need only look |
00003040  66 6f 72 20 69 6e 74 65  72 73 65 63 74 69 6f 6e  |for intersection|
00003050  73 20 6f 6e 20 74 68 65  20 62 6f 75 6e 64 61 72  |s on the boundar|
00003060  69 65 73 2e 20 57 65 20  68 61 76 65 20 74 6f 20  |ies. We have to |
00003070  70 65 72 66 6f 72 6d 20  73 65 70 65 72 61 74 65  |perform seperate|
00003080  20 63 61 73 74 20 62 65  63 61 75 73 65 20 6a 75  | cast because ju|
00003090  73 74 20 63 61 73 74 69  6e 67 20 6f 6e 65 20 72  |st casting one r|
000030a0  61 79 20 63 6f 6d 70 6c  69 63 61 74 65 73 20 74  |ay complicates t|
000030b0  68 65 20 6d 61 74 74 65  72 20 61 6e 64 20 69 74  |he matter and it|
000030c0  20 64 6f 65 73 6e 27 74  20 67 69 76 65 20 6d 75  | doesn't give mu|
000030d0  63 68 20 73 70 65 65 64  20 69 6e 63 72 65 61 73  |ch speed increas|
000030e0  65 2c 20 69 66 20 61 6e  79 2e 20 2a 2f 0a 0a 2f  |e, if any. */../|
000030f0  2a 20 4e 45 57 20 4c 49  4e 45 20 3a 20 57 65 20  |* NEW LINE : We |
00003100  68 61 76 65 20 74 6f 20  63 68 65 63 6b 20 74 6f  |have to check to|
00003110  20 73 65 65 20 69 66 20  74 68 65 20 76 69 65 77  | see if the view|
00003120  69 6e 67 20 61 6e 67 6c  65 20 69 73 20 61 74 20  |ing angle is at |
00003130  74 68 65 20 61 73 79 6d  70 74 6f 74 65 73 2c 20  |the asymptotes, |
00003140  75 6e 66 6f 72 74 75 6e  61 74 65 6c 79 20 74 68  |unfortunately th|
00003150  65 20 66 69 78 65 64 20  70 6f 69 6e 74 20 73 79  |e fixed point sy|
00003160  73 74 65 6d 20 63 61 6e  6e 6f 74 20 73 74 6f 72  |stem cannot stor|
00003170  65 20 74 68 65 20 76 61  6c 75 65 73 20 68 65 6c  |e the values hel|
00003180  64 20 61 74 20 74 68 65  73 65 20 61 6e 67 6c 65  |d at these angle|
00003190  73 2c 20 73 6f 20 77 65  20 68 61 76 65 20 74 6f  |s, so we have to|
000031a0  20 61 76 6f 69 64 20 74  68 65 69 72 20 75 73 65  | avoid their use|
000031b0  2e 20 54 68 69 73 20 69  73 20 6e 6f 74 20 76 65  |. This is not ve|
000031c0  72 79 20 65 6c 65 67 61  6e 74 20 49 20 6b 6e 6f  |ry elegant I kno|
000031d0  77 2c 20 62 75 74 20 69  74 20 73 61 76 65 73 20  |w, but it saves |
000031e0  61 20 6c 6f 74 20 6f 66  20 68 65 61 64 20 61 63  |a lot of head ac|
000031f0  68 65 73 20 61 6e 64 20  6e 6f 20 6f 6e 65 20 63  |hes and no one c|
00003200  61 6e 20 74 65 6c 6c 20  77 65 27 76 65 20 64 6f  |an tell we've do|
00003210  6e 65 20 69 74 21 20 2a  2f 0a 0a 69 66 28 76 69  |ne it! */..if(vi|
00003220  65 77 5f 61 6e 67 6c 65  3d 3d 41 4e 47 4c 45 5f  |ew_angle==ANGLE_|
00003230  30 20 7c 7c 20 76 69 65  77 5f 61 6e 67 6c 65 3d  |0 || view_angle=|
00003240  3d 41 4e 47 4c 45 5f 39  30 20 7c 7c 20 76 69 65  |=ANGLE_90 || vie|
00003250  77 5f 61 6e 67 6c 65 20  3d 3d 41 4e 47 4c 45 5f  |w_angle ==ANGLE_|
00003260  31 38 30 20 7c 7c 20 76  69 65 77 5f 61 6e 67 6c  |180 || view_angl|
00003270  65 3d 3d 41 4e 47 4c 45  5f 32 37 30 29 76 69 65  |e==ANGLE_270)vie|
00003280  77 5f 61 6e 67 6c 65 2b  2b 3b 0a 2f 2a 20 53 45  |w_angle++;./* SE|
00003290  43 54 49 4f 4e 20 31 20  3a 20 43 41 4c 43 55 4c  |CTION 1 : CALCUL|
000032a0  41 54 49 4e 47 20 54 48  45 20 46 49 52 53 54 20  |ATING THE FIRST |
000032b0  58 20 61 6e 64 20 59 20  49 4e 54 45 52 53 45 43  |X and Y INTERSEC|
000032c0  54 49 4f 4e 53 2a 2f 0a  2f 2a 20 4f 6e 63 65 20  |TIONS*/./* Once |
000032d0  77 65 20 68 61 76 65 20  64 6f 6e 65 20 74 68 69  |we have done thi|
000032e0  73 20 74 68 65 20 66 6f  6c 6c 6f 77 69 6e 67 20  |s the following |
000032f0  69 6e 74 65 72 73 65 63  74 69 6f 6e 73 20 61 72  |intersections ar|
00003300  65 20 65 61 73 79 2a 2f  0a 0a 0a 2f 2a 20 54 68  |e easy*/.../* Th|
00003310  65 20 58 20 43 41 53 54  49 4e 47 20 52 41 59 20  |e X CASTING RAY |
00003320  3a 20 68 65 72 65 20 77  65 20 74 65 73 74 20 74  |: here we test t|
00003330  6f 20 73 65 65 20 69 66  20 74 68 65 20 61 6e 67  |o see if the ang|
00003340  6c 65 20 6f 66 20 74 68  65 20 72 61 79 20 69 73  |le of the ray is|
00003350  20 66 61 63 69 6e 67 20  75 70 77 61 72 64 73 2e  | facing upwards.|
00003360  20 57 65 20 6e 65 65 64  20 74 6f 20 6b 6e 6f 77  | We need to know|
00003370  20 77 68 69 63 68 20 68  61 6c 66 70 6c 61 6e 65  | which halfplane|
00003380  20 77 65 27 72 65 20 63  61 73 74 69 6e 67 20 66  | we're casting f|
00003390  72 6f 6d 20 72 65 6c 61  74 69 76 65 20 74 6f 20  |rom relative to |
000033a0  74 68 65 20 79 2d 61 78  69 73 2e 20 2a 2f 0a 0a  |the y-axis. */..|
000033b0  0a 20 69 66 20 28 76 69  65 77 5f 61 6e 67 6c 65  |. if (view_angle|
000033c0  20 3e 3d 20 41 4e 47 4c  45 5f 30 20 26 26 20 76  | >= ANGLE_0 && v|
000033d0  69 65 77 5f 61 6e 67 6c  65 20 3c 20 41 4e 47 4c  |iew_angle < ANGL|
000033e0  45 5f 31 38 30 29 0a 20  20 20 20 20 20 20 7b 0a  |E_180).       {.|
000033f0  2f 2a 20 69 66 20 73 6f  20 74 68 65 6e 20 77 65  |/* if so then we|
00003400  20 61 73 73 69 67 6e 20  76 61 72 69 61 62 6c 65  | assign variable|
00003410  73 20 74 6f 20 74 68 61  74 20 65 66 66 65 63 74  |s to that effect|
00003420  2e 20 57 65 20 6d 75 73  74 20 63 6f 6d 70 75 74  |. We must comput|
00003430  65 20 74 68 65 20 66 69  72 73 74 20 68 6f 72 69  |e the first hori|
00003440  7a 6f 6e 74 61 6c 20 6c  69 6e 65 20 74 68 61 74  |zontal line that|
00003450  20 63 6f 75 6c 64 20 62  65 20 69 6e 74 65 72 73  | could be inters|
00003460  65 63 74 65 64 20 77 69  74 68 20 74 68 65 20 72  |ected with the r|
00003470  61 79 2e 20 4e 6f 74 65  20 3a 20 69 74 20 77 69  |ay. Note : it wi|
00003480  6c 6c 20 62 65 20 61 62  6f 76 65 20 74 68 65 20  |ll be above the |
00003490  76 69 65 77 65 72 2e 2a  2f 0a 0a 79 5f 62 6f 75  |viewer.*/..y_bou|
000034a0  6e 64 20 3d 20 28 43 45  4c 4c 5f 59 5f 53 49 5a  |nd = (CELL_Y_SIZ|
000034b0  45 20 2b 20 28 76 69 65  77 5f 79 20 26 20 30 78  |E + (view_y & 0x|
000034c0  66 66 63 30 29 29 3b 20  2f 2a 20 74 68 69 73 20  |ffc0)); /* this |
000034d0  6c 69 6e 65 20 69 73 20  6d 65 72 65 6c 79 20 61  |line is merely a|
000034e0  6e 20 6f 70 74 69 6d 69  7a 65 64 20 76 65 72 73  |n optimized vers|
000034f0  69 6f 6e 20 6f 66 20 43  45 4c 4c 5f 59 5f 53 49  |ion of CELL_Y_SI|
00003500  5a 45 20 2b 20 28 76 69  65 77 5f 79 20 25 20 36  |ZE + (view_y % 6|
00003510  34 29 2e 20 49 20 75 73  65 20 69 74 20 6d 61 6e  |4). I use it man|
00003520  79 20 74 69 6d 65 73 20  69 6e 20 74 68 69 73 20  |y times in this |
00003530  65 6e 67 69 6e 65 2e 20  2a 2f 0a 0a 79 5f 64 65  |engine. */..y_de|
00003540  6c 74 61 20 3d 20 43 45  4c 4c 5f 59 5f 53 49 5a  |lta = CELL_Y_SIZ|
00003550  45 3b 20 2f 2a 20 74 68  69 73 20 6d 65 61 6e 73  |E; /* this means|
00003560  20 74 68 61 74 20 66 6f  72 20 65 76 65 72 79 20  | that for every |
00003570  6d 6f 76 65 6d 65 6e 74  20 6f 66 20 74 68 65 20  |movement of the |
00003580  72 61 79 2c 20 74 68 65  20 79 20 62 6f 75 6e 64  |ray, the y bound|
00003590  61 72 79 20 6d 6f 76 65  73 20 75 70 20 6f 6e 65  |ary moves up one|
000035a0  20 63 65 6c 6c 2c 20 77  68 69 63 68 20 69 74 20  | cell, which it |
000035b0  77 6f 75 6c 64 2e 20 49  74 20 69 73 20 74 68 65  |would. It is the|
000035c0  20 64 65 6c 74 61 20 74  6f 20 67 65 74 20 74 6f  | delta to get to|
000035d0  20 74 68 65 20 6e 65 78  74 20 68 6f 72 69 7a 6f  | the next horizo|
000035e0  6e 74 61 6c 20 6c 69 6e  65 20 2a 2f 0a 0a 2f 2a  |ntal line */../*|
000035f0  20 6e 65 78 74 20 77 65  20 75 73 65 20 74 68 65  | next we use the|
00003600  20 69 6e 76 65 72 73 65  20 74 61 6e 20 66 75 6e  | inverse tan fun|
00003610  63 74 69 6f 6e 20 74 6f  20 63 61 6c 63 75 6c 61  |ction to calcula|
00003620  74 65 20 74 68 65 20 69  6e 69 74 69 61 6c 20 70  |te the initial p|
00003630  6f 73 69 74 69 6f 6e 20  6f 66 20 74 68 65 20 78  |osition of the x|
00003640  20 62 6f 75 6e 64 61 72  79 20 73 65 61 72 63 68  | boundary search|
00003650  69 6e 67 20 72 61 79 20  6f 6e 20 69 74 73 20 66  |ing ray on its f|
00003660  69 72 73 74 20 69 6e 74  65 72 73 65 63 74 69 6f  |irst intersectio|
00003670  6e 2e 20 57 65 20 68 61  76 65 20 74 6f 20 75 73  |n. We have to us|
00003680  65 20 74 61 6e 20 62 65  63 61 75 73 65 20 69 74  |e tan because it|
00003690  20 69 73 20 72 65 6c 61  74 65 64 20 74 6f 20 73  | is related to s|
000036a0  6c 6f 70 65 73 20 2a 2f  0a 0a 2f 2a 20 4e 45 57  |lopes */../* NEW|
000036b0  20 46 49 58 45 44 20 50  4f 49 4e 54 20 43 41 4c  | FIXED POINT CAL|
000036c0  43 55 4c 41 54 49 4f 4e  20 6f 66 0a 78 69 20 3d  |CULATION of.xi =|
000036d0  20 28 66 6c 6f 61 74 29  28 69 6e 76 5f 74 61 6e  | (float)(inv_tan|
000036e0  5f 74 61 62 6c 65 5b 76  69 65 77 5f 61 6e 67 6c  |_table[view_angl|
000036f0  65 5d 20 2a 20 28 79 5f  62 6f 75 6e 64 20 2d 20  |e] * (y_bound - |
00003700  76 69 65 77 5f 79 29 29  20 2b 76 69 65 77 5f 78  |view_y)) +view_x|
00003710  3b 20 2a 2f 0a 0a 78 69  3d 28 28 79 5f 62 6f 75  |; */..xi=((y_bou|
00003720  6e 64 2d 76 69 65 77 5f  79 29 29 2a 28 69 6e 76  |nd-view_y))*(inv|
00003730  5f 74 61 6e 5f 74 61 62  6c 65 5b 76 69 65 77 5f  |_tan_table[view_|
00003740  61 6e 67 6c 65 5d 29 3b  0a 78 69 2b 3d 28 76 69  |angle]);.xi+=(vi|
00003750  65 77 5f 78 3c 3c 31 36  29 3b 0a 0a 2f 2a 20 74  |ew_x<<16);../* t|
00003760  68 69 73 20 6d 65 61 6e  73 20 74 68 61 74 20 74  |his means that t|
00003770  68 65 20 71 75 61 64 72  61 6e 74 20 6f 66 20 74  |he quadrant of t|
00003780  68 65 20 72 61 79 20 69  73 20 6e 6f 74 20 6e 65  |he ray is not ne|
00003790  67 61 74 69 76 65 2c 20  74 68 61 74 20 69 73 20  |gative, that is |
000037a0  74 68 65 20 6e 65 78 74  20 79 20 62 6f 75 6e 64  |the next y bound|
000037b0  61 72 79 20 77 69 6c 6c  20 61 70 70 65 61 72 20  |ary will appear |
000037c0  61 62 6f 76 65 20 74 68  65 20 76 69 65 77 20 70  |above the view p|
000037d0  6f 69 6e 74 20 61 6e 64  20 6e 6f 74 20 62 65 6c  |oint and not bel|
000037e0  6f 77 20 28 69 6e 20 74  65 72 6d 73 20 6f 66 20  |ow (in terms of |
000037f0  6c 6f 6f 6b 69 6e 67 20  64 6f 77 6e 20 6f 6e 20  |looking down on |
00003800  74 68 65 20 76 69 65 77  65 72 29 2e 20 54 68 69  |the viewer). Thi|
00003810  73 20 69 73 20 74 68 65  20 63 65 6c 6c 20 64 65  |s is the cell de|
00003820  6c 74 61 20 2a 2f 0a 6e  65 78 74 5f 79 5f 63 65  |lta */.next_y_ce|
00003830  6c 6c 20 3d 20 30 3b 0a  0a 20 20 20 20 20 20 20  |ll = 0;..       |
00003840  7d 0a 2f 2a 20 69 66 20  74 68 65 20 76 69 65 77  |}./* if the view|
00003850  69 6e 67 20 61 6e 67 6c  65 20 69 73 20 67 72 65  |ing angle is gre|
00003860  61 74 65 72 20 74 68 61  6e 20 31 38 30 20 64 65  |ater than 180 de|
00003870  67 72 65 65 73 20 61 6e  64 20 6c 65 73 73 20 74  |grees and less t|
00003880  68 61 6e 20 32 37 30 20  64 65 67 72 65 65 73 20  |han 270 degrees |
00003890  74 68 65 6e 20 77 65 20  68 61 76 65 20 74 6f 20  |then we have to |
000038a0  64 6f 20 6f 74 68 65 72  20 63 61 6c 63 75 6c 61  |do other calcula|
000038b0  74 69 6f 6e 73 20 28 6c  6f 77 65 72 20 68 61 6c  |tions (lower hal|
000038c0  66 20 70 6c 61 6e 65 29  20 2a 2f 0a 20 20 20 20  |f plane) */.    |
000038d0  65 6c 73 65 0a 20 20 20  20 20 20 20 7b 0a 2f 2a  |else.       {./*|
000038e0  20 77 65 20 6b 6e 6f 77  20 74 68 61 74 20 62 65  | we know that be|
000038f0  63 61 75 73 65 20 74 68  65 20 76 69 65 77 69 6e  |cause the viewin|
00003900  67 20 61 6e 67 6c 65 20  69 73 20 64 6f 77 6e 77  |g angle is downw|
00003910  61 72 64 73 2c 20 73 6f  20 74 68 65 6e 20 74 68  |ards, so then th|
00003920  65 20 68 6f 72 69 7a 6f  6e 74 61 6c 20 69 6e 74  |e horizontal int|
00003930  65 72 73 65 63 74 69 6f  6e 20 68 61 73 20 74 6f  |ersection has to|
00003940  20 62 65 20 42 45 4c 4f  57 20 74 68 65 20 76 69  | be BELOW the vi|
00003950  65 77 65 72 20 2a 2f 0a  79 5f 62 6f 75 6e 64 20  |ewer */.y_bound |
00003960  3d 20 28 69 6e 74 29 28  76 69 65 77 5f 79 20 26  |= (int)(view_y &|
00003970  20 30 78 66 66 63 30 29  3b 0a 0a 2f 2a 20 62 65  | 0xffc0);../* be|
00003980  63 61 75 73 65 20 6f 66  20 74 68 69 73 20 77 65  |cause of this we|
00003990  20 61 6c 73 6f 20 6b 6e  6f 77 20 74 68 61 74 20  | also know that |
000039a0  74 68 65 20 6e 65 78 74  20 59 20 69 6e 74 65 72  |the next Y inter|
000039b0  73 65 63 74 69 6f 6e 73  20 77 69 6c 6c 20 62 65  |sections will be|
000039c0  20 61 20 63 65 6c 6c 20  62 65 6c 6f 77 20 65 61  | a cell below ea|
000039d0  63 68 20 6f 74 68 65 72  2e 20 53 6f 20 74 68 65  |ch other. So the|
000039e0  20 64 65 6c 74 61 20 66  6f 72 20 65 61 63 68 20  | delta for each |
000039f0  68 6f 72 69 7a 6f 6e 74  61 6c 20 69 6e 74 65 72  |horizontal inter|
00003a00  73 65 63 74 69 6f 6e 20  77 69 6c 6c 20 62 65 20  |section will be |
00003a10  61 20 63 65 6c 6c 20 62  65 6c 6f 77 20 20 74 68  |a cell below  th|
00003a20  65 20 6c 61 73 74 20 2a  2f 0a 79 5f 64 65 6c 74  |e last */.y_delt|
00003a30  61 20 3d 20 2d 43 45 4c  4c 5f 59 5f 53 49 5a 45  |a = -CELL_Y_SIZE|
00003a40  3b 0a 0a 2f 2a 20 77 65  20 61 67 61 69 6e 20 75  |;../* we again u|
00003a50  73 65 20 74 68 65 20 74  61 6e 67 65 6e 74 20 66  |se the tangent f|
00003a60  75 6e 63 74 69 6f 6e 2c  20 6a 75 73 74 20 61 73  |unction, just as|
00003a70  20 62 65 66 6f 72 65 2c  20 74 6f 20 63 61 6c 63  | before, to calc|
00003a80  75 6c 61 74 65 20 74 68  65 20 66 69 72 73 74 20  |ulate the first |
00003a90  78 20 69 6e 74 65 72 73  65 63 74 69 6f 6e 20 77  |x intersection w|
00003aa0  69 74 68 20 61 20 62 6f  75 6e 64 61 72 79 2e 20  |ith a boundary. |
00003ab0  2a 2f 0a 0a 2f 2a 20 4e  45 57 20 46 49 58 45 44  |*/../* NEW FIXED|
00003ac0  20 50 4f 49 4e 54 2c 20  49 20 77 6f 6e 27 74 20  | POINT, I won't |
00003ad0  73 68 6f 77 20 74 68 65  20 6f 6c 64 20 6c 69 6e  |show the old lin|
00003ae0  65 73 20 61 6e 79 20 6d  6f 72 65 20 2a 2f 0a 0a  |es any more */..|
00003af0  78 69 3d 28 28 79 5f 62  6f 75 6e 64 2d 76 69 65  |xi=((y_bound-vie|
00003b00  77 5f 79 29 29 2a 28 69  6e 76 5f 74 61 6e 5f 74  |w_y))*(inv_tan_t|
00003b10  61 62 6c 65 5b 76 69 65  77 5f 61 6e 67 6c 65 5d  |able[view_angle]|
00003b20  29 3b 0a 78 69 2b 3d 28  76 69 65 77 5f 78 3c 3c  |);.xi+=(view_x<<|
00003b30  31 36 29 3b 0a 0a 2f 2a  20 61 6e 64 20 77 65 20  |16);../* and we |
00003b40  6b 6e 6f 77 20 61 6c 73  6f 20 74 68 61 74 20 74  |know also that t|
00003b50  68 65 20 71 75 61 64 72  61 6e 74 20 69 73 20 62  |he quadrant is b|
00003b60  65 6c 6f 77 20 74 68 65  20 70 6c 61 79 65 72 2c  |elow the player,|
00003b70  20 73 6f 20 74 68 65 20  63 65 6c 6c 20 79 20 64  | so the cell y d|
00003b80  65 6c 74 61 20 77 69 6c  6c 20 62 65 20 6e 65 67  |elta will be neg|
00003b90  61 74 69 76 65 20 2a 2f  0a 0a 6e 65 78 74 5f 79  |ative */..next_y|
00003ba0  5f 63 65 6c 6c 20 3d 20  2d 31 3b 0a 0a 20 20 20  |_cell = -1;..   |
00003bb0  20 20 20 20 7d 0a 2f 2a  20 59 20 52 41 59 20 3a  |    }./* Y RAY :|
00003bc0  20 77 65 20 64 6f 20 73  69 6d 69 6c 61 72 20 63  | we do similar c|
00003bd0  61 6c 63 75 6c 61 74 69  6f 6e 73 20 62 75 74 20  |alculations but |
00003be0  74 68 69 73 20 74 69 6d  65 20 74 6f 20 63 61 6c  |this time to cal|
00003bf0  63 75 6c 61 74 65 20 74  68 65 20 66 69 72 73 74  |culate the first|
00003c00  20 79 20 69 6e 74 65 72  73 65 63 74 69 6f 6e 73  | y intersections|
00003c10  20 2a 2f 0a 0a 2f 2a 20  77 65 20 74 65 73 74 20  | */../* we test |
00003c20  74 6f 20 73 65 65 20 69  66 20 74 68 65 20 76 69  |to see if the vi|
00003c30  65 77 20 61 6e 67 6c 65  20 69 73 20 77 69 74 68  |ew angle is with|
00003c40  69 6e 20 74 68 65 20 76  65 72 74 69 63 61 6c 20  |in the vertical |
00003c50  61 73 79 6d 70 74 6f 74  65 73 20 6f 66 20 33 36  |asymptotes of 36|
00003c60  30 20 64 65 67 72 65 65  73 2e 20 57 65 20 6e 65  |0 degrees. We ne|
00003c70  65 64 20 74 6f 20 6b 6e  6f 77 20 77 68 69 63 68  |ed to know which|
00003c80  20 68 61 6c 66 70 6c 61  6e 65 20 77 65 27 72 65  | halfplane we're|
00003c90  20 63 61 73 74 69 6e 67  20 66 72 6f 6d 20 72 65  | casting from re|
00003ca0  6c 61 74 69 76 65 20 74  6f 20 74 68 65 20 78 2d  |lative to the x-|
00003cb0  61 78 69 73 2e 20 2a 2f  0a 0a 69 66 20 28 76 69  |axis. */..if (vi|
00003cc0  65 77 5f 61 6e 67 6c 65  20 3c 20 41 4e 47 4c 45  |ew_angle < ANGLE|
00003cd0  5f 39 30 20 7c 7c 20 76  69 65 77 5f 61 6e 67 6c  |_90 || view_angl|
00003ce0  65 20 3e 3d 20 41 4e 47  4c 45 5f 32 37 30 29 0a  |e >= ANGLE_270).|
00003cf0  20 20 20 20 20 20 20 7b  0a 2f 2a 20 77 65 20 63  |       {./* we c|
00003d00  61 6e 20 64 65 64 75 63  65 20 63 65 72 74 61 69  |an deduce certai|
00003d10  6e 20 74 68 69 6e 67 73  2c 20 6a 75 73 74 20 61  |n things, just a|
00003d20  73 20 77 69 74 68 20 74  68 65 20 78 20 72 61 79  |s with the x ray|
00003d30  2e 20 57 65 20 6b 6e 6f  77 20 74 68 61 74 20 62  |. We know that b|
00003d40  65 63 61 75 73 65 20 74  68 65 20 76 69 65 77 20  |ecause the view |
00003d50  61 6e 67 6c 65 20 69 73  20 74 6f 20 74 68 65 20  |angle is to the |
00003d60  72 69 67 68 74 2c 20 74  68 65 20 6e 65 78 74 20  |right, the next |
00003d70  58 20 62 6f 75 6e 64 61  72 79 20 28 77 68 69 63  |X boundary (whic|
00003d80  68 20 69 73 20 63 6f 6e  73 74 61 6e 74 29 20 77  |h is constant) w|
00003d90  69 6c 6c 20 62 65 20 74  6f 20 74 68 65 20 52 49  |ill be to the RI|
00003da0  47 48 54 20 6f 66 20 74  68 65 20 76 69 65 77 65  |GHT of the viewe|
00003db0  72 2e 20 2a 2f 0a 78 5f  62 6f 75 6e 64 20 3d 20  |r. */.x_bound = |
00003dc0  28 69 6e 74 29 28 43 45  4c 4c 5f 58 5f 53 49 5a  |(int)(CELL_X_SIZ|
00003dd0  45 20 2b 20 28 76 69 65  77 5f 78 20 26 20 30 78  |E + (view_x & 0x|
00003de0  66 66 63 30 29 29 3b 0a  0a 2f 2a 20 6e 6f 74 69  |ffc0));../* noti|
00003df0  63 65 20 74 68 69 73 20  72 65 63 75 72 72 69 6e  |ce this recurrin|
00003e00  67 20 6f 70 74 69 6d 69  7a 61 74 69 6f 6e 20 6f  |g optimization o|
00003e10  66 20 76 69 65 77 5f 78  20 25 20 36 34 20 2a 2f  |f view_x % 64 */|
00003e20  0a 0a 2f 2a 20 61 6e 64  20 77 65 20 61 6c 73 6f  |../* and we also|
00003e30  20 6b 6e 6f 77 20 74 68  61 74 20 65 61 63 68 20  | know that each |
00003e40  76 65 72 74 69 63 61 6c  20 63 65 6c 6c 20 62 6f  |vertical cell bo|
00003e50  75 6e 64 61 72 79 20 61  66 74 65 72 20 74 68 65  |undary after the|
00003e60  20 66 69 72 73 74 20 77  69 6c 6c 20 62 65 20 61  | first will be a|
00003e70  20 63 65 6c 6c 27 73 20  77 69 64 74 68 20 61 77  | cell's width aw|
00003e80  61 79 20 2a 2f 0a 0a 78  5f 64 65 6c 74 61 20 3d  |ay */..x_delta =|
00003e90  20 43 45 4c 4c 5f 58 5f  53 49 5a 45 3b 0a 2f 2a  | CELL_X_SIZE;./*|
00003ea0  20 74 68 69 73 20 74 69  6d 65 20 77 65 20 75 73  | this time we us|
00003eb0  65 20 74 68 65 20 74 61  6e 67 65 6e 74 20 66 75  |e the tangent fu|
00003ec0  6e 63 74 69 6f 6e 20 28  6e 6f 74 20 74 68 65 20  |nction (not the |
00003ed0  69 6e 76 65 72 73 65 20  74 61 6e 29 20 74 6f 20  |inverse tan) to |
00003ee0  63 61 6c 63 75 6c 61 74  65 20 77 68 65 72 65 20  |calculate where |
00003ef0  74 68 65 20 66 69 72 73  74 20 79 20 62 6f 75 6e  |the first y boun|
00003f00  64 61 72 79 20 69 6e 74  65 72 73 65 63 74 69 6f  |dary intersectio|
00003f10  6e 20 77 69 6c 6c 20 6f  63 63 75 72 29 2e 20 2a  |n will occur). *|
00003f20  2f 0a 0a 2f 2a 20 4e 45  57 20 46 49 58 45 44 20  |/../* NEW FIXED |
00003f30  50 4f 49 4e 54 20 2a 2f  0a 0a 79 69 3d 28 28 78  |POINT */..yi=((x|
00003f40  5f 62 6f 75 6e 64 20 2d  20 76 69 65 77 5f 78 29  |_bound - view_x)|
00003f50  29 2a 28 74 61 6e 5f 74  61 62 6c 65 5b 76 69 65  |)*(tan_table[vie|
00003f60  77 5f 61 6e 67 6c 65 5d  29 3b 0a 79 69 2b 3d 28  |w_angle]);.yi+=(|
00003f70  76 69 65 77 5f 79 3c 3c  31 36 29 3b 0a 2f 2a 20  |view_y<<16);./* |
00003f80  61 6e 64 20 77 65 20 6b  6e 6f 77 20 61 6c 73 6f  |and we know also|
00003f90  20 74 68 61 74 20 62 65  63 61 75 73 65 20 74 68  | that because th|
00003fa0  65 20 76 69 65 77 20 69  73 20 70 6f 73 69 74 69  |e view is positi|
00003fb0  76 65 2c 20 74 68 65 20  6e 65 78 74 5f 78 5f 63  |ve, the next_x_c|
00003fc0  65 6c 6c 20 64 65 6c 74  61 20 64 6f 65 73 20 6e  |ell delta does n|
00003fd0  6f 74 20 6e 65 65 64 20  74 6f 20 62 65 20 6e 65  |ot need to be ne|
00003fe0  67 61 74 69 76 65 20 2a  2f 0a 0a 6e 65 78 74 5f  |gative */..next_|
00003ff0  78 5f 63 65 6c 6c 20 3d  20 30 3b 0a 0a 20 20 20  |x_cell = 0;..   |
00004000  20 20 20 20 7d 0a 2f 2a  20 6f 74 68 65 72 77 69  |    }./* otherwi|
00004010  73 65 2c 20 69 66 20 74  68 65 20 76 69 65 77 69  |se, if the viewi|
00004020  6e 67 20 61 6e 67 6c 65  20 69 73 20 74 6f 77 61  |ng angle is towa|
00004030  72 64 73 20 74 68 65 20  6f 74 68 65 72 20 64 69  |rds the other di|
00004040  72 65 63 74 69 6f 6e 2e  2e 2e 2a 2f 0a 20 20 20  |rection...*/.   |
00004050  20 65 6c 73 65 0a 20 20  20 20 20 20 20 7b 0a 2f  | else.       {./|
00004060  2a 20 77 65 20 6b 6e 6f  77 20 74 68 61 74 20 74  |* we know that t|
00004070  68 65 20 66 69 72 73 74  20 78 20 62 6f 75 6e 64  |he first x bound|
00004080  61 72 79 20 63 61 6e 20  6f 63 63 75 72 20 6f 6e  |ary can occur on|
00004090  6c 79 20 74 6f 20 74 68  65 20 6c 65 66 74 20 6f  |ly to the left o|
000040a0  66 20 74 68 65 20 76 69  65 77 65 72 20 62 65 63  |f the viewer bec|
000040b0  61 75 73 65 20 74 68 65  20 72 61 79 20 61 6e 67  |ause the ray ang|
000040c0  6c 65 20 69 73 20 66 61  63 69 6e 67 20 6c 65 66  |le is facing lef|
000040d0  74 2e 20 53 6f 20 77 65  20 63 61 6e 20 64 6f 20  |t. So we can do |
000040e0  76 69 65 77 5f 78 20 25  20 36 34 20 74 6f 20 63  |view_x % 64 to c|
000040f0  61 6c 63 75 6c 61 74 65  20 74 68 65 20 66 69 72  |alculate the fir|
00004100  73 74 20 76 65 72 74 69  63 61 6c 20 62 6f 75 6e  |st vertical boun|
00004110  64 61 72 79 2c 20 74 68  69 73 20 73 68 6f 75 6c  |dary, this shoul|
00004120  64 20 62 65 20 62 65 63  6f 6d 69 6e 67 20 6f 62  |d be becoming ob|
00004130  76 69 6f 75 73 20 2a 2f  0a 78 5f 62 6f 75 6e 64  |vious */.x_bound|
00004140  20 3d 20 28 69 6e 74 29  28 76 69 65 77 5f 78 20  | = (int)(view_x |
00004150  26 20 30 78 66 66 63 30  29 3b 0a 0a 2f 2a 20 77  |& 0xffc0);../* w|
00004160  65 20 61 6c 73 6f 20 6b  6e 6f 77 20 74 68 61 74  |e also know that|
00004170  20 74 68 65 20 64 65 6c  74 61 20 66 6f 72 20 74  | the delta for t|
00004180  68 65 20 63 65 6c 6c 20  77 69 6c 6c 20 62 65 20  |he cell will be |
00004190  74 6f 20 74 68 65 20 6c  65 66 74 2c 20 65 61 63  |to the left, eac|
000041a0  68 20 74 69 6d 65 20 74  68 65 20 72 61 79 20 6d  |h time the ray m|
000041b0  6f 76 65 73 20 74 6f 20  74 68 65 20 6e 65 78 74  |oves to the next|
000041c0  20 62 6f 75 6e 64 61 72  79 20 74 68 65 20 6e 65  | boundary the ne|
000041d0  78 74 20 76 65 72 74 69  63 61 6c 20 69 6e 74 65  |xt vertical inte|
000041e0  72 73 65 63 74 69 6f 6e  20 77 69 6c 6c 20 62 65  |rsection will be|
000041f0  20 61 20 63 65 6c 6c 20  74 6f 20 74 68 65 20 6c  | a cell to the l|
00004200  65 66 74 20 74 68 61 6e  20 74 68 65 20 6c 61 73  |eft than the las|
00004210  74 2e 20 2a 2f 0a 78 5f  64 65 6c 74 61 20 3d 20  |t. */.x_delta = |
00004220  2d 43 45 4c 4c 5f 58 5f  53 49 5a 45 3b 0a 0a 2f  |-CELL_X_SIZE;../|
00004230  2a 20 77 65 20 75 73 65  20 74 68 65 20 74 61 6e  |* we use the tan|
00004240  67 65 6e 74 61 6c 20 66  75 6e 63 74 69 6f 6e 20  |gental function |
00004250  61 67 61 69 6e 20 74 6f  20 63 61 6c 63 75 6c 61  |again to calcula|
00004260  74 65 20 74 68 65 20 70  6f 73 69 74 69 6f 6e 20  |te the position |
00004270  6f 6e 20 74 68 65 20 68  6f 72 69 7a 6f 6e 74 61  |on the horizonta|
00004280  6c 20 69 6e 74 65 72 73  65 63 74 69 6f 6e 73 20  |l intersections |
00004290  2a 2f 0a 0a 2f 2a 20 4e  45 57 20 46 49 58 45 44  |*/../* NEW FIXED|
000042a0  20 50 4f 49 4e 54 20 2a  2f 0a 0a 79 69 3d 28 28  | POINT */..yi=((|
000042b0  78 5f 62 6f 75 6e 64 20  2d 20 76 69 65 77 5f 78  |x_bound - view_x|
000042c0  29 29 2a 28 74 61 6e 5f  74 61 62 6c 65 5b 76 69  |))*(tan_table[vi|
000042d0  65 77 5f 61 6e 67 6c 65  5d 29 3b 0a 79 69 2b 3d  |ew_angle]);.yi+=|
000042e0  28 76 69 65 77 5f 79 3c  3c 31 36 29 3b 0a 2f 2a  |(view_y<<16);./*|
000042f0  20 61 6e 64 20 77 65 20  61 6c 73 6f 20 6b 6e 6f  | and we also kno|
00004300  77 20 74 68 61 74 20 74  68 65 20 78 20 63 65 6c  |w that the x cel|
00004310  6c 20 76 61 6c 75 65 20  77 69 6c 6c 20 62 65 20  |l value will be |
00004320  6d 69 6e 75 73 2c 20 62  65 63 61 75 73 65 20 61  |minus, because a|
00004330  73 20 74 68 65 20 72 61  79 20 6d 6f 76 65 73 20  |s the ray moves |
00004340  74 6f 20 61 6e 6f 74 68  65 72 20 63 65 6c 6c 2c  |to another cell,|
00004350  20 62 65 63 61 75 73 65  20 74 68 65 20 72 61 79  | because the ray|
00004360  20 69 73 20 67 6f 69 6e  67 20 6c 65 66 74 2c 20  | is going left, |
00004370  74 68 65 20 76 61 6c 75  65 20 6d 75 73 74 20 62  |the value must b|
00004380  65 20 6d 69 6e 75 73 2e  20 2a 2f 0a 6e 65 78 74  |e minus. */.next|
00004390  5f 78 5f 63 65 6c 6c 20  3d 20 2d 31 3b 0a 0a 20  |_x_cell = -1;.. |
000043a0  20 20 20 20 20 20 7d 0a  0a 2f 2a 20 4e 6f 77 20  |      }../* Now |
000043b0  77 65 20 68 61 76 65 20  70 65 72 66 6f 72 6d 65  |we have performe|
000043c0  64 20 74 68 65 20 73 6c  69 67 68 74 6c 79 20 74  |d the slightly t|
000043d0  72 69 63 6b 79 20 74 61  73 6b 20 6f 66 20 74 68  |ricky task of th|
000043e0  65 20 66 69 72 73 74 20  69 6e 74 65 72 73 65 63  |e first intersec|
000043f0  74 69 6f 6e 73 2c 20 77  65 20 63 61 6e 20 6d 6f  |tions, we can mo|
00004400  76 65 20 6f 6e 20 74 6f  20 63 61 6c 63 75 6c 61  |ve on to calcula|
00004410  74 69 6e 67 20 74 68 65  20 6e 65 78 74 20 6f 6e  |ting the next on|
00004420  65 73 2e 20 54 68 69 73  20 69 73 20 6d 6f 72 65  |es. This is more|
00004430  20 73 69 6d 70 6c 65 2c  20 61 73 20 77 65 20 6b  | simple, as we k|
00004440  6e 6f 77 20 74 68 61 74  20 74 68 65 20 69 6e 74  |now that the int|
00004450  65 72 73 65 63 74 69 6f  6e 73 20 63 61 6e 20 6f  |ersections can o|
00004460  6e 6c 79 20 6f 63 63 75  72 20 61 74 20 63 65 6c  |nly occur at cel|
00004470  6c 20 62 6f 75 6e 64 61  72 69 65 73 2e 2a 2f 0a  |l boundaries.*/.|
00004480  0a 2f 2a 20 53 45 43 54  49 4f 4e 20 32 20 3a 20  |./* SECTION 2 : |
00004490  54 65 73 74 69 6e 67 20  66 6f 72 20 66 75 72 74  |Testing for furt|
000044a0  68 65 72 20 69 6e 74 65  72 73 65 63 74 69 6f 6e  |her intersection|
000044b0  73 20 2a 2f 0a 0a 2f 2a  20 74 68 65 73 65 20 66  |s */../* these f|
000044c0  6c 61 67 73 20 73 74 6f  72 65 20 69 66 20 63 61  |lags store if ca|
000044d0  73 74 69 6e 67 20 6f 66  20 62 6f 74 68 20 72 61  |sting of both ra|
000044e0  79 73 20 69 73 20 63 6f  6d 70 6c 65 74 65 20 2a  |ys is complete *|
000044f0  2f 0a 78 72 61 79 3d 79  72 61 79 3d 78 74 72 61  |/.xray=yray=xtra|
00004500  6e 73 5f 64 6f 6e 65 3d  79 74 72 61 6e 73 5f 64  |ns_done=ytrans_d|
00004510  6f 6e 65 3d 30 3b 0a 0a  2f 2a 20 58 20 52 61 79  |one=0;../* X Ray|
00004520  20 69 73 20 66 69 72 73  74 20 2a 2f 0a 2f 2a 20  | is first */./* |
00004530  62 65 63 61 75 73 65 20  77 65 20 61 72 65 20 74  |because we are t|
00004540  65 73 74 69 6e 67 20 66  6f 72 20 65 61 63 68 20  |esting for each |
00004550  6e 65 78 74 20 69 6e 74  65 72 73 65 63 74 69 6f  |next intersectio|
00004560  6e 2c 20 77 65 20 63 61  6e 20 66 69 67 75 72 65  |n, we can figure|
00004570  20 6f 75 74 20 6d 6f 72  65 20 65 61 73 69 6c 79  | out more easily|
00004580  20 74 68 65 20 66 6f 6c  6c 6f 77 69 6e 67 20 69  | the following i|
00004590  6e 74 65 72 73 65 63 74  69 6f 6e 73 2e 20 2a 2f  |ntersections. */|
000045a0  0a 2f 2a 20 74 68 69 73  20 69 73 20 61 20 6c 6f  |./* this is a lo|
000045b0  6f 6b 20 75 70 20 74 61  62 6c 65 20 68 6f 6c 64  |ok up table hold|
000045c0  69 6e 67 20 74 68 65 20  6e 65 78 74 20 79 20 69  |ing the next y i|
000045d0  6e 74 65 72 63 65 70 74  73 2c 20 62 61 73 65 64  |ntercepts, based|
000045e0  20 6f 6e 20 74 68 65 20  74 61 6e 67 65 6e 74 61  | on the tangenta|
000045f0  6c 20 66 75 6e 63 74 69  6f 6e 20 61 6e 64 20 74  |l function and t|
00004600  68 65 20 73 69 7a 65 20  6f 66 20 63 65 6c 6c 73  |he size of cells|
00004610  2e 20 42 61 73 69 63 61  6c 6c 79 20 77 65 20 61  |. Basically we a|
00004620  64 64 20 74 68 69 73 20  74 6f 20 74 68 65 20 72  |dd this to the r|
00004630  61 79 20 65 61 63 68 20  74 69 6d 65 20 77 65 20  |ay each time we |
00004640  6d 6f 76 65 20 69 74 20  61 20 62 69 74 20 6d 6f  |move it a bit mo|
00004650  72 65 2c 20 73 65 61 72  63 68 69 6e 67 20 66 6f  |re, searching fo|
00004660  72 20 61 20 77 61 6c 6c  20 61 74 20 61 20 63 65  |r a wall at a ce|
00004670  6c 6c 20 62 6f 75 6e 64  61 72 79 20 2a 2f 0a 0a  |ll boundary */..|
00004680  2f 2a 20 4e 45 57 20 46  49 58 45 44 20 50 4f 49  |/* NEW FIXED POI|
00004690  4e 54 2c 20 6e 6f 74 65  20 74 68 65 20 73 68 69  |NT, note the shi|
000046a0  66 74 20 33 20 74 69 6d  65 73 20 74 6f 20 74 68  |ft 3 times to th|
000046b0  65 20 6c 65 66 74 2c 20  74 68 65 20 65 71 75 69  |e left, the equi|
000046c0  76 61 6c 65 6e 74 20 6f  66 20 61 20 6d 75 6c 74  |valent of a mult|
000046d0  69 70 6c 79 20 62 79 20  38 2c 20 74 68 69 73 20  |iply by 8, this |
000046e0  74 61 6b 65 73 20 6e 6f  20 74 69 6d 65 2c 20 61  |takes no time, a|
000046f0  6e 64 20 72 65 61 6c 6c  79 20 49 20 64 6f 6e 27  |nd really I don'|
00004700  74 20 6b 6e 6f 77 20 77  68 79 20 49 27 76 65 20  |t know why I've |
00004710  64 6f 6e 65 20 69 74 20  6c 69 6b 65 20 74 68 69  |done it like thi|
00004720  73 21 20 49 74 20 77 6f  72 6b 73 2e 20 2a 2f 0a  |s! It works. */.|
00004730  0a 78 61 64 64 3d 79 5f  73 74 65 70 5b 76 69 65  |.xadd=y_step[vie|
00004740  77 5f 61 6e 67 6c 65 5d  3c 3c 33 3b 0a 0a 2f 2a  |w_angle]<<3;../*|
00004750  20 73 74 61 72 74 20 63  61 73 74 69 6e 67 20 74  | start casting t|
00004760  68 65 20 78 20 72 61 79  20 2a 2f 0a 77 68 69 6c  |he x ray */.whil|
00004770  65 28 21 78 72 61 79 29  0a 7b 0a 2f 2a 20 63 6f  |e(!xray).{./* co|
00004780  6d 70 75 74 65 20 63 75  72 72 65 6e 74 20 63 65  |mpute current ce|
00004790  6c 6c 20 70 6f 73 69 74  69 6f 6e 20 6f 66 20 74  |ll position of t|
000047a0  68 65 20 72 61 79 20 74  6f 20 69 6e 73 70 65 63  |he ray to inspec|
000047b0  74 2a 2f 0a 0a 63 65 6c  6c 5f 78 20 3d 20 28 20  |t*/..cell_x = ( |
000047c0  28 78 5f 62 6f 75 6e 64  2b 6e 65 78 74 5f 78 5f  |(x_bound+next_x_|
000047d0  63 65 6c 6c 29 20 3e 3e  20 43 45 4c 4c 5f 58 5f  |cell) >> CELL_X_|
000047e0  53 49 5a 45 5f 46 50 29  3b 0a 2f 2a 20 4e 6f 74  |SIZE_FP);./* Not|
000047f0  65 20 77 65 20 68 61 76  65 20 74 6f 20 73 68 69  |e we have to shi|
00004800  66 74 20 6e 6f 74 20 6f  6e 6c 79 20 62 79 20 36  |ft not only by 6|
00004810  2c 20 62 75 74 20 61 6c  73 6f 20 62 79 20 31 36  |, but also by 16|
00004820  20 74 6f 20 63 6f 6e 76  65 72 74 20 42 41 43 4b  | to convert BACK|
00004830  20 74 6f 20 6e 6f 72 6d  61 6c 20 6d 61 74 68 73  | to normal maths|
00004840  20 2a 2f 0a 63 65 6c 6c  5f 79 20 3d 20 28 69 6e  | */.cell_y = (in|
00004850  74 29 79 69 3e 3e 32 32  3b 0a 0a 2f 2a 20 62 6f  |t)yi>>22;../* bo|
00004860  74 68 20 6f 66 20 74 68  65 20 61 62 6f 76 65 20  |th of the above |
00004870  65 78 61 6d 70 6c 65 73  20 75 73 65 20 62 69 6e  |examples use bin|
00004880  61 72 79 20 73 68 69 66  74 69 6e 67 20 74 6f 20  |ary shifting to |
00004890  61 63 68 69 65 76 65 20  61 20 64 69 76 69 64 65  |achieve a divide|
000048a0  20 62 79 20 36 34 2e 20  43 65 6c 6c 5f 79 20 63  | by 64. Cell_y c|
000048b0  6f 6d 70 75 74 61 74 69  6f 6e 20 75 73 65 73 20  |omputation uses |
000048c0  69 64 65 6e 74 69 63 61  6c 20 74 65 63 68 6e 69  |identical techni|
000048d0  71 75 65 73 20 74 6f 20  74 68 6f 73 65 20 63 6f  |ques to those co|
000048e0  76 65 72 65 64 20 69 6e  20 74 68 65 20 6d 61 67  |vered in the mag|
000048f0  61 7a 69 6e 65 2e 20 43  65 6c 6c 5f 78 20 69 73  |azine. Cell_x is|
00004900  20 63 61 6c 63 75 6c 61  74 65 64 20 62 79 20 75  | calculated by u|
00004910  73 69 6e 67 20 74 68 65  20 78 5f 62 6f 75 6e 64  |sing the x_bound|
00004920  20 61 6e 64 20 6e 65 78  74 5f 78 5f 63 65 6c 6c  | and next_x_cell|
00004930  20 76 61 6c 75 65 73 20  63 61 6c 63 75 6c 61 74  | values calculat|
00004940  65 64 20 62 65 66 6f 72  65 68 61 6e 64 2e 20 2a  |ed beforehand. *|
00004950  2f 0a 0a 69 66 28 63 65  6c 6c 5f 78 3c 30 29 63  |/..if(cell_x<0)c|
00004960  65 6c 6c 5f 78 3d 30 3b  69 66 28 63 65 6c 6c 5f  |ell_x=0;if(cell_|
00004970  78 3e 36 33 29 63 65 6c  6c 5f 78 3d 36 33 3b 0a  |x>63)cell_x=63;.|
00004980  69 66 28 63 65 6c 6c 5f  79 3c 30 29 63 65 6c 6c  |if(cell_y<0)cell|
00004990  5f 79 3d 30 3b 69 66 28  63 65 6c 6c 5f 79 3e 36  |_y=0;if(cell_y>6|
000049a0  33 29 63 65 6c 6c 5f 79  3d 36 33 3b 0a 2f 2a 20  |3)cell_y=63;./* |
000049b0  74 68 65 73 65 20 73 69  6d 70 6c 65 20 6c 69 6e  |these simple lin|
000049c0  65 73 20 65 6e 73 75 72  65 20 74 68 61 74 20 74  |es ensure that t|
000049d0  68 65 20 72 61 79 20 64  6f 65 73 6e 27 74 20 67  |he ray doesn't g|
000049e0  6f 20 6f 75 74 20 6f 66  20 74 68 65 20 77 6f 72  |o out of the wor|
000049f0  6c 64 2c 20 74 68 6f 75  67 68 20 74 68 65 79 20  |ld, though they |
00004a00  61 72 65 6e 27 74 20 72  65 61 6c 6c 79 20 6e 65  |aren't really ne|
00004a10  65 64 65 64 2e 20 2a 2f  0a 0a 2f 2a 20 77 65 20  |eded. */../* we |
00004a20  6c 6f 6f 6b 20 75 70 20  69 6e 20 74 68 65 20 77  |look up in the w|
00004a30  6f 72 6c 64 20 66 69 6c  65 20 74 6f 20 73 65 65  |orld file to see|
00004a40  20 69 66 20 74 68 65 72  65 20 69 73 20 61 20 77  | if there is a w|
00004a50  61 6c 6c 20 61 74 20 74  68 65 20 69 6e 74 65 72  |all at the inter|
00004a60  73 65 63 74 69 6f 6e 20  6f 66 20 6f 75 72 20 72  |section of our r|
00004a70  61 79 20 2a 2f 0a 0a 69  66 20 28 28 78 5f 68 69  |ay */..if ((x_hi|
00004a80  74 5f 74 79 70 65 20 3d  77 6f 72 6c 64 5b 63 65  |t_type =world[ce|
00004a90  6c 6c 5f 79 5d 5b 63 65  6c 6c 5f 78 5d 29 21 3d  |ll_y][cell_x])!=|
00004aa0  30 29 0a 7b 0a 20 2f 2a  20 6f 72 20 61 6e 79 20  |0).{. /* or any |
00004ab0  28 65 78 74 72 61 20 6f  72 20 64 69 66 66 65 72  |(extra or differ|
00004ac0  65 6e 74 29 20 74 69 6c  65 20 76 61 6c 75 65 20  |ent) tile value |
00004ad0  79 6f 75 20 77 69 73 68  20 2a 2f 0a 69 66 28 78  |you wish */.if(x|
00004ae0  5f 68 69 74 5f 74 79 70  65 3d 3d 39 20 7c 7c 20  |_hit_type==9 || |
00004af0  78 5f 68 69 74 5f 74 79  70 65 3d 3d 37 20 7c 7c  |x_hit_type==7 |||
00004b00  20 78 5f 68 69 74 5f 74  79 70 65 3d 3d 31 30 29  | x_hit_type==10)|
00004b10  7b 0a 20 20 2f 2a 54 48  45 4e 20 54 48 45 20 57  |{.  /*THEN THE W|
00004b20  41 4c 4c 20 49 53 20 54  52 41 4e 53 50 41 52 45  |ALL IS TRANSPARE|
00004b30  4e 54 21 21 21 2a 2f 0a  20 78 74 72 61 6e 73 5f  |NT!!!*/. xtrans_|
00004b40  64 69 73 74 3d 28 28 79  69 2d 28 76 69 65 77 5f  |dist=((yi-(view_|
00004b50  79 3c 3c 31 36 29 29 3e  3e 38 29 2a 28 69 6e 76  |y<<16))>>8)*(inv|
00004b60  5f 73 69 6e 5f 74 61 62  6c 65 5b 76 69 65 77 5f  |_sin_table[view_|
00004b70  61 6e 67 6c 65 5d 3e 3e  38 29 3b 0a 20 78 74 72  |angle]>>8);. xtr|
00004b80  61 6e 73 5f 74 79 70 65  3d 78 5f 68 69 74 5f 74  |ans_type=x_hit_t|
00004b90  79 70 65 3b 0a 20 78 74  72 61 6e 73 5f 63 6f 6c  |ype;. xtrans_col|
00004ba0  3d 28 28 69 6e 74 29 28  79 69 3e 3e 31 36 29 20  |=((int)(yi>>16) |
00004bb0  26 20 30 78 30 30 33 66  29 3b 0a 20 78 74 72 61  |& 0x003f);. xtra|
00004bc0  6e 73 5f 64 6f 6e 65 3d  46 4f 55 4e 44 5f 57 41  |ns_done=FOUND_WA|
00004bd0  4c 4c 3b 0a 2f 2a 20 77  65 20 72 65 63 6f 72 64  |LL;./* we record|
00004be0  20 61 6c 6c 20 72 65 71  75 69 72 65 64 20 64 65  | all required de|
00004bf0  74 61 69 6c 73 20 74 68  65 6e 20 63 6f 6e 74 69  |tails then conti|
00004c00  6e 75 65 20 2a 2f 0a 20  20 20 20 20 20 20 20 20  |nue */.         |
00004c10  20 20 20 20 20 20 20 20  7d 0a 0a 65 6c 73 65 0a  |        }..else.|
00004c20  7b 0a 2f 2a 20 69 66 20  73 6f 20 77 65 20 63 61  |{./* if so we ca|
00004c30  6c 63 75 6c 61 74 65 20  74 68 65 20 64 69 73 74  |lculate the dist|
00004c40  61 6e 63 65 20 74 6f 20  69 74 20 75 73 69 6e 67  |ance to it using|
00004c50  20 74 68 65 20 6f 6c 64  20 4f 2d 4c 65 76 65 6c  | the old O-Level|
00004c60  20 74 65 63 68 6e 69 71  75 65 20 6f 66 20 75 73  | technique of us|
00004c70  69 6e 67 20 73 69 6e 65  20 61 6e 64 20 63 6f 73  |ing sine and cos|
00004c80  69 6e 65 20 69 6e 73 74  65 61 64 20 6f 66 20 64  |ine instead of d|
00004c90  6f 69 6e 67 20 74 68 65  20 73 74 61 6e 64 61 72  |oing the standar|
00004ca0  64 20 50 59 54 48 41 47  4f 52 41 53 20 74 65 63  |d PYTHAGORAS tec|
00004cb0  68 6e 69 71 75 65 2e 2a  2f 0a 0a 2f 2a 20 4e 45  |hnique.*/../* NE|
00004cc0  57 20 46 49 58 45 44 20  50 4f 49 4e 54 20 63 61  |W FIXED POINT ca|
00004cd0  6c 63 75 6c 61 74 69 6f  6e 2c 20 6e 6f 74 69 63  |lculation, notic|
00004ce0  65 20 74 68 61 74 20 69  6e 20 74 68 69 73 20 6e  |e that in this n|
00004cf0  65 78 74 20 6c 69 6e 65  20 77 65 20 68 61 76 65  |ext line we have|
00004d00  20 62 6f 74 68 20 61 20  63 6f 6e 76 65 72 73 69  | both a conversi|
00004d10  6f 6e 20 54 4f 20 66 69  78 65 64 20 70 6f 69 6e  |on TO fixed poin|
00004d20  74 20 28 76 69 65 77 5f  79 29 20 61 6e 64 20 61  |t (view_y) and a|
00004d30  6c 73 6f 20 74 68 65 20  63 68 65 63 6b 20 61 67  |lso the check ag|
00004d40  61 69 6e 73 74 20 6f 76  65 72 20 66 6c 6f 77 20  |ainst over flow |
00004d50  69 73 20 76 65 72 79 20  61 70 70 61 72 65 6e 74  |is very apparent|
00004d60  2c 20 77 65 20 73 68 61  72 65 20 74 68 65 20 61  |, we share the a|
00004d70  63 63 75 72 61 63 79 2e  20 53 65 65 20 74 68 65  |ccuracy. See the|
00004d80  20 61 72 74 69 63 6c 65  20 66 6f 72 20 6d 6f 72  | article for mor|
00004d90  65 20 64 65 74 61 69 6c  73 20 2a 2f 0a 0a 64 69  |e details */..di|
00004da0  73 74 5f 78 20 20 3d 20  28 20 28 79 69 20 2d 20  |st_x  = ( (yi - |
00004db0  28 76 69 65 77 5f 79 3c  3c 31 36 29 29 3e 3e 38  |(view_y<<16))>>8|
00004dc0  29 20 2a 20 28 69 6e 76  5f 73 69 6e 5f 74 61 62  |) * (inv_sin_tab|
00004dd0  6c 65 5b 76 69 65 77 5f  61 6e 67 6c 65 5d 3e 3e  |le[view_angle]>>|
00004de0  38 29 3b 0a 2f 2a 20 77  65 20 61 6c 73 6f 20 73  |8);./* we also s|
00004df0  61 76 65 20 74 68 65 20  65 78 61 63 74 20 70 6f  |ave the exact po|
00004e00  73 69 74 69 6f 6e 20 6f  66 20 74 68 65 20 69 6e  |sition of the in|
00004e10  74 65 72 73 65 63 74 69  6f 6e 20 62 65 63 61 75  |tersection becau|
00004e20  73 65 20 77 65 20 77 69  6c 6c 20 6e 65 65 64 20  |se we will need |
00004e30  69 74 20 6c 61 74 65 72  20 74 6f 20 61 64 64 20  |it later to add |
00004e40  74 65 78 74 75 72 65 20  6d 61 70 70 69 6e 67 2e  |texture mapping.|
00004e50  20 2a 2f 0a 0a 2f 2a 20  57 65 20 73 61 76 65 20  | */../* We save |
00004e60  79 69 20 61 66 74 65 72  20 63 6f 6e 76 65 72 74  |yi after convert|
00004e70  69 6e 67 20 69 74 20 62  61 63 6b 20 74 6f 20 6e  |ing it back to n|
00004e80  6f 72 6d 61 6c 20 6d 61  74 68 73 20 2a 2f 0a 0a  |ormal maths */..|
00004e90  79 69 5f 73 61 76 65 20  3d 20 28 69 6e 74 29 79  |yi_save = (int)y|
00004ea0  69 3e 3e 31 36 3b 0a 0a  2f 2a 20 62 65 63 61 75  |i>>16;../* becau|
00004eb0  73 65 20 74 68 65 20 78  20 72 61 79 20 68 61 73  |se the x ray has|
00004ec0  20 66 6f 75 6e 64 20 61  20 77 61 6c 6c 2c 20 77  | found a wall, w|
00004ed0  65 20 63 61 6e 20 73 74  6f 70 20 63 61 73 74 69  |e can stop casti|
00004ee0  6e 67 20 2a 2f 0a 78 72  61 79 3d 46 4f 55 4e 44  |ng */.xray=FOUND|
00004ef0  5f 57 41 4c 4c 3b 0a 0a  7d 0a 7d 0a 0a 0a 2f 2a  |_WALL;..}.}.../*|
00004f00  20 69 66 20 6e 6f 74 2c  20 77 65 20 63 6f 6d 70  | if not, we comp|
00004f10  75 74 65 20 74 68 65 20  6e 65 78 74 20 70 6f 73  |ute the next pos|
00004f20  73 69 62 6c 65 20 69 6e  74 65 72 73 65 63 74 69  |sible intersecti|
00004f30  6f 6e 20 2a 2f 0a 79 69  20 2b 3d 78 61 64 64 3b  |on */.yi +=xadd;|
00004f40  20 2f 2a 20 46 49 58 45  44 20 50 4f 49 4e 54 20  | /* FIXED POINT |
00004f50  41 44 44 49 54 49 4f 4e  20 72 65 71 75 69 72 65  |ADDITION require|
00004f60  73 20 6e 6f 20 65 78 74  72 61 20 77 6f 72 6b 20  |s no extra work |
00004f70  2a 2f 0a 78 5f 62 6f 75  6e 64 20 2b 3d 20 78 5f  |*/.x_bound += x_|
00004f80  64 65 6c 74 61 3b 20 2f  2a 20 61 6e 64 20 77 65  |delta; /* and we|
00004f90  20 61 6c 73 6f 20 63 61  6c 63 75 6c 61 74 65 20  | also calculate |
00004fa0  74 68 65 20 6e 65 78 74  20 68 6f 72 69 7a 6f 6e  |the next horizon|
00004fb0  74 61 6c 20 62 6f 75 6e  64 61 72 79 2c 20 77 68  |tal boundary, wh|
00004fc0  69 63 68 20 77 65 20 6b  6e 6f 77 20 77 69 6c 6c  |ich we know will|
00004fd0  20 62 65 20 78 5f 64 65  6c 74 61 20 61 77 61 79  | be x_delta away|
00004fe0  2c 20 6e 6f 20 6e 65 65  64 20 66 6f 72 20 63 6f  |, no need for co|
00004ff0  6d 70 6c 65 78 20 77 6f  72 6b 69 6e 67 73 2e 20  |mplex workings. |
00005000  2a 2f 0a 0a 7d 0a 2f 2a  20 53 45 43 54 49 4f 4e  |*/..}./* SECTION|
00005010  20 33 20 2a 2f 0a 2f 2a  20 57 45 20 4e 4f 57 20  | 3 */./* WE NOW |
00005020  64 6f 20 65 78 61 63 74  6c 79 20 74 68 65 20 73  |do exactly the s|
00005030  61 6d 65 20 62 75 74 20  66 6f 72 20 74 68 65 20  |ame but for the |
00005040  79 72 61 79 2c 20 77 65  20 63 61 73 74 20 69 74  |yray, we cast it|
00005050  20 6f 75 74 2c 20 63 68  65 63 6b 20 66 6f 72 20  | out, check for |
00005060  61 20 77 61 6c 6c 2c 20  69 66 20 74 68 65 72 65  |a wall, if there|
00005070  20 69 73 20 6f 6e 65 20  77 65 20 74 61 6b 65 20  | is one we take |
00005080  74 68 65 20 64 69 73 74  61 6e 63 65 20 74 6f 20  |the distance to |
00005090  69 74 20 65 74 63 2c 20  69 66 20 6e 6f 74 2c 20  |it etc, if not, |
000050a0  77 65 20 6d 6f 76 65 20  20 74 68 65 20 72 61 79  |we move  the ray|
000050b0  20 75 6e 74 69 6c 20 61  20 77 61 6c 6c 20 69 74  | until a wall it|
000050c0  20 66 6f 75 6e 64 2e 20  2a 2f 0a 0a 2f 2a 20 6c  | found. */../* l|
000050d0  6f 6f 6b 20 75 70 20 74  68 65 20 76 61 6c 75 65  |ook up the value|
000050e0  20 74 6f 20 61 64 64 20  74 6f 20 74 68 65 20 72  | to add to the r|
000050f0  61 79 20 65 61 63 68 20  74 69 6d 65 20 77 65 20  |ay each time we |
00005100  6d 6f 76 65 20 69 74 20  2a 2f 0a 0a 2f 2a 20 53  |move it */../* S|
00005110  65 65 20 61 62 6f 76 65  20 66 6f 72 20 6d 6f 72  |ee above for mor|
00005120  65 20 69 6e 66 6f 72 6d  61 74 69 6f 6e 2c 20 74  |e information, t|
00005130  68 69 73 20 69 73 20 46  49 58 45 44 20 50 4f 49  |his is FIXED POI|
00005140  4e 54 20 72 65 6d 65 6d  62 65 72 20 2a 2f 0a 79  |NT remember */.y|
00005150  61 64 64 3d 78 5f 73 74  65 70 5b 76 69 65 77 5f  |add=x_step[view_|
00005160  61 6e 67 6c 65 5d 3c 3c  33 3b 0a 0a 2f 2a 20 73  |angle]<<3;../* s|
00005170  74 61 72 74 20 63 61 73  74 69 6e 67 20 74 68 65  |tart casting the|
00005180  20 72 61 79 20 2a 2f 0a  77 68 69 6c 65 28 21 79  | ray */.while(!y|
00005190  72 61 79 29 0a 7b 0a 0a  2f 2a 20 63 6f 6d 70 75  |ray).{../* compu|
000051a0  74 65 20 63 75 72 72 65  6e 74 20 63 65 6c 6c 20  |te current cell |
000051b0  74 6f 20 69 6e 73 70 65  63 74 20 2a 2f 0a 0a 2f  |to inspect */../|
000051c0  2a 20 42 65 63 61 75 73  65 20 58 49 20 49 53 20  |* Because XI IS |
000051d0  49 4e 20 46 49 58 45 44  20 50 4f 49 4e 54 20 77  |IN FIXED POINT w|
000051e0  65 20 68 61 76 65 20 74  6f 20 6e 6f 74 20 6f 6e  |e have to not on|
000051f0  6c 79 20 64 69 76 69 64  65 20 62 79 20 36 34 20  |ly divide by 64 |
00005200  62 75 74 20 61 6c 73 6f  20 77 65 20 68 61 76 65  |but also we have|
00005210  20 74 6f 20 63 6f 6e 76  65 72 74 20 42 41 43 4b  | to convert BACK|
00005220  20 74 6f 20 6e 6f 72 6d  61 6c 20 6d 61 74 68 73  | to normal maths|
00005230  20 2a 2f 0a 0a 63 65 6c  6c 5f 78 20 3d 20 28 69  | */..cell_x = (i|
00005240  6e 74 29 78 69 3e 3e 32  32 3b 0a 63 65 6c 6c 5f  |nt)xi>>22;.cell_|
00005250  79 20 3d 20 28 20 28 79  5f 62 6f 75 6e 64 20 2b  |y = ( (y_bound +|
00005260  20 6e 65 78 74 5f 79 5f  63 65 6c 6c 29 20 3e 3e  | next_y_cell) >>|
00005270  20 43 45 4c 4c 5f 59 5f  53 49 5a 45 5f 46 50 29  | CELL_Y_SIZE_FP)|
00005280  3b 0a 2f 2a 20 74 68 65  73 65 20 63 61 6c 63 75  |;./* these calcu|
00005290  6c 61 74 69 6f 6e 73 20  77 6f 72 6b 20 6f 75 74  |lations work out|
000052a0  20 77 68 69 63 68 20 63  65 6c 6c 73 20 74 68 65  | which cells the|
000052b0  20 72 61 79 20 69 73 20  69 6e 2c 20 72 65 61 64  | ray is in, read|
000052c0  79 20 74 6f 20 63 68 65  63 6b 20 66 6f 72 20 77  |y to check for w|
000052d0  61 6c 6c 73 20 69 6e 20  74 68 65 20 77 6f 72 6c  |alls in the worl|
000052e0  64 5b 5d 5b 5d 20 61 72  72 61 79 2e 20 54 68 65  |d[][] array. The|
000052f0  79 20 62 6f 74 68 20 75  73 65 20 62 69 6e 61 72  |y both use binar|
00005300  79 20 73 68 69 66 74 69  6e 67 20 74 6f 20 70 65  |y shifting to pe|
00005310  72 66 6f 72 6d 20 64 69  76 69 64 65 20 62 79 20  |rform divide by |
00005320  36 34 27 73 2e 20 2a 2f  0a 0a 2f 2a 20 63 68 65  |64's. */../* che|
00005330  63 6b 20 74 68 61 74 20  74 68 65 20 72 61 79 20  |ck that the ray |
00005340  68 61 73 20 6e 6f 74 20  67 6f 6e 65 20 6f 75 74  |has not gone out|
00005350  20 6f 66 20 74 68 65 20  77 6f 72 6c 64 2c 20 74  | of the world, t|
00005360  68 6f 75 67 68 20 74 68  69 73 20 69 73 6e 27 74  |hough this isn't|
00005370  20 72 65 61 6c 6c 79 20  6e 65 63 65 73 73 61 72  | really necessar|
00005380  79 20 2a 2f 0a 69 66 28  63 65 6c 6c 5f 78 3c 30  |y */.if(cell_x<0|
00005390  29 63 65 6c 6c 5f 78 3d  30 3b 69 66 28 63 65 6c  |)cell_x=0;if(cel|
000053a0  6c 5f 78 3e 36 33 29 63  65 6c 6c 5f 78 3d 36 33  |l_x>63)cell_x=63|
000053b0  3b 0a 69 66 28 63 65 6c  6c 5f 79 3c 30 29 63 65  |;.if(cell_y<0)ce|
000053c0  6c 6c 5f 79 3d 30 3b 69  66 28 63 65 6c 6c 5f 79  |ll_y=0;if(cell_y|
000053d0  3e 36 33 29 63 65 6c 6c  5f 79 3d 36 33 3b 0a 0a  |>63)cell_y=63;..|
000053e0  2f 2a 20 6c 6f 6f 6b 20  61 6e 64 20 73 65 65 20  |/* look and see |
000053f0  69 66 20 74 68 65 72 65  20 69 73 20 61 20 77 61  |if there is a wa|
00005400  6c 6c 20 61 74 20 74 68  65 20 63 75 72 72 65 6e  |ll at the curren|
00005410  74 20 70 6f 69 6e 74 20  6f 66 20 69 6e 74 65 72  |t point of inter|
00005420  73 65 63 74 69 6f 6e 20  2a 2f 0a 0a 69 66 20 28  |section */..if (|
00005430  28 79 5f 68 69 74 5f 74  79 70 65 20 3d 20 77 6f  |(y_hit_type = wo|
00005440  72 6c 64 5b 63 65 6c 6c  5f 79 5d 5b 63 65 6c 6c  |rld[cell_y][cell|
00005450  5f 78 5d 29 21 3d 30 29  0a 7b 0a 69 66 28 79 5f  |_x])!=0).{.if(y_|
00005460  68 69 74 5f 74 79 70 65  3d 3d 39 20 7c 7c 20 79  |hit_type==9 || y|
00005470  5f 68 69 74 5f 74 79 70  65 3d 3d 37 20 7c 7c 20  |_hit_type==7 || |
00005480  79 5f 68 69 74 5f 74 79  70 65 3d 3d 31 30 29 7b  |y_hit_type==10){|
00005490  0a 20 20 2f 2a 54 48 45  4e 20 54 48 45 20 57 41  |.  /*THEN THE WA|
000054a0  4c 4c 20 49 53 20 54 52  41 4e 53 50 41 52 45 4e  |LL IS TRANSPAREN|
000054b0  54 21 21 21 2a 2f 0a 79  74 72 61 6e 73 5f 64 69  |T!!!*/.ytrans_di|
000054c0  73 74 3d 28 28 78 69 2d  28 76 69 65 77 5f 78 3c  |st=((xi-(view_x<|
000054d0  3c 31 36 29 29 3e 3e 38  29 2a 28 69 6e 76 5f 63  |<16))>>8)*(inv_c|
000054e0  6f 73 5f 74 61 62 6c 65  5b 76 69 65 77 5f 61 6e  |os_table[view_an|
000054f0  67 6c 65 5d 3e 3e 38 29  3b 0a 79 74 72 61 6e 73  |gle]>>8);.ytrans|
00005500  5f 74 79 70 65 3d 79 5f  68 69 74 5f 74 79 70 65  |_type=y_hit_type|
00005510  3b 0a 79 74 72 61 6e 73  5f 63 6f 6c 3d 28 28 69  |;.ytrans_col=((i|
00005520  6e 74 29 28 78 69 3e 3e  31 36 29 20 26 20 30 78  |nt)(xi>>16) & 0x|
00005530  30 30 33 66 29 3b 0a 79  74 72 61 6e 73 5f 64 6f  |003f);.ytrans_do|
00005540  6e 65 3d 46 4f 55 4e 44  5f 57 41 4c 4c 3b 0a 7d  |ne=FOUND_WALL;.}|
00005550  0a 2f 2a 20 77 65 20 72  65 63 6f 72 64 20 61 6c  |./* we record al|
00005560  6c 20 72 65 71 75 69 72  65 64 20 64 65 74 61 69  |l required detai|
00005570  6c 73 20 74 68 65 6e 20  63 6f 6e 74 69 6e 75 65  |ls then continue|
00005580  20 2a 2f 0a 0a 65 6c 73  65 0a 7b 0a 0a 0a 0a 2f  | */..else.{..../|
00005590  2a 20 55 73 65 20 74 68  65 20 6f 6c 64 20 4f 2d  |* Use the old O-|
000055a0  4c 65 76 65 6c 20 74 72  69 61 6e 67 6c 65 20 6d  |Level triangle m|
000055b0  65 74 68 6f 64 20 6f 66  20 63 61 6c 75 6c 61 74  |ethod of calulat|
000055c0  69 6e 67 20 64 69 73 74  61 6e 63 65 20 75 73 69  |ing distance usi|
000055d0  6e 67 20 63 6f 73 2c 20  72 61 74 68 65 72 20 74  |ng cos, rather t|
000055e0  68 61 6e 20 75 73 69 6e  67 20 50 59 54 48 41 47  |han using PYTHAG|
000055f0  4f 52 41 53 2c 20 77 68  69 63 68 20 69 73 20 73  |ORAS, which is s|
00005600  6c 6f 77 65 72 20 62 65  63 61 75 73 65 20 69 74  |lower because it|
00005610  20 75 73 65 73 20 61 20  73 71 75 61 72 65 20 72  | uses a square r|
00005620  6f 6f 74 21 20 2a 2f 0a  2f 2a 20 46 49 58 45 44  |oot! */./* FIXED|
00005630  20 50 4f 49 4e 54 20 63  61 6c 63 75 6c 61 74 69  | POINT calculati|
00005640  6f 6e 2c 20 6a 75 73 74  20 74 68 65 20 73 61 6d  |on, just the sam|
00005650  65 20 61 73 20 74 68 65  20 69 6e 76 5f 73 69 6e  |e as the inv_sin|
00005660  20 63 61 6c 63 75 6c 61  74 69 6f 6e 20 73 65 65  | calculation see|
00005670  20 61 62 6f 76 65 2e 20  2a 2f 0a 64 69 73 74 5f  | above. */.dist_|
00005680  79 20 20 3d 20 28 20 28  78 69 20 2d 20 28 76 69  |y  = ( (xi - (vi|
00005690  65 77 5f 78 3c 3c 31 36  29 29 3e 3e 38 29 20 2a  |ew_x<<16))>>8) *|
000056a0  20 28 69 6e 76 5f 63 6f  73 5f 74 61 62 6c 65 5b  | (inv_cos_table[|
000056b0  76 69 65 77 5f 61 6e 67  6c 65 5d 3e 3e 38 29 3b  |view_angle]>>8);|
000056c0  0a 0a 2f 2a 20 73 61 76  65 20 74 68 65 20 65 78  |../* save the ex|
000056d0  61 63 74 20 69 6e 74 65  72 73 65 63 74 69 6f 6e  |act intersection|
000056e0  20 70 6f 69 6e 74 2c 20  77 65 20 77 69 6c 6c 20  | point, we will |
000056f0  6e 65 65 64 20 69 74 20  6c 61 74 65 72 20 2a 2f  |need it later */|
00005700  0a 2f 2a 20 53 61 6d 65  20 61 73 20 61 6f 62 76  |./* Same as aobv|
00005710  65 2c 20 76 65 72 79 20  73 69 6d 70 6c 65 20 63  |e, very simple c|
00005720  6f 6e 76 65 72 73 69 6f  6e 20 62 61 63 6b 20 66  |onversion back f|
00005730  72 6f 6d 20 46 49 58 45  44 20 50 4f 49 4e 54 20  |rom FIXED POINT |
00005740  74 6f 20 6e 6f 72 6d 61  6c 20 6d 61 74 68 73 20  |to normal maths |
00005750  2a 2f 0a 78 69 5f 73 61  76 65 20 3d 20 28 69 6e  |*/.xi_save = (in|
00005760  74 29 78 69 3e 3e 31 36  3b 0a 2f 2a 20 53 54 4f  |t)xi>>16;./* STO|
00005770  50 20 79 20 63 61 73 74  69 6e 67 20 69 6e 20 74  |P y casting in t|
00005780  68 61 74 20 63 61 73 65  2c 20 61 20 77 61 6c 6c  |hat case, a wall|
00005790  20 68 61 73 20 62 65 65  6e 20 66 6f 75 6e 64 2e  | has been found.|
000057a0  20 2a 2f 0a 79 72 61 79  3d 46 4f 55 4e 44 5f 57  | */.yray=FOUND_W|
000057b0  41 4c 4c 3b 0a 7d 0a 7d  0a 0a 0a 2f 2a 20 69 66  |ALL;.}.}.../* if|
000057c0  20 6e 6f 74 2c 20 6d 6f  76 65 20 74 68 65 20 72  | not, move the r|
000057d0  61 79 20 6f 6e 20 2a 2f  0a 78 69 2b 3d 79 61 64  |ay on */.xi+=yad|
000057e0  64 3b 20 2f 2a 20 41 47  41 49 4e 2c 20 6e 6f 20  |d; /* AGAIN, no |
000057f0  65 78 74 72 61 20 77 6f  72 6b 20 69 73 20 72 65  |extra work is re|
00005800  71 75 69 72 65 64 20 66  6f 72 20 46 49 58 45 44  |quired for FIXED|
00005810  20 50 4f 49 4e 54 20 41  44 44 49 54 49 4f 4e 20  | POINT ADDITION |
00005820  2a 2f 0a 79 5f 62 6f 75  6e 64 20 2b 3d 20 79 5f  |*/.y_bound += y_|
00005830  64 65 6c 74 61 3b 20 2f  2a 20 61 6e 64 20 6d 6f  |delta; /* and mo|
00005840  76 65 20 74 6f 20 74 68  65 20 6e 65 78 74 20 76  |ve to the next v|
00005850  65 72 74 69 63 61 6c 20  62 6f 75 6e 64 61 72 79  |ertical boundary|
00005860  20 70 6f 73 69 74 69 6f  6e 20 2a 2f 0a 0a 0a 0a  | position */....|
00005870  7d 0a 0a 2f 2a 20 53 45  43 54 49 4f 4e 20 34 2a  |}../* SECTION 4*|
00005880  2f 0a 2f 2a 20 42 6f 74  68 20 72 61 79 73 20 68  |/./* Both rays h|
00005890  61 76 65 20 62 65 65 6e  20 63 61 73 74 2c 20 62  |ave been cast, b|
000058a0  6f 74 68 20 72 61 79 73  20 68 61 76 65 20 6d 65  |oth rays have me|
000058b0  74 20 61 20 77 61 6c 6c  2c 20 77 65 20 6e 6f 77  |t a wall, we now|
000058c0  20 6e 65 65 64 20 74 6f  20 73 65 65 20 77 68 69  | need to see whi|
000058d0  63 68 20 69 73 20 63 6c  6f 73 65 72 2c 20 61 6e  |ch is closer, an|
000058e0  64 20 74 68 65 6e 20 70  6c 6f 74 20 69 74 20 63  |d then plot it c|
000058f0  6f 72 72 65 63 74 6c 79  2e 20 2a 2f 0a 0a 2f 2a  |orrectly. */../*|
00005900  20 66 69 6e 64 20 6f 75  74 20 77 68 69 63 68 20  | find out which |
00005910  77 61 6c 6c 20 28 78 20  6f 72 20 79 29 20 69 73  |wall (x or y) is|
00005920  20 6e 65 61 72 65 72 20  74 68 65 20 76 69 65 77  | nearer the view|
00005930  65 72 2e 20 2a 2f 0a 0a  2f 2a 20 77 65 20 68 61  |er. */../* we ha|
00005940  76 65 20 61 6c 74 65 72  65 64 20 74 68 69 73 20  |ve altered this |
00005950  64 69 73 74 61 6e 63 65  20 63 68 65 63 6b 69 6e  |distance checkin|
00005960  67 20 6c 69 6e 65 20 74  6f 20 61 76 6f 69 64 20  |g line to avoid |
00005970  6d 69 6e 75 73 20 64 69  73 74 61 6e 63 65 73 20  |minus distances |
00005980  62 65 69 6e 67 20 73 65  6c 65 63 74 65 64 20 74  |being selected t|
00005990  6f 20 64 72 61 77 2c 20  77 68 69 63 68 20 70 72  |o draw, which pr|
000059a0  6f 64 75 63 65 73 20 6c  61 72 67 65 20 73 70 69  |oduces large spi|
000059b0  6b 65 73 20 6f 6e 20 74  68 65 20 73 63 72 65 65  |kes on the scree|
000059c0  6e 21 20 41 67 61 69 6e  20 74 68 69 73 20 69 73  |n! Again this is|
000059d0  20 62 65 63 61 75 73 65  20 6f 66 20 66 69 78 65  | because of fixe|
000059e0  64 20 70 6f 69 6e 74 20  2a 2f 0a 0a 20 20 20 20  |d point */..    |
000059f0  69 66 20 28 64 69 73 74  5f 78 20 3c 20 64 69 73  |if (dist_x < dis|
00005a00  74 5f 79 20 26 26 20 64  69 73 74 5f 78 3e 30 20  |t_y && dist_x>0 |
00005a10  7c 7c 20 64 69 73 74 5f  79 3c 30 29 0a 0a 20 20  ||| dist_y<0)..  |
00005a20  20 20 20 20 20 7b 0a 0a  0a 2f 2a 20 77 65 20 6e  |     {.../* we n|
00005a30  65 65 64 20 74 6f 20 74  61 6b 65 20 69 6e 74 6f  |eed to take into|
00005a40  20 61 63 63 6f 75 6e 74  20 68 65 72 65 2c 20 77  | account here, w|
00005a50  68 65 6e 20 63 6f 6d 70  75 74 69 6e 67 20 74 68  |hen computing th|
00005a60  65 20 73 63 61 6c 65 20  6f 66 20 74 68 65 20 76  |e scale of the v|
00005a70  65 72 74 69 63 61 6c 20  73 74 72 69 70 20 28 73  |ertical strip (s|
00005a80  6c 69 76 65 72 29 20 74  6f 20 62 65 20 64 72 61  |liver) to be dra|
00005a90  77 6e 2c 20 61 20 70 68  65 6e 65 6d 65 6e 6f 6e  |wn, a phenemenon|
00005aa0  20 28 6f 66 20 73 6f 72  74 73 29 20 6b 6e 6f 77  | (of sorts) know|
00005ab0  6e 20 61 73 20 74 68 65  20 22 66 69 73 68 20 62  |n as the "fish b|
00005ac0  6f 77 6c 20 65 66 66 65  63 74 22 2e 20 54 68 69  |owl effect". Thi|
00005ad0  73 20 69 73 20 63 61 75  73 65 64 20 62 79 20 6d  |s is caused by m|
00005ae0  69 7a 69 6e 67 20 6f 66  20 63 61 72 74 65 73 69  |izing of cartesi|
00005af0  61 6e 20 61 6e 64 20 70  6f 6c 61 72 20 63 6f 6f  |an and polar coo|
00005b00  72 64 69 6e 61 74 65 73  2e 20 54 6f 20 67 65 74  |rdinates. To get|
00005b10  20 72 69 64 20 6f 66 20  69 74 20 77 65 20 75 73  | rid of it we us|
00005b20  65 20 74 68 65 20 63 6f  73 69 6e 65 20 66 75 6e  |e the cosine fun|
00005b30  63 74 69 6f 6e 2e 20 49  20 68 61 76 65 20 63 6f  |ction. I have co|
00005b40  6d 62 69 6e 65 64 20 6f  74 68 65 72 20 6d 75 6c  |mbined other mul|
00005b50  74 69 70 6c 69 65 73 20  6f 66 20 61 20 76 65 72  |tiplies of a ver|
00005b60  74 69 63 61 6c 20 73 63  61 6c 69 6e 67 20 66 61  |tical scaling fa|
00005b70  63 74 6f 72 20 77 69 74  68 20 74 68 65 20 63 6f  |ctor with the co|
00005b80  73 69 6e 65 20 74 72 61  6e 73 66 6f 72 6d 61 74  |sine transformat|
00005b90  69 6f 6e 20 74 6f 20 73  61 76 65 20 74 69 6d 65  |ion to save time|
00005ba0  2e 20 41 6c 6c 20 77 65  20 65 76 65 6e 74 75 61  |. All we eventua|
00005bb0  6c 6c 79 20 62 65 20 65  78 70 6c 61 69 6e 65 64  |lly be explained|
00005bc0  2e 20 59 6f 75 20 63 6f  75 6c 64 20 72 65 70 6c  |. You could repl|
00005bd0  61 63 65 20 74 68 65 20  6c 69 6e 65 20 77 69 74  |ace the line wit|
00005be0  68 20 73 63 61 6c 65 3d  31 33 33 31 32 2f 64 69  |h scale=13312/di|
00005bf0  73 74 5f 78 2b 2b 20 61  6e 64 20 73 65 65 20 77  |st_x++ and see w|
00005c00  68 61 74 20 77 65 69 72  64 20 72 65 73 75 6c 74  |hat weird result|
00005c10  73 20 79 6f 75 20 67 65  74 21 20 2a 2f 0a 0a 2f  |s you get! */../|
00005c20  2a 20 4e 45 57 20 4e 45  57 20 4e 45 57 20 3a 20  |* NEW NEW NEW : |
00005c30  57 65 20 68 61 76 65 20  66 69 78 65 64 20 70 6f  |We have fixed po|
00005c40  69 6e 74 20 68 65 72 65  2c 20 61 6e 64 20 75 73  |int here, and us|
00005c50  69 6e 67 20 74 68 65 20  72 65 63 69 70 72 6f 63  |ing the reciproc|
00005c60  61 6c 20 74 61 62 6c 65  20 28 73 65 65 20 61 72  |al table (see ar|
00005c70  6f 75 6e 64 29 20 77 65  20 64 6f 6e 27 74 20 68  |ound) we don't h|
00005c80  61 76 65 20 74 6f 20 64  6f 20 61 20 6c 65 6e 67  |ave to do a leng|
00005c90  74 68 79 20 64 69 76 69  64 65 21 20 4e 6f 74 69  |thy divide! Noti|
00005ca0  63 65 20 68 6f 77 20 77  65 20 63 6f 6e 76 65 72  |ce how we conver|
00005cb0  74 20 64 69 73 74 5f 78  20 62 61 63 6b 20 74 6f  |t dist_x back to|
00005cc0  20 6e 6f 72 6d 61 6c 20  74 6f 20 69 6e 64 65 78  | normal to index|
00005cd0  20 74 68 65 20 72 65 63  69 70 5f 74 61 62 6c 65  | the recip_table|
00005ce0  20 61 72 72 61 79 2c 20  61 6e 64 20 74 68 61 74  | array, and that|
00005cf0  20 61 6c 6c 20 61 63 63  75 72 61 63 79 20 69 73  | all accuracy is|
00005d00  20 6c 6f 73 74 20 77 69  74 68 20 74 68 65 20 63  | lost with the c|
00005d10  6f 73 5f 74 61 62 6c 65  2c 20 62 65 63 61 75 73  |os_table, becaus|
00005d20  65 20 61 6c 6c 20 69 74  73 20 66 69 67 75 72 65  |e all its figure|
00005d30  73 20 61 72 65 20 61 62  6f 76 65 20 7a 65 72 6f  |s are above zero|
00005d40  20 28 73 65 65 20 61 75  61 5f 74 61 62 6c 65 73  | (see aua_tables|
00005d50  29 20 61 6e 64 20 61 6c  73 6f 20 74 68 61 74 20  |) and also that |
00005d60  77 65 20 61 63 74 75 61  6c 6c 79 20 63 6f 6e 76  |we actually conv|
00005d70  65 72 74 20 74 68 65 20  77 68 6f 6c 65 20 61 6e  |ert the whole an|
00005d80  73 77 65 72 20 62 61 63  6b 20 74 6f 20 6e 6f 72  |swer back to nor|
00005d90  6d 61 6c 20 6d 61 74 68  73 20 66 6f 72 20 73 63  |mal maths for sc|
00005da0  61 6c 65 20 2a 2f 0a 0a  73 63 61 6c 65 20 3d 20  |ale */..scale = |
00005db0  28 69 6e 74 29 28 20 28  63 6f 73 5f 74 61 62 6c  |(int)( (cos_tabl|
00005dc0  65 5b 72 61 79 5d 3e 3e  31 36 29 20 2a 20 28 72  |e[ray]>>16) * (r|
00005dd0  65 63 69 70 5f 74 61 62  6c 65 5b 64 69 73 74 5f  |ecip_table[dist_|
00005de0  78 3e 3e 31 36 5d 29 20  3e 3e 31 36 29 3b 0a 0a  |x>>16]) >>16);..|
00005df0  2f 2a 20 61 73 73 69 67  6e 20 74 68 65 20 76 61  |/* assign the va|
00005e00  72 69 61 62 6c 65 73 20  77 65 20 6e 65 65 64 20  |riables we need |
00005e10  74 6f 20 74 68 65 20 76  61 72 69 61 62 6c 65 73  |to the variables|
00005e20  20 74 6f 20 62 65 20 70  61 73 73 65 64 20 74 6f  | to be passed to|
00005e30  20 74 68 65 20 41 53 4d  20 73 6c 69 76 65 72 20  | the ASM sliver |
00005e40  72 65 6e 64 65 72 65 72  20 28 73 75 70 65 72 20  |renderer (super |
00005e50  66 61 73 74 21 29 20 2a  2f 0a 69 66 28 73 63 61  |fast!) */.if(sca|
00005e60  6c 65 3e 53 43 52 45 45  4e 5f 48 45 49 47 48 54  |le>SCREEN_HEIGHT|
00005e70  29 0a 7b 0a 0a 20 20 73  63 61 6c 65 3d 53 43 52  |).{..  scale=SCR|
00005e80  45 45 4e 5f 48 45 49 47  48 54 2d 31 3b 0a 7d 0a  |EEN_HEIGHT-1;.}.|
00005e90  0a 76 61 72 69 61 62 6c  65 73 5b 32 5d 3d 73 63  |.variables[2]=sc|
00005ea0  61 6c 65 3b 20 2f 2a 73  74 6f 72 65 73 20 74 68  |ale; /*stores th|
00005eb0  65 20 73 63 61 6c 65 20  6f 66 20 74 68 65 20 73  |e scale of the s|
00005ec0  74 72 69 70 20 28 68 65  69 67 68 74 20 6f 66 20  |trip (height of |
00005ed0  69 74 29 2a 2f 0a 76 61  72 69 61 62 6c 65 73 5b  |it)*/.variables[|
00005ee0  33 5d 3d 72 61 79 3b 20  2f 2a 20 77 65 20 75 73  |3]=ray; /* we us|
00005ef0  65 20 72 61 79 20 61 73  20 74 68 65 20 78 20 70  |e ray as the x p|
00005f00  6f 73 69 74 69 6f 6e 20  74 6f 20 70 6c 6f 74 20  |osition to plot |
00005f10  74 6f 20 28 30 2d 33 31  39 29 2a 2f 0a 76 61 72  |to (0-319)*/.var|
00005f20  69 61 62 6c 65 73 5b 31  5d 3d 28 69 6e 74 29 26  |iables[1]=(int)&|
00005f30  77 61 6c 6c 73 5b 78 5f  68 69 74 5f 74 79 70 65  |walls[x_hit_type|
00005f40  5d 5b 28 79 69 5f 73 61  76 65 20 26 20 30 78 30  |][(yi_save & 0x0|
00005f50  30 33 66 29 5d 3b 0a 76  61 72 69 61 62 6c 65 73  |03f)];.variables|
00005f60  5b 34 5d 3d 28 72 65 63  69 70 5f 74 61 62 6c 65  |[4]=(recip_table|
00005f70  5b 73 63 61 6c 65 5d 3c  3c 36 29 3b 0a 2f 2a 20  |[scale]<<6);./* |
00005f80  61 6e 64 20 77 65 20 63  61 6c 6c 20 74 68 65 20  |and we call the |
00005f90  61 73 73 65 6d 62 6c 65  72 20 66 75 6e 63 74 69  |assembler functi|
00005fa0  6f 6e 20 28 65 78 70 6c  61 69 6e 65 64 20 61 74  |on (explained at|
00005fb0  20 61 20 6c 61 74 65 72  20 64 61 74 65 29 2a 2f  | a later date)*/|
00005fc0  0a 6f 75 72 6c 69 62 5f  6e 65 77 28 26 76 61 72  |.ourlib_new(&var|
00005fd0  69 61 62 6c 65 73 5b 30  5d 29 3b 0a 73 63 61 6c  |iables[0]);.scal|
00005fe0  65 5f 61 72 72 61 79 5b  72 61 79 5d 3d 73 63 61  |e_array[ray]=sca|
00005ff0  6c 65 3b 0a 20 20 20 20  20 20 20 7d 0a 2f 2a 20  |le;.       }./* |
00006000  65 6c 73 65 20 74 68 65  20 64 69 73 74 5f 79 20  |else the dist_y |
00006010  77 61 73 20 6e 65 61 72  65 72 2c 20 65 76 65 72  |was nearer, ever|
00006020  79 74 68 69 6e 67 20 66  72 6f 6d 20 61 62 6f 76  |ything from abov|
00006030  65 20 61 70 70 6c 69 65  73 20 2a 2f 0a 20 20 20  |e applies */.   |
00006040  20 65 6c 73 65 0a 20 20  20 20 20 20 20 7b 0a 0a  | else.       {..|
00006050  2f 2a 20 61 76 6f 69 64  20 66 69 73 68 20 62 6f  |/* avoid fish bo|
00006060  77 6c 20 65 66 66 65 63  74 20 61 6e 64 20 73 63  |wl effect and sc|
00006070  61 6c 65 20 70 72 6f 70  65 72 6c 79 20 77 69 74  |ale properly wit|
00006080  68 20 46 49 58 45 44 20  50 4f 49 4e 54 20 63 6c  |h FIXED POINT cl|
00006090  65 76 65 72 20 62 69 74  73 21 2c 20 73 65 65 20  |ever bits!, see |
000060a0  61 62 6f 76 65 20 2a 2f  0a 73 63 61 6c 65 20 3d  |above */.scale =|
000060b0  20 28 69 6e 74 29 28 20  28 63 6f 73 5f 74 61 62  | (int)( (cos_tab|
000060c0  6c 65 5b 72 61 79 5d 3e  3e 31 36 29 20 2a 20 28  |le[ray]>>16) * (|
000060d0  72 65 63 69 70 5f 74 61  62 6c 65 5b 64 69 73 74  |recip_table[dist|
000060e0  5f 79 3e 3e 31 36 5d 29  20 3e 3e 20 31 36 29 3b  |_y>>16]) >> 16);|
000060f0  0a 0a 0a 2f 2a 20 73 65  74 20 75 70 20 76 61 72  |.../* set up var|
00006100  69 61 62 6c 65 73 20 66  6f 72 20 6f 75 72 20 73  |iables for our s|
00006110  6c 69 76 65 72 20 65 6e  67 69 6e 65 2c 20 73 65  |liver engine, se|
00006120  65 20 61 62 6f 76 65 20  2a 2f 0a 69 66 28 73 63  |e above */.if(sc|
00006130  61 6c 65 3e 53 43 52 45  45 4e 5f 48 45 49 47 48  |ale>SCREEN_HEIGH|
00006140  54 29 0a 7b 0a 0a 20 20  73 63 61 6c 65 3d 53 43  |T).{..  scale=SC|
00006150  52 45 45 4e 5f 48 45 49  47 48 54 2d 31 3b 0a 7d  |REEN_HEIGHT-1;.}|
00006160  0a 0a 76 61 72 69 61 62  6c 65 73 5b 32 5d 3d 73  |..variables[2]=s|
00006170  63 61 6c 65 3b 20 2f 2a  73 74 6f 72 65 73 20 74  |cale; /*stores t|
00006180  68 65 20 73 63 61 6c 65  20 6f 66 20 74 68 65 20  |he scale of the |
00006190  73 74 72 69 70 20 28 68  65 69 67 68 74 20 6f 66  |strip (height of|
000061a0  20 69 74 29 2a 2f 0a 76  61 72 69 61 62 6c 65 73  | it)*/.variables|
000061b0  5b 33 5d 3d 72 61 79 3b  20 2f 2a 20 77 65 20 75  |[3]=ray; /* we u|
000061c0  73 65 20 72 61 79 20 61  73 20 74 68 65 20 78 20  |se ray as the x |
000061d0  70 6f 73 69 74 69 6f 6e  20 74 6f 20 70 6c 6f 74  |position to plot|
000061e0  20 74 6f 20 28 30 2d 33  31 39 29 2a 2f 0a 76 61  | to (0-319)*/.va|
000061f0  72 69 61 62 6c 65 73 5b  31 5d 3d 28 69 6e 74 29  |riables[1]=(int)|
00006200  26 77 61 6c 6c 73 5b 79  5f 68 69 74 5f 74 79 70  |&walls[y_hit_typ|
00006210  65 2b 31 5d 5b 28 78 69  5f 73 61 76 65 20 26 20  |e+1][(xi_save & |
00006220  30 78 30 30 33 66 29 5d  3b 0a 76 61 72 69 61 62  |0x003f)];.variab|
00006230  6c 65 73 5b 34 5d 3d 28  72 65 63 69 70 5f 74 61  |les[4]=(recip_ta|
00006240  62 6c 65 5b 73 63 61 6c  65 5d 3c 3c 36 29 3b 0a  |ble[scale]<<6);.|
00006250  2f 2a 20 6e 6f 74 69 63  65 20 77 65 20 61 64 64  |/* notice we add|
00006260  20 6f 6e 65 20 74 6f 20  74 68 65 20 77 61 6c 6c  | one to the wall|
00006270  20 67 72 61 70 68 69 63  20 73 65 6c 65 63 74 69  | graphic selecti|
00006280  6f 6e 2c 20 73 6f 20 74  68 65 20 64 61 72 6b 65  |on, so the darke|
00006290  72 20 74 69 6c 65 20 69  73 20 75 73 65 64 20 66  |r tile is used f|
000062a0  6f 72 20 61 64 64 65 64  20 76 61 72 69 61 74 69  |or added variati|
000062b0  6f 6e 2e 20 53 65 65 20  74 68 65 20 61 72 74 69  |on. See the arti|
000062c0  63 6c 65 20 66 6f 72 20  6d 6f 72 65 20 64 65 74  |cle for more det|
000062d0  61 69 6c 73 20 6f 66 20  74 68 69 73 20 73 6f 72  |ails of this sor|
000062e0  74 20 6f 66 20 73 68 61  64 69 6e 67 2c 20 69 66  |t of shading, if|
000062f0  20 79 6f 75 20 77 61 6e  74 20 74 6f 20 63 61 6c  | you want to cal|
00006300  6c 20 69 74 20 74 68 61  74 21 20 2a 2f 0a 0a 2f  |l it that! */../|
00006310  2a 20 63 61 6c 6c 20 6f  75 72 20 73 6c 69 76 65  |* call our slive|
00006320  72 20 65 6e 67 69 6e 65  20 2a 2f 0a 6f 75 72 6c  |r engine */.ourl|
00006330  69 62 5f 6e 65 77 28 26  76 61 72 69 61 62 6c 65  |ib_new(&variable|
00006340  73 5b 30 5d 29 3b 0a 73  63 61 6c 65 5f 61 72 72  |s[0]);.scale_arr|
00006350  61 79 5b 72 61 79 5d 3d  73 63 61 6c 65 3b 0a 20  |ay[ray]=scale;. |
00006360  20 20 20 20 20 20 7d 0a  2f 2a 20 69 74 20 69 73  |      }./* it is|
00006370  20 68 65 72 65 20 74 68  61 74 20 77 65 20 64 72  | here that we dr|
00006380  61 77 20 74 68 65 20 6f  76 65 72 6c 61 79 69 6e  |aw the overlayin|
00006390  67 20 74 72 61 6e 73 70  61 72 65 6e 74 20 77 61  |g transparent wa|
000063a0  6c 6c 20 2a 2f 0a 69 66  28 78 74 72 61 6e 73 5f  |ll */.if(xtrans_|
000063b0  64 6f 6e 65 20 26 26 20  78 74 72 61 6e 73 5f 64  |done && xtrans_d|
000063c0  69 73 74 3c 64 69 73 74  5f 79 29 0a 7b 0a 20 20  |ist<dist_y).{.  |
000063d0  73 63 61 6c 65 3d 28 69  6e 74 29 28 28 63 6f 73  |scale=(int)((cos|
000063e0  5f 74 61 62 6c 65 5b 72  61 79 5d 3e 3e 31 36 29  |_table[ray]>>16)|
000063f0  20 2a 20 28 72 65 63 69  70 5f 74 61 62 6c 65 5b  | * (recip_table[|
00006400  78 74 72 61 6e 73 5f 64  69 73 74 3e 3e 31 36 5d  |xtrans_dist>>16]|
00006410  29 3e 3e 31 36 29 3b 0a  20 20 69 66 28 73 63 61  |)>>16);.  if(sca|
00006420  6c 65 3e 53 43 52 45 45  4e 5f 48 45 49 47 48 54  |le>SCREEN_HEIGHT|
00006430  29 73 63 61 6c 65 3d 53  43 52 45 45 4e 5f 48 45  |)scale=SCREEN_HE|
00006440  49 47 48 54 2d 31 3b 0a  20 20 76 61 72 69 61 62  |IGHT-1;.  variab|
00006450  6c 65 73 5b 32 5d 3d 73  63 61 6c 65 3b 0a 20 20  |les[2]=scale;.  |
00006460  76 61 72 69 61 62 6c 65  73 5b 33 5d 3d 72 61 79  |variables[3]=ray|
00006470  3b 0a 20 20 76 61 72 69  61 62 6c 65 73 5b 34 5d  |;.  variables[4]|
00006480  3d 28 72 65 63 69 70 5f  74 61 62 6c 65 5b 73 63  |=(recip_table[sc|
00006490  61 6c 65 5d 3c 3c 36 29  3b 0a 20 20 76 61 72 69  |ale]<<6);.  vari|
000064a0  61 62 6c 65 73 5b 31 5d  3d 28 69 6e 74 29 26 77  |ables[1]=(int)&w|
000064b0  61 6c 6c 73 5b 78 74 72  61 6e 73 5f 74 79 70 65  |alls[xtrans_type|
000064c0  5d 5b 78 74 72 61 6e 73  5f 63 6f 6c 5d 3b 0a 0a  |][xtrans_col];..|
000064d0  2f 2a 20 6e 6f 77 20 63  61 6c 6c 20 6f 75 72 20  |/* now call our |
000064e0  73 70 65 63 69 61 6c 20  66 75 6e 63 74 69 6f 6e  |special function|
000064f0  20 77 68 69 63 68 20 74  72 65 61 74 73 20 63 6f  | which treats co|
00006500  6c 6f 72 20 30 20 61 73  20 61 20 6d 61 73 6b 20  |lor 0 as a mask |
00006510  2a 2f 0a 0a 6f 75 72 6c  69 62 5f 6e 65 77 5f 6d  |*/..ourlib_new_m|
00006520  61 73 6b 28 76 61 72 69  61 62 6c 65 73 29 3b 0a  |ask(variables);.|
00006530  6d 69 72 72 6f 72 5f 61  72 72 61 79 5b 72 61 79  |mirror_array[ray|
00006540  5d 3d 30 3b 0a 69 66 28  78 74 72 61 6e 73 5f 74  |]=0;.if(xtrans_t|
00006550  79 70 65 3d 3d 31 30 29  6d 69 72 72 6f 72 5f 61  |ype==10)mirror_a|
00006560  72 72 61 79 5b 72 61 79  5d 3d 32 35 35 3b 0a 65  |rray[ray]=255;.e|
00006570  6c 73 65 20 73 63 61 6c  65 5f 61 72 72 61 79 5b  |lse scale_array[|
00006580  72 61 79 5d 3d 73 63 61  6c 65 3b 0a 7d 0a 65 6c  |ray]=scale;.}.el|
00006590  73 65 20 69 66 28 79 74  72 61 6e 73 5f 64 6f 6e  |se if(ytrans_don|
000065a0  65 20 26 26 20 79 74 72  61 6e 73 5f 64 69 73 74  |e && ytrans_dist|
000065b0  3c 64 69 73 74 5f 78 29  0a 7b 0a 20 20 73 63 61  |<dist_x).{.  sca|
000065c0  6c 65 3d 28 69 6e 74 29  28 28 63 6f 73 5f 74 61  |le=(int)((cos_ta|
000065d0  62 6c 65 5b 72 61 79 5d  3e 3e 31 36 29 20 2a 20  |ble[ray]>>16) * |
000065e0  28 72 65 63 69 70 5f 74  61 62 6c 65 5b 79 74 72  |(recip_table[ytr|
000065f0  61 6e 73 5f 64 69 73 74  3e 3e 31 36 5d 29 3e 3e  |ans_dist>>16])>>|
00006600  31 36 29 3b 0a 20 20 69  66 28 73 63 61 6c 65 3e  |16);.  if(scale>|
00006610  53 43 52 45 45 4e 5f 48  45 49 47 48 54 29 73 63  |SCREEN_HEIGHT)sc|
00006620  61 6c 65 3d 53 43 52 45  45 4e 5f 48 45 49 47 48  |ale=SCREEN_HEIGH|
00006630  54 2d 31 3b 0a 20 20 76  61 72 69 61 62 6c 65 73  |T-1;.  variables|
00006640  5b 32 5d 3d 73 63 61 6c  65 3b 0a 20 20 76 61 72  |[2]=scale;.  var|
00006650  69 61 62 6c 65 73 5b 33  5d 3d 72 61 79 3b 0a 20  |iables[3]=ray;. |
00006660  20 76 61 72 69 61 62 6c  65 73 5b 34 5d 3d 28 72  | variables[4]=(r|
00006670  65 63 69 70 5f 74 61 62  6c 65 5b 73 63 61 6c 65  |ecip_table[scale|
00006680  5d 3c 3c 36 29 3b 0a 20  20 76 61 72 69 61 62 6c  |]<<6);.  variabl|
00006690  65 73 5b 31 5d 3d 28 69  6e 74 29 26 77 61 6c 6c  |es[1]=(int)&wall|
000066a0  73 5b 79 74 72 61 6e 73  5f 74 79 70 65 5d 5b 79  |s[ytrans_type][y|
000066b0  74 72 61 6e 73 5f 63 6f  6c 5d 3b 0a 0a 2f 2a 20  |trans_col];../* |
000066c0  6e 6f 77 20 63 61 6c 6c  20 6f 75 72 20 73 70 65  |now call our spe|
000066d0  63 69 61 6c 20 66 75 6e  63 74 69 6f 6e 20 77 68  |cial function wh|
000066e0  69 63 68 20 74 72 65 61  74 73 20 63 6f 6c 6f 72  |ich treats color|
000066f0  20 30 20 61 73 20 61 20  6d 61 73 6b 20 2a 2f 0a  | 0 as a mask */.|
00006700  0a 6f 75 72 6c 69 62 5f  6e 65 77 5f 6d 61 73 6b  |.ourlib_new_mask|
00006710  28 76 61 72 69 61 62 6c  65 73 29 3b 0a 0a 6d 69  |(variables);..mi|
00006720  72 72 6f 72 5f 61 72 72  61 79 5b 72 61 79 5d 3d  |rror_array[ray]=|
00006730  30 3b 0a 69 66 28 79 74  72 61 6e 73 5f 74 79 70  |0;.if(ytrans_typ|
00006740  65 3d 3d 31 30 29 6d 69  72 72 6f 72 5f 61 72 72  |e==10)mirror_arr|
00006750  61 79 5b 72 61 79 5d 3d  32 35 35 3b 0a 65 6c 73  |ay[ray]=255;.els|
00006760  65 20 73 63 61 6c 65 5f  61 72 72 61 79 5b 72 61  |e scale_array[ra|
00006770  79 5d 3d 73 63 61 6c 65  3b 0a 7d 0a 0a 0a 0a 0a  |y]=scale;.}.....|
00006780  2f 2a 20 74 68 69 73 20  72 61 79 20 68 61 73 20  |/* this ray has |
00006790  62 65 65 6e 20 66 69 6e  69 73 68 65 64 2e 20 49  |been finished. I|
000067a0  6e 63 72 65 61 73 65 20  74 68 65 20 61 6e 67 6c  |ncrease the angl|
000067b0  65 20 6f 66 20 74 68 65  20 6e 65 78 74 20 72 61  |e of the next ra|
000067c0  79 20 61 6e 64 20 73 74  61 72 74 20 61 67 61 69  |y and start agai|
000067d0  6e 21 20 2a 2f 0a 0a 20  20 20 20 69 66 20 28 2b  |n! */..    if (+|
000067e0  2b 76 69 65 77 5f 61 6e  67 6c 65 3e 3d 41 4e 47  |+view_angle>=ANG|
000067f0  4c 45 5f 33 36 30 29 0a  20 20 20 20 20 20 20 7b  |LE_360).       {|
00006800  0a 20 20 20 20 20 20 20  2f 2a 20 74 68 69 73 20  |.       /* this |
00006810  65 6e 73 75 72 65 73 20  74 68 61 74 20 74 68 65  |ensures that the|
00006820  20 72 61 79 20 61 6e 67  6c 65 20 64 6f 65 73 6e  | ray angle doesn|
00006830  27 74 20 67 6f 20 6f 76  65 72 20 33 36 30 20 64  |'t go over 360 d|
00006840  65 67 72 65 65 73 21 20  2a 2f 0a 20 20 20 20 20  |egrees! */.     |
00006850  20 20 76 69 65 77 5f 61  6e 67 6c 65 3d 30 3b 0a  |  view_angle=0;.|
00006860  0a 20 20 20 20 20 20 20  7d 0a 2f 2a 20 72 61 79  |.       }./* ray|
00006870  20 6c 6f 6f 70 20 2a 2f  0a 20 20 20 20 7d 0a 2f  | loop */.    }./|
00006880  2a 20 65 6e 64 20 72 61  79 20 63 61 73 74 65 72  |* end ray caster|
00006890  20 65 6e 67 69 6e 65 20  2a 2f 0a 2f 2a 20 6f 62  | engine */./* ob|
000068a0  6a 65 63 74 73 2a 2f 0a  0a 0a 7d 0a 0a 0a 0a 2f  |jects*/...}..../|
000068b0  2a 20 74 68 69 73 20 66  75 6e 63 74 69 6f 6e 20  |* this function |
000068c0  67 72 61 62 73 20 61 6c  6c 20 74 68 65 20 64 69  |grabs all the di|
000068d0  66 66 65 72 65 6e 74 20  77 61 6c 6c 73 20 66 72  |fferent walls fr|
000068e0  6f 6d 20 61 20 73 69 6e  67 6c 65 20 66 69 6c 65  |om a single file|
000068f0  20 2a 2f 0a 0a 76 6f 69  64 20 61 75 61 5f 67 72  | */..void aua_gr|
00006900  61 70 68 69 63 73 28 76  6f 69 64 29 0a 7b 0a 69  |aphics(void).{.i|
00006910  6e 74 20 78 2c 20 2f 2a  20 74 68 69 73 20 69 73  |nt x, /* this is|
00006920  20 75 73 65 64 20 74 6f  20 73 74 6f 72 65 20 74  | used to store t|
00006930  68 65 20 78 20 63 6f 6f  72 64 69 6e 61 74 65 20  |he x coordinate |
00006940  6f 66 20 61 20 70 6f 69  6e 74 20 6f 6e 20 74 68  |of a point on th|
00006950  65 20 73 63 72 65 65 6e  20 2a 2f 0a 20 20 20 20  |e screen */.    |
00006960  79 2c 20 2f 2a 20 74 68  69 73 20 69 73 20 75 73  |y, /* this is us|
00006970  65 64 20 74 6f 20 73 74  6f 72 65 20 74 68 65 20  |ed to store the |
00006980  79 20 63 6f 6f 72 64 69  6e 61 74 65 20 6f 66 20  |y coordinate of |
00006990  61 20 70 6f 69 6e 74 20  6f 6e 20 74 68 65 20 73  |a point on the s|
000069a0  63 72 65 65 6e 20 2a 2f  0a 20 20 20 20 77 61 6c  |creen */.    wal|
000069b0  6c 5f 6e 75 6d 62 65 72  3b 20 2f 2a 20 74 68 69  |l_number; /* thi|
000069c0  73 20 77 69 6c 6c 20 62  65 20 75 73 65 64 20 74  |s will be used t|
000069d0  6f 20 69 6e 64 65 78 20  74 68 65 20 77 61 6c 6c  |o index the wall|
000069e0  73 5b 78 5d 5b 5d 20 63  68 61 72 20 61 72 72 61  |s[x][] char arra|
000069f0  79 20 2a 2f 0a 0a 2f 2a  20 66 69 72 73 74 20 6f  |y */../* first o|
00006a00  66 20 61 6c 6c 20 77 65  20 67 65 74 20 74 68 65  |f all we get the|
00006a10  20 67 72 61 70 68 69 63  73 20 66 69 6c 65 20 3c  | graphics file <|
00006a20  41 55 41 52 61 79 24 44  69 72 3e 2e 67 72 61 70  |AUARay$Dir>.grap|
00006a30  68 69 63 73 20 6f 6e 74  6f 20 74 68 65 20 73 63  |hics onto the sc|
00006a40  72 65 65 6e 20 2a 2f 0a  0a 73 79 73 74 65 6d 28  |reen */..system(|
00006a50  22 2a 53 63 72 65 65 6e  4c 6f 61 64 20 3c 41 55  |"*ScreenLoad <AU|
00006a60  41 52 61 79 24 44 69 72  3e 2e 67 72 61 70 68 69  |ARay$Dir>.graphi|
00006a70  63 73 22 29 3b 0a 0a 2f  2a 20 6e 65 78 74 20 77  |cs");../* next w|
00006a80  65 20 73 74 61 72 74 20  67 72 61 62 62 69 6e 67  |e start grabbing|
00006a90  20 65 61 63 68 20 74 69  6c 65 2c 20 36 34 20 78  | each tile, 64 x|
00006aa0  20 36 34 20 70 69 78 65  6c 73 2c 20 69 6e 74 6f  | 64 pixels, into|
00006ab0  20 74 68 65 20 77 61 6c  6c 73 5b 5d 5b 5d 20 61  | the walls[][] a|
00006ac0  72 72 61 79 20 2a 2f 0a  0a 2f 2a 20 77 65 20 75  |rray */../* we u|
00006ad0  73 65 20 74 68 69 73 20  6c 61 72 67 65 20 66 6f  |se this large fo|
00006ae0  72 20 6c 6f 6f 70 20 61  74 20 74 68 65 20 6f 75  |r loop at the ou|
00006af0  72 6c 69 62 5f 62 69 74  6d 61 70 5f 67 72 61 62  |rlib_bitmap_grab|
00006b00  20 66 75 6e 63 74 69 6f  6e 20 74 6f 20 69 6e 76  | function to inv|
00006b10  69 64 75 61 6c 6c 79 20  67 72 61 62 20 65 61 63  |idually grab eac|
00006b20  68 20 74 69 6c 65 20 69  6e 74 6f 20 69 74 73 20  |h tile into its |
00006b30  6f 77 6e 20 77 61 6c 6c  73 5b 78 5d 5b 5d 20 61  |own walls[x][] a|
00006b40  72 72 61 79 20 73 6c 6f  74 2c 20 6e 6f 74 65 20  |rray slot, note |
00006b50  74 68 61 74 20 77 65 20  43 41 4e 27 54 20 48 41  |that we CAN'T HA|
00006b60  56 45 20 57 41 4c 4c 20  30 20 61 73 20 74 68 69  |VE WALL 0 as thi|
00006b70  73 20 72 65 70 72 65 73  65 6e 74 73 20 61 20 67  |s represents a g|
00006b80  61 70 20 69 6e 20 74 68  65 20 77 6f 72 6c 64 21  |ap in the world!|
00006b90  20 2a 2f 0a 0a 6f 75 72  6c 69 62 5f 6b 69 6c 6c  | */..ourlib_kill|
00006ba0  63 75 72 73 6f 72 28 29  3b 20 2f 2a 20 67 65 74  |cursor(); /* get|
00006bb0  20 72 69 64 20 6f 66 20  63 75 72 73 6f 72 20 66  | rid of cursor f|
00006bc0  69 72 73 74 20 2a 2f 0a  0a 66 6f 72 28 77 61 6c  |irst */..for(wal|
00006bd0  6c 5f 6e 75 6d 62 65 72  3d 31 2c 79 3d 30 3b 79  |l_number=1,y=0;y|
00006be0  3c 32 35 36 3b 79 2b 3d  57 41 4c 4c 5f 48 45 49  |<256;y+=WALL_HEI|
00006bf0  47 48 54 29 66 6f 72 28  78 3d 30 3b 78 3c 33 32  |GHT)for(x=0;x<32|
00006c00  30 3b 78 2b 3d 57 41 4c  4c 5f 57 49 44 54 48 2c  |0;x+=WALL_WIDTH,|
00006c10  77 61 6c 6c 5f 6e 75 6d  62 65 72 2b 2b 29 0a 7b  |wall_number++).{|
00006c20  0a 2f 2a 20 74 68 69 73  20 63 61 6c 6c 73 20 74  |./* this calls t|
00006c30  68 65 20 66 75 6e 63 74  69 6f 6e 20 6f 75 72 6c  |he function ourl|
00006c40  69 62 5f 62 69 74 6d 61  70 5f 67 72 61 62 20 28  |ib_bitmap_grab (|
00006c50  49 20 73 61 69 64 20 69  74 20 77 6f 75 6c 64 20  |I said it would |
00006c60  62 65 20 68 61 6e 64 79  21 29 20 77 68 69 63 68  |be handy!) which|
00006c70  20 67 72 61 62 73 20 74  68 65 20 61 72 65 61 20  | grabs the area |
00006c80  6f 66 20 73 63 72 65 65  6e 20 6d 65 6d 6f 72 79  |of screen memory|
00006c90  20 6d 61 72 6b 65 64 20  62 79 20 74 68 65 20 66  | marked by the f|
00006ca0  69 72 73 74 20 66 6f 75  72 20 70 61 72 61 6d 65  |irst four parame|
00006cb0  74 65 72 73 2c 20 73 74  6f 72 65 73 20 69 74 20  |ters, stores it |
00006cc0  69 6e 20 74 68 65 20 62  79 74 65 20 61 72 72 61  |in the byte arra|
00006cd0  79 20 70 6f 69 6e 74 65  72 20 69 6e 20 70 61 72  |y pointer in par|
00006ce0  61 6d 65 74 65 72 20 66  69 76 65 2c 20 72 65 61  |ameter five, rea|
00006cf0  64 69 6e 67 20 69 74 20  61 6c 6c 20 66 72 6f 6d  |ding it all from|
00006d00  20 74 68 65 20 73 63 72  65 65 6e 20 70 6f 69 6e  | the screen poin|
00006d10  74 65 64 20 74 6f 20 62  79 20 73 63 72 65 65 6e  |ted to by screen|
00006d20  5f 61 64 64 72 65 73 73  20 2a 2f 0a 0a 6f 75 72  |_address */..our|
00006d30  6c 69 62 5f 62 69 74 6d  61 70 5f 67 72 61 62 28  |lib_bitmap_grab(|
00006d40  78 2c 79 2c 78 2b 57 41  4c 4c 5f 57 49 44 54 48  |x,y,x+WALL_WIDTH|
00006d50  2d 31 2c 79 2b 57 41 4c  4c 5f 48 45 49 47 48 54  |-1,y+WALL_HEIGHT|
00006d60  2d 31 2c 26 77 61 6c 6c  73 5b 77 61 6c 6c 5f 6e  |-1,&walls[wall_n|
00006d70  75 6d 62 65 72 5d 5b 30  5d 2c 73 63 72 65 65 6e  |umber][0],screen|
00006d80  5f 61 64 64 72 65 73 73  29 3b 0a 0a 2f 2a 20 74  |_address);../* t|
00006d90  68 69 73 20 6d 61 6b 65  73 20 73 75 72 65 20 77  |his makes sure w|
00006da0  65 20 64 6f 6e 27 74 20  67 6f 20 6f 76 65 72 20  |e don't go over |
00006db0  6f 75 72 20 6e 75 6d 62  65 72 20 6f 66 20 77 61  |our number of wa|
00006dc0  6c 6c 73 20 6c 69 6d 69  74 20 2a 2f 0a 0a 69 66  |lls limit */..if|
00006dd0  28 77 61 6c 6c 5f 6e 75  6d 62 65 72 3e 3d 57 41  |(wall_number>=WA|
00006de0  4c 4c 5f 4e 55 4d 42 45  52 29 62 72 65 61 6b 3b  |LL_NUMBER)break;|
00006df0  0a 7d 0a 0a 2f 2a 20 6e  65 77 20 73 74 75 66 66  |.}../* new stuff|
00006e00  20 6c 6f 61 64 20 69 6e  20 6f 62 6a 65 63 74 73  | load in objects|
00006e10  20 73 65 70 61 72 61 74  65 6c 79 20 2a 2f 0a 2f  | separately */./|
00006e20  2a 20 73 65 65 20 61 62  6f 76 65 20 66 6f 72 20  |* see above for |
00006e30  63 6f 6d 6d 65 6e 74 73  20 28 69 74 73 20 69 64  |comments (its id|
00006e40  65 6e 74 69 63 61 6c 29  20 2a 2f 0a 73 79 73 74  |entical) */.syst|
00006e50  65 6d 28 22 2a 53 63 72  65 65 6e 4c 6f 61 64 20  |em("*ScreenLoad |
00006e60  3c 41 55 41 52 61 79 24  44 69 72 3e 2e 4f 62 6a  |<AUARay$Dir>.Obj|
00006e70  67 72 61 70 68 69 63 22  29 3b 0a 6f 75 72 6c 69  |graphic");.ourli|
00006e80  62 5f 6b 69 6c 6c 63 75  72 73 6f 72 28 29 3b 0a  |b_killcursor();.|
00006e90  0a 66 6f 72 28 77 61 6c  6c 5f 6e 75 6d 62 65 72  |.for(wall_number|
00006ea0  3d 31 2c 79 3d 30 3b 79  3c 32 35 36 3b 79 2b 3d  |=1,y=0;y<256;y+=|
00006eb0  57 41 4c 4c 5f 48 45 49  47 48 54 29 66 6f 72 28  |WALL_HEIGHT)for(|
00006ec0  78 3d 30 3b 78 3c 33 32  30 3b 78 2b 3d 57 41 4c  |x=0;x<320;x+=WAL|
00006ed0  4c 5f 57 49 44 54 48 2c  77 61 6c 6c 5f 6e 75 6d  |L_WIDTH,wall_num|
00006ee0  62 65 72 2b 2b 29 0a 7b  0a 6f 75 72 6c 69 62 5f  |ber++).{.ourlib_|
00006ef0  62 69 74 6d 61 70 5f 67  72 61 62 28 78 2c 79 2c  |bitmap_grab(x,y,|
00006f00  78 2b 36 33 2c 79 2b 36  33 2c 26 6f 62 6a 67 72  |x+63,y+63,&objgr|
00006f10  61 70 68 69 63 73 5b 77  61 6c 6c 5f 6e 75 6d 62  |aphics[wall_numb|
00006f20  65 72 5d 5b 30 5d 2c 73  63 72 65 65 6e 5f 61 64  |er][0],screen_ad|
00006f30  64 72 65 73 73 29 3b 0a  69 66 28 77 61 6c 6c 5f  |dress);.if(wall_|
00006f40  6e 75 6d 62 65 72 3e 57  41 4c 4c 5f 4e 55 4d 42  |number>WALL_NUMB|
00006f50  45 52 29 62 72 65 61 6b  3b 0a 7d 0a 0a 2f 2a 20  |ER)break;.}../* |
00006f60  4e 45 57 20 62 6f 74 74  6f 6d 20 62 61 72 20 67  |NEW bottom bar g|
00006f70  72 61 70 68 69 63 73 20  63 6f 64 65 2c 20 68 65  |raphics code, he|
00006f80  72 65 20 77 65 20 67 72  61 62 20 74 68 65 20 73  |re we grab the s|
00006f90  70 72 69 74 65 20 2a 2f  0a 73 79 73 74 65 6d 28  |prite */.system(|
00006fa0  22 2a 73 63 72 65 65 6e  6c 6f 61 64 20 3c 41 55  |"*screenload <AU|
00006fb0  41 52 61 79 24 44 69 72  3e 2e 42 6f 74 74 6f 6d  |ARay$Dir>.Bottom|
00006fc0  62 61 72 22 29 3b 0a 6f  75 72 6c 69 62 5f 62 69  |bar");.ourlib_bi|
00006fd0  74 6d 61 70 5f 67 72 61  62 28 30 2c 32 30 36 2c  |tmap_grab(0,206,|
00006fe0  33 31 39 2c 32 35 35 2c  62 61 72 5f 67 72 61 70  |319,255,bar_grap|
00006ff0  68 69 63 2c 73 63 72 65  65 6e 5f 61 64 64 72 65  |hic,screen_addre|
00007000  73 73 29 3b 0a 0a 0a 7d  0a 0a 2f 2a 20 74 68 69  |ss);...}../* thi|
00007010  73 20 66 75 6e 63 74 69  6f 6e 20 6c 6f 61 64 73  |s function loads|
00007020  20 69 6e 20 74 68 65 20  64 61 74 61 20 66 72 6f  | in the data fro|
00007030  6d 20 6f 75 72 20 77 6f  72 6c 64 20 74 65 78 74  |m our world text|
00007040  20 66 69 6c 65 20 61 6e  64 20 73 74 6f 72 65 73  | file and stores|
00007050  20 69 74 20 69 6e 20 74  68 65 20 77 6f 72 6c 64  | it in the world|
00007060  5b 5d 5b 5d 20 61 72 72  61 79 20 2a 2f 0a 0a 76  |[][] array */..v|
00007070  6f 69 64 20 61 75 61 5f  77 6f 72 6c 64 28 76 6f  |oid aua_world(vo|
00007080  69 64 29 0a 7b 0a 0a 46  49 4c 45 20 2a 77 6f 72  |id).{..FILE *wor|
00007090  6c 64 5f 66 69 6c 65 3b  20 2f 2a 20 77 65 20 6e  |ld_file; /* we n|
000070a0  65 65 64 20 61 20 66 69  6c 65 20 70 6f 69 6e 74  |eed a file point|
000070b0  65 72 20 61 73 20 77 65  20 77 69 6c 6c 20 62 65  |er as we will be|
000070c0  20 6c 6f 61 64 69 6e 67  20 69 6e 20 74 65 78 74  | loading in text|
000070d0  20 2a 2f 0a 0a 69 6e 74  20 72 6f 77 2c 20 2f 2a  | */..int row, /*|
000070e0  20 74 68 69 73 20 77 69  6c 6c 20 62 65 20 75 73  | this will be us|
000070f0  65 64 20 74 6f 20 69 6e  64 65 78 20 74 68 65 20  |ed to index the |
00007100  77 6f 72 6c 64 5b 5d 5b  5d 20 61 72 72 61 79 20  |world[][] array |
00007110  2a 2f 0a 20 20 20 20 63  6f 6c 75 6d 6e 2c 63 6f  |*/.    column,co|
00007120  75 6e 74 65 72 3d 30 3b  20 2f 2a 20 74 68 69 73  |unter=0; /* this|
00007130  20 77 69 6c 6c 20 62 65  20 75 73 65 64 20 74 6f  | will be used to|
00007140  20 69 6e 64 65 78 20 74  68 65 20 77 6f 72 6c 64  | index the world|
00007150  5b 5d 5b 5d 20 61 72 72  61 79 20 2a 2f 0a 0a 63  |[][] array */..c|
00007160  68 61 72 20 63 68 3b 20  2f 2a 20 74 68 69 73 20  |har ch; /* this |
00007170  69 73 20 75 73 65 64 20  74 6f 20 73 74 6f 72 65  |is used to store|
00007180  20 65 61 63 68 20 6e 75  6d 62 65 72 20 61 73 20  | each number as |
00007190  69 74 20 69 73 20 6c 6f  61 64 65 64 20 69 6e 20  |it is loaded in |
000071a0  2a 2f 0a 0a 2f 2a 20 6f  70 65 6e 20 74 68 65 20  |*/../* open the |
000071b0  77 6f 72 6c 64 20 66 69  6c 65 2c 20 69 66 20 69  |world file, if i|
000071c0  74 20 69 73 20 6e 6f 74  20 74 68 65 72 65 20 74  |t is not there t|
000071d0  68 65 6e 20 65 78 69 74  20 74 68 65 20 70 72 6f  |hen exit the pro|
000071e0  67 72 61 6d 20 2a 2f 0a  0a 69 66 28 21 28 77 6f  |gram */..if(!(wo|
000071f0  72 6c 64 5f 66 69 6c 65  3d 66 6f 70 65 6e 28 22  |rld_file=fopen("|
00007200  3c 41 55 41 52 61 79 24  44 69 72 3e 2e 77 6f 72  |<AUARay$Dir>.wor|
00007210  6c 64 22 2c 22 72 22 29  29 29 65 78 69 74 28 31  |ld","r")))exit(1|
00007220  29 3b 0a 0a 2f 2a 20 74  68 69 73 20 70 72 6f 67  |);../* this prog|
00007230  72 61 6d 20 6c 6f 61 64  73 20 69 6e 20 74 68 65  |ram loads in the|
00007240  20 64 61 74 61 20 66 72  6f 6d 20 74 68 65 20 77  | data from the w|
00007250  6f 72 6c 64 20 66 69 6c  65 2c 20 72 6f 77 20 62  |orld file, row b|
00007260  79 20 72 6f 77 2c 20 63  6f 6c 75 6d 6e 20 62 79  |y row, column by|
00007270  20 63 6f 6c 75 6d 6e 20  75 73 69 6e 67 20 74 68  | column using th|
00007280  65 20 67 65 74 63 28 29  20 41 4e 53 49 20 66 75  |e getc() ANSI fu|
00007290  6e 63 74 69 6f 6e 20 2a  2f 0a 0a 66 6f 72 28 72  |nction */..for(r|
000072a0  6f 77 3d 30 3b 72 6f 77  3c 57 4f 52 4c 44 5f 48  |ow=0;row<WORLD_H|
000072b0  45 49 47 48 54 3b 72 6f  77 2b 2b 29 0a 7b 0a 66  |EIGHT;row++).{.f|
000072c0  6f 72 28 63 6f 6c 75 6d  6e 3d 30 3b 63 6f 6c 75  |or(column=0;colu|
000072d0  6d 6e 3c 57 4f 52 4c 44  5f 57 49 44 54 48 3b 63  |mn<WORLD_WIDTH;c|
000072e0  6f 6c 75 6d 6e 2b 2b 29  0a 7b 0a 77 68 69 6c 65  |olumn++).{.while|
000072f0  28 28 63 68 3d 67 65 74  63 28 77 6f 72 6c 64 5f  |((ch=getc(world_|
00007300  66 69 6c 65 29 29 3d 3d  31 30 29 7b 7d 20 2f 2a  |file))==10){} /*|
00007310  20 74 68 69 73 20 66 69  6c 74 65 72 73 20 6f 75  | this filters ou|
00007320  74 20 61 6e 79 20 6d 65  73 73 2c 20 74 68 6f 75  |t any mess, thou|
00007330  67 68 20 6e 6f 74 20 6f  66 74 65 6e 20 75 73 65  |gh not often use|
00007340  64 21 20 2a 2f 0a 0a 69  66 28 63 68 3d 3d 27 20  |d! */..if(ch==' |
00007350  27 29 63 68 3d 30 3b 20  2f 2a 74 68 69 73 20 65  |')ch=0; /*this e|
00007360  6e 73 75 72 65 73 20 74  68 65 20 63 6f 72 72 65  |nsures the corre|
00007370  63 74 20 76 61 6c 75 65  20 69 73 20 73 74 6f 72  |ct value is stor|
00007380  65 64 2c 20 69 66 20 74  68 65 72 65 20 69 73 20  |ed, if there is |
00007390  61 20 67 61 70 20 69 6e  20 74 68 65 20 66 69 6c  |a gap in the fil|
000073a0  65 2c 20 74 68 69 73 20  6d 65 61 6e 73 20 61 20  |e, this means a |
000073b0  73 70 61 63 65 20 69 6e  20 74 68 65 20 77 6f 72  |space in the wor|
000073c0  6c 64 2c 20 61 20 7a 65  72 6f 20 2a 2f 0a 65 6c  |ld, a zero */.el|
000073d0  73 65 20 63 68 3d 63 68  2d 27 30 27 3b 0a 0a 2f  |se ch=ch-'0';../|
000073e0  2a 20 74 68 69 73 20 6e  65 77 20 6c 69 6e 65 20  |* this new line |
000073f0  77 69 6c 6c 20 28 73 68  6f 75 6c 64 21 29 20 63  |will (should!) c|
00007400  6f 6e 76 65 72 74 20 6c  65 74 74 65 72 73 20 69  |onvert letters i|
00007410  6e 74 6f 20 74 68 65 69  72 20 61 70 70 72 6f 70  |nto their approp|
00007420  72 69 61 74 65 20 6e 75  6d 62 65 72 20 2a 2f 0a  |riate number */.|
00007430  0a 69 66 28 63 68 3e 31  35 29 63 68 2d 3d 37 3b  |.if(ch>15)ch-=7;|
00007440  0a 0a 77 6f 72 6c 64 5b  28 57 4f 52 4c 44 5f 48  |..world[(WORLD_H|
00007450  45 49 47 48 54 2d 31 29  2d 72 6f 77 5d 5b 63 6f  |EIGHT-1)-row][co|
00007460  6c 75 6d 6e 5d 3d 63 68  3b 20 2f 2a 20 74 68 69  |lumn]=ch; /* thi|
00007470  73 20 66 69 6e 61 6c 6c  79 20 73 74 6f 72 65 73  |s finally stores|
00007480  20 74 68 65 20 76 61 6c  75 65 20 69 6e 20 74 68  | the value in th|
00007490  65 20 63 6f 72 72 65 63  74 20 70 6f 73 69 74 69  |e correct positi|
000074a0  6f 6e 20 2a 2f 0a 0a 2f  2a 70 72 69 6e 74 66 28  |on */../*printf(|
000074b0  22 25 64 22 2c 63 68 29  3b 20 75 6e 63 6f 6d 6d  |"%d",ch); uncomm|
000074c0  65 6e 74 20 74 68 69 73  20 6c 69 6e 65 20 74 6f  |ent this line to|
000074d0  20 73 65 65 20 74 68 65  20 77 6f 72 6c 64 20 64  | see the world d|
000074e0  61 74 61 20 6c 6f 61 64  65 64 20 69 6e 20 2a 2f  |ata loaded in */|
000074f0  0a 7d 0a 2f 2a 70 72 69  6e 74 66 28 22 5c 6e 22  |.}./*printf("\n"|
00007500  29 3b 20 75 6e 63 6f 6d  6d 65 6e 74 20 74 68 69  |); uncomment thi|
00007510  73 20 6c 69 6e 65 20 74  6f 20 73 65 65 20 74 68  |s line to see th|
00007520  65 20 77 6f 72 6c 64 20  64 61 74 61 20 6c 6f 61  |e world data loa|
00007530  64 65 64 20 69 6e 20 2a  2f 0a 7d 0a 0a 2f 2a 20  |ded in */.}../* |
00007540  77 68 65 6e 20 61 6c 6c  20 69 73 20 64 6f 6e 65  |when all is done|
00007550  2c 20 63 6c 6f 73 65 20  74 68 65 20 66 69 6c 65  |, close the file|
00007560  20 2a 2f 0a 66 63 6c 6f  73 65 28 77 6f 72 6c 64  | */.fclose(world|
00007570  5f 66 69 6c 65 29 3b 0a  0a 2f 2a 20 6e 65 77 20  |_file);../* new |
00007580  70 61 72 74 20 74 6f 20  6c 6f 61 64 20 69 6e 20  |part to load in |
00007590  6f 62 6a 65 63 74 20 64  61 74 61 2c 20 73 65 65  |object data, see|
000075a0  20 61 62 6f 76 65 20 66  6f 72 20 63 6f 6d 6d 65  | above for comme|
000075b0  6e 74 73 20 2a 2f 0a 0a  69 66 28 21 28 77 6f 72  |nts */..if(!(wor|
000075c0  6c 64 5f 66 69 6c 65 3d  66 6f 70 65 6e 28 22 3c  |ld_file=fopen("<|
000075d0  41 55 41 52 61 79 24 44  69 72 3e 2e 6f 62 6a 77  |AUARay$Dir>.objw|
000075e0  6f 72 6c 64 22 2c 22 72  22 29 29 29 20 65 78 69  |orld","r"))) exi|
000075f0  74 28 31 29 3b 0a 66 6f  72 28 72 6f 77 3d 30 3b  |t(1);.for(row=0;|
00007600  72 6f 77 3c 57 4f 52 4c  44 5f 48 45 49 47 48 54  |row<WORLD_HEIGHT|
00007610  3b 72 6f 77 2b 2b 29 0a  7b 0a 20 20 66 6f 72 28  |;row++).{.  for(|
00007620  63 6f 6c 75 6d 6e 3d 30  3b 63 6f 6c 75 6d 6e 3c  |column=0;column<|
00007630  57 4f 52 4c 44 5f 57 49  44 54 48 3b 63 6f 6c 75  |WORLD_WIDTH;colu|
00007640  6d 6e 2b 2b 29 0a 20 20  7b 0a 20 20 77 68 69 6c  |mn++).  {.  whil|
00007650  65 28 28 63 68 3d 67 65  74 63 28 77 6f 72 6c 64  |e((ch=getc(world|
00007660  5f 66 69 6c 65 29 29 3d  3d 31 30 29 7b 7d 0a 20  |_file))==10){}. |
00007670  20 69 66 28 63 68 3d 3d  27 20 27 29 63 68 3d 30  | if(ch==' ')ch=0|
00007680  3b 0a 20 20 65 6c 73 65  20 63 68 3d 63 68 2d 27  |;.  else ch=ch-'|
00007690  30 27 3b 0a 20 20 69 66  28 63 68 3e 31 36 29 63  |0';.  if(ch>16)c|
000076a0  68 2d 3d 37 3b 0a 0a 6f  62 6a 65 63 74 73 5b 28  |h-=7;..objects[(|
000076b0  57 4f 52 4c 44 5f 48 45  49 47 48 54 2d 31 29 2d  |WORLD_HEIGHT-1)-|
000076c0  72 6f 77 5d 5b 63 6f 6c  75 6d 6e 5d 3d 63 68 3b  |row][column]=ch;|
000076d0  0a 0a 20 20 7d 0a 7d 0a  0a 66 63 6c 6f 73 65 28  |..  }.}..fclose(|
000076e0  77 6f 72 6c 64 5f 66 69  6c 65 29 3b 0a 0a 7d 0a  |world_file);..}.|
000076f0  0a 0a 2f 2a 20 4e 45 57  45 52 20 4d 41 49 4e 20  |../* NEWER MAIN |
00007700  66 75 6e 63 74 69 6f 6e  20 2e 0a 0a 41 6c 6c 20  |function ...All |
00007710  63 68 61 6e 67 65 73 20  61 72 65 20 63 6f 6d 6d  |changes are comm|
00007720  65 6e 74 65 64 20 2a 2f  0a 0a 76 6f 69 64 20 6d  |ented */..void m|
00007730  61 69 6e 28 69 6e 74 20  61 72 67 63 2c 63 68 61  |ain(int argc,cha|
00007740  72 20 2a 61 72 67 76 5b  5d 29 0a 7b 0a 20 20 69  |r *argv[]).{.  i|
00007750  6e 74 20 76 69 65 77 5f  78 2c 20 2f 2a 20 74 68  |nt view_x, /* th|
00007760  69 73 20 68 6f 6c 64 73  20 74 68 65 20 76 69 65  |is holds the vie|
00007770  77 69 6e 67 20 78 20 63  6f 6f 72 64 69 6e 61 74  |wing x coordinat|
00007780  65 20 2a 2f 0a 20 20 20  20 20 20 76 69 65 77 5f  |e */.      view_|
00007790  79 2c 20 2f 2a 20 74 68  69 73 20 68 6f 6c 64 73  |y, /* this holds|
000077a0  20 74 68 65 20 76 69 65  77 69 6e 67 20 79 20 63  | the viewing y c|
000077b0  6f 6f 72 64 69 6e 61 74  65 20 2a 2f 0a 20 20 20  |oordinate */.   |
000077c0  20 20 20 76 69 65 77 5f  61 6e 67 6c 65 3b 20 2f  |   view_angle; /|
000077d0  2a 20 74 68 69 73 20 68  6f 6c 64 73 20 74 68 65  |* this holds the|
000077e0  20 76 69 65 77 69 6e 67  20 61 6e 67 6c 65 20 69  | viewing angle i|
000077f0  6e 20 66 69 78 65 64 20  75 6e 69 74 73 20 30 2d  |n fixed units 0-|
00007800  31 39 32 30 20 2a 2f 0a  0a 20 20 69 6e 74 0a 20  |1920 */..  int. |
00007810  20 20 20 20 20 64 6f 6e  65 3d 30 2c 20 20 20 20  |     done=0,    |
00007820  2f 2a 20 66 6c 61 67 20  74 6f 20 69 6e 64 69 63  |/* flag to indic|
00007830  61 74 65 20 69 66 20 74  68 65 20 75 73 65 72 20  |ate if the user |
00007840  77 61 6e 74 73 20 74 6f  20 71 75 69 74 20 2a 2f  |wants to quit */|
00007850  0a 20 20 20 20 20 20 64  78 2c 20 20 20 20 20 20  |.      dx,      |
00007860  20 20 2f 2a 20 6d 6f 76  65 6d 65 6e 74 20 76 61  |  /* movement va|
00007870  72 69 61 62 6c 65 73 20  66 6f 72 20 74 68 65 20  |riables for the |
00007880  76 69 65 77 65 72 20 2a  2f 0a 20 20 20 20 20 20  |viewer */.      |
00007890  64 79 2c 0a 20 20 20 20  20 20 79 5f 63 65 6c 6c  |dy,.      y_cell|
000078a0  2c 20 20 20 20 2f 2a 20  74 68 65 73 65 20 4e 45  |,    /* these NE|
000078b0  57 20 76 61 72 69 61 62  6c 65 73 20 61 72 65 20  |W variables are |
000078c0  75 73 65 64 20 74 6f 20  73 74 6f 72 65 20 74 68  |used to store th|
000078d0  65 20 70 6c 61 79 65 72  2f 76 69 65 77 65 72 2a  |e player/viewer*|
000078e0  2f 0a 20 20 20 20 20 20  78 5f 63 65 6c 6c 2c 20  |/.      x_cell, |
000078f0  20 20 20 2f 2a 20 77 6f  72 6c 64 20 70 6f 73 69  |   /* world posi|
00007900  74 69 6f 6e 73 2c 20 66  6f 72 20 63 61 6c 63 75  |tions, for calcu|
00007910  6c 61 74 69 6e 67 20 76  69 65 77 65 72 20 68 69  |lating viewer hi|
00007920  74 74 69 6e 67 20 77 61  6c 6c 73 20 2a 2f 0a 20  |tting walls */. |
00007930  20 20 20 20 20 79 5f 73  75 62 5f 63 65 6c 6c 2c  |     y_sub_cell,|
00007940  0a 20 20 20 20 20 20 78  5f 73 75 62 5f 63 65 6c  |.      x_sub_cel|
00007950  6c 2c 0a 20 20 20 20 20  20 74 69 6d 65 5f 73 74  |l,.      time_st|
00007960  61 72 74 2c 0a 20 20 20  20 20 20 74 69 6d 65 5f  |art,.      time_|
00007970  66 69 6e 69 73 68 2c 20  2f 2a 20 54 68 65 73 65  |finish, /* These|
00007980  20 6c 61 73 74 20 66 65  77 20 76 61 72 69 61 62  | last few variab|
00007990  6c 65 73 20 61 72 65 20  75 73 65 64 20 74 6f 20  |les are used to |
000079a0  77 6f 72 6b 20 6f 75 74  20 2a 2f 0a 20 20 20 20  |work out */.    |
000079b0  20 20 66 72 61 6d 65 73  3d 30 2c 20 20 20 20 2f  |  frames=0,    /|
000079c0  2a 20 74 68 65 20 66 72  61 6d 65 73 20 70 65 72  |* the frames per|
000079d0  20 73 65 63 2e 20 6f 66  20 74 68 65 20 73 79 73  | sec. of the sys|
000079e0  74 65 6d 2c 20 73 6c 6f  77 20 66 6f 72 20 6e 6f  |tem, slow for no|
000079f0  77 21 20 2a 2f 0a 20 20  20 20 20 20 64 6f 6f 72  |w! */.      door|
00007a00  5f 78 2c 0a 20 20 20 20  20 20 64 6f 6f 72 5f 79  |_x,.      door_y|
00007a10  2c 20 20 20 20 20 20 2f  2a 20 54 68 65 73 65 20  |,      /* These |
00007a20  6e 65 77 20 76 61 72 69  61 62 6c 65 73 20 77 69  |new variables wi|
00007a30  6c 6c 20 62 65 20 75 73  65 64 20 66 6f 72 20 64  |ll be used for d|
00007a40  6f 6f 72 20 74 68 69 6e  67 73 20 2a 2f 0a 20 20  |oor things */.  |
00007a50  20 20 20 20 73 63 72 65  65 6e 5f 6c 69 6d 69 74  |    screen_limit|
00007a60  3b 0a 0a 2f 2a 20 4e 65  77 20 4f 62 6a 65 63 74  |;../* New Object|
00007a70  20 43 6f 64 65 20 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  | Code **********|
00007a80  2a 2a 2a 2a 2a 2a 2a 20  41 64 64 65 64 20 41 72  |******* Added Ar|
00007a90  74 69 63 6c 65 20 35 20  2d 20 67 6f 6f 64 20 73  |ticle 5 - good s|
00007aa0  74 75 66 66 20 21 20 2a  2f 0a 69 6e 74 20 6f 62  |tuff ! */.int ob|
00007ab0  6a 65 63 74 5f 78 2c 6f  62 6a 65 63 74 5f 79 2c  |ject_x,object_y,|
00007ac0  74 72 61 6e 73 5f 78 2c  74 72 61 6e 73 5f 7a 2c  |trans_x,trans_z,|
00007ad0  73 63 72 65 65 6e 5f 78  2c 73 63 72 65 65 6e 5f  |screen_x,screen_|
00007ae0  79 31 2c 73 63 72 65 65  6e 5f 79 32 2c 74 65 6d  |y1,screen_y2,tem|
00007af0  70 5f 31 2c 63 6f 75 6e  74 65 72 2c 73 63 61 6c  |p_1,counter,scal|
00007b00  65 2c 76 61 72 69 61 62  6c 65 73 5b 37 5d 2c 69  |e,variables[7],i|
00007b10  6e 64 65 78 2c 69 6e 63  72 65 6d 65 6e 74 2c 67  |ndex,increment,g|
00007b20  72 69 64 5f 78 2c 67 72  69 64 5f 79 2c 6f 62 6a  |rid_x,grid_y,obj|
00007b30  65 63 74 5f 74 79 70 65  2c 73 74 61 72 74 5f 78  |ect_type,start_x|
00007b40  2c 73 74 61 72 74 5f 79  2c 73 74 6f 70 5f 78 2c  |,start_y,stop_x,|
00007b50  73 74 6f 70 5f 79 2c 6d  6f 76 65 5f 78 2c 6d 6f  |stop_y,move_x,mo|
00007b60  76 65 5f 79 2c 74 76 69  65 77 5f 78 2c 74 76 69  |ve_y,tview_x,tvi|
00007b70  65 77 5f 79 2c 74 76 69  65 77 5f 61 6e 67 6c 65  |ew_y,tview_angle|
00007b80  3b 0a 2f 2a 20 4e 65 77  20 4f 62 6a 65 63 74 20  |;./* New Object |
00007b90  43 6f 64 65 20 56 61 72  69 61 62 6c 65 73 20 4f  |Code Variables O|
00007ba0  76 65 72 20 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |ver ************|
00007bb0  2a 2a 2a 20 53 65 65 20  4c 61 74 65 72 20 69 6e  |*** See Later in|
00007bc0  20 4d 61 69 6e 28 29 20  2a 2f 0a 2f 2a 20 4e 45  | Main() */./* NE|
00007bd0  57 20 6f 62 6a 65 63 74  20 4d 4f 56 49 4e 47 20  |W object MOVING |
00007be0  63 6f 64 65 20 61 6e 64  20 61 72 72 61 79 73 20  |code and arrays |
00007bf0  61 72 65 20 6e 6f 77 20  69 6e 20 74 68 69 73 20  |are now in this |
00007c00  66 75 6e 63 74 69 6f 6e  20 2a 2f 0a 0a 20 2f 2a  |function */.. /*|
00007c10  20 70 61 74 74 65 72 6e  20 6f 66 20 6d 6f 76 65  | pattern of move|
00007c20  6d 65 6e 74 73 20 2a 2f  0a 66 6c 6f 61 74 20 6f  |ments */.float o|
00007c30  62 6a 65 63 74 5f 6d 6f  76 65 5f 69 6e 63 72 65  |bject_move_incre|
00007c40  6d 65 6e 74 3d 30 2e 30  30 30 30 3b 20 20 20 20  |ment=0.0000;    |
00007c50  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 61 6d  |           /* am|
00007c60  6f 75 6e 74 20 74 6f 20  61 64 64 20 74 6f 20 69  |ount to add to i|
00007c70  6e 64 65 78 20 65 61 63  68 20 66 72 61 6d 65 20  |ndex each frame |
00007c80  2a 2f 0a 66 6c 6f 61 74  20 6f 62 6a 65 63 74 5f  |*/.float object_|
00007c90  6d 6f 76 65 5f 69 6e 64  65 78 3d 30 2e 30 30 30  |move_index=0.000|
00007ca0  30 3b 0a 69 6e 74 20 6f  62 6a 65 63 74 5f 74 65  |0;.int object_te|
00007cb0  6d 70 5f 6d 6f 76 65 5f  69 6e 64 65 78 3d 30 3b  |mp_move_index=0;|
00007cc0  0a 69 6e 74 20 6f 62 6a  65 63 74 5f 6d 6f 76 65  |.int object_move|
00007cd0  5f 66 6f 75 6e 64 3d 30  3b 20 20 20 20 20 20 20  |_found=0;       |
00007ce0  20 20 20 20 20 2f 2a 20  66 6c 61 67 20 74 6f 20  |     /* flag to |
00007cf0  73 61 79 20 69 66 20 6d  6f 76 69 6e 67 20 6f 62  |say if moving ob|
00007d00  6a 65 63 74 20 66 6f 75  6e 64 20 2a 2f 0a 20 20  |ject found */.  |
00007d10  20 2f 2a 20 76 61 6c 75  65 73 20 74 6f 20 68 6f  | /* values to ho|
00007d20  6c 64 20 6d 6f 76 69 6e  67 20 6f 62 6a 65 63 74  |ld moving object|
00007d30  20 2a 2f 0a 69 6e 74 20  6f 62 6a 65 63 74 5f 6d  | */.int object_m|
00007d40  6f 76 65 5f 6e 65 77 5f  78 2c 6f 62 6a 65 63 74  |ove_new_x,object|
00007d50  5f 6d 6f 76 65 5f 6e 65  77 5f 79 3b 20 2f 2a 20  |_move_new_y; /* |
00007d60  6e 65 77 20 76 61 6c 75  65 73 20 6f 66 20 6f 62  |new values of ob|
00007d70  6a 65 63 74 20 2a 2f 0a  0a 2f 2a 20 4e 45 57 20  |ject */../* NEW |
00007d80  64 65 6d 6f 20 66 69 6c  65 20 77 68 69 63 68 20  |demo file which |
00007d90  63 61 6e 20 6c 6f 61 64  2f 73 74 6f 72 65 20 64  |can load/store d|
00007da0  65 6d 6f 20 69 6e 66 6f  72 6d 61 74 69 6f 6e 20  |emo information |
00007db0  66 6f 72 20 61 20 77 61  6c 6b 74 68 72 6f 75 67  |for a walkthroug|
00007dc0  68 2a 2f 0a 0a 46 49 4c  45 20 2a 64 65 6d 6f 5f  |h*/..FILE *demo_|
00007dd0  66 69 6c 65 3b 0a 0a 2f  2a 20 4e 45 57 20 73 79  |file;../* NEW sy|
00007de0  73 74 65 6d 20 6f 66 20  70 61 73 73 69 6e 67 2c  |stem of passing,|
00007df0  20 77 65 20 75 73 65 20  74 68 65 20 73 74 61 6e  | we use the stan|
00007e00  64 61 72 64 20 61 72 67  63 20 61 6e 64 20 61 72  |dard argc and ar|
00007e10  67 76 20 74 6f 20 73 75  70 70 6c 79 20 70 61 72  |gv to supply par|
00007e20  61 6d 65 74 65 72 73 20  74 6f 20 74 68 65 20 65  |ameters to the e|
00007e30  6e 67 69 6e 65 2e 20 46  49 52 53 54 20 77 65 20  |ngine. FIRST we |
00007e40  6d 75 73 74 20 65 78 74  72 61 63 74 20 74 68 65  |must extract the|
00007e50  6d 3a 2a 2f 0a 0a 2f 2a  20 63 68 65 63 6b 20 74  |m:*/../* check t|
00007e60  68 61 74 20 63 6f 72 72  65 63 74 20 6e 75 6d 62  |hat correct numb|
00007e70  65 72 20 6f 66 20 70 61  72 61 6d 65 74 65 72 73  |er of parameters|
00007e80  20 68 61 76 65 20 62 65  65 6e 20 70 61 73 73 65  | have been passe|
00007e90  64 20 2a 2f 0a 0a 69 66  28 61 72 67 63 21 3d 31  |d */..if(argc!=1|
00007ea0  35 29 0a 7b 0a 2f 2a 20  71 75 69 74 20 69 66 20  |5).{./* quit if |
00007eb0  6e 6f 74 20 2a 2f 0a 70  72 69 6e 74 66 28 22 45  |not */.printf("E|
00007ec0  72 72 6f 72 3a 20 49 6e  63 6f 72 72 65 63 74 20  |rror: Incorrect |
00007ed0  6e 75 6d 62 65 72 20 6f  66 20 70 61 72 61 6d 65  |number of parame|
00007ee0  74 65 72 73 20 70 61 73  73 65 64 2e 20 5f 45 78  |ters passed. _Ex|
00007ef0  69 74 69 6e 67 5c 6e 22  29 3b 20 65 78 69 74 28  |iting\n"); exit(|
00007f00  31 29 3b 0a 2f 2a 20 22  62 65 65 70 22 20 28 6f  |1);./* "beep" (o|
00007f10  6e 20 6d 6f 73 74 20 6d  61 63 68 69 6e 65 73 29  |n most machines)|
00007f20  2a 2f 20 70 75 74 63 68  61 72 28 27 5c 61 27 29  |*/ putchar('\a')|
00007f30  3b 0a 7d 0a 2f 2a 20 75  73 65 20 61 74 6f 69 20  |;.}./* use atoi |
00007f40  74 6f 20 67 65 74 20 69  74 20 72 69 67 68 74 20  |to get it right |
00007f50  2a 2f 0a 2f 2a 20 49 4e  50 55 54 20 41 4c 4c 20  |*/./* INPUT ALL |
00007f60  56 41 4c 55 45 53 20 46  52 4f 4d 20 43 4f 4d 4d  |VALUES FROM COMM|
00007f70  41 4e 44 20 4c 49 4e 45  20 75 73 69 6e 67 20 41  |AND LINE using A|
00007f80  54 4f 49 20 61 6e 64 20  74 68 65 6e 20 77 6f 72  |TOI and then wor|
00007f90  6b 20 6f 75 74 20 6e 65  65 64 65 64 2a 2f 0a 2f  |k out needed*/./|
00007fa0  2a 20 61 6e 67 6c 65 20  76 61 6c 75 65 73 20 66  |* angle values f|
00007fb0  6f 72 20 74 68 65 20 72  61 79 20 63 61 73 74 69  |or the ray casti|
00007fc0  6e 67 20 65 6e 67 69 6e  65 2e 20 2a 2f 0a 76 69  |ng engine. */.vi|
00007fd0  65 77 5f 78 3d 61 74 6f  69 28 61 72 67 76 5b 31  |ew_x=atoi(argv[1|
00007fe0  5d 29 3b 0a 76 69 65 77  5f 79 3d 61 74 6f 69 28  |]);.view_y=atoi(|
00007ff0  61 72 67 76 5b 32 5d 29  3b 0a 76 69 65 77 5f 61  |argv[2]);.view_a|
00008000  6e 67 6c 65 3d 61 74 6f  69 28 61 72 67 76 5b 33  |ngle=atoi(argv[3|
00008010  5d 29 3b 0a 53 43 52 45  45 4e 5f 57 49 44 54 48  |]);.SCREEN_WIDTH|
00008020  3d 61 74 6f 69 28 61 72  67 76 5b 34 5d 29 3b 0a  |=atoi(argv[4]);.|
00008030  53 43 52 45 45 4e 5f 48  45 49 47 48 54 3d 61 74  |SCREEN_HEIGHT=at|
00008040  6f 69 28 61 72 67 76 5b  35 5d 29 3b 0a 41 4e 47  |oi(argv[5]);.ANG|
00008050  4c 45 5f 33 36 30 3d 61  74 6f 69 28 61 72 67 76  |LE_360=atoi(argv|
00008060  5b 36 5d 29 3b 0a 41 4e  47 4c 45 5f 31 38 30 3d  |[6]);.ANGLE_180=|
00008070  41 4e 47 4c 45 5f 33 36  30 2f 32 3b 41 4e 47 4c  |ANGLE_360/2;ANGL|
00008080  45 5f 39 30 3d 41 4e 47  4c 45 5f 31 38 30 2f 32  |E_90=ANGLE_180/2|
00008090  3b 0a 41 4e 47 4c 45 5f  36 3d 61 74 6f 69 28 61  |;.ANGLE_6=atoi(a|
000080a0  72 67 76 5b 39 5d 29 3b  0a 41 4e 47 4c 45 5f 33  |rgv[9]);.ANGLE_3|
000080b0  30 3d 28 69 6e 74 29 41  4e 47 4c 45 5f 39 30 2f  |0=(int)ANGLE_90/|
000080c0  33 3b 0a 41 4e 47 4c 45  5f 30 3d 30 3b 0a 41 4e  |3;.ANGLE_0=0;.AN|
000080d0  47 4c 45 5f 32 37 30 3d  41 4e 47 4c 45 5f 39 30  |GLE_270=ANGLE_90|
000080e0  2a 33 3b 0a 56 45 52 54  49 43 41 4c 5f 53 43 41  |*3;.VERTICAL_SCA|
000080f0  4c 45 3d 61 74 6f 69 28  61 72 67 76 5b 37 5d 29  |LE=atoi(argv[7])|
00008100  3b 0a 53 54 45 50 5f 4c  45 4e 47 54 48 3d 61 74  |;.STEP_LENGTH=at|
00008110  6f 69 28 61 72 67 76 5b  38 5d 29 3b 0a 56 49 45  |oi(argv[8]);.VIE|
00008120  57 56 41 52 3d 61 74 6f  69 28 61 72 67 76 5b 31  |WVAR=atoi(argv[1|
00008130  30 5d 29 3b 0a 56 49 45  57 56 41 52 54 3d 61 74  |0]);.VIEWVART=at|
00008140  6f 69 28 61 72 67 76 5b  31 31 5d 29 3b 0a 44 45  |oi(argv[11]);.DE|
00008150  4d 4f 5f 52 45 41 44 3d  61 74 6f 69 28 61 72 67  |MO_READ=atoi(arg|
00008160  76 5b 31 32 5d 29 3b 0a  44 45 4d 4f 5f 57 52 49  |v[12]);.DEMO_WRI|
00008170  54 45 3d 61 74 6f 69 28  61 72 67 76 5b 31 33 5d  |TE=atoi(argv[13]|
00008180  29 3b 0a 6f 62 6a 65 63  74 5f 6d 6f 76 65 5f 69  |);.object_move_i|
00008190  6e 63 72 65 6d 65 6e 74  3d 61 74 6f 69 28 61 72  |ncrement=atoi(ar|
000081a0  67 76 5b 31 34 5d 29 3b  0a 2f 2a 20 63 6f 6e 76  |gv[14]);./* conv|
000081b0  65 72 74 20 6f 62 6a 65  63 74 5f 69 6e 72 65 6d  |ert object_inrem|
000081c0  65 6e 74 20 70 72 6f 70  65 72 6c 79 20 2a 2f 0a  |ent properly */.|
000081d0  69 66 28 6f 62 6a 65 63  74 5f 6d 6f 76 65 5f 69  |if(object_move_i|
000081e0  6e 63 72 65 6d 65 6e 74  3d 3d 30 29 6f 62 6a 65  |ncrement==0)obje|
000081f0  63 74 5f 6d 6f 76 65 5f  69 6e 63 72 65 6d 65 6e  |ct_move_incremen|
00008200  74 3d 31 3b 0a 6f 62 6a  65 63 74 5f 6d 6f 76 65  |t=1;.object_move|
00008210  5f 69 6e 63 72 65 6d 65  6e 74 3d 28 66 6c 6f 61  |_increment=(floa|
00008220  74 29 31 2f 6f 62 6a 65  63 74 5f 6d 6f 76 65 5f  |t)1/object_move_|
00008230  69 6e 63 72 65 6d 65 6e  74 3b 0a 0a 73 63 72 65  |increment;..scre|
00008240  65 6e 5f 6c 69 6d 69 74  3d 28 33 32 30 2d 53 43  |en_limit=(320-SC|
00008250  52 45 45 4e 5f 57 49 44  54 48 29 3e 3e 32 3b 0a  |REEN_WIDTH)>>2;.|
00008260  2f 2a 20 4e 6f 77 20 77  65 20 70 72 69 6e 74 20  |/* Now we print |
00008270  74 68 65 20 69 6e 66 6f  72 6d 61 74 69 6f 6e 20  |the information |
00008280  6a 75 73 74 20 66 6f 72  20 74 68 65 20 69 6e 66  |just for the inf|
00008290  6f 72 6d 61 74 69 6f 6e  20 6f 66 20 74 68 65 20  |ormation of the |
000082a0  75 73 65 72 20 2a 2f 0a  70 72 69 6e 74 66 28 22  |user */.printf("|
000082b0  5f 70 72 65 2d 73 74 61  72 74 3a 20 73 77 69 74  |_pre-start: swit|
000082c0  63 68 69 6e 67 20 74 6f  20 4d 6f 64 65 20 28 31  |ching to Mode (1|
000082d0  35 29 20 2d 20 68 69 67  68 20 72 65 73 20 66 6f  |5) - high res fo|
000082e0  72 20 74 65 78 74 2e 5c  6e 22 29 3b 0a 6f 75 72  |r text.\n");.our|
000082f0  6c 69 62 5f 63 68 61 6e  67 65 6d 6f 64 65 28 31  |lib_changemode(1|
00008300  35 29 3b 0a 70 72 69 6e  74 66 28 22 23 23 23 23  |5);.printf("####|
00008310  23 23 23 23 23 23 23 23  23 23 20 53 59 53 54 45  |########## SYSTE|
00008320  4d 20 53 54 41 52 54 2d  55 50 20 23 23 23 23 23  |M START-UP #####|
00008330  23 23 23 23 23 23 23 23  23 23 23 23 23 23 5c 6e  |##############\n|
00008340  22 29 3b 0a 70 72 69 6e  74 66 28 22 5f 73 79 73  |");.printf("_sys|
00008350  74 65 6d 20 76 61 72 69  61 62 6c 65 73 3a 20 76  |tem variables: v|
00008360  69 65 77 5f 78 3a 20 25  64 20 76 69 65 77 5f 79  |iew_x: %d view_y|
00008370  3a 20 25 64 20 76 69 65  77 5f 61 6e 67 6c 65 3a  |: %d view_angle:|
00008380  20 25 64 5c 6e 73 63 72  65 65 6e 5f 77 69 64 74  | %d\nscreen_widt|
00008390  68 3a 20 25 64 20 73 63  72 65 65 6e 5f 68 65 69  |h: %d screen_hei|
000083a0  67 68 74 3a 20 25 64 5c  6e 61 6e 67 6c 65 5f 33  |ght: %d\nangle_3|
000083b0  36 30 3a 20 25 64 20 76  65 72 74 69 63 61 6c 5f  |60: %d vertical_|
000083c0  73 63 61 6c 65 3a 20 25  64 20 73 74 65 70 5f 6c  |scale: %d step_l|
000083d0  65 6e 67 74 68 3a 20 25  64 5c 6e 76 69 65 77 76  |ength: %d\nviewv|
000083e0  61 72 73 3a 20 25 64 20  25 64 5c 6e 64 65 6d 6f  |ars: %d %d\ndemo|
000083f0  5f 72 65 61 64 3a 20 25  64 20 64 65 6d 6f 5f 77  |_read: %d demo_w|
00008400  72 69 74 65 3a 20 25 64  20 6f 62 6a 65 63 74 5f  |rite: %d object_|
00008410  6d 6f 76 65 5f 69 6e 63  72 65 6d 65 6e 74 3a 20  |move_increment: |
00008420  25 66 5c 6e 5c 6e 22 2c  76 69 65 77 5f 78 2c 76  |%f\n\n",view_x,v|
00008430  69 65 77 5f 79 2c 76 69  65 77 5f 61 6e 67 6c 65  |iew_y,view_angle|
00008440  2c 53 43 52 45 45 4e 5f  57 49 44 54 48 2c 53 43  |,SCREEN_WIDTH,SC|
00008450  52 45 45 4e 5f 48 45 49  47 48 54 2c 41 4e 47 4c  |REEN_HEIGHT,ANGL|
00008460  45 5f 33 36 30 2c 56 45  52 54 49 43 41 4c 5f 53  |E_360,VERTICAL_S|
00008470  43 41 4c 45 2c 53 54 45  50 5f 4c 45 4e 47 54 48  |CALE,STEP_LENGTH|
00008480  2c 56 49 45 57 56 41 52  2c 56 49 45 57 56 41 52  |,VIEWVAR,VIEWVAR|
00008490  54 2c 44 45 4d 4f 5f 52  45 41 44 2c 44 45 4d 4f  |T,DEMO_READ,DEMO|
000084a0  5f 57 52 49 54 45 2c 6f  62 6a 65 63 74 5f 6d 6f  |_WRITE,object_mo|
000084b0  76 65 5f 69 6e 63 72 65  6d 65 6e 74 29 3b 0a 0a  |ve_increment);..|
000084c0  0a 69 66 28 44 45 4d 4f  5f 57 52 49 54 45 3d 3d  |.if(DEMO_WRITE==|
000084d0  31 29 7b 0a 69 66 28 21  28 64 65 6d 6f 5f 66 69  |1){.if(!(demo_fi|
000084e0  6c 65 3d 66 6f 70 65 6e  28 22 3c 41 55 41 52 61  |le=fopen("<AUARa|
000084f0  79 24 44 69 72 3e 2e 64  65 6d 6f 22 2c 22 77 22  |y$Dir>.demo","w"|
00008500  29 29 29 65 78 69 74 28  31 29 3b 0a 70 72 69 6e  |)))exit(1);.prin|
00008510  74 66 28 22 5f 66 69 6c  65 20 61 63 63 65 73 73  |tf("_file access|
00008520  3a 20 77 72 69 74 69 6e  67 20 74 6f 20 66 69 6c  |: writing to fil|
00008530  65 5c 6e 22 29 3b 0a 7d  0a 65 6c 73 65 20 69 66  |e\n");.}.else if|
00008540  28 44 45 4d 4f 5f 52 45  41 44 3d 3d 31 29 0a 7b  |(DEMO_READ==1).{|
00008550  0a 20 20 69 66 28 21 28  64 65 6d 6f 5f 66 69 6c  |.  if(!(demo_fil|
00008560  65 3d 66 6f 70 65 6e 28  22 3c 41 55 41 52 61 79  |e=fopen("<AUARay|
00008570  24 44 69 72 3e 2e 64 65  6d 6f 22 2c 22 72 22 29  |$Dir>.demo","r")|
00008580  29 29 65 78 69 74 28 31  29 3b 0a 20 20 70 72 69  |))exit(1);.  pri|
00008590  6e 74 66 28 22 5f 66 69  6c 65 20 61 63 63 65 73  |ntf("_file acces|
000085a0  73 3a 20 72 65 61 64 69  6e 67 20 64 65 6d 6f 20  |s: reading demo |
000085b0  66 69 6c 65 5c 6e 5c 6e  22 29 3b 0a 7d 0a 0a 2f  |file\n\n");.}../|
000085c0  2a 20 44 4f 4e 45 2e 20  4e 6f 77 20 63 6f 6e 74  |* DONE. Now cont|
000085d0  69 6e 75 65 20 61 73 20  6e 6f 72 6d 61 6c 20 77  |inue as normal w|
000085e0  69 74 68 20 74 68 65 20  70 72 6f 67 72 61 6d 20  |ith the program |
000085f0  2a 2f 0a 2f 2a 20 49 74  20 69 73 20 68 65 72 65  |*/./* It is here|
00008600  20 74 68 61 74 20 77 65  20 73 65 65 20 69 66 20  | that we see if |
00008610  74 68 65 20 44 45 4d 4f  46 4c 41 47 20 69 73 20  |the DEMOFLAG is |
00008620  73 65 74 20 74 6f 20 72  65 61 64 2f 77 72 69 74  |set to read/writ|
00008630  65 20 64 65 6d 6f 73 20  2a 2f 0a 0a 0a 0a 2f 2a  |e demos */..../*|
00008640  20 6e 6f 77 20 77 65 20  63 61 6c 6c 20 61 75 61  | now we call aua|
00008650  5f 77 6f 72 6c 64 20 74  6f 20 6c 6f 61 64 20 69  |_world to load i|
00008660  6e 20 74 68 65 20 74 65  78 74 20 77 6f 72 6c 64  |n the text world|
00008670  20 66 69 6c 65 20 77 68  69 63 68 20 64 65 66 69  | file which defi|
00008680  6e 65 73 20 6f 75 72 20  77 61 6c 6c 73 20 74 79  |nes our walls ty|
00008690  70 65 20 61 6e 64 20 6c  61 79 6f 75 74 20 2a 2f  |pe and layout */|
000086a0  0a 0a 70 72 69 6e 74 66  28 22 5c 6e 5f 66 69 6c  |..printf("\n_fil|
000086b0  65 20 61 63 63 65 73 73  3a 20 6c 6f 61 64 69 6e  |e access: loadin|
000086c0  67 20 69 6e 20 74 65 78  74 20 66 69 6c 65 20 3c  |g in text file <|
000086d0  41 55 41 52 61 79 24 44  69 72 3e 2e 77 6f 72 6c  |AUARay$Dir>.worl|
000086e0  64 5c 6e 5c 6e 22 29 3b  0a 61 75 61 5f 77 6f 72  |d\n\n");.aua_wor|
000086f0  6c 64 28 29 3b 0a 0a 2f  2a 20 63 68 65 63 6b 20  |ld();../* check |
00008700  74 6f 20 73 65 65 20 69  66 20 74 68 65 20 76 69  |to see if the vi|
00008710  65 77 65 72 20 69 73 20  69 6e 73 69 64 65 20 61  |ewer is inside a|
00008720  20 67 61 6d 65 20 63 65  6c 6c 20 57 41 4c 4c 2c  | game cell WALL,|
00008730  20 77 68 69 63 68 20 77  6f 75 6c 64 20 62 65 20  | which would be |
00008740  62 61 64 20 6e 65 77 73  21 20 2a 2f 0a 0a 69 66  |bad news! */..if|
00008750  28 77 6f 72 6c 64 5b 76  69 65 77 5f 79 3e 3e 36  |(world[view_y>>6|
00008760  5d 5b 76 69 65 77 5f 78  3e 3e 36 5d 29 0a 7b 0a  |][view_x>>6]).{.|
00008770  20 20 70 72 69 6e 74 66  28 22 5c 6e 5f 65 72 72  |  printf("\n_err|
00008780  6f 72 3a 20 42 61 64 20  63 6f 6f 72 64 69 6e 61  |or: Bad coordina|
00008790  74 65 73 20 67 69 76 65  6e 2c 20 76 69 65 77 65  |tes given, viewe|
000087a0  72 20 69 73 20 49 4e 20  61 20 57 41 4c 4c 21 2c  |r is IN a WALL!,|
000087b0  20 65 78 69 74 69 6e 67  5c 6e 22 29 3b 0a 20 20  | exiting\n");.  |
000087c0  65 78 69 74 28 31 29 3b  0a 7d 0a 0a 2f 2a 20 6e  |exit(1);.}../* n|
000087d0  6f 77 20 77 65 20 63 61  6c 6c 20 61 75 61 5f 74  |ow we call aua_t|
000087e0  61 62 6c 65 73 20 74 6f  20 67 65 6e 65 72 61 74  |ables to generat|
000087f0  65 20 73 6f 6d 65 20 6c  6f 6f 6b 2d 75 70 20 74  |e some look-up t|
00008800  61 62 6c 65 73 20 66 6f  72 20 74 68 65 20 65 6e  |ables for the en|
00008810  67 69 6e 65 20 74 6f 20  75 73 65 2c 20 6c 6f 6f  |gine to use, loo|
00008820  6b 2d 75 70 73 20 61 72  65 20 65 78 70 6c 61 69  |k-ups are explai|
00008830  6e 65 64 20 75 70 20 61  74 20 74 68 65 20 74 6f  |ned up at the to|
00008840  70 20 6f 66 20 74 68 65  20 66 69 6c 65 20 6e 65  |p of the file ne|
00008850  78 74 20 74 6f 20 74 68  65 20 67 6c 6f 62 61 6c  |xt to the global|
00008860  20 76 61 72 69 61 62 6c  65 73 20 2a 2f 0a 0a 70  | variables */..p|
00008870  72 69 6e 74 66 28 22 5f  6d 61 69 6e 3a 20 63 61  |rintf("_main: ca|
00008880  6c 6c 20 61 75 61 5f 74  61 62 6c 65 73 28 29 20  |ll aua_tables() |
00008890  28 6c 6f 6e 67 20 74 69  6d 65 20 6f 6e 20 73 6c  |(long time on sl|
000088a0  6f 77 65 72 20 6d 61 63  68 69 6e 65 73 29 5c 6e  |ower machines)\n|
000088b0  5c 6e 22 29 3b 0a 2f 2a  20 6e 65 77 65 72 20 66  |\n");./* newer f|
000088c0  69 78 65 64 20 70 6f 69  6e 74 20 76 65 72 73 69  |ixed point versi|
000088d0  6f 6e 20 2a 2f 0a 61 75  61 5f 74 61 62 6c 65 73  |on */.aua_tables|
000088e0  28 29 3b 0a 0a 2f 2a 20  61 6c 6c 20 69 73 20 64  |();../* all is d|
000088f0  6f 6e 65 20 69 6e 20 74  65 72 6d 73 20 6f 66 20  |one in terms of |
00008900  69 6e 70 75 74 20 66 6f  72 20 6e 6f 77 2e 20 57  |input for now. W|
00008910  65 20 6e 65 65 64 20 74  6f 20 73 77 69 74 63 68  |e need to switch|
00008920  20 74 6f 20 4d 6f 64 65  20 31 33 20 2a 2f 0a 0a  | to Mode 13 */..|
00008930  70 72 69 6e 74 66 28 22  5f 73 63 72 65 65 6e 3a  |printf("_screen:|
00008940  20 73 77 69 74 63 68 69  6e 67 20 74 6f 20 4d 6f  | switching to Mo|
00008950  64 65 20 31 33 5c 6e 5c  6e 22 29 3b 0a 0a 2f 2a  |de 13\n\n");../*|
00008960  20 63 61 6c 6c 20 6f 75  72 6c 69 62 5f 63 68 61  | call ourlib_cha|
00008970  6e 67 65 6d 6f 64 65 20  74 6f 20 73 77 69 74 63  |ngemode to switc|
00008980  68 20 74 6f 20 6d 6f 64  65 20 31 33 20 2a 2f 0a  |h to mode 13 */.|
00008990  0a 6f 75 72 6c 69 62 5f  63 68 61 6e 67 65 6d 6f  |.ourlib_changemo|
000089a0  64 65 28 31 33 29 3b 0a  0a 2f 2a 20 63 61 6c 6c  |de(13);../* call|
000089b0  20 6f 75 72 6c 69 62 5f  66 69 6e 64 73 63 72 65  | ourlib_findscre|
000089c0  65 6e 20 74 6f 20 67 65  74 20 74 68 65 20 73 63  |en to get the sc|
000089d0  72 65 65 6e 20 62 61 73  65 20 61 64 64 72 65 73  |reen base addres|
000089e0  73 20 6f 66 20 6d 6f 64  65 20 31 33 2c 20 20 77  |s of mode 13,  w|
000089f0  69 74 68 6f 75 74 20 74  68 65 20 63 6f 72 72 65  |ithout the corre|
00008a00  63 74 20 61 64 64 72 65  73 73 20 77 65 20 63 61  |ct address we ca|
00008a10  6e 27 74 20 64 72 61 77  20 61 6e 79 74 68 69 6e  |n't draw anythin|
00008a20  67 20 61 6e 64 20 74 68  65 20 63 6f 6d 70 75 74  |g and the comput|
00008a30  65 72 20 63 6f 75 6c 64  20 63 72 61 73 68 20 2a  |er could crash *|
00008a40  2f 0a 0a 73 63 72 65 65  6e 5f 61 64 64 72 65 73  |/..screen_addres|
00008a50  73 3d 28 63 68 61 72 20  2a 29 6f 75 72 6c 69 62  |s=(char *)ourlib|
00008a60  5f 66 69 6e 64 73 63 72  65 65 6e 28 29 3b 0a 2f  |_findscreen();./|
00008a70  2a 20 4e 45 57 20 4c 4f  41 44 20 54 49 54 4c 45  |* NEW LOAD TITLE|
00008a80  20 53 43 52 45 45 4e 20  2a 2f 0a 73 79 73 74 65  | SCREEN */.syste|
00008a90  6d 28 22 2a 53 63 72 65  65 6e 4c 6f 61 64 20 3c  |m("*ScreenLoad <|
00008aa0  41 55 41 52 61 79 24 44  69 72 3e 2e 74 69 74 6c  |AUARay$Dir>.titl|
00008ab0  65 22 29 3b 6f 75 72 6c  69 62 5f 6b 69 6c 6c 63  |e");ourlib_killc|
00008ac0  75 72 73 6f 72 28 29 3b  0a 6f 75 72 6c 69 62 5f  |ursor();.ourlib_|
00008ad0  77 61 69 74 28 32 30 30  29 3b 0a 2f 2a 6f 75 72  |wait(200);./*our|
00008ae0  6c 69 62 5f 73 63 72 65  65 6e 5f 64 69 73 73 6f  |lib_screen_disso|
00008af0  6c 76 65 28 73 63 72 65  65 6e 5f 61 64 64 72 65  |lve(screen_addre|
00008b00  73 73 2c 38 31 39 32 30  29 3b 20 55 53 45 20 49  |ss,81920); USE I|
00008b10  46 20 57 41 4e 54 45 44  20 2a 2f 0a 0a 2f 2a 20  |F WANTED */../* |
00008b20  54 48 45 4e 20 57 41 49  54 20 54 48 45 4e 20 53  |THEN WAIT THEN S|
00008b30  43 52 45 45 4e 44 49 53  53 4f 4c 56 45 20 4f 55  |CREENDISSOLVE OU|
00008b40  54 2c 20 73 65 65 20 61  62 6f 76 65 20 2a 2f 0a  |T, see above */.|
00008b50  0a 2f 2a 20 6e 6f 77 20  77 65 20 6e 65 65 64 20  |./* now we need |
00008b60  74 6f 20 2a 73 63 72 65  65 6e 6c 6f 61 64 20 6f  |to *screenload o|
00008b70  75 72 20 67 72 61 70 68  69 63 73 20 66 69 6c 65  |ur graphics file|
00008b80  2c 20 61 6e 64 20 67 72  61 62 20 65 61 63 68 20  |, and grab each |
00008b90  69 6e 64 69 76 69 64 75  61 6c 20 77 61 6c 6c 20  |individual wall |
00008ba0  67 72 61 70 68 69 63 20  6f 6e 65 20 62 79 20 6f  |graphic one by o|
00008bb0  6e 65 2c 20 74 68 65 20  66 75 6e 63 74 69 6f 6e  |ne, the function|
00008bc0  20 61 75 61 5f 67 72 61  70 68 69 63 73 20 64 6f  | aua_graphics do|
00008bd0  65 73 20 74 68 69 73 20  2a 2f 0a 0a 61 75 61 5f  |es this */..aua_|
00008be0  67 72 61 70 68 69 63 73  28 29 3b 0a 0a 0a 2f 2a  |graphics();.../*|
00008bf0  20 4e 4f 57 20 77 65 20  63 61 6c 6c 20 73 65 74  | NOW we call set|
00008c00  75 70 5f 73 63 72 65 65  6e 73 2c 20 61 20 73 6d  |up_screens, a sm|
00008c10  61 6c 6c 20 66 75 6e 63  74 69 6f 6e 20 77 68 69  |all function whi|
00008c20  63 68 20 68 65 6c 70 73  20 77 69 74 68 20 62 61  |ch helps with ba|
00008c30  6e 6b 69 6e 67 20 2a 2f  0a 2f 2a 20 57 69 74 68  |nking */./* With|
00008c40  20 61 6c 6c 20 74 68 65  20 64 61 74 61 20 6c 6f  | all the data lo|
00008c50  61 64 65 64 20 69 6e 20  77 65 20 73 68 61 6c 6c  |aded in we shall|
00008c60  20 74 72 79 20 61 6e 64  20 69 6e 69 74 69 61 74  | try and initiat|
00008c70  65 20 53 43 52 45 45 4e  20 42 41 4e 4b 53 2e 20  |e SCREEN BANKS. |
00008c80  46 69 72 73 74 20 77 65  20 63 68 61 6e 67 65 20  |First we change |
00008c90  74 6f 20 4d 4f 44 45 20  31 35 2c 20 73 6f 20 74  |to MODE 15, so t|
00008ca0  68 61 74 20 73 63 72 65  65 6e 20 6d 65 6d 6f 72  |hat screen memor|
00008cb0  79 20 62 65 63 6f 6d 65  73 20 61 76 61 69 6c 61  |y becomes availa|
00008cc0  62 6c 65 20 66 6f 72 20  74 77 6f 20 74 69 6d 65  |ble for two time|
00008cd0  73 20 4d 4f 44 45 20 31  33 20 2a 2f 0a 0a 6f 75  |s MODE 13 */..ou|
00008ce0  72 6c 69 62 5f 73 65 74  75 70 5f 73 63 72 65 65  |rlib_setup_scree|
00008cf0  6e 73 28 29 3b 0a 6f 75  72 6c 69 62 5f 63 68 61  |ns();.ourlib_cha|
00008d00  6e 67 65 6d 6f 64 65 28  31 35 29 3b 0a 0a 2f 2a  |ngemode(15);../*|
00008d10  20 4e 6f 77 20 77 65 20  73 77 69 74 63 68 20 74  | Now we switch t|
00008d20  6f 20 4d 4f 44 45 20 31  33 2c 20 61 6e 64 20 67  |o MODE 13, and g|
00008d30  65 74 20 74 68 65 20 66  69 72 73 74 20 73 63 72  |et the first scr|
00008d40  65 65 6e 20 61 64 64 72  65 73 73 20 2a 2f 0a 0a  |een address */..|
00008d50  6f 75 72 6c 69 62 5f 63  68 61 6e 67 65 6d 6f 64  |ourlib_changemod|
00008d60  65 28 31 33 29 3b 0a 6f  75 72 6c 69 62 5f 6b 69  |e(13);.ourlib_ki|
00008d70  6c 6c 63 75 72 73 6f 72  28 29 3b 0a 0a 73 63 72  |llcursor();..scr|
00008d80  65 65 6e 5f 61 64 64 72  65 73 73 3d 28 63 68 61  |een_address=(cha|
00008d90  72 20 2a 29 6f 75 72 6c  69 62 5f 66 69 6e 64 73  |r *)ourlib_finds|
00008da0  63 72 65 65 6e 28 29 3b  0a 0a 2f 2a 20 4e 45 57  |creen();../* NEW|
00008db0  20 63 6f 64 65 20 74 6f  20 70 6c 6f 74 20 74 68  | code to plot th|
00008dc0  65 20 62 6f 74 74 6f 6d  20 62 61 72 20 6f 6e 20  |e bottom bar on |
00008dd0  74 68 65 20 73 63 72 65  65 6e 20 2a 2f 0a 6f 75  |the screen */.ou|
00008de0  72 6c 69 62 5f 62 69 74  6d 61 70 5f 70 6c 6f 74  |rlib_bitmap_plot|
00008df0  28 30 2c 32 30 36 2c 33  31 39 2c 32 35 35 2c 62  |(0,206,319,255,b|
00008e00  61 72 5f 67 72 61 70 68  69 63 2c 73 63 72 65 65  |ar_graphic,scree|
00008e10  6e 5f 61 64 64 72 65 73  73 29 3b 0a 0a 2f 2a 20  |n_address);../* |
00008e20  4e 6f 77 20 77 65 20 73  77 69 74 63 68 20 74 6f  |Now we switch to|
00008e30  20 74 68 65 20 6f 74 68  65 72 20 73 63 72 65 65  | the other scree|
00008e40  6e 20 62 61 6e 6b 20 61  6e 64 20 67 65 74 20 74  |n bank and get t|
00008e50  68 65 20 6f 74 68 65 72  20 73 63 72 65 65 6e 20  |he other screen |
00008e60  61 64 64 72 65 73 73 20  2a 2f 0a 0a 6f 75 72 6c  |address */..ourl|
00008e70  69 62 5f 73 69 6d 70 6c  65 73 77 69 74 63 68 28  |ib_simpleswitch(|
00008e80  29 3b 0a 0a 73 63 72 65  65 6e 5f 61 64 64 72 65  |);..screen_addre|
00008e90  73 73 5f 62 61 6e 6b 3d  28 63 68 61 72 20 2a 29  |ss_bank=(char *)|
00008ea0  6f 75 72 6c 69 62 5f 66  69 6e 64 73 63 72 65 65  |ourlib_findscree|
00008eb0  6e 28 29 3b 0a 6f 75 72  6c 69 62 5f 73 6c 6f 77  |n();.ourlib_slow|
00008ec0  63 6c 65 61 72 28 73 63  72 65 65 6e 5f 61 64 64  |clear(screen_add|
00008ed0  72 65 73 73 5f 62 61 6e  6b 2c 38 31 39 32 30 2c  |ress_bank,81920,|
00008ee0  30 29 3b 0a 6f 75 72 6c  69 62 5f 62 69 74 6d 61  |0);.ourlib_bitma|
00008ef0  70 5f 70 6c 6f 74 28 30  2c 32 30 36 2c 33 31 39  |p_plot(0,206,319|
00008f00  2c 32 35 35 2c 62 61 72  5f 67 72 61 70 68 69 63  |,255,bar_graphic|
00008f10  2c 73 63 72 65 65 6e 5f  61 64 64 72 65 73 73 5f  |,screen_address_|
00008f20  62 61 6e 6b 29 3b 0a 0a  0a 6f 75 72 6c 69 62 5f  |bank);...ourlib_|
00008f30  6b 69 6c 6c 63 75 72 73  6f 72 28 29 3b 0a 2f 2a  |killcursor();./*|
00008f40  20 53 77 69 74 63 68 20  62 61 63 6b 20 74 6f 20  | Switch back to |
00008f50  74 68 65 20 6f 74 68 65  72 20 73 63 72 65 65 6e  |the other screen|
00008f60  20 2a 2f 0a 0a 6f 75 72  6c 69 62 5f 73 69 6d 70  | */..ourlib_simp|
00008f70  6c 65 73 77 69 74 63 68  28 29 3b 0a 0a 2f 2a 20  |leswitch();../* |
00008f80  4e 4f 57 20 77 65 20 63  61 6e 20 63 61 6c 6c 20  |NOW we can call |
00008f90  73 65 74 75 70 20 62 61  63 6b 67 72 6f 75 6e 64  |setup background|
00008fa0  2c 20 74 6f 20 74 65 6c  6c 20 74 68 65 20 73 63  |, to tell the sc|
00008fb0  72 65 65 6e 20 63 6c 65  61 72 65 72 20 74 68 65  |reen clearer the|
00008fc0  20 63 6f 6c 6f 75 72 20  6f 66 20 74 68 65 20 66  | colour of the f|
00008fd0  6c 6f 6f 72 20 61 6e 64  20 63 65 69 6c 69 6e 67  |loor and ceiling|
00008fe0  73 20 77 65 20 77 61 6e  74 2e 2a 2f 0a 0a 6f 75  |s we want.*/..ou|
00008ff0  72 6c 69 62 5f 73 65 74  75 70 5f 62 61 63 6b 67  |rlib_setup_backg|
00009000  72 6f 75 6e 64 28 32 30  38 2c 34 35 29 3b 0a 0a  |round(208,45);..|
00009010  2f 2a 20 4e 4f 57 20 77  65 20 63 61 6e 20 73 74  |/* NOW we can st|
00009020  61 72 74 20 74 68 65 20  6d 61 69 6e 20 6c 6f 6f  |art the main loo|
00009030  70 2c 20 65 78 69 74 61  62 6c 65 20 6f 6e 6c 79  |p, exitable only|
00009040  20 62 79 20 70 72 65 73  73 69 6e 67 20 74 68 65  | by pressing the|
00009050  20 51 20 6b 65 79 2e 20  55 73 65 20 74 68 65 20  | Q key. Use the |
00009060  43 75 72 73 6f 72 73 20  74 6f 20 6d 6f 76 65 20  |Cursors to move |
00009070  74 68 65 20 76 69 65 77  70 6f 69 6e 74 20 61 72  |the viewpoint ar|
00009080  6f 75 6e 64 20 2a 2f 0a  2f 2a 20 57 65 20 73 68  |ound */./* We sh|
00009090  61 6c 6c 20 61 6c 73 6f  20 74 61 6b 65 20 61 20  |all also take a |
000090a0  72 65 61 64 69 6e 67 20  74 6f 20 77 6f 72 6b 20  |reading to work |
000090b0  6f 75 74 20 74 68 65 20  66 72 61 6d 65 20 72 61  |out the frame ra|
000090c0  74 65 20 6f 66 20 74 68  65 20 73 79 73 74 65 6d  |te of the system|
000090d0  2c 20 73 6c 6f 77 20 66  6f 72 20 6e 6f 77 20 2a  |, slow for now *|
000090e0  2f 0a 0a 2f 2a 20 4e 45  57 20 41 44 4a 55 53 54  |/../* NEW ADJUST|
000090f0  49 4e 47 20 4c 49 4e 45  53 20 3a 20 77 65 20 61  |ING LINES : we a|
00009100  64 64 20 61 6e 20 6f 66  66 73 65 74 20 74 6f 20  |dd an offset to |
00009110  62 6f 74 68 20 73 63 72  65 65 6e 20 6d 65 6d 6f  |both screen memo|
00009120  72 79 20 61 72 65 61 73  20 69 6e 20 6f 72 64 65  |ry areas in orde|
00009130  72 20 74 6f 20 63 65 6e  74 72 65 20 74 68 65 20  |r to centre the |
00009140  69 6d 61 67 65 20 69 6e  20 74 68 65 20 6d 69 64  |image in the mid|
00009150  64 6c 65 20 6f 66 20 74  68 65 20 73 63 72 65 65  |dle of the scree|
00009160  6e 20 6e 6f 20 6d 61 74  74 65 72 20 77 68 61 74  |n no matter what|
00009170  20 73 69 7a 65 20 2a 2f  0a 0a 73 63 72 65 65 6e  | size */..screen|
00009180  5f 61 64 64 72 65 73 73  2b 3d 28 33 32 30 2d 53  |_address+=(320-S|
00009190  43 52 45 45 4e 5f 57 49  44 54 48 29 3e 3e 31 3b  |CREEN_WIDTH)>>1;|
000091a0  0a 73 63 72 65 65 6e 5f  61 64 64 72 65 73 73 5f  |.screen_address_|
000091b0  62 61 6e 6b 2b 3d 28 33  32 30 2d 53 43 52 45 45  |bank+=(320-SCREE|
000091c0  4e 5f 57 49 44 54 48 29  3e 3e 31 3b 0a 0a 6f 75  |N_WIDTH)>>1;..ou|
000091d0  72 6c 69 62 5f 6b 69 6c  6c 63 75 72 73 6f 72 28  |rlib_killcursor(|
000091e0  29 3b 20 2f 2a 20 67 65  74 20 72 69 64 20 6f 66  |); /* get rid of|
000091f0  20 74 68 65 20 63 75 72  73 6f 72 20 66 6c 61 73  | the cursor flas|
00009200  68 69 6e 67 20 61 77 61  79 20 2a 2f 0a 74 69 6d  |hing away */.tim|
00009210  65 5f 73 74 61 72 74 3d  6f 75 72 6c 69 62 5f 67  |e_start=ourlib_g|
00009220  65 74 74 69 6d 65 28 29  3b 0a 0a 77 68 69 6c 65  |ettime();..while|
00009230  28 21 64 6f 6e 65 29 20  2f 2a 20 74 68 65 20 6c  |(!done) /* the l|
00009240  6f 6f 70 20 77 69 6c 6c  20 63 6f 6e 74 69 6e 75  |oop will continu|
00009250  65 20 75 6e 74 69 6c 20  64 6f 6e 65 20 2a 2f 0a  |e until done */.|
00009260  7b 0a 0a 20 6f 75 72 6c  69 62 5f 66 61 73 74 63  |{.. ourlib_fastc|
00009270  6c 67 5f 74 77 6f 28 73  63 72 65 65 6e 5f 61 64  |lg_two(screen_ad|
00009280  64 72 65 73 73 2c 53 43  52 45 45 4e 5f 57 49 44  |dress,SCREEN_WID|
00009290  54 48 2c 53 43 52 45 45  4e 5f 48 45 49 47 48 54  |TH,SCREEN_HEIGHT|
000092a0  29 3b 20 2f 2a 20 77 65  20 63 61 6c 6c 20 74 68  |); /* we call th|
000092b0  65 20 66 6c 6f 6f 72 2f  63 65 69 6c 69 6e 67 20  |e floor/ceiling |
000092c0  66 75 6e 63 74 69 6f 6e  20 74 6f 20 63 6f 6c 6f  |function to colo|
000092d0  75 72 20 74 68 65 20 77  68 6f 6c 65 20 73 63 72  |ur the whole scr|
000092e0  65 65 6e 20 2a 2f 0a 2f  2a 20 74 68 65 6e 20 77  |een */./* then w|
000092f0  65 20 63 61 6c 6c 20 74  68 65 20 72 61 79 20 63  |e call the ray c|
00009300  61 73 74 65 72 20 74 6f  20 64 72 61 77 20 6f 76  |aster to draw ov|
00009310  65 72 20 69 74 20 2a 2f  0a 20 61 75 61 5f 72 61  |er it */. aua_ra|
00009320  79 63 61 73 74 65 72 28  76 69 65 77 5f 78 2c 76  |ycaster(view_x,v|
00009330  69 65 77 5f 79 2c 76 69  65 77 5f 61 6e 67 6c 65  |iew_y,view_angle|
00009340  29 3b 0a 0a 64 78 3d 64  79 3d 30 3b 0a 0a 2f 2a  |);..dx=dy=0;../*|
00009350  20 6e 6f 77 20 77 65 20  74 65 73 74 20 66 6f 72  | now we test for|
00009360  20 64 69 66 66 65 72 65  6e 74 20 6b 65 79 20 70  | different key p|
00009370  72 65 73 73 65 73 20 61  6e 64 20 74 61 6b 65 20  |resses and take |
00009380  61 63 74 69 6f 6e 20 61  63 63 6f 72 64 69 6e 67  |action according|
00009390  6c 79 20 2a 2f 0a 0a 69  66 28 6f 75 72 6c 69 62  |ly */..if(ourlib|
000093a0  5f 6b 65 79 64 6f 77 6e  28 31 36 29 3d 3d 32 35  |_keydown(16)==25|
000093b0  35 29 64 6f 6e 65 3d 31  3b 20 2f 2a 20 69 66 20  |5)done=1; /* if |
000093c0  51 20 69 73 20 70 72 65  73 73 65 64 20 74 68 65  |Q is pressed the|
000093d0  6e 20 71 75 69 74 20 2a  2f 0a 0a 2f 2a 20 4c 45  |n quit */../* LE|
000093e0  46 54 20 2a 2f 0a 69 66  28 6f 75 72 6c 69 62 5f  |FT */.if(ourlib_|
000093f0  6b 65 79 64 6f 77 6e 28  31 32 31 29 3d 3d 32 35  |keydown(121)==25|
00009400  35 29 0a 7b 0a 20 20 69  66 28 28 76 69 65 77 5f  |5).{.  if((view_|
00009410  61 6e 67 6c 65 2d 3d 41  4e 47 4c 45 5f 36 29 3c  |angle-=ANGLE_6)<|
00009420  41 4e 47 4c 45 5f 30 29  0a 20 20 76 69 65 77 5f  |ANGLE_0).  view_|
00009430  61 6e 67 6c 65 3d 41 4e  47 4c 45 5f 33 36 30 3b  |angle=ANGLE_360;|
00009440  0a 7d 0a 0a 2f 2a 52 49  47 48 54 20 2a 2f 0a 69  |.}../*RIGHT */.i|
00009450  66 28 6f 75 72 6c 69 62  5f 6b 65 79 64 6f 77 6e  |f(ourlib_keydown|
00009460  28 32 35 29 3d 3d 32 35  35 29 0a 7b 0a 20 20 69  |(25)==255).{.  i|
00009470  66 28 28 76 69 65 77 5f  61 6e 67 6c 65 2b 3d 41  |f((view_angle+=A|
00009480  4e 47 4c 45 5f 36 29 3e  41 4e 47 4c 45 5f 33 36  |NGLE_6)>ANGLE_36|
00009490  30 29 0a 20 20 76 69 65  77 5f 61 6e 67 6c 65 3d  |0).  view_angle=|
000094a0  41 4e 47 4c 45 5f 30 3b  0a 7d 0a 2f 2a 20 55 50  |ANGLE_0;.}./* UP|
000094b0  20 61 6e 64 20 44 4f 57  4e 20 2a 2f 0a 69 66 28  | and DOWN */.if(|
000094c0  6f 75 72 6c 69 62 5f 6b  65 79 64 6f 77 6e 28 35  |ourlib_keydown(5|
000094d0  37 29 3d 3d 32 35 35 29  0a 7b 0a 20 20 64 78 3d  |7)==255).{.  dx=|
000094e0  64 78 5f 74 61 62 6c 65  5b 76 69 65 77 5f 61 6e  |dx_table[view_an|
000094f0  67 6c 65 5d 3b 0a 20 20  64 79 3d 64 79 5f 74 61  |gle];.  dy=dy_ta|
00009500  62 6c 65 5b 76 69 65 77  5f 61 6e 67 6c 65 5d 3b  |ble[view_angle];|
00009510  0a 7d 0a 0a 69 66 28 6f  75 72 6c 69 62 5f 6b 65  |.}..if(ourlib_ke|
00009520  79 64 6f 77 6e 28 34 31  29 3d 3d 32 35 35 29 0a  |ydown(41)==255).|
00009530  7b 0a 0a 20 20 64 78 3d  2d 64 78 5f 74 61 62 6c  |{..  dx=-dx_tabl|
00009540  65 5b 76 69 65 77 5f 61  6e 67 6c 65 5d 3b 0a 20  |e[view_angle];. |
00009550  20 64 79 3d 2d 64 79 5f  74 61 62 6c 65 5b 76 69  | dy=-dy_table[vi|
00009560  65 77 5f 61 6e 67 6c 65  5d 3b 0a 7d 0a 0a 2f 2a  |ew_angle];.}../*|
00009570  20 4e 4f 57 20 77 65 20  6e 65 65 64 20 74 6f 20  | NOW we need to |
00009580  6d 6f 76 65 20 74 68 65  20 70 6c 61 79 65 72 20  |move the player |
00009590  61 6e 64 20 72 65 63 61  6c 63 75 6c 61 74 65 20  |and recalculate |
000095a0  74 68 65 20 63 65 6c 6c  20 74 68 65 20 76 69 65  |the cell the vie|
000095b0  77 65 72 20 69 73 20 69  6e 2c 20 61 6e 64 20 41  |wer is in, and A|
000095c0  4c 53 4f 20 63 68 65 63  6b 20 74 6f 20 73 65 65  |LSO check to see|
000095d0  20 69 66 20 74 68 65 20  70 6c 61 79 65 72 20 68  | if the player h|
000095e0  61 73 20 68 69 74 20 61  20 77 61 6c 6c 20 2a 2f  |as hit a wall */|
000095f0  0a 0a 2f 2a 20 57 61 74  63 68 20 66 6f 72 20 74  |../* Watch for t|
00009600  68 65 20 63 6f 6e 76 65  72 73 69 6f 6e 73 20 6f  |he conversions o|
00009610  66 20 66 69 78 65 64 20  70 6f 69 6e 74 20 61 6e  |f fixed point an|
00009620  64 20 74 68 69 6e 67 73  20 2a 2f 0a 0a 2f 2a 20  |d things */../* |
00009630  50 6c 61 79 65 72 20 58  20 61 63 74 75 61 6c 6c  |Player X actuall|
00009640  79 20 69 73 20 69 6e 20  6e 6f 72 6d 61 6c 20 6d  |y is in normal m|
00009650  61 74 68 73 20 2a 2f 0a  20 76 69 65 77 5f 78 3d  |aths */. view_x=|
00009660  20 28 69 6e 74 29 28 28  76 69 65 77 5f 78 3c 3c  | (int)((view_x<<|
00009670  31 36 29 2b 64 78 29 3e  3e 31 36 3b 0a 20 76 69  |16)+dx)>>16;. vi|
00009680  65 77 5f 79 3d 20 28 69  6e 74 29 28 28 76 69 65  |ew_y= (int)((vie|
00009690  77 5f 79 3c 3c 31 36 29  2b 64 79 29 3e 3e 31 36  |w_y<<16)+dy)>>16|
000096a0  3b 0a 0a 2f 2a 20 44 45  4d 4f 20 48 41 4e 44 4c  |;../* DEMO HANDL|
000096b0  49 4e 47 20 43 4f 44 45  20 43 4f 4d 45 53 20 48  |ING CODE COMES H|
000096c0  45 52 45 20 2a 2f 0a 2f  2a 20 4e 6f 74 65 20 74  |ERE */./* Note t|
000096d0  68 61 74 20 74 68 69 73  20 69 73 20 64 65 73 63  |hat this is desc|
000096e0  72 69 62 65 64 20 62 72  69 65 66 6c 79 20 69 6e  |ribed briefly in|
000096f0  20 61 72 74 69 63 6c 65  20 35 20 2a 2f 0a 0a 69  | article 5 */..i|
00009700  66 28 44 45 4d 4f 5f 57  52 49 54 45 20 7c 7c 20  |f(DEMO_WRITE || |
00009710  44 45 4d 4f 5f 52 45 41  44 29 0a 7b 0a 74 76 69  |DEMO_READ).{.tvi|
00009720  65 77 5f 78 3d 76 69 65  77 5f 78 3b 0a 74 76 69  |ew_x=view_x;.tvi|
00009730  65 77 5f 79 3d 76 69 65  77 5f 79 3b 0a 74 76 69  |ew_y=view_y;.tvi|
00009740  65 77 5f 61 6e 67 6c 65  3d 76 69 65 77 5f 61 6e  |ew_angle=view_an|
00009750  67 6c 65 3b 0a 69 66 28  44 45 4d 4f 5f 57 52 49  |gle;.if(DEMO_WRI|
00009760  54 45 29 0a 7b 0a 20 20  2f 2a 20 54 68 65 73 65  |TE).{.  /* These|
00009770  20 6c 69 6e 65 73 20 63  61 6e 20 62 65 20 75 73  | lines can be us|
00009780  65 64 20 74 6f 20 72 65  63 6f 72 64 20 74 68 65  |ed to record the|
00009790  20 64 69 72 65 63 74 69  6f 6e 20 6f 66 20 61 20  | direction of a |
000097a0  6d 6f 76 69 6e 67 20 6f  62 6a 65 63 74 2a 2f 0a  |moving object*/.|
000097b0  20 20 2f 2a 74 76 69 65  77 5f 61 6e 67 6c 65 3d  |  /*tview_angle=|
000097c0  31 39 3b 0a 20 20 69 66  28 76 69 65 77 5f 61 6e  |19;.  if(view_an|
000097d0  67 6c 65 3e 41 4e 47 4c  45 5f 30 20 26 26 20 76  |gle>ANGLE_0 && v|
000097e0  69 65 77 5f 61 6e 67 6c  65 3c 41 4e 47 4c 45 5f  |iew_angle<ANGLE_|
000097f0  39 30 29 74 76 69 65 77  5f 61 6e 67 6c 65 3d 31  |90)tview_angle=1|
00009800  39 3b 0a 20 20 69 66 28  76 69 65 77 5f 61 6e 67  |9;.  if(view_ang|
00009810  6c 65 3e 3d 41 4e 47 4c  45 5f 39 30 20 26 26 20  |le>=ANGLE_90 && |
00009820  76 69 65 77 5f 61 6e 67  6c 65 3c 41 4e 47 4c 45  |view_angle<ANGLE|
00009830  5f 31 38 30 29 74 76 69  65 77 5f 61 6e 67 6c 65  |_180)tview_angle|
00009840  3d 31 37 3b 0a 20 20 69  66 28 76 69 65 77 5f 61  |=17;.  if(view_a|
00009850  6e 67 6c 65 3e 3d 41 4e  47 4c 45 5f 31 38 30 20  |ngle>=ANGLE_180 |
00009860  26 26 20 76 69 65 77 5f  61 6e 67 6c 65 3c 41 4e  |&& view_angle<AN|
00009870  47 4c 45 5f 32 37 30 29  74 76 69 65 77 5f 61 6e  |GLE_270)tview_an|
00009880  67 6c 65 3d 31 35 3b 0a  20 20 69 66 28 76 69 65  |gle=15;.  if(vie|
00009890  77 5f 61 6e 67 6c 65 3e  3d 41 4e 47 4c 45 5f 32  |w_angle>=ANGLE_2|
000098a0  37 30 20 26 26 20 76 69  65 77 5f 61 6e 67 6c 65  |70 && view_angle|
000098b0  3c 41 4e 47 4c 45 5f 33  36 30 29 74 76 69 65 77  |<ANGLE_360)tview|
000098c0  5f 61 6e 67 6c 65 3d 31  30 3b 2a 2f 0a 0a 20 20  |_angle=10;*/..  |
000098d0  66 70 72 69 6e 74 66 28  64 65 6d 6f 5f 66 69 6c  |fprintf(demo_fil|
000098e0  65 2c 22 25 64 20 25 64  20 25 64 20 22 2c 74 76  |e,"%d %d %d ",tv|
000098f0  69 65 77 5f 78 2c 74 76  69 65 77 5f 79 2c 74 76  |iew_x,tview_y,tv|
00009900  69 65 77 5f 61 6e 67 6c  65 29 3b 0a 0a 7d 0a 69  |iew_angle);..}.i|
00009910  66 28 44 45 4d 4f 5f 52  45 41 44 29 69 66 28 28  |f(DEMO_READ)if((|
00009920  66 73 63 61 6e 66 28 64  65 6d 6f 5f 66 69 6c 65  |fscanf(demo_file|
00009930  2c 22 25 64 20 25 64 20  25 64 20 22 2c 26 74 76  |,"%d %d %d ",&tv|
00009940  69 65 77 5f 78 2c 26 74  76 69 65 77 5f 79 2c 26  |iew_x,&tview_y,&|
00009950  74 76 69 65 77 5f 61 6e  67 6c 65 29 29 3d 3d 45  |tview_angle))==E|
00009960  4f 46 29 72 65 77 69 6e  64 28 64 65 6d 6f 5f 66  |OF)rewind(demo_f|
00009970  69 6c 65 29 3b 0a 76 69  65 77 5f 78 3d 74 76 69  |ile);.view_x=tvi|
00009980  65 77 5f 78 3b 0a 76 69  65 77 5f 79 3d 74 76 69  |ew_x;.view_y=tvi|
00009990  65 77 5f 79 3b 0a 76 69  65 77 5f 61 6e 67 6c 65  |ew_y;.view_angle|
000099a0  3d 74 76 69 65 77 5f 61  6e 67 6c 65 3b 0a 7d 0a  |=tview_angle;.}.|
000099b0  2f 2a 20 4e 45 57 20 4f  50 54 49 4d 49 5a 45 44  |/* NEW OPTIMIZED|
000099c0  20 56 45 52 53 49 4f 4e  53 20 4f 46 20 4d 4f 56  | VERSIONS OF MOV|
000099d0  49 4e 47 20 54 48 45 20  50 4c 41 59 45 52 20 2a  |ING THE PLAYER *|
000099e0  2f 0a 0a 20 78 5f 63 65  6c 6c 20 3d 20 76 69 65  |/.. x_cell = vie|
000099f0  77 5f 78 3e 3e 36 3b 0a  20 79 5f 63 65 6c 6c 20  |w_x>>6;. y_cell |
00009a00  3d 20 76 69 65 77 5f 79  3e 3e 36 3b 0a 0a 20 78  |= view_y>>6;.. x|
00009a10  5f 73 75 62 5f 63 65 6c  6c 20 3d 20 76 69 65 77  |_sub_cell = view|
00009a20  5f 78 20 26 20 30 78 30  30 33 66 3b 0a 20 79 5f  |_x & 0x003f;. y_|
00009a30  73 75 62 5f 63 65 6c 6c  20 3d 20 76 69 65 77 5f  |sub_cell = view_|
00009a40  79 20 26 20 30 78 30 30  33 66 3b 0a 0a 2f 2a 20  |y & 0x003f;../* |
00009a50  43 48 45 43 4b 20 74 6f  20 73 65 65 20 69 66 20  |CHECK to see if |
00009a60  70 6c 61 79 65 72 20 68  61 73 20 77 61 6c 6b 65  |player has walke|
00009a70  64 20 69 6e 74 6f 20 77  61 6c 6c 73 20 2a 2f 0a  |d into walls */.|
00009a80  20 69 66 20 28 28 64 78  3e 3e 38 29 3e 30 20 29  | if ((dx>>8)>0 )|
00009a90  7b 0a 20 69 66 20 28 28  77 6f 72 6c 64 5b 79 5f  |{. if ((world[y_|
00009aa0  63 65 6c 6c 5d 5b 78 5f  63 65 6c 6c 2b 31 5d 20  |cell][x_cell+1] |
00009ab0  21 3d 20 30 29 20 20 26  26 20 28 78 5f 73 75 62  |!= 0)  && (x_sub|
00009ac0  5f 63 65 6c 6c 3e 28 43  45 4c 4c 5f 58 5f 53 49  |_cell>(CELL_X_SI|
00009ad0  5a 45 2d 43 4c 4f 53 45  53 54 29 29 29 0a 20 20  |ZE-CLOSEST))).  |
00009ae0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 7b 0a  |              {.|
00009af0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00009b00  76 69 65 77 5f 78 2d 3d  20 28 78 5f 73 75 62 5f  |view_x-= (x_sub_|
00009b10  63 65 6c 6c 2d 28 43 45  4c 4c 5f 58 5f 53 49 5a  |cell-(CELL_X_SIZ|
00009b20  45 2d 43 4c 4f 53 45 53  54 20 29 29 3b 0a 20 20  |E-CLOSEST ));.  |
00009b30  20 20 20 20 20 20 20 20  20 20 20 20 20 20 7d 0a  |              }.|
00009b40  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00009b50  7d 0a 20 65 6c 73 65 0a  20 7b 0a 20 69 66 20 28  |}. else. {. if (|
00009b60  20 28 77 6f 72 6c 64 5b  79 5f 63 65 6c 6c 5d 5b  | (world[y_cell][|
00009b70  78 5f 63 65 6c 6c 2d 31  5d 20 21 3d 20 30 29 20  |x_cell-1] != 0) |
00009b80  20 26 26 20 28 78 5f 73  75 62 5f 63 65 6c 6c 20  | && (x_sub_cell |
00009b90  3c 20 28 43 4c 4f 53 45  53 54 29 20 29 20 29 0a  |< (CLOSEST) ) ).|
00009ba0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00009bb0  7b 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |{.              |
00009bc0  20 20 76 69 65 77 5f 78  2b 3d 20 28 43 4c 4f 53  |  view_x+= (CLOS|
00009bd0  45 53 54 2d 78 5f 73 75  62 5f 63 65 6c 6c 29 20  |EST-x_sub_cell) |
00009be0  3b 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;.              |
00009bf0  20 20 7d 0a 20 7d 0a 0a  20 69 66 20 28 28 64 79  |  }. }.. if ((dy|
00009c00  3e 3e 38 29 3e 30 20 29  7b 0a 20 69 66 20 28 20  |>>8)>0 ){. if ( |
00009c10  28 77 6f 72 6c 64 5b 28  79 5f 63 65 6c 6c 2b 31  |(world[(y_cell+1|
00009c20  29 5d 5b 78 5f 63 65 6c  6c 5d 20 21 3d 20 30 29  |)][x_cell] != 0)|
00009c30  20 20 26 26 0a 20 20 20  20 20 20 20 20 20 20 20  |  &&.           |
00009c40  20 20 20 20 20 28 79 5f  73 75 62 5f 63 65 6c 6c  |     (y_sub_cell|
00009c50  20 3e 20 28 43 45 4c 4c  5f 59 5f 53 49 5a 45 2d  | > (CELL_Y_SIZE-|
00009c60  43 4c 4f 53 45 53 54 20  29 20 29 20 29 0a 20 20  |CLOSEST ) ) ).  |
00009c70  20 20 20 20 20 20 20 20  20 20 20 20 20 20 7b 0a  |              {.|
00009c80  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00009c90  76 69 65 77 5f 79 2d 3d  20 28 79 5f 73 75 62 5f  |view_y-= (y_sub_|
00009ca0  63 65 6c 6c 2d 28 43 45  4c 4c 5f 59 5f 53 49 5a  |cell-(CELL_Y_SIZ|
00009cb0  45 2d 43 4c 4f 53 45 53  54 20 29 29 3b 0a 20 20  |E-CLOSEST ));.  |
00009cc0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 7d 0a  |              }.|
00009cd0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00009ce0  7d 0a 20 65 6c 73 65 0a  20 7b 0a 20 69 66 20 28  |}. else. {. if (|
00009cf0  20 28 77 6f 72 6c 64 5b  28 79 5f 63 65 6c 6c 2d  | (world[(y_cell-|
00009d00  31 29 5d 5b 78 5f 63 65  6c 6c 5d 20 21 3d 20 30  |1)][x_cell] != 0|
00009d10  29 20 20 26 26 20 28 79  5f 73 75 62 5f 63 65 6c  |)  && (y_sub_cel|
00009d20  6c 20 3c 20 28 43 4c 4f  53 45 53 54 29 20 29 20  |l < (CLOSEST) ) |
00009d30  29 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |).              |
00009d40  20 20 7b 0a 20 20 20 20  20 20 20 20 20 20 20 20  |  {.            |
00009d50  20 20 20 20 76 69 65 77  5f 79 2b 3d 20 28 43 4c  |    view_y+= (CL|
00009d60  4f 53 45 53 54 2d 79 5f  73 75 62 5f 63 65 6c 6c  |OSEST-y_sub_cell|
00009d70  29 3b 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |);.             |
00009d80  20 20 20 7d 0a 20 7d 0a  0a 0a 0a 2f 2a 20 4e 45  |   }. }..../* NE|
00009d90  57 20 44 4f 4f 52 20 63  6f 64 65 2e 20 41 20 22  |W DOOR code. A "|
00009da0  70 72 6f 62 65 22 20 69  73 20 73 65 6e 74 20 6f  |probe" is sent o|
00009db0  75 74 20 69 6e 20 66 72  6f 6e 74 20 6f 66 20 74  |ut in front of t|
00009dc0  68 65 20 70 6c 61 79 65  72 2c 20 69 66 20 61 20  |he player, if a |
00009dd0  64 6f 6f 72 20 74 69 6c  65 20 69 73 20 66 6f 75  |door tile is fou|
00009de0  6e 64 20 6e 65 61 72 20  69 74 20 74 68 65 6e 20  |nd near it then |
00009df0  74 68 65 20 62 6c 6f 63  6b 20 69 73 20 64 65 73  |the block is des|
00009e00  74 72 6f 79 65 64 2e 20  2a 2f 0a 0a 69 66 28 6f  |troyed. */..if(o|
00009e10  75 72 6c 69 62 5f 6b 65  79 64 6f 77 6e 28 39 38  |urlib_keydown(98|
00009e20  29 3d 3d 32 35 35 29 0a  7b 0a 2f 2a 20 55 73 65  |)==255).{./* Use|
00009e30  20 73 69 6d 69 6c 61 72  20 74 65 63 68 6e 69 71  | similar techniq|
00009e40  75 65 73 20 74 6f 20 61  62 6f 76 65 20 74 6f 20  |ues to above to |
00009e50  66 69 6e 64 20 64 6f 6f  72 20 2a 2f 0a 0a 64 78  |find door */..dx|
00009e60  3d 64 78 5f 74 61 62 6c  65 5b 76 69 65 77 5f 61  |=dx_table[view_a|
00009e70  6e 67 6c 65 5d 3b 0a 64  79 3d 64 79 5f 74 61 62  |ngle];.dy=dy_tab|
00009e80  6c 65 5b 76 69 65 77 5f  61 6e 67 6c 65 5d 3b 0a  |le[view_angle];.|
00009e90  0a 2f 2a 20 43 61 6c 63  75 6c 61 74 65 20 64 6f  |./* Calculate do|
00009ea0  6f 72 20 78 20 61 6e 64  20 79 2c 20 69 74 20 69  |or x and y, it i|
00009eb0  73 20 69 6e 20 6e 6f 72  6d 61 6c 20 6d 61 74 68  |s in normal math|
00009ec0  73 20 2a 2f 0a 20 64 6f  6f 72 5f 78 3d 20 28 69  |s */. door_x= (i|
00009ed0  6e 74 29 28 28 76 69 65  77 5f 78 3c 3c 31 36 29  |nt)((view_x<<16)|
00009ee0  2b 28 64 78 3c 3c 33 29  29 3e 3e 31 36 3b 0a 20  |+(dx<<3))>>16;. |
00009ef0  64 6f 6f 72 5f 79 3d 20  28 69 6e 74 29 28 28 76  |door_y= (int)((v|
00009f00  69 65 77 5f 79 3c 3c 31  36 29 2b 28 64 79 3c 3c  |iew_y<<16)+(dy<<|
00009f10  33 29 29 3e 3e 31 36 3b  0a 0a 2f 2a 20 4e 45 57  |3))>>16;../* NEW|
00009f20  20 4f 50 54 49 4d 49 5a  45 44 20 56 45 52 53 49  | OPTIMIZED VERSI|
00009f30  4f 4e 53 20 4f 46 20 46  49 4e 44 49 4e 20 44 4f  |ONS OF FINDIN DO|
00009f40  4f 52 53 20 2a 2f 0a 2f  2a 20 6e 6f 77 20 66 69  |ORS */./* now fi|
00009f50  6e 64 20 74 68 65 20 63  65 6c 6c 20 77 65 20 61  |nd the cell we a|
00009f60  72 65 20 6c 6f 6f 6b 69  6e 67 20 69 6e 20 77 69  |re looking in wi|
00009f70  74 68 20 74 68 65 20 73  74 61 6e 64 61 72 64 20  |th the standard |
00009f80  65 71 75 61 74 69 6f 6e  20 2a 2f 0a 0a 20 78 5f  |equation */.. x_|
00009f90  63 65 6c 6c 20 3d 20 28  69 6e 74 29 64 6f 6f 72  |cell = (int)door|
00009fa0  5f 78 3e 3e 36 3b 0a 20  79 5f 63 65 6c 6c 20 3d  |_x>>6;. y_cell =|
00009fb0  20 28 69 6e 74 29 64 6f  6f 72 5f 79 3e 3e 36 3b  | (int)door_y>>6;|
00009fc0  0a 0a 2f 2a 20 43 68 65  63 6b 20 69 66 20 61 20  |../* Check if a |
00009fd0  64 6f 6f 72 73 20 69 73  20 70 72 65 73 65 6e 74  |doors is present|
00009fe0  20 2a 2f 0a 0a 69 66 28  77 6f 72 6c 64 5b 79 5f  | */..if(world[y_|
00009ff0  63 65 6c 6c 5d 5b 78 5f  63 65 6c 6c 5d 3d 3d 37  |cell][x_cell]==7|
0000a000  20 2f 2a 20 4f 52 20 57  48 41 54 45 56 45 52 20  | /* OR WHATEVER |
0000a010  59 4f 55 20 4c 49 4b 45  20 2a 2f 29 0a 7b 0a 77  |YOU LIKE */).{.w|
0000a020  6f 72 6c 64 5b 79 5f 63  65 6c 6c 5d 5b 78 5f 63  |orld[y_cell][x_c|
0000a030  65 6c 6c 5d 3d 30 3b 20  2f 2a 20 6f 72 20 61 6c  |ell]=0; /* or al|
0000a040  74 65 72 6e 61 74 69 76  65 6c 79 20 64 6f 20 77  |ternatively do w|
0000a050  68 61 74 20 79 6f 75 20  6c 69 6b 65 20 2a 2f 0a  |hat you like */.|
0000a060  7d 0a 7d 0a 0a 0a 2f 2a  20 4e 45 57 20 53 49 4d  |}.}.../* NEW SIM|
0000a070  50 4c 45 20 53 48 4f 4f  54 45 52 20 63 6f 64 65  |PLE SHOOTER code|
0000a080  2e 20 59 6f 75 20 63 61  6e 20 61 64 64 20 61 73  |. You can add as|
0000a090  20 6d 61 6e 79 20 66 75  72 74 68 65 72 20 74 65  | many further te|
0000a0a0  73 74 73 20 61 73 20 79  6f 75 20 6c 69 6b 65 20  |sts as you like |
0000a0b0  2a 2f 0a 2f 2a 20 4c 69  6b 65 20 6d 61 6e 79 20  |*/./* Like many |
0000a0c0  61 64 64 69 74 69 6f 6e  73 20 74 68 69 73 20 6d  |additions this m|
0000a0d0  6f 6e 74 68 2c 20 74 68  69 73 20 69 73 20 6a 75  |onth, this is ju|
0000a0e0  73 74 20 61 20 73 69 6d  70 6c 65 20 73 74 61 72  |st a simple star|
0000a0f0  74 65 72 20 66 6f 72 20  79 6f 75 20 61 6c 6c 20  |ter for you all |
0000a100  2a 2f 0a 0a 69 66 28 6f  75 72 6c 69 62 5f 6b 65  |*/..if(ourlib_ke|
0000a110  79 64 6f 77 6e 28 37 29  3d 3d 32 35 35 29 0a 7b  |ydown(7)==255).{|
0000a120  0a 2f 2a 20 55 73 65 20  73 69 6d 69 6c 61 72 20  |./* Use similar |
0000a130  74 65 63 68 6e 69 71 75  65 73 20 74 6f 20 61 62  |techniques to ab|
0000a140  6f 76 65 20 74 6f 20 66  69 6e 64 20 64 6f 6f 72  |ove to find door|
0000a150  20 2a 2f 0a 70 75 74 63  68 61 72 28 27 5c 61 27  | */.putchar('\a'|
0000a160  29 3b 0a 64 78 3d 64 78  5f 74 61 62 6c 65 5b 76  |);.dx=dx_table[v|
0000a170  69 65 77 5f 61 6e 67 6c  65 5d 3b 0a 64 79 3d 64  |iew_angle];.dy=d|
0000a180  79 5f 74 61 62 6c 65 5b  76 69 65 77 5f 61 6e 67  |y_table[view_ang|
0000a190  6c 65 5d 3b 0a 0a 0a 20  64 6f 6f 72 5f 78 3d 20  |le];... door_x= |
0000a1a0  28 69 6e 74 29 28 28 76  69 65 77 5f 78 3c 3c 31  |(int)((view_x<<1|
0000a1b0  36 29 2b 28 64 78 3c 3c  31 29 29 3e 3e 31 36 3b  |6)+(dx<<1))>>16;|
0000a1c0  0a 20 64 6f 6f 72 5f 79  3d 20 28 69 6e 74 29 28  |. door_y= (int)(|
0000a1d0  28 76 69 65 77 5f 79 3c  3c 31 36 29 2b 28 64 79  |(view_y<<16)+(dy|
0000a1e0  3c 3c 31 29 29 3e 3e 31  36 3b 0a 0a 0a 0a 20 78  |<<1))>>16;.... x|
0000a1f0  5f 63 65 6c 6c 20 3d 20  28 69 6e 74 29 64 6f 6f  |_cell = (int)doo|
0000a200  72 5f 78 3e 3e 36 3b 0a  20 79 5f 63 65 6c 6c 20  |r_x>>6;. y_cell |
0000a210  3d 20 28 69 6e 74 29 64  6f 6f 72 5f 79 3e 3e 36  |= (int)door_y>>6|
0000a220  3b 0a 2f 2a 20 43 68 65  63 6b 20 69 66 20 61 20  |;./* Check if a |
0000a230  6f 62 6a 65 63 74 20 69  73 20 70 72 65 73 65 6e  |object is presen|
0000a240  74 20 2a 2f 0a 69 66 28  6f 62 6a 65 63 74 73 5b  |t */.if(objects[|
0000a250  79 5f 63 65 6c 6c 5d 5b  78 5f 63 65 6c 6c 5d 2f  |y_cell][x_cell]/|
0000a260  2a 20 4f 52 20 57 48 41  54 45 56 45 52 20 59 4f  |* OR WHATEVER YO|
0000a270  55 20 4c 49 4b 45 20 2a  2f 29 0a 7b 0a 6f 62 6a  |U LIKE */).{.obj|
0000a280  65 63 74 73 5b 79 5f 63  65 6c 6c 5d 5b 78 5f 63  |ects[y_cell][x_c|
0000a290  65 6c 6c 5d 3d 30 3b 20  2f 2a 20 6f 72 20 61 6c  |ell]=0; /* or al|
0000a2a0  74 65 72 6e 61 74 69 76  65 6c 79 20 64 6f 20 77  |ternatively do w|
0000a2b0  68 61 74 20 79 6f 75 20  6c 69 6b 65 20 2a 2f 0a  |hat you like */.|
0000a2c0  7d 0a 65 6c 73 65 0a 7b  0a 0a 0a 20 64 6f 6f 72  |}.else.{... door|
0000a2d0  5f 78 3d 20 28 69 6e 74  29 28 28 76 69 65 77 5f  |_x= (int)((view_|
0000a2e0  78 3c 3c 31 36 29 2b 28  64 78 3c 3c 32 29 29 3e  |x<<16)+(dx<<2))>|
0000a2f0  3e 31 36 3b 0a 20 64 6f  6f 72 5f 79 3d 20 28 69  |>16;. door_y= (i|
0000a300  6e 74 29 28 28 76 69 65  77 5f 79 3c 3c 31 36 29  |nt)((view_y<<16)|
0000a310  2b 28 64 79 3c 3c 32 29  29 3e 3e 31 36 3b 0a 0a  |+(dy<<2))>>16;..|
0000a320  20 78 5f 63 65 6c 6c 20  3d 20 28 69 6e 74 29 64  | x_cell = (int)d|
0000a330  6f 6f 72 5f 78 3e 3e 36  3b 0a 20 79 5f 63 65 6c  |oor_x>>6;. y_cel|
0000a340  6c 20 3d 20 28 69 6e 74  29 64 6f 6f 72 5f 79 3e  |l = (int)door_y>|
0000a350  3e 36 3b 0a 2f 2a 20 43  68 65 63 6b 20 69 66 20  |>6;./* Check if |
0000a360  61 20 6f 62 6a 65 63 74  20 69 73 20 70 72 65 73  |a object is pres|
0000a370  65 6e 74 20 2a 2f 0a 69  66 28 6f 62 6a 65 63 74  |ent */.if(object|
0000a380  73 5b 79 5f 63 65 6c 6c  5d 5b 78 5f 63 65 6c 6c  |s[y_cell][x_cell|
0000a390  5d 2f 2a 20 4f 52 20 57  48 41 54 45 56 45 52 20  |]/* OR WHATEVER |
0000a3a0  59 4f 55 20 4c 49 4b 45  20 2a 2f 29 0a 7b 0a 6f  |YOU LIKE */).{.o|
0000a3b0  62 6a 65 63 74 73 5b 79  5f 63 65 6c 6c 5d 5b 78  |bjects[y_cell][x|
0000a3c0  5f 63 65 6c 6c 5d 3d 30  3b 20 2f 2a 20 6f 72 20  |_cell]=0; /* or |
0000a3d0  61 6c 74 65 72 6e 61 74  69 76 65 6c 79 20 64 6f  |alternatively do|
0000a3e0  20 77 68 61 74 20 79 6f  75 20 6c 69 6b 65 20 2a  | what you like *|
0000a3f0  2f 0a 7d 0a 65 6c 73 65  0a 7b 0a 0a 2f 2a 20 43  |/.}.else.{../* C|
0000a400  61 6c 63 75 6c 61 74 65  20 62 75 6c 6c 65 74 73  |alculate bullets|
0000a410  20 78 20 61 6e 64 20 79  2c 20 69 74 20 69 73 20  | x and y, it is |
0000a420  69 6e 20 6e 6f 72 6d 61  6c 20 6d 61 74 68 73 20  |in normal maths |
0000a430  2a 2f 0a 20 64 6f 6f 72  5f 78 3d 20 28 69 6e 74  |*/. door_x= (int|
0000a440  29 28 28 76 69 65 77 5f  78 3c 3c 31 36 29 2b 28  |)((view_x<<16)+(|
0000a450  64 78 3c 3c 33 29 29 3e  3e 31 36 3b 0a 20 64 6f  |dx<<3))>>16;. do|
0000a460  6f 72 5f 79 3d 20 28 69  6e 74 29 28 28 76 69 65  |or_y= (int)((vie|
0000a470  77 5f 79 3c 3c 31 36 29  2b 28 64 79 3c 3c 33 29  |w_y<<16)+(dy<<3)|
0000a480  29 3e 3e 31 36 3b 0a 0a  20 78 5f 63 65 6c 6c 20  |)>>16;.. x_cell |
0000a490  3d 20 28 69 6e 74 29 64  6f 6f 72 5f 78 3e 3e 36  |= (int)door_x>>6|
0000a4a0  3b 0a 20 79 5f 63 65 6c  6c 20 3d 20 28 69 6e 74  |;. y_cell = (int|
0000a4b0  29 64 6f 6f 72 5f 79 3e  3e 36 3b 0a 2f 2a 20 43  |)door_y>>6;./* C|
0000a4c0  68 65 63 6b 20 69 66 20  61 20 64 6f 6f 72 73 20  |heck if a doors |
0000a4d0  69 73 20 70 72 65 73 65  6e 74 20 2a 2f 0a 69 66  |is present */.if|
0000a4e0  28 6f 62 6a 65 63 74 73  5b 79 5f 63 65 6c 6c 5d  |(objects[y_cell]|
0000a4f0  5b 78 5f 63 65 6c 6c 5d  2f 2a 20 4f 52 20 57 48  |[x_cell]/* OR WH|
0000a500  41 54 45 56 45 52 20 59  4f 55 20 4c 49 4b 45 20  |ATEVER YOU LIKE |
0000a510  2a 2f 29 0a 7b 0a 6f 62  6a 65 63 74 73 5b 79 5f  |*/).{.objects[y_|
0000a520  63 65 6c 6c 5d 5b 78 5f  63 65 6c 6c 5d 3d 30 3b  |cell][x_cell]=0;|
0000a530  20 2f 2a 20 6f 72 20 61  6c 74 65 72 6e 61 74 69  | /* or alternati|
0000a540  76 65 6c 79 20 64 6f 20  77 68 61 74 20 79 6f 75  |vely do what you|
0000a550  20 6c 69 6b 65 20 2a 2f  0a 7d 0a 0a 7d 0a 0a 7d  | like */.}..}..}|
0000a560  0a 0a 0a 0a 0a 0a 7d 0a  0a 0a 0a 2f 2a 20 4e 65  |......}..../* Ne|
0000a570  77 20 4f 62 6a 65 63 74  20 43 6f 64 65 20 2a 2a  |w Object Code **|
0000a580  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
0000a590  20 41 64 64 65 64 20 41  72 74 69 63 6c 65 20 35  | Added Article 5|
0000a5a0  2c 20 67 6f 6f 64 20 73  74 75 66 66 21 20 20 20  |, good stuff!   |
0000a5b0  2a 2f 0a 2f 2a 20 54 68  69 73 20 63 6f 64 65 20  |*/./* This code |
0000a5c0  63 79 63 6c 65 73 20 74  68 72 6f 75 67 68 20 74  |cycles through t|
0000a5d0  68 65 20 6f 62 6a 65 63  74 73 20 61 6e 64 20 70  |he objects and p|
0000a5e0  6c 6f 74 73 20 74 68 65  6d 20 61 70 70 72 6f 70  |lots them approp|
0000a5f0  72 69 61 74 65 6c 79 0a  20 20 20 69 66 20 74 68  |riately.   if th|
0000a600  65 79 20 61 72 65 20 76  69 73 69 62 6c 65 20 62  |ey are visible b|
0000a610  79 20 74 68 65 20 76 69  65 77 65 72 2e 20 53 65  |y the viewer. Se|
0000a620  65 20 41 52 54 49 43 4c  45 20 35 20 66 6f 72 20  |e ARTICLE 5 for |
0000a630  6d 6f 72 65 20 64 65 74  61 69 6c 73 2e 2a 2f 0a  |more details.*/.|
0000a640  0a 2f 2a 20 46 69 72 73  74 6c 79 2c 20 73 65 74  |./* Firstly, set|
0000a650  20 75 70 20 76 61 72 69  61 62 6c 65 73 20 77 65  | up variables we|
0000a660  20 6b 6e 6f 77 20 61 72  65 20 67 6f 69 6e 67 20  | know are going |
0000a670  74 6f 20 62 65 20 75 73  65 64 20 2a 2f 0a 76 61  |to be used */.va|
0000a680  72 69 61 62 6c 65 73 5b  30 5d 3d 28 69 6e 74 29  |riables[0]=(int)|
0000a690  73 63 72 65 65 6e 5f 61  64 64 72 65 73 73 3b 0a  |screen_address;.|
0000a6a0  76 61 72 69 61 62 6c 65  73 5b 32 5d 3d 53 43 52  |variables[2]=SCR|
0000a6b0  45 45 4e 5f 48 45 49 47  48 54 3b 0a 2f 2a 20 4e  |EEN_HEIGHT;./* N|
0000a6c0  65 78 74 20 77 65 20 6c  6f 6f 70 20 74 68 72 6f  |ext we loop thro|
0000a6d0  75 67 68 20 61 6c 6c 20  74 68 65 20 76 69 73 69  |ugh all the visi|
0000a6e0  62 6c 65 20 73 71 75 61  72 65 73 20 74 6f 20 73  |ble squares to s|
0000a6f0  65 65 20 69 66 20 61 6e  20 6f 62 6a 65 63 74 20  |ee if an object |
0000a700  68 61 73 20 62 65 65 6e  20 66 6f 75 6e 64 20 2a  |has been found *|
0000a710  2f 0a 0a 69 66 28 76 69  65 77 5f 61 6e 67 6c 65  |/..if(view_angle|
0000a720  3e 41 4e 47 4c 45 5f 30  20 26 26 20 76 69 65 77  |>ANGLE_0 && view|
0000a730  5f 61 6e 67 6c 65 3c 41  4e 47 4c 45 5f 39 30 29  |_angle<ANGLE_90)|
0000a740  0a 7b 0a 73 74 61 72 74  5f 78 3d 28 76 69 65 77  |.{.start_x=(view|
0000a750  5f 78 3e 3e 36 29 2b 31  35 3b 0a 73 74 61 72 74  |_x>>6)+15;.start|
0000a760  5f 79 3d 28 76 69 65 77  5f 79 3e 3e 36 29 2b 31  |_y=(view_y>>6)+1|
0000a770  35 3b 0a 73 74 6f 70 5f  78 3d 28 76 69 65 77 5f  |5;.stop_x=(view_|
0000a780  78 3e 3e 36 29 2d 35 3b  0a 73 74 6f 70 5f 79 3d  |x>>6)-5;.stop_y=|
0000a790  28 76 69 65 77 5f 79 3e  3e 36 29 2d 35 3b 0a 6d  |(view_y>>6)-5;.m|
0000a7a0  6f 76 65 5f 78 3d 2d 31  3b 0a 6d 6f 76 65 5f 79  |ove_x=-1;.move_y|
0000a7b0  3d 2d 31 3b 0a 69 66 28  73 74 6f 70 5f 78 3c 30  |=-1;.if(stop_x<0|
0000a7c0  29 73 74 6f 70 5f 78 3d  30 3b 69 66 28 73 74 6f  |)stop_x=0;if(sto|
0000a7d0  70 5f 78 3e 36 33 29 73  74 6f 70 5f 78 3d 36 33  |p_x>63)stop_x=63|
0000a7e0  3b 0a 69 66 28 73 74 61  72 74 5f 78 3c 30 29 73  |;.if(start_x<0)s|
0000a7f0  74 61 72 74 5f 78 3d 30  3b 69 66 28 73 74 61 72  |tart_x=0;if(star|
0000a800  74 5f 78 3e 36 33 29 73  74 61 72 74 5f 78 3d 36  |t_x>63)start_x=6|
0000a810  33 3b 0a 69 66 28 73 74  6f 70 5f 79 3c 30 29 73  |3;.if(stop_y<0)s|
0000a820  74 6f 70 5f 79 3d 30 3b  69 66 28 73 74 6f 70 5f  |top_y=0;if(stop_|
0000a830  79 3e 36 33 29 73 74 6f  70 5f 79 3d 36 33 3b 0a  |y>63)stop_y=63;.|
0000a840  69 66 28 73 74 61 72 74  5f 79 3c 30 29 73 74 61  |if(start_y<0)sta|
0000a850  72 74 5f 79 3d 30 3b 69  66 28 73 74 61 72 74 5f  |rt_y=0;if(start_|
0000a860  79 3e 36 33 29 73 74 61  72 74 5f 79 3d 36 33 3b  |y>63)start_y=63;|
0000a870  0a 0a 0a 7d 0a 65 6c 73  65 20 69 66 28 76 69 65  |...}.else if(vie|
0000a880  77 5f 61 6e 67 6c 65 3e  3d 41 4e 47 4c 45 5f 39  |w_angle>=ANGLE_9|
0000a890  30 20 26 26 20 76 69 65  77 5f 61 6e 67 6c 65 3c  |0 && view_angle<|
0000a8a0  41 4e 47 4c 45 5f 31 38  30 29 0a 7b 0a 20 20 73  |ANGLE_180).{.  s|
0000a8b0  74 61 72 74 5f 78 3d 28  76 69 65 77 5f 78 3e 3e  |tart_x=(view_x>>|
0000a8c0  36 29 2d 31 35 3b 0a 20  20 73 74 61 72 74 5f 79  |6)-15;.  start_y|
0000a8d0  3d 28 76 69 65 77 5f 79  3e 3e 36 29 2b 31 35 3b  |=(view_y>>6)+15;|
0000a8e0  0a 20 20 73 74 6f 70 5f  78 3d 28 76 69 65 77 5f  |.  stop_x=(view_|
0000a8f0  78 3e 3e 36 29 2b 35 3b  0a 20 20 73 74 6f 70 5f  |x>>6)+5;.  stop_|
0000a900  79 3d 28 76 69 65 77 5f  79 3e 3e 36 29 2d 35 3b  |y=(view_y>>6)-5;|
0000a910  0a 6d 6f 76 65 5f 78 3d  31 3b 0a 6d 6f 76 65 5f  |.move_x=1;.move_|
0000a920  79 3d 2d 31 3b 0a 69 66  28 73 74 6f 70 5f 78 3c  |y=-1;.if(stop_x<|
0000a930  30 29 73 74 6f 70 5f 78  3d 30 3b 69 66 28 73 74  |0)stop_x=0;if(st|
0000a940  6f 70 5f 78 3e 36 33 29  73 74 6f 70 5f 78 3d 36  |op_x>63)stop_x=6|
0000a950  33 3b 0a 69 66 28 73 74  61 72 74 5f 78 3c 30 29  |3;.if(start_x<0)|
0000a960  73 74 61 72 74 5f 78 3d  30 3b 69 66 28 73 74 61  |start_x=0;if(sta|
0000a970  72 74 5f 78 3e 36 33 29  73 74 61 72 74 5f 78 3d  |rt_x>63)start_x=|
0000a980  36 33 3b 0a 69 66 28 73  74 6f 70 5f 79 3c 30 29  |63;.if(stop_y<0)|
0000a990  73 74 6f 70 5f 79 3d 30  3b 69 66 28 73 74 6f 70  |stop_y=0;if(stop|
0000a9a0  5f 79 3e 36 33 29 73 74  6f 70 5f 79 3d 36 33 3b  |_y>63)stop_y=63;|
0000a9b0  0a 69 66 28 73 74 61 72  74 5f 79 3c 30 29 73 74  |.if(start_y<0)st|
0000a9c0  61 72 74 5f 79 3d 30 3b  69 66 28 73 74 61 72 74  |art_y=0;if(start|
0000a9d0  5f 79 3e 36 33 29 73 74  61 72 74 5f 79 3d 36 33  |_y>63)start_y=63|
0000a9e0  3b 0a 7d 0a 65 6c 73 65  20 69 66 28 76 69 65 77  |;.}.else if(view|
0000a9f0  5f 61 6e 67 6c 65 3e 3d  41 4e 47 4c 45 5f 31 38  |_angle>=ANGLE_18|
0000aa00  30 20 26 26 20 76 69 65  77 5f 61 6e 67 6c 65 3c  |0 && view_angle<|
0000aa10  41 4e 47 4c 45 5f 32 37  30 29 0a 7b 0a 20 20 73  |ANGLE_270).{.  s|
0000aa20  74 61 72 74 5f 78 3d 28  76 69 65 77 5f 78 3e 3e  |tart_x=(view_x>>|
0000aa30  36 29 2d 31 35 3b 0a 20  20 73 74 61 72 74 5f 79  |6)-15;.  start_y|
0000aa40  3d 28 76 69 65 77 5f 79  3e 3e 36 29 2d 31 35 3b  |=(view_y>>6)-15;|
0000aa50  0a 20 20 73 74 6f 70 5f  78 3d 28 76 69 65 77 5f  |.  stop_x=(view_|
0000aa60  78 3e 3e 36 29 2b 35 3b  0a 20 20 73 74 6f 70 5f  |x>>6)+5;.  stop_|
0000aa70  79 3d 28 76 69 65 77 5f  79 3e 3e 36 29 2b 35 3b  |y=(view_y>>6)+5;|
0000aa80  0a 6d 6f 76 65 5f 78 3d  31 3b 0a 6d 6f 76 65 5f  |.move_x=1;.move_|
0000aa90  79 3d 31 3b 0a 69 66 28  73 74 6f 70 5f 78 3c 30  |y=1;.if(stop_x<0|
0000aaa0  29 73 74 6f 70 5f 78 3d  30 3b 69 66 28 73 74 6f  |)stop_x=0;if(sto|
0000aab0  70 5f 78 3e 36 33 29 73  74 6f 70 5f 78 3d 36 33  |p_x>63)stop_x=63|
0000aac0  3b 0a 69 66 28 73 74 61  72 74 5f 78 3c 30 29 73  |;.if(start_x<0)s|
0000aad0  74 61 72 74 5f 78 3d 30  3b 69 66 28 73 74 61 72  |tart_x=0;if(star|
0000aae0  74 5f 78 3e 36 33 29 73  74 61 72 74 5f 78 3d 36  |t_x>63)start_x=6|
0000aaf0  33 3b 0a 69 66 28 73 74  6f 70 5f 79 3c 30 29 73  |3;.if(stop_y<0)s|
0000ab00  74 6f 70 5f 79 3d 30 3b  69 66 28 73 74 6f 70 5f  |top_y=0;if(stop_|
0000ab10  79 3e 36 33 29 73 74 6f  70 5f 79 3d 36 33 3b 0a  |y>63)stop_y=63;.|
0000ab20  69 66 28 73 74 61 72 74  5f 79 3c 30 29 73 74 61  |if(start_y<0)sta|
0000ab30  72 74 5f 79 3d 30 3b 69  66 28 73 74 61 72 74 5f  |rt_y=0;if(start_|
0000ab40  79 3e 36 33 29 73 74 61  72 74 5f 79 3d 36 33 3b  |y>63)start_y=63;|
0000ab50  0a 7d 0a 65 6c 73 65 0a  7b 0a 0a 20 20 73 74 61  |.}.else.{..  sta|
0000ab60  72 74 5f 78 3d 28 76 69  65 77 5f 78 3e 3e 36 29  |rt_x=(view_x>>6)|
0000ab70  2b 31 35 3b 0a 20 20 73  74 61 72 74 5f 79 3d 28  |+15;.  start_y=(|
0000ab80  76 69 65 77 5f 79 3e 3e  36 29 2d 31 35 3b 0a 20  |view_y>>6)-15;. |
0000ab90  20 73 74 6f 70 5f 78 3d  28 76 69 65 77 5f 78 3e  | stop_x=(view_x>|
0000aba0  3e 36 29 2d 35 3b 0a 20  20 73 74 6f 70 5f 79 3d  |>6)-5;.  stop_y=|
0000abb0  28 76 69 65 77 5f 79 3e  3e 36 29 2b 35 3b 0a 20  |(view_y>>6)+5;. |
0000abc0  20 6d 6f 76 65 5f 78 3d  2d 31 3b 0a 20 20 6d 6f  | move_x=-1;.  mo|
0000abd0  76 65 5f 79 3d 31 3b 0a  69 66 28 73 74 6f 70 5f  |ve_y=1;.if(stop_|
0000abe0  78 3c 30 29 73 74 6f 70  5f 78 3d 30 3b 69 66 28  |x<0)stop_x=0;if(|
0000abf0  73 74 6f 70 5f 78 3e 36  33 29 73 74 6f 70 5f 78  |stop_x>63)stop_x|
0000ac00  3d 36 33 3b 0a 69 66 28  73 74 61 72 74 5f 78 3c  |=63;.if(start_x<|
0000ac10  30 29 73 74 61 72 74 5f  78 3d 30 3b 69 66 28 73  |0)start_x=0;if(s|
0000ac20  74 61 72 74 5f 78 3e 36  33 29 73 74 61 72 74 5f  |tart_x>63)start_|
0000ac30  78 3d 36 33 3b 0a 69 66  28 73 74 6f 70 5f 79 3c  |x=63;.if(stop_y<|
0000ac40  30 29 73 74 6f 70 5f 79  3d 30 3b 69 66 28 73 74  |0)stop_y=0;if(st|
0000ac50  6f 70 5f 79 3e 36 33 29  73 74 6f 70 5f 79 3d 36  |op_y>63)stop_y=6|
0000ac60  33 3b 0a 69 66 28 73 74  61 72 74 5f 79 3c 30 29  |3;.if(start_y<0)|
0000ac70  73 74 61 72 74 5f 79 3d  30 3b 69 66 28 73 74 61  |start_y=0;if(sta|
0000ac80  72 74 5f 79 3e 36 33 29  73 74 61 72 74 5f 79 3d  |rt_y>63)start_y=|
0000ac90  36 33 3b 0a 7d 0a 0a 0a  0a 66 6f 72 28 67 72 69  |63;.}....for(gri|
0000aca0  64 5f 78 3d 73 74 61 72  74 5f 78 3b 67 72 69 64  |d_x=start_x;grid|
0000acb0  5f 78 21 3d 73 74 6f 70  5f 78 3b 67 72 69 64 5f  |_x!=stop_x;grid_|
0000acc0  78 2b 3d 6d 6f 76 65 5f  78 29 66 6f 72 28 67 72  |x+=move_x)for(gr|
0000acd0  69 64 5f 79 3d 73 74 61  72 74 5f 79 3b 67 72 69  |id_y=start_y;gri|
0000ace0  64 5f 79 21 3d 73 74 6f  70 5f 79 3b 67 72 69 64  |d_y!=stop_y;grid|
0000acf0  5f 79 2b 3d 6d 6f 76 65  5f 79 29 0a 7b 0a 0a 0a  |_y+=move_y).{...|
0000ad00  20 20 69 66 28 21 28 6f  62 6a 65 63 74 5f 74 79  |  if(!(object_ty|
0000ad10  70 65 3d 6f 62 6a 65 63  74 73 5b 67 72 69 64 5f  |pe=objects[grid_|
0000ad20  79 5d 5b 67 72 69 64 5f  78 5d 29 29 63 6f 6e 74  |y][grid_x]))cont|
0000ad30  69 6e 75 65 3b 0a 0a 0a  20 20 2f 2a 20 41 6e 20  |inue;...  /* An |
0000ad40  6f 62 6a 65 63 74 20 68  61 73 20 62 65 65 6e 20  |object has been |
0000ad50  66 6f 75 6e 64 20 69 6e  20 74 68 69 73 20 67 72  |found in this gr|
0000ad60  69 64 20 73 71 75 61 72  65 2c 20 67 6f 6f 64 21  |id square, good!|
0000ad70  2a 2f 0a 20 20 2f 2a 20  69 6e 20 74 68 61 74 20  |*/.  /* in that |
0000ad80  63 61 73 65 20 77 65 20  70 72 6f 63 65 73 73 20  |case we process |
0000ad90  61 6e 64 20 70 6c 6f 74  20 74 68 65 20 6f 62 6a  |and plot the obj|
0000ada0  65 63 74 20 2a 2f 0a 0a  2f 2a 20 4e 45 57 20 4d  |ect */../* NEW M|
0000adb0  4f 56 49 4e 47 20 4f 42  4a 45 43 54 20 63 6f 64  |OVING OBJECT cod|
0000adc0  65 2e 20 54 68 69 73 20  69 73 20 61 63 74 75 61  |e. This is actua|
0000add0  6c 6c 79 20 76 65 72 79  20 73 69 6d 70 6c 65 20  |lly very simple |
0000ade0  61 6e 64 20 63 61 6e 20  62 65 20 64 6f 6e 65 20  |and can be done |
0000adf0  69 6e 20 2a 2f 0a 2f 2a  20 61 20 5f 76 61 72 69  |in */./* a _vari|
0000ae00  65 74 79 5f 20 6f 66 20  77 61 79 73 2e 20 54 68  |ety_ of ways. Th|
0000ae10  69 73 20 69 73 20 6a 75  73 74 20 6f 6e 65 20 6f  |is is just one o|
0000ae20  66 20 74 68 65 6d 2c 20  61 6e 64 20 6e 6f 74 20  |f them, and not |
0000ae30  74 68 65 20 62 65 73 74  20 3b 2d 29 20 2a 2f 0a  |the best ;-) */.|
0000ae40  2f 2a 0a 69 66 28 6f 62  6a 65 63 74 5f 74 79 70  |/*.if(object_typ|
0000ae50  65 3d 3d 31 30 20 7c 7c  20 6f 62 6a 65 63 74 5f  |e==10 || object_|
0000ae60  74 79 70 65 3d 3d 31 35  20 7c 7c 20 6f 62 6a 65  |type==15 || obje|
0000ae70  63 74 5f 74 79 70 65 3d  3d 31 37 20 7c 7c 20 6f  |ct_type==17 || o|
0000ae80  62 6a 65 63 74 5f 74 79  70 65 3d 3d 31 39 29 0a  |bject_type==19).|
0000ae90  7b 0a 20 6f 62 6a 65 63  74 5f 78 3d 6f 62 6a 65  |{. object_x=obje|
0000aea0  63 74 5f 6d 6f 76 65 5f  78 3b 0a 20 6f 62 6a 65  |ct_move_x;. obje|
0000aeb0  63 74 5f 79 3d 6f 62 6a  65 63 74 5f 6d 6f 76 65  |ct_y=object_move|
0000aec0  5f 79 3b 0a 7d 0a 65 6c  73 65 2a 2f 0a 7b 0a 20  |_y;.}.else*/.{. |
0000aed0  20 20 20 20 20 6f 62 6a  65 63 74 5f 78 3d 28 67  |     object_x=(g|
0000aee0  72 69 64 5f 78 3c 3c 36  29 2b 33 32 3b 0a 20 20  |rid_x<<6)+32;.  |
0000aef0  20 20 20 20 6f 62 6a 65  63 74 5f 79 3d 28 67 72  |    object_y=(gr|
0000af00  69 64 5f 79 3c 3c 36 29  2b 33 32 3b 0a 7d 0a 20  |id_y<<6)+32;.}. |
0000af10  2f 2a 20 6e 6f 77 20 77  65 20 68 61 76 65 20 74  |/* now we have t|
0000af20  6f 20 72 6f 74 61 74 65  20 74 68 65 20 6f 62 6a  |o rotate the obj|
0000af30  65 63 74 73 20 63 6f 6f  72 64 69 6e 61 74 65 73  |ects coordinates|
0000af40  20 61 72 6f 75 6e 64 20  74 68 65 20 76 69 65 77  | around the view|
0000af50  65 72 20 2a 2f 0a 20 20  20 20 20 20 2f 2a 20 74  |er */.      /* t|
0000af60  6f 20 65 73 74 61 62 6c  69 73 68 20 77 68 65 72  |o establish wher|
0000af70  65 20 69 74 20 69 73 20  6f 6e 20 74 68 65 20 76  |e it is on the v|
0000af80  69 65 77 20 70 6c 61 6e  65 20 2c 75 73 69 6e 67  |iew plane ,using|
0000af90  20 73 74 61 6e 64 61 72  64 20 72 6f 74 73 2e 2a  | standard rots.*|
0000afa0  2f 0a 0a 20 20 20 20 20  20 74 72 61 6e 73 5f 78  |/..      trans_x|
0000afb0  3d 28 20 28 6f 62 6a 65  63 74 5f 78 2d 76 69 65  |=( (object_x-vie|
0000afc0  77 5f 78 29 2a 63 6f 73  6f 5f 74 61 62 6c 65 5b  |w_x)*coso_table[|
0000afd0  76 69 65 77 5f 61 6e 67  6c 65 5d 2b 28 6f 62 6a  |view_angle]+(obj|
0000afe0  65 63 74 5f 79 2d 76 69  65 77 5f 79 29 2a 0a 20  |ect_y-view_y)*. |
0000aff0  20 20 20 20 20 73 69 6e  6f 5f 74 61 62 6c 65 5b  |     sino_table[|
0000b000  76 69 65 77 5f 61 6e 67  6c 65 5d 29 3e 3e 31 36  |view_angle])>>16|
0000b010  3b 0a 20 20 20 20 20 20  74 72 61 6e 73 5f 7a 3d  |;.      trans_z=|
0000b020  28 2d 28 6f 62 6a 65 63  74 5f 78 2d 76 69 65 77  |(-(object_x-view|
0000b030  5f 78 29 2a 73 69 6e 6f  5f 74 61 62 6c 65 5b 76  |_x)*sino_table[v|
0000b040  69 65 77 5f 61 6e 67 6c  65 5d 2b 28 6f 62 6a 65  |iew_angle]+(obje|
0000b050  63 74 5f 79 2d 76 69 65  77 5f 79 29 2a 0a 20 20  |ct_y-view_y)*.  |
0000b060  20 20 20 20 63 6f 73 6f  5f 74 61 62 6c 65 5b 76  |    coso_table[v|
0000b070  69 65 77 5f 61 6e 67 6c  65 5d 29 3e 3e 31 36 3b  |iew_angle])>>16;|
0000b080  0a 20 20 20 20 20 20 2f  2a 20 6e 6f 77 20 69 66  |.      /* now if|
0000b090  20 74 68 65 20 6f 62 6a  65 63 74 20 69 73 20 69  | the object is i|
0000b0a0  6e 66 72 6f 6e 74 20 6f  66 20 74 68 65 20 76 69  |nfront of the vi|
0000b0b0  65 77 65 72 20 77 65 20  67 6f 20 66 75 72 74 68  |ewer we go furth|
0000b0c0  65 72 20 2a 2f 0a 20 20  20 20 20 20 69 66 28 74  |er */.      if(t|
0000b0d0  72 61 6e 73 5f 7a 3c 30  29 63 6f 6e 74 69 6e 75  |rans_z<0)continu|
0000b0e0  65 3b 20 2f 2a 20 65 6c  73 65 20 77 65 20 6d 6f  |e; /* else we mo|
0000b0f0  76 65 20 74 6f 20 6e 65  78 74 20 6f 62 6a 65 63  |ve to next objec|
0000b100  74 20 2a 2f 0a 0a 20 20  20 20 20 20 20 20 2f 2a  |t */..        /*|
0000b110  20 77 65 20 68 61 76 65  20 74 6f 20 77 6f 72 6b  | we have to work|
0000b120  20 6f 75 74 20 73 63 72  65 65 6e 20 70 6f 73 69  | out screen posi|
0000b130  74 69 6f 6e 73 20 6e 6f  77 20 28 61 62 6f 76 65  |tions now (above|
0000b140  20 61 6e 64 20 62 65 6c  6f 77 21 29 20 2a 2f 0a  | and below!) */.|
0000b150  20 20 20 20 20 20 20 20  20 74 65 6d 70 5f 31 3d  |         temp_1=|
0000b160  28 28 28 56 49 45 57 56  41 52 54 3c 3c 35 29 20  |(((VIEWVART<<5) |
0000b170  2a 20 72 65 63 69 70 5f  74 61 62 6c 65 5b 74 72  |* recip_table[tr|
0000b180  61 6e 73 5f 7a 5d 29 29  3e 3e 31 36 3b 0a 20 20  |ans_z]))>>16;.  |
0000b190  20 20 20 20 20 20 73 63  72 65 65 6e 5f 79 31 3d  |      screen_y1=|
0000b1a0  31 30 30 2d 74 65 6d 70  5f 31 3b 20 2f 2a 20 31  |100-temp_1; /* 1|
0000b1b0  32 38 20 61 6e 64 20 31  36 30 20 68 65 72 65 20  |28 and 160 here |
0000b1c0  69 6e 64 69 63 61 74 65  20 6f 72 69 67 69 6e 73  |indicate origins|
0000b1d0  20 61 74 20 74 68 65 2a  2f 0a 20 20 20 20 20 20  | at the*/.      |
0000b1e0  20 20 73 63 72 65 65 6e  5f 79 32 3d 31 30 30 2b  |  screen_y2=100+|
0000b1f0  74 65 6d 70 5f 31 3b 20  2f 2a 20 63 65 6e 74 65  |temp_1; /* cente|
0000b200  72 20 6f 66 20 74 68 65  20 73 63 72 65 65 6e 20  |r of the screen |
0000b210  6f 66 63 6f 75 72 73 65  20 2a 2f 0a 20 20 20 20  |ofcourse */.    |
0000b220  20 20 20 20 2f 2a 20 74  68 65 20 61 62 6f 76 65  |    /* the above|
0000b230  20 6c 69 6e 65 73 20 77  6f 72 6b 73 20 6f 75 74  | lines works out|
0000b240  20 74 68 65 20 74 6f 70  20 61 6e 64 20 62 6f 74  | the top and bot|
0000b250  74 6f 6d 20 6f 66 20 74  68 65 20 6f 62 6a 65 63  |tom of the objec|
0000b260  74 20 2a 2f 0a 69 66 28  28 73 63 61 6c 65 3d 73  |t */.if((scale=s|
0000b270  63 72 65 65 6e 5f 79 32  2d 73 63 72 65 65 6e 5f  |creen_y2-screen_|
0000b280  79 31 29 3e 4d 41 58 5f  53 43 41 4c 45 29 63 6f  |y1)>MAX_SCALE)co|
0000b290  6e 74 69 6e 75 65 3b 0a  0a 20 20 20 20 20 20 20  |ntinue;..       |
0000b2a0  20 73 63 72 65 65 6e 5f  78 3d 31 36 30 20 2b 20  | screen_x=160 + |
0000b2b0  28 20 28 20 56 49 45 57  56 41 52 2a 74 72 61 6e  |( ( VIEWVAR*tran|
0000b2c0  73 5f 78 20 2a 20 72 65  63 69 70 5f 74 61 62 6c  |s_x * recip_tabl|
0000b2d0  65 5b 74 72 61 6e 73 5f  7a 5d 29 3e 3e 31 36 29  |e[trans_z])>>16)|
0000b2e0  3b 0a 0a 20 20 20 20 20  20 20 20 69 66 28 73 63  |;..        if(sc|
0000b2f0  61 6c 65 3e 28 53 43 52  45 45 4e 5f 48 45 49 47  |ale>(SCREEN_HEIG|
0000b300  48 54 29 29 0a 20 20 20  20 20 20 20 20 7b 0a 0a  |HT)).        {..|
0000b310  20 20 20 20 20 20 20 20  20 20 73 63 61 6c 65 3d  |          scale=|
0000b320  53 43 52 45 45 4e 5f 48  45 49 47 48 54 3b 0a 0a  |SCREEN_HEIGHT;..|
0000b330  20 20 20 20 20 20 20 20  7d 0a 20 20 20 20 20 20  |        }.      |
0000b340  20 20 76 61 72 69 61 62  6c 65 73 5b 35 5d 3d 73  |  variables[5]=s|
0000b350  63 72 65 65 6e 5f 79 31  3b 0a 20 20 20 20 20 20  |creen_y1;.      |
0000b360  20 20 2f 2a 20 61 62 6f  76 65 20 6c 69 6e 65 20  |  /* above line |
0000b370  77 6f 72 6b 73 20 6f 75  74 20 73 63 61 6c 65 20  |works out scale |
0000b380  66 72 6f 6d 20 79 31 20  61 6e 64 20 79 32 20 72  |from y1 and y2 r|
0000b390  65 61 64 79 20 66 6f 72  20 64 72 61 77 69 6e 67  |eady for drawing|
0000b3a0  20 2a 2f 0a 20 20 20 20  20 20 20 20 73 63 72 65  | */.        scre|
0000b3b0  65 6e 5f 78 2d 3d 73 63  61 6c 65 3e 3e 31 3b 0a  |en_x-=scale>>1;.|
0000b3c0  20 20 20 20 20 20 20 20  2f 2a 20 77 65 20 6f 66  |        /* we of|
0000b3d0  66 73 65 74 20 73 63 72  65 65 6e 5f 78 20 73 6f  |fset screen_x so|
0000b3e0  20 74 68 65 6e 20 77 65  20 61 72 65 20 61 74 20  | then we are at |
0000b3f0  74 68 65 20 6c 65 66 74  20 6f 66 20 74 68 65 20  |the left of the |
0000b400  6f 62 6a 65 63 74 20 2a  2f 20 20 20 20 20 20 20  |object */       |
0000b410  20 20 20 20 20 69 6e 63  72 65 6d 65 6e 74 3d 28  |     increment=(|
0000b420  69 6e 74 29 28 72 65 63  69 70 5f 74 61 62 6c 65  |int)(recip_table|
0000b430  5b 73 63 61 6c 65 5d 3c  3c 36 29 3b 0a 20 20 20  |[scale]<<6);.   |
0000b440  20 20 20 20 20 76 61 72  69 61 62 6c 65 73 5b 33  |     variables[3|
0000b450  5d 3d 73 63 61 6c 65 3b  0a 0a 0a 0a 2f 2a 20 4e  |]=scale;..../* N|
0000b460  45 57 20 6d 6f 76 69 6e  67 20 6f 62 6a 65 63 74  |EW moving object|
0000b470  20 64 65 74 65 63 74 6f  72 20 63 68 65 63 6b 73  | detector checks|
0000b480  20 74 6f 20 73 65 65 20  69 66 20 6f 62 6a 65 63  | to see if objec|
0000b490  74 20 69 73 20 6f 66 20  6d 6f 76 69 6e 67 20 73  |t is of moving s|
0000b4a0  6f 72 74 20 2a 2f 0a 0a  0a 20 20 20 20 20 20 20  |ort */...       |
0000b4b0  20 2f 2a 20 61 62 6f 76  65 20 6c 69 6e 65 20 70  | /* above line p|
0000b4c0  72 65 70 61 72 65 73 20  6d 6f 72 65 20 76 61 72  |repares more var|
0000b4d0  69 61 62 6c 65 73 20 66  6f 72 20 74 68 65 20 6f  |iables for the o|
0000b4e0  75 72 6c 69 62 20 66 75  6e 63 74 69 6f 6e 20 20  |urlib function  |
0000b4f0  20 20 2a 2f 0a 20 20 20  20 20 20 20 20 2f 2a 20  |  */.        /* |
0000b500  6e 65 78 74 20 77 65 20  73 65 74 20 75 70 20 66  |next we set up f|
0000b510  69 78 65 64 20 70 6f 69  6e 74 20 73 79 73 74 65  |ixed point syste|
0000b520  6d 73 20 74 6f 20 69 6e  64 65 78 20 74 68 65 20  |ms to index the |
0000b530  6f 62 6a 65 63 74 20 67  72 61 70 68 69 63 20 2a  |object graphic *|
0000b540  2f 0a 20 20 20 20 20 20  20 20 2f 2a 20 77 68 69  |/.        /* whi|
0000b550  6c 65 20 77 65 20 64 72  61 77 20 69 74 2e 20 49  |le we draw it. I|
0000b560  6e 73 74 65 61 64 20 6f  66 20 66 6c 6f 61 74 69  |nstead of floati|
0000b570  6e 67 20 70 6f 69 6e 74  20 74 68 69 73 20 69 73  |ng point this is|
0000b580  20 6f 66 20 63 6f 75 72  73 65 20 20 2a 2f 0a 20  | of course  */. |
0000b590  20 20 20 20 20 20 20 69  6e 64 65 78 3d 30 3b 0a  |       index=0;.|
0000b5a0  20 20 20 20 20 20 20 20  2f 2a 20 6e 65 78 74 20  |        /* next |
0000b5b0  77 65 20 75 73 65 20 61  20 63 6f 75 6e 74 65 72  |we use a counter|
0000b5c0  20 74 6f 20 63 6f 75 6e  74 20 69 66 20 77 65 20  | to count if we |
0000b5d0  68 61 76 65 20 66 69 6e  69 73 68 65 64 20 64 72  |have finished dr|
0000b5e0  61 77 69 6e 67 20 69 74  2e 20 2a 2f 0a 20 20 20  |awing it. */.   |
0000b5f0  20 20 20 20 20 63 6f 75  6e 74 65 72 3d 73 63 61  |     counter=sca|
0000b600  6c 65 3b 0a 20 20 20 20  20 20 20 20 2f 2a 20 69  |le;.        /* i|
0000b610  6e 69 74 69 61 6c 69 73  65 20 61 20 6c 6f 6f 70  |nitialise a loop|
0000b620  20 74 6f 20 72 65 6e 64  65 72 20 65 61 63 68 20  | to render each |
0000b630  73 6c 69 76 65 72 20 6f  6e 65 20 62 79 20 6f 6e  |sliver one by on|
0000b640  65 20 2a 2f 0a 20 20 20  20 20 20 20 20 2f 2a 20  |e */.        /* |
0000b650  6b 65 65 70 20 67 6f 69  6e 67 20 75 6e 74 69 6c  |keep going until|
0000b660  20 6f 66 66 20 74 68 65  20 73 63 72 65 65 6e 20  | off the screen |
0000b670  6f 72 20 6a 75 73 74 20  66 69 6e 69 73 68 65 64  |or just finished|
0000b680  21 20 2a 2f 0a 0a 0a 20  77 68 69 6c 65 28 73 63  |! */... while(sc|
0000b690  72 65 65 6e 5f 78 3e 2d  36 34 20 26 26 20 73 63  |reen_x>-64 && sc|
0000b6a0  72 65 65 6e 5f 78 3c 53  43 52 45 45 4e 5f 57 49  |reen_x<SCREEN_WI|
0000b6b0  44 54 48 20 26 26 20 63  6f 75 6e 74 65 72 3e 30  |DTH && counter>0|
0000b6c0  29 0a 20 20 20 20 20 20  20 20 20 20 20 7b 0a 2f  |).           {./|
0000b6d0  2a 20 4e 45 57 20 6d 69  72 72 6f 72 20 63 6f 64  |* NEW mirror cod|
0000b6e0  65 2c 20 77 65 20 68 61  76 65 20 74 6f 20 62 65  |e, we have to be|
0000b6f0  20 63 61 72 65 66 75 6c  20 74 6f 20 6d 61 6b 65  | careful to make|
0000b700  20 69 74 20 6c 6f 6f 6b  20 67 6f 6f 64 20 2a 2f  | it look good */|
0000b710  0a 69 66 28 6d 69 72 72  6f 72 5f 61 72 72 61 79  |.if(mirror_array|
0000b720  5b 73 63 72 65 65 6e 5f  78 5d 3d 3d 32 35 35 20  |[screen_x]==255 |
0000b730  26 26 20 73 63 61 6c 65  3e 73 63 61 6c 65 5f 61  |&& scale>scale_a|
0000b740  72 72 61 79 5b 73 63 72  65 65 6e 5f 78 5d 29 0a  |rray[screen_x]).|
0000b750  7b 0a 20 20 76 61 72 69  61 62 6c 65 73 5b 31 5d  |{.  variables[1]|
0000b760  3d 28 69 6e 74 29 26 6f  62 6a 67 72 61 70 68 69  |=(int)&objgraphi|
0000b770  63 73 5b 6f 62 6a 65 63  74 5f 74 79 70 65 5d 5b  |cs[object_type][|
0000b780  28 69 6e 74 29 69 6e 64  65 78 3e 3e 31 36 5d 3b  |(int)index>>16];|
0000b790  0a 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |..              |
0000b7a0  20 20 20 20 76 61 72 69  61 62 6c 65 73 5b 34 5d  |    variables[4]|
0000b7b0  3d 73 63 72 65 65 6e 5f  78 3b 0a 0a 20 20 20 20  |=screen_x;..    |
0000b7c0  20 20 20 20 20 20 20 20  20 20 20 20 20 6f 75 72  |             our|
0000b7d0  6c 69 62 5f 73 6c 69 76  65 72 5f 6d 61 73 6b 5f  |lib_sliver_mask_|
0000b7e0  6d 69 72 72 6f 72 28 76  61 72 69 61 62 6c 65 73  |mirror(variables|
0000b7f0  29 3b 0a 7d 0a 65 6c 73  65 7b 0a 20 20 20 20 20  |);.}.else{.     |
0000b800  20 20 20 20 20 20 20 20  20 2f 2a 20 63 68 65 63  |         /* chec|
0000b810  6b 20 74 6f 20 73 65 65  20 69 66 20 6f 62 6a 65  |k to see if obje|
0000b820  63 74 20 69 73 20 69 6e  66 72 6f 6e 74 20 6f 66  |ct is infront of|
0000b830  20 77 61 6c 6c 2c 20 69  6d 70 6f 72 74 61 6e 74  | wall, important|
0000b840  21 20 2a 2f 0a 20 20 20  20 20 20 20 20 20 20 20  |! */.           |
0000b850  20 20 20 69 66 28 73 63  61 6c 65 3e 73 63 61 6c  |   if(scale>scal|
0000b860  65 5f 61 72 72 61 79 5b  73 63 72 65 65 6e 5f 78  |e_array[screen_x|
0000b870  5d 20 26 26 20 73 63 72  65 65 6e 5f 78 3e 73 63  |] && screen_x>sc|
0000b880  72 65 65 6e 5f 6c 69 6d  69 74 29 0a 20 20 20 20  |reen_limit).    |
0000b890  20 20 20 20 20 20 20 20  20 20 20 20 20 20 7b 0a  |              {.|
0000b8a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
0000b8b0  20 20 2f 2a 20 69 66 20  73 6f 20 64 72 61 77 20  |  /* if so draw |
0000b8c0  74 68 69 73 20 73 6c 69  76 65 72 21 20 2a 2f 0a  |this sliver! */.|
0000b8d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
0000b8e0  20 76 61 72 69 61 62 6c  65 73 5b 31 5d 3d 28 69  | variables[1]=(i|
0000b8f0  6e 74 29 26 6f 62 6a 67  72 61 70 68 69 63 73 5b  |nt)&objgraphics[|
0000b900  6f 62 6a 65 63 74 5f 74  79 70 65 5d 5b 28 69 6e  |object_type][(in|
0000b910  74 29 69 6e 64 65 78 3e  3e 31 36 5d 3b 0a 0a 20  |t)index>>16];.. |
0000b920  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
0000b930  20 76 61 72 69 61 62 6c  65 73 5b 34 5d 3d 73 63  | variables[4]=sc|
0000b940  72 65 65 6e 5f 78 3b 0a  0a 20 20 20 20 20 20 20  |reen_x;..       |
0000b950  20 20 20 20 20 20 20 20  20 20 6f 75 72 6c 69 62  |          ourlib|
0000b960  5f 73 6c 69 76 65 72 5f  6d 61 73 6b 28 76 61 72  |_sliver_mask(var|
0000b970  69 61 62 6c 65 73 29 3b  0a 20 20 20 20 20 20 20  |iables);.       |
0000b980  20 20 20 20 20 20 20 20  20 20 20 7d 0a 0a 7d 20  |           }..} |
0000b990  2f 2a 20 61 64 64 20 6f  6e 20 67 72 61 70 68 69  |/* add on graphi|
0000b9a0  63 20 69 6e 63 72 65 6d  65 6e 74 2c 20 64 65 63  |c increment, dec|
0000b9b0  72 65 61 73 65 20 63 6f  75 6e 74 65 72 20 61 6e  |rease counter an|
0000b9c0  64 20 6d 6f 76 65 20 74  6f 20 6e 65 78 74 20 63  |d move to next c|
0000b9d0  6f 6c 75 6d 6e 20 2a 2f  20 20 20 20 20 69 6e 64  |olumn */     ind|
0000b9e0  65 78 2b 3d 69 6e 63 72  65 6d 65 6e 74 3b 0a 20  |ex+=increment;. |
0000b9f0  20 63 6f 75 6e 74 65 72  2d 2d 3b 0a 20 20 73 63  | counter--;.  sc|
0000ba00  72 65 65 6e 5f 78 2b 2b  3b 0a 20 20 20 20 20 20  |reen_x++;.      |
0000ba10  20 20 20 20 20 7d 0a 0a  0a 7d 0a 2f 2a 20 4f 62  |     }...}./* Ob|
0000ba20  6a 65 63 74 20 43 6f 64  65 20 4f 56 45 52 20 2a  |ject Code OVER *|
0000ba30  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 20 43 6f 6e  |************ Con|
0000ba40  74 69 6e 75 65 20 61 73  20 6e 6f 72 6d 61 6c 20  |tinue as normal |
0000ba50  2a 2f 0a 2f 2a 20 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |*/./* **********|
0000ba60  2a 2a 2a 2a 2a 20 53 65  65 20 41 72 74 69 63 6c  |***** See Articl|
0000ba70  65 20 35 20 66 6f 72 20  6d 6f 72 65 20 64 65 74  |e 5 for more det|
0000ba80  61 69 6c 73 20 2a 2f 0a  0a 2f 2a 20 4e 45 57 20  |ails */../* NEW |
0000ba90  6d 6f 76 69 6e 67 20 6f  62 6a 65 63 74 20 3a 20  |moving object : |
0000baa0  57 65 20 61 64 64 20 61  20 73 6d 61 6c 6c 20 62  |We add a small b|
0000bab0  69 74 20 6f 66 20 63 6f  64 65 20 74 6f 20 6d 6f  |it of code to mo|
0000bac0  76 65 20 74 68 65 20 6f  62 6a 65 63 74 20 2a 2f  |ve the object */|
0000bad0  0a 2f 2a 6f 62 6a 65 63  74 73 5b 6f 62 6a 65 63  |./*objects[objec|
0000bae0  74 5f 6d 6f 76 65 5f 79  3e 3e 36 5d 5b 6f 62 6a  |t_move_y>>6][obj|
0000baf0  65 63 74 5f 6d 6f 76 65  5f 78 3e 3e 36 5d 3d 30  |ect_move_x>>6]=0|
0000bb00  3b 0a 6f 62 6a 65 63 74  5f 6d 6f 76 65 5f 78 3d  |;.object_move_x=|
0000bb10  6f 62 6a 65 63 74 5f 6d  6f 76 65 5b 28 69 6e 74  |object_move[(int|
0000bb20  29 6f 62 6a 65 63 74 5f  6d 6f 76 65 5f 69 6e 64  |)object_move_ind|
0000bb30  65 78 5d 3b 0a 6f 62 6a  65 63 74 5f 6d 6f 76 65  |ex];.object_move|
0000bb40  5f 79 3d 6f 62 6a 65 63  74 5f 6d 6f 76 65 5b 28  |_y=object_move[(|
0000bb50  69 6e 74 29 6f 62 6a 65  63 74 5f 6d 6f 76 65 5f  |int)object_move_|
0000bb60  69 6e 64 65 78 2b 31 5d  3b 0a 6f 62 6a 65 63 74  |index+1];.object|
0000bb70  73 5b 6f 62 6a 65 63 74  5f 6d 6f 76 65 5f 79 3e  |s[object_move_y>|
0000bb80  3e 36 5d 5b 6f 62 6a 65  63 74 5f 6d 6f 76 65 5f  |>6][object_move_|
0000bb90  78 3e 3e 36 5d 3d 6f 62  6a 65 63 74 5f 6d 6f 76  |x>>6]=object_mov|
0000bba0  65 5b 6f 62 6a 65 63 74  5f 6d 6f 76 65 5f 69 6e  |e[object_move_in|
0000bbb0  64 65 78 2b 32 5d 3b 0a  6f 62 6a 65 63 74 5f 6d  |dex+2];.object_m|
0000bbc0  6f 76 65 5f 69 6e 64 65  78 2b 3d 33 3b 69 66 28  |ove_index+=3;if(|
0000bbd0  6f 62 6a 65 63 74 5f 6d  6f 76 65 5f 69 6e 64 65  |object_move_inde|
0000bbe0  78 3e 31 30 30 29 6f 62  6a 65 63 74 5f 6d 6f 76  |x>100)object_mov|
0000bbf0  65 5f 69 6e 64 65 78 3d  30 3b 2a 2f 0a 2f 2a 20  |e_index=0;*/./* |
0000bc00  50 48 45 57 21 20 4e 6f  77 20 77 65 20 63 61 6e  |PHEW! Now we can|
0000bc10  20 77 61 69 74 20 66 6f  72 20 61 20 76 79 73 6e  | wait for a vysn|
0000bc20  63 20 61 6e 64 20 74 68  65 6e 20 73 77 69 74 63  |c and then switc|
0000bc30  68 20 74 68 65 20 76 69  65 77 73 2f 62 61 6e 6b  |h the views/bank|
0000bc40  73 20 6f 76 65 72 20 6f  74 20 20 70 72 6f 64 75  |s over ot  produ|
0000bc50  63 65 20 66 6c 69 63 6b  65 72 2d 66 72 65 65 20  |ce flicker-free |
0000bc60  61 6e 69 6d 61 74 69 6f  6e 20 2a 2f 0a 0a 6f 75  |animation */..ou|
0000bc70  72 6c 69 62 5f 77 61 69  74 76 73 79 6e 63 28 29  |rlib_waitvsync()|
0000bc80  3b 0a 6f 75 72 6c 69 62  5f 73 69 6d 70 6c 65 73  |;.ourlib_simples|
0000bc90  77 69 74 63 68 28 29 3b  0a 0a 2f 2a 20 57 65 20  |witch();../* We |
0000bca0  61 6c 73 6f 20 68 61 76  65 20 74 6f 20 73 77 69  |also have to swi|
0000bcb0  74 63 68 20 74 68 65 20  6d 65 6d 6f 72 79 20 61  |tch the memory a|
0000bcc0  64 64 72 65 73 73 65 73  20 61 72 6f 75 6e 64 20  |ddresses around |
0000bcd0  73 6f 20 6f 75 72 20 66  75 6e 63 74 69 6f 6e 73  |so our functions|
0000bce0  20 64 72 61 77 20 74 6f  20 74 68 65 20 63 6f 72  | draw to the cor|
0000bcf0  72 65 63 74 20 6d 65 6d  6f 72 79 20 2a 2f 0a 0a  |rect memory */..|
0000bd00  73 63 72 65 65 6e 5f 61  64 64 72 65 73 73 5f 74  |screen_address_t|
0000bd10  65 6d 70 3d 73 63 72 65  65 6e 5f 61 64 64 72 65  |emp=screen_addre|
0000bd20  73 73 5f 62 61 6e 6b 3b  0a 73 63 72 65 65 6e 5f  |ss_bank;.screen_|
0000bd30  61 64 64 72 65 73 73 5f  62 61 6e 6b 3d 73 63 72  |address_bank=scr|
0000bd40  65 65 6e 5f 61 64 64 72  65 73 73 3b 0a 73 63 72  |een_address;.scr|
0000bd50  65 65 6e 5f 61 64 64 72  65 73 73 3d 73 63 72 65  |een_address=scre|
0000bd60  65 6e 5f 61 64 64 72 65  73 73 5f 74 65 6d 70 3b  |en_address_temp;|
0000bd70  0a 0a 2f 2a 20 61 64 64  20 6f 6e 65 20 74 6f 20  |../* add one to |
0000bd80  74 68 65 20 66 72 61 6d  65 73 20 63 6f 75 6e 74  |the frames count|
0000bd90  2c 20 77 65 20 61 72 65  20 63 6f 75 6e 74 69 6e  |, we are countin|
0000bda0  67 20 74 68 65 20 6e 75  6d 62 65 72 20 6f 66 20  |g the number of |
0000bdb0  66 72 61 6d 65 73 20 67  65 6e 65 72 61 74 65 64  |frames generated|
0000bdc0  20 20 2a 2f 0a 66 72 61  6d 65 73 2b 2b 3b 0a 0a  |  */.frames++;..|
0000bdd0  7d 0a 2f 2a 20 72 65 63  6f 72 64 20 74 68 65 20  |}./* record the |
0000bde0  74 69 6d 65 20 73 74 6f  70 70 65 64 20 2a 2f 0a  |time stopped */.|
0000bdf0  0a 74 69 6d 65 5f 66 69  6e 69 73 68 3d 6f 75 72  |.time_finish=our|
0000be00  6c 69 62 5f 67 65 74 74  69 6d 65 28 29 3b 0a 0a  |lib_gettime();..|
0000be10  2f 2a 20 74 61 6b 65 20  61 20 73 63 72 65 65 6e  |/* take a screen|
0000be20  73 68 6f 74 2c 20 75 73  69 6e 67 20 2a 73 63 72  |shot, using *scr|
0000be30  65 65 6e 20 73 61 76 65  2c 20 61 6e 64 20 73 61  |een save, and sa|
0000be40  76 65 20 69 74 20 69 6e  73 69 64 65 20 74 68 65  |ve it inside the|
0000be50  20 64 69 72 65 63 74 6f  72 79 20 2a 2f 0a 0a 73  | directory */..s|
0000be60  79 73 74 65 6d 28 22 2a  53 63 72 65 65 6e 53 61  |ystem("*ScreenSa|
0000be70  76 65 20 3c 41 55 41 52  61 79 24 44 69 72 3e 2e  |ve <AUARay$Dir>.|
0000be80  73 63 72 73 68 6f 74 22  29 3b 0a 69 66 28 44 45  |scrshot");.if(DE|
0000be90  4d 4f 5f 52 45 41 44 20  7c 7c 20 44 45 4d 4f 5f  |MO_READ || DEMO_|
0000bea0  57 52 49 54 45 29 66 63  6c 6f 73 65 28 64 65 6d  |WRITE)fclose(dem|
0000beb0  6f 5f 66 69 6c 65 29 3b  0a 2f 2a 20 63 6c 6f 73  |o_file);./* clos|
0000bec0  65 20 64 6f 77 6e 20 74  68 65 20 73 63 72 65 65  |e down the scree|
0000bed0  6e 73 20 75 73 69 6e 67  20 61 6e 20 6f 75 72 6c  |ns using an ourl|
0000bee0  69 62 20 66 75 6e 63 74  69 6f 6e 20 2a 2f 0a 0a  |ib function */..|
0000bef0  6f 75 72 6c 69 62 5f 63  6c 6f 73 65 64 6f 77 6e  |ourlib_closedown|
0000bf00  5f 73 63 72 65 65 6e 73  28 29 3b 0a 0a 2f 2a 20  |_screens();../* |
0000bf10  63 68 61 6e 67 65 20 74  6f 20 6d 6f 64 65 20 31  |change to mode 1|
0000bf20  35 20 61 6e 64 20 62 72  69 6e 67 20 62 61 63 6b  |5 and bring back|
0000bf30  20 74 68 65 20 63 75 72  73 6f 72 20 6a 75 73 74  | the cursor just|
0000bf40  20 69 6e 20 63 61 73 65  20 2a 2f 0a 0a 6f 75 72  | in case */..our|
0000bf50  6c 69 62 5f 63 68 61 6e  67 65 6d 6f 64 65 28 31  |lib_changemode(1|
0000bf60  35 29 3b 0a 6f 75 72 6c  69 62 5f 72 65 76 69 76  |5);.ourlib_reviv|
0000bf70  65 63 75 72 73 6f 72 28  29 3b 0a 0a 2f 2a 20 70  |ecursor();../* p|
0000bf80  72 69 6e 74 20 74 68 65  20 63 61 6c 63 75 6c 61  |rint the calcula|
0000bf90  74 69 6f 6e 20 61 6e 64  20 6f 74 68 65 72 20 69  |tion and other i|
0000bfa0  6e 66 6f 2e 20 2a 2f 0a  70 72 69 6e 74 66 28 22  |nfo. */.printf("|
0000bfb0  2a 2a 2a 2a 2a 2a 2a 20  46 52 41 4d 45 53 20 50  |******* FRAMES P|
0000bfc0  45 52 20 53 45 43 4f 4e  44 20 2a 2a 2a 2a 2a 2a  |ER SECOND ******|
0000bfd0  2a 2a 5c 6e 25 66 22 2c  28 66 6c 6f 61 74 29 66  |**\n%f",(float)f|
0000bfe0  72 61 6d 65 73 2f 28 66  6c 6f 61 74 29 28 28 74  |rames/(float)((t|
0000bff0  69 6d 65 5f 66 69 6e 69  73 68 2d 74 69 6d 65 5f  |ime_finish-time_|
0000c000  73 74 61 72 74 29 2f 31  30 30 29 29 3b 0a 0a 7d  |start)/100));..}|
0000c010  0a 0a                                             |..|
0000c012