⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game.c

📁 小型游戏引擎
💻 C
📖 第 1 页 / 共 5 页
字号:
											sector[j].ceilingstat |= 64;											sector[j].floorstat |= 64;										}										subwaytracksector[subwaytrackcnt][subwaynumsectors[subwaytrackcnt]] = j;										subwaynumsectors[subwaytrackcnt]++;									}					}				subwayvel[subwaytrackcnt] = 64;				subwaypausetime[subwaytrackcnt] = 720;				startwall = sector[i].wallptr;				endwall = startwall+sector[i].wallnum;				for(k=startwall;k<endwall;k++)					if (wall[k].x > subwaytrackx1[subwaytrackcnt])						if (wall[k].y > subwaytracky1[subwaytrackcnt])							if (wall[k].x < subwaytrackx2[subwaytrackcnt])								if (wall[k].y < subwaytracky2[subwaytrackcnt])									setinterpolation(&wall[k].x);				for(j=1;j<subwaynumsectors[subwaytrackcnt];j++)				{					dasector = subwaytracksector[subwaytrackcnt][j];					startwall = sector[dasector].wallptr;					endwall = startwall+sector[dasector].wallnum;					for(k=startwall;k<endwall;k++)						setinterpolation(&wall[k].x);					for(k=headspritesect[dasector];k>=0;k=nextspritesect[k])						if (statrate[sprite[k].statnum] < 0)							setinterpolation(&sprite[k].x);				}				subwaytrackcnt++;				break;		}		if (sector[i].floorpicnum == FLOORMIRROR)			floormirrorsector[mirrorcnt++] = i;	}		/* Scan wall tags */	mirrorcnt = 0;	tilesizx[MIRROR] = 0;	tilesizy[MIRROR] = 0;	for(i=0;i<MAXMIRRORS;i++)	{		tilesizx[i+MIRRORLABEL] = 0;		tilesizy[i+MIRRORLABEL] = 0;	}	ypanningwallcnt = 0;	for(i=0;i<numwalls;i++)	{		if (wall[i].lotag == 1) ypanningwalllist[ypanningwallcnt++] = i;		s = wall[i].nextsector;		if ((s >= 0) && (wall[i].overpicnum == MIRROR) && (wall[i].cstat&32))		{			if ((sector[s].floorstat&1) == 0)			{				wall[i].overpicnum = MIRRORLABEL+mirrorcnt;				sector[s].ceilingpicnum = MIRRORLABEL+mirrorcnt;				sector[s].floorpicnum = MIRRORLABEL+mirrorcnt;				sector[s].floorstat |= 1;				mirrorwall[mirrorcnt] = i;				mirrorsector[mirrorcnt] = s;				mirrorcnt++;			}			else				wall[i].overpicnum = sector[s].ceilingpicnum;		}	}		/* Invalidate textures in sector behind mirror */	for(i=0;i<mirrorcnt;i++)	{		k = mirrorsector[i];		startwall = sector[k].wallptr;		endwall = startwall + sector[k].wallnum;		for(j=startwall;j<endwall;j++)		{			wall[j].picnum = MIRROR;			wall[j].overpicnum = MIRROR;		}	}		/* Scan sprite tags&picnum's */	turnspritecnt = 0;	for(i=0;i<MAXSPRITES;i++)	{		if (sprite[i].lotag == 3) turnspritelist[turnspritecnt++] = i;		if (sprite[i].statnum < MAXSTATUS)    /* That is, if sprite exists */			switch(sprite[i].picnum)			{				case BROWNMONSTER:              /* All cases here put the sprite */					if ((sprite[i].cstat&128) == 0)					{						sprite[i].z -= ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1);						sprite[i].cstat |= 128;					}					sprite[i].extra = sprite[i].ang;					sprite[i].clipdist = mulscale7(sprite[i].xrepeat,tilesizx[sprite[i].picnum]);					if (sprite[i].statnum != 1) changespritestat(i,2);   /* on waiting for you (list 2) */					sprite[i].lotag = mulscale5(sprite[i].xrepeat,sprite[i].yrepeat);					sprite[i].cstat |= 0x101;    /* Set the hitscan sensitivity bit */					break;				case AL:					sprite[i].cstat |= 0x101;    /* Set the hitscan sensitivity bit */					sprite[i].lotag = 0x60;					changespritestat(i,0);					break;				case EVILAL:					sprite[i].cstat |= 0x101;    /* Set the hitscan sensitivity bit */					sprite[i].lotag = 0x60;					changespritestat(i,10);					break;			}	}	for(i=MAXSPRITES-1;i>=0;i--) copybuf(&sprite[i].x,&osprite[i].x,3);	searchmap(cursectnum[connecthead]);	lockclock = 0;	ototalclock = 0;	gotlastpacketclock = 0;	screensize = xdim;	dax = ((xdim-screensize)>>1);	dax2 = dax+screensize-1;	day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1);	day2 = day + scale(screensize,ydim-32,xdim)-1;	setview(dax,day,dax2,day2);	startofdynamicinterpolations = numinterpolations;}long changehealth(short snum, short deltahealth){	/*long dax, day;*/	/*short good, k, startwall, endwall, s;*/	if (health[snum] > 0)	{		health[snum] += deltahealth;		if (health[snum] > 999) health[snum] = 999;		if (health[snum] <= 0)		{			health[snum] = -1;			wsayfollow("death.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1);			sprite[playersprite[snum]].picnum = SKELETON;		}		if ((snum == screenpeek) && (screensize <= xdim))		{			if (health[snum] > 0)				sprintf((char*)&tempbuf,"Health:%3ld",health[snum]);			else				sprintf((char*)&tempbuf,"YOU STINK!");			printext((xdim>>1)-(strlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80);		}	}	return(health[snum] <= 0);      /* You were just injured */}void changenumbombs(short snum, short deltanumbombs) {   /* Andy did this */	numbombs[snum] += deltanumbombs;	if (numbombs[snum] > 999) numbombs[snum] = 999;	if (numbombs[snum] <= 0) {		wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1);		numbombs[snum] = 0;	}	if ((snum == screenpeek) && (screensize <= xdim)) {		sprintf((char*)&tempbuf,"B:%3d",numbombs[snum]);		printext(8L,(ydim - 28L),tempbuf,ALPHABET,80);	}}void changenummissiles(short snum, short deltanummissiles) {   /* Andy did this */	nummissiles[snum] += deltanummissiles;	if (nummissiles[snum] > 999) nummissiles[snum] = 999;	if (nummissiles[snum] <= 0) {		wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1);		nummissiles[snum] = 0;	}	if ((snum == screenpeek) && (screensize <= xdim)) {		sprintf((char*)&tempbuf,"M:%3d",nummissiles[snum]);		printext(8L,(ydim - 20L),tempbuf,ALPHABET,80);	}}void changenumgrabbers(short snum, short deltanumgrabbers) {   /* Andy did this */	numgrabbers[snum] += deltanumgrabbers;	if (numgrabbers[snum] > 999) numgrabbers[snum] = 999;	if (numgrabbers[snum] <= 0) {		wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1);		numgrabbers[snum] = 0;	}	if ((snum == screenpeek) && (screensize <= xdim)) {		sprintf((char*)&tempbuf,"G:%3d",numgrabbers[snum]);		printext(8L,(ydim - 12L),tempbuf,ALPHABET,80);	}}void findrandomspot(long *x, long *y, short *sectnum){	short startwall, endwall, s, dasector;	long dax, day, daz, minx, maxx, miny, maxy, cnt;	for(cnt=256;cnt>=0;cnt--)	{		do		{			dasector = mulscale16(krand(),numsectors);		} while ((sector[dasector].ceilingz+(8<<8) >= sector[dasector].floorz) || ((sector[dasector].lotag|sector[dasector].hitag) != 0) || ((sector[dasector].floorstat&1) != 0));		startwall = sector[dasector].wallptr;		endwall = startwall+sector[dasector].wallnum;		if (endwall <= startwall) continue;		dax = 0L;		day = 0L;		minx = 0x7fffffff; maxx = 0x80000000;		miny = 0x7fffffff; maxy = 0x80000000;		for(s=startwall;s<endwall;s++)		{			dax += wall[s].x;			day += wall[s].y;			if (wall[s].x < minx) minx = wall[s].x;			if (wall[s].x > maxx) maxx = wall[s].x;			if (wall[s].y < miny) miny = wall[s].y;			if (wall[s].y > maxy) maxy = wall[s].y;		}		if ((maxx-minx <= 256) || (maxy-miny <= 256)) continue;		dax /= (endwall-startwall);		day /= (endwall-startwall);		if (inside(dax,day,dasector) == 0) continue;		daz = sector[dasector].floorz-(32<<8);		if (pushmove(&dax,&day,&daz,&dasector,128L,4<<8,4<<8,CLIPMASK0) < 0) continue;		*x = dax; *y = day; *sectnum = dasector;		return;	}}long getanimationgoal(long animptr){	long i;	for(i=animatecnt-1;i>=0;i--)		if ((long *)animptr == animateptr[i]) return(i);	return(-1);}long setanimation(long *animptr, long thegoal, long thevel, long theacc){	long i, j;	if (animatecnt >= MAXANIMATES) return(-1);	j = animatecnt;	for(i=animatecnt-1;i>=0;i--)		if (animptr == animateptr[i])			{ j = i; break; }	setinterpolation(animptr);	animateptr[j] = animptr;	animategoal[j] = thegoal;	animatevel[j] = thevel;	animateacc[j] = theacc;	if (j == animatecnt) animatecnt++;	return(j);}void operatesector(short dasector){     /* Door code */	long i, j, datag;	long daz, dax2, day2, centx, centy;	short startwall, endwall, wallfind[2];	datag = sector[dasector].lotag;	startwall = sector[dasector].wallptr;	endwall = startwall + sector[dasector].wallnum;	centx = 0L, centy = 0L;	for(i=startwall;i<endwall;i++)	{		centx += wall[i].x;		centy += wall[i].y;	}	centx /= (endwall-startwall);	centy /= (endwall-startwall);		/* Simple door that moves up  (tag 8 is a combination of tags 6 & 7) */	if ((datag == 6) || (datag == 8))    /* If the sector in front is a door */	{		i = getanimationgoal((long)&sector[dasector].ceilingz);		if (i >= 0)      /* If door already moving, reverse its direction */		{			if (datag == 8)				daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);			else				daz = sector[dasector].floorz;			if (animategoal[i] == daz)				animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;			else				animategoal[i] = daz;			animatevel[i] = 0;		}		else      /* else insert the door's ceiling on the animation list */		{			if (sector[dasector].ceilingz == sector[dasector].floorz)				daz = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;			else			{				if (datag == 8)					daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);				else					daz = sector[dasector].floorz;			}			if ((j = setanimation(&sector[dasector].ceilingz,daz,6L,6L)) >= 0)				wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);		}	}		/* Simple door that moves down */	if ((datag == 7) || (datag == 8)) /* If the sector in front's elevator */	{		i = getanimationgoal((long)&sector[dasector].floorz);		if (i >= 0)      /* If elevator already moving, reverse its direction */		{			if (datag == 8)				daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);			else				daz = sector[dasector].ceilingz;			if (animategoal[i] == daz)				animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;			else				animategoal[i] = daz;			animatevel[i] = 0;		}		else      /* else insert the elevator's ceiling on the animation list */		{			if (sector[dasector].floorz == sector[dasector].ceilingz)				daz = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;			else			{				if (datag == 8)					daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);				else					daz = sector[dasector].ceilingz;			}			if ((j = setanimation(&sector[dasector].floorz,daz,6L,6L)) >= 0)				wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);		}	}	if (datag == 9)   /* Smooshy-wall sideways double-door */	{		/*         * find any points with either same x or same y coordinate		 *  as center (centx, centy) - should be 2 points found.         */		wallfind[0] = -1;		wallfind[1] = -1;		for(i=startwall;i<endwall;i++)			if ((wall[i].x == centx) || (wall[i].y == centy))			{				if (wallfind[0] == -1)					wallfind[0] = i;				else					wallfind[1] = i;			}		for(j=0;j<2;j++)		{			if ((wall[wallfind[j]].x == centx) && (wall[wallfind[j]].y == centy))			{				/*                 * find what direction door should open by averaging the				 *  2 neighboring points of wallfind[0] & wallfind[1].                 */				i = wallfind[j]-1; if (i < startwall) i = endwall-1;				dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x;				day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y;				if (dax2 != 0)				{					dax2 = wall[wall[wall[wallfind[j]].point2].point2].x;					dax2 -= wall[wall[wallfind[j]].point2].x;					setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -