Esempio n. 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--;
}
Esempio n. 2
0
void checkPortalPlayerWarp(player_s* pl, portal_s* p)
{
	if(!pl || !p || !p->open || !p->target || !p->target->open)return;
	vect3Df_s v;
	float x, y, z;
	bool r=isPointInPortal(p, pl->object.position, &v, &x, &y, &z);
	if(r)
	{
		// printf("z : %f\n",p->oldPlayerZ);
		if(p->oldPlayerR && (z>=0.0f && p->oldPlayerZ<=0.0f))
		{
			// currentPortal=p;
			warpPlayer(p, pl);
			// gravityGunTarget=-1;
		}

		pl->oldInPortal=pl->inPortal;

		if(fabs(z) < PLAYER_RADIUS)pl->inPortal=true;
		else pl->inPortal=false;
	}
	p->oldPlayerR = r;
	p->oldPlayerZ = z;
}
Esempio n. 3
0
void updateTurret(turret_struct* t)
{
	if(!t || !t->used)return;
	
	if(!t->OBB || !t->OBB->used){t->OBB=NULL;t->used=false;return;}
	
	t->counter+=2;t->counter%=63; //TEMP
	if(t->dead)t->counter=31;
	editPalette((u16*)t->OBB->modelInstance.palette,0,RGB15(abs(31-t->counter),0,0)); //TEMP
	
	int32* m=t->OBB->transformationMatrix;
	room_struct* r=getPlayer()->currentRoom;
	if(!r)return;

	int32 angle, d;
	bool b=pointInTurretSight(t, getPlayer()->object->position, &angle, &d);
	if(b)
	{
		vect3D u=vectDifference(getPlayer()->object->position,t->laserOrigin);
		int32 d=magnitude(u);
		u=divideVect(u,d);
		if(collideLineMap(&gameRoom, NULL, t->laserOrigin, u, d, NULL, NULL))b=false;
	}

	switch(t->state)
	{
		case TURRET_CLOSED:
			changeAnimation(&t->OBB->modelInstance, 0, false);
			t->drawShot[0]=t->drawShot[1]=0;

			if(b && !t->dead){t->state=TURRET_OPENING; playSFX(turretDeploySFX);}
			break;
		case TURRET_OPENING:
			if(t->OBB->modelInstance.currentAnim==2)
			{
				t->state=TURRET_OPEN;
			}else if(t->OBB->modelInstance.currentAnim!=1)
			{
				changeAnimation(&t->OBB->modelInstance, 2, false);
				changeAnimation(&t->OBB->modelInstance, 1, true);
			}
			t->drawShot[0]=t->drawShot[1]=0;
			break;
		case TURRET_OPEN:
			{
				if(angle>mulf32(sinLerp(TURRET_SIGHTANGLE/3),d))changeAnimation(&t->OBB->modelInstance, 4, false);
				else if(angle<-mulf32(sinLerp(TURRET_SIGHTANGLE/3),d))changeAnimation(&t->OBB->modelInstance, 5, false);
				else changeAnimation(&t->OBB->modelInstance, 2, false);

				int i;
				for(i=0;i<2;i++)
				{
					if(!t->drawShot[i] && !(rand()%3))
					{
						t->drawShot[i]=rand()%8;
						t->shotAngle[i]=rand();

						shootPlayer(NULL, normalize(vectDifference(t->laserDestination,t->laserOrigin)), 6);
						playSFX(turretFireSFX);
					}

					if(t->drawShot[i])t->drawShot[i]--;
				}

				if(!b || t->dead){t->state=TURRET_CLOSING; playSFX(turretRetractSFX);}
			}
			break;
		case TURRET_CLOSING:
			if(t->OBB->modelInstance.currentAnim==0)
			{
				t->state=TURRET_CLOSED;
			}else if(t->OBB->modelInstance.currentAnim!=3)
			{
				changeAnimation(&t->OBB->modelInstance, 0, false);
				changeAnimation(&t->OBB->modelInstance, 3, true);
			}
			t->drawShot[0]=t->drawShot[1]=0;
			break;
	}

	if(!t->dead)
	{
		t->laserOrigin=addVect(vectDivInt(t->OBB->position,4),evalVectMatrix33(m,laserOrigin));
		t->laserDestination=addVect(t->laserOrigin,vect(m[2],m[5],m[8]));

		if(b)t->laserDestination=getPlayer()->object->position;

		vect3D dir=normalize(vectDifference(t->laserDestination,t->laserOrigin));
		t->laserThroughPortal=false;

		laserProgression(r, &t->laserOrigin, &t->laserDestination, dir);
		
		int32 x, y, z;
		vect3D v;
		portal_struct* portal=NULL;
		if(isPointInPortal(&portal1, t->laserDestination, &v, &x, &y, &z))portal=&portal1;
		if(abs(z)>=32)portal=NULL;
		if(!portal)
		{
			if(isPointInPortal(&portal2, t->laserDestination, &v, &x, &y, &z))portal=&portal2;
			if(abs(z)>=32)portal=NULL;
		}
		if(portal)
		{
			t->laserDestination=addVect(t->laserDestination,vectMult(dir,TILESIZE));


			t->laserThroughPortal=true;
			dir=warpVector(portal,dir);
			t->laserOrigin2=addVect(portal->targetPortal->position, warpVector(portal, vectDifference(t->laserDestination, portal->position)));
			t->laserDestination2=addVect(t->laserOrigin2,dir);
			
			laserProgression(r, &t->laserOrigin2, &t->laserDestination2, dir);
			

			t->laserOrigin2=addVect(t->laserOrigin2,vectMult(dir,-TILESIZE));
		}

		if(m[4]<sinLerp(8192/2))t->dead=true;
	}
	
	updateAnimation(&t->OBB->modelInstance);
}