All pastes #160061 Raw Edit

Unnamed

public c v1 · immutable
·published 2006-09-03 20:38 UTC
rendered paste body
void update_field(short player_x, short player_y, short player_angle) {	short angle=player_angle-30;	short ray=0;	short drawn=0;	raytrace horiz;	raytrace vert;					if(angle>0 && angle<180)			horiz.step_y=-WALL_SIDE;	if(angle>180 && angle<360)			horiz.step_y=WALL_SIDE;						if(angle<90 && angle>270)			vert.step_x=-WALL_SIDE;	if(angle>90 && angle<270)			vert.step_x=WALL_SIDE;			for(;ray<PLANE_WIDTH;ray++,angle+=ANGLE_INCREMENT) {		/////////////////////////////////////////////		//_____cast ray, and look for collision____//		/////////////////////////////////////////////		if(angle != 0 && angle != 180)			horiz.step_x=WALL_SIDE/tan(angle);		vert.step_y=WALL_SIDE*tan(angle);				drawn=0;				//set initial horizontal collision point		if(angle>0 && angle<180)				horiz.point_y=((player_y/WALL_SIDE)*WALL_SIDE)-1;		if(angle>180 && angle<360)				horiz.point_y=((player_y/WALL_SIDE)*WALL_SIDE)+WALL_SIDE;						horiz.grid_y=horiz.point_y/WALL_SIDE; //the y grid coordinate of the questioned wall		if(angle!=0 && angle!=180) //watch out for divide by zero					horiz.point_x=player_x+(player_y-horiz.point_y)/tan(angle);		horiz.grid_x=horiz.point_x/WALL_SIDE; //the y grid coordinate of the questioned wall		//______________________________________				//set initial vertical collision point			if(angle<90 && angle>270)				vert.point_x=(vert.point_x/WALL_SIDE)*WALL_SIDE+WALL_SIDE;		if(angle>90 && angle<270)				vert.point_x=(vert.point_x/WALL_SIDE)*WALL_SIDE-1;		vert.grid_x=vert.point_y/WALL_SIDE;				vert.point_y=player_y+(player_x-vert.point_x)*tan(angle);		vert.grid_y=vert.point_y/WALL_SIDE;		//______________________________________				//we now have the initial grid coords for vert and horiz checking				//check for collision		while(horiz.grid_y>=0 && horiz.grid_y<MAP_HEIGHT && horiz.grid_x>=0 && horiz.grid_x<MAP_WIDTH		&& vert.grid_y>=0 && vert.grid_y<MAP_HEIGHT && vert.grid_x>=0 && vert.grid_x<MAP_WIDTH) {				//___check for horizontal collision___//										if(map[horiz.grid_y][horiz.grid_x] && angle !=0 && angle != 180) {					//draw the strip					drawn=1;					break;				}				if(map[vert.grid_y][vert.grid_x]) {					//draw the strip					drawn=1;					break;				}												//move to the next possible wall position				horiz.grid_y=(horiz.point_y+=horiz.step_y)/WALL_SIDE;				horiz.grid_x=(horiz.point_x+=horiz.step_x)/WALL_SIDE;				vert.grid_y=(vert.point_y+=vert.step_y)/WALL_SIDE;				vert.grid_x=(vert.point_x+=vert.step_x)/WALL_SIDE;					}					}					}@HEADER:#define MAP_HEIGHT 8#define MAP_WIDTH 8#define FOV 60#define PLAYER_HEIGHT 16#define WALL_SIDE 64#define PLANE_HEIGHT 100#define PLANE_WIDTH 160#define ANGLE_INCREMENT FOV/PLANE_WIDTHextern char map[MAP_HEIGHT][MAP_WIDTH];typedef struct {	short point_x;	short point_y;	short grid_x;	short grid_y;	short step_y;	short step_x;} raytrace;