示例#1
0
void updateEnergyBall(room_s* r, energyBall_s* eb)
{
	if(!eb)return;
	
	vect3Df_s l=eb->position;
	
	vect3Df_s ip=l, normal;
	rectangle_s* col=collideGridCell(getCurrentCell(r,eb->position), eb->launcher?eb->launcher->surface:NULL, l, eb->direction, eb->speed, &ip, &normal);
	if(!col)col=collideGridCell(getCurrentCell(r,vaddf(eb->position,vmulf(eb->direction,eb->speed))), eb->launcher?eb->launcher->surface:NULL, l, eb->direction, eb->speed, &ip, &normal);
	if(col)
	{
		// printf("COL COL COL %d\n",col->collides);
		energyDevice_s* ed=isEnergyCatcherSurface(col);
		if(ed && !ed->active)
		{
			//caught
			md2InstanceChangeAnimation(&ed->modelInstance,2,false);
			md2InstanceChangeAnimation(&ed->modelInstance,1,true);
			killEnergyBall(eb);
			if(eb->launcher)eb->launcher->active=false;
			ed->active=true;
			return;
		}

		vect3Df_s v=vect3Df(0,0,0);
		float x, y, z;
		portal_s* portal=NULL;
		int i;
		for(i=0; i<NUM_PORTALS && !portal; i++)
		{
			if(isPointInPortal(&portals[i],ip,&v,&x,&y,&z))portal=&portals[i];
			if(portal && fabs(z)>=0.1f)portal=NULL;
		}
		if(portal && !portal->target)portal=NULL;
		if(!portal)
		{
			eb->position=ip;
			eb->direction=vsubf(eb->direction,vmulf(normal,2*vdotf(eb->direction,normal)));
			eb->position=vaddf(eb->position,vmulf(eb->direction,ENERGYBALLSIZE));
		}else if(portal->target && portal->open && portal->target->open){
			eb->position=vaddf(eb->position,vmulf(eb->direction,eb->speed));
			warpEnergyBall(portal,eb);
			eb->position=vaddf(eb->position,vmulf(eb->direction,eb->speed));
		}

	}else{
		eb->position=vaddf(eb->position,vmulf(eb->direction,eb->speed));
	}
	
	md2InstanceUpdate(&eb->modelInstance);
	
	if(!eb->life)killEnergyBall(eb);
	else eb->life--;
}
示例#2
0
文件: turrets.c 项目: Almamu/portalDS
void laserProgression(room_struct* r, vect3D* origin, vect3D* destination, vect3D dir)
{
	if(!r || !origin || !destination)return;
	vect3D ip;
	vect3D l=*origin;
	vect3D v=vectDifference(addVect(l,vectMult(dir,32)),convertSize(vect(r->position.x,0,r->position.y)));
	gridCell_struct* gc=getCurrentCell(r,l);
	while(gc && !collideGridCell(gc, NULL, v, dir, inttof32(100), &ip, NULL))
	{
		l=addVect(l,vectMult(dir,CELLSIZE*TILESIZE*2));
		gc=getCurrentCell(r,l);
	}
	if(gc)*destination=addVect(ip,convertSize(vect(r->position.x,0,r->position.y)));
}