Ejemplo 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--;
}
Ejemplo n.º 2
0
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)));
}
Ejemplo n.º 3
0
int Maze::undoMove(point loc) {
   if (!validRoom(loc))
      return 0;
   
   // TODO:  possibly not just empty, but last maze status before moveCurrent()
//   cerr << "currCell: " << currCell.y << ", " << currCell.x << endl;
 //  cerr << "undo: " << (currCell.x==loc.x&&currCell.y==loc.y);

   getCurrentCell()->setMazeStatus(getCurrentCell()->getOldMazeStatus());
   getCell(loc.y, loc.x)->setMazeStatus(CURRENT);
//   grid[currCell.y][currCell.x].setMazeStatus(EMPTY);
//   grid[loc.y][loc.x].setMazeStatus(CURRENT);
   currCell = loc;
   --nodesVisited;

  // cerr << "End-currCell: " << currCell.x << ", " << currCell.y << endl;
	onNodesVisitedChanged();
   // TODO:  update m_noVisited counter
   
   return 1;
}
Ejemplo n.º 4
0
bool checkObjectCollision(physicalPoint_s* o, room_s* r)
{	
	bool ret=false;

	gridCell_s* gc = getCurrentCell(r, o->position);

	// listCell_s* l = r->rectangles.first;
	// while(l)
	// {
	// 	if(l->data.collides)
	// 	{
	// 		l->data.touched = collideRectangle(o, convertRectangleVector(l->data.position), convertRectangleVector(l->data.size));
	// 		ret = l->data.touched || ret;
	// 	}
	// 	l = l->next;
	// }

	int i;
	for(i=0;i<gc->numRectangles;i++)
	{
		rectangle_s* rec=gc->rectangles[i];
		if(rec->collides)
		{
			rec->touched = collideRectangle(o, convertRectangleVector(rec->position), convertRectangleVector(rec->size));
			ret = rec->touched || ret;
		}
	}

	//platforms
	for(i=0;i<NUMPLATFORMS;i++)
	{
		if(platform[i].used && collideRectangle(o,vaddf(platform[i].position,vect3Df(-PLATFORMSIZE,0,-PLATFORMSIZE)),vect3Df(PLATFORMSIZE*2,0,PLATFORMSIZE*2))) //add culling
		{
			platform[i].touched=true;
			ret=true;
		}
	}

	//elevators
	u8 val=0;
	if((entryWallDoor.used && checkObjectElevatorCollision(o,r,&entryWallDoor.elevator)) || (exitWallDoor.used && (val=checkObjectElevatorCollision(o,r,&exitWallDoor.elevator))))ret=true;
	if(val==2)closeElevator(&exitWallDoor.elevator);
	
	//timed buttons
	if(checkObjectTimedButtonsCollision(o,r))ret=true;

	return ret;
}
Ejemplo n.º 5
0
/*
 * moves the little guy to the right point
 */
int Maze::moveCurrent(point loc) {
   if (!validRoom(loc))
      exitWithPopup("You passed an invalid cell id to draw_arrow",0);
   
   //cerr << "moveCurrent: " <<  currCell.y << ", " << currCell.x;
//   cerr << ", (" << getCurrentCell() << ", " << getCell(loc.y, loc.x) << ")\n";

   getCurrentCell()->setMazeStatus(SEARCHED);
//   cerr << "moveCurrent: " << getCurrentCell()->getMazeStatus() << endl;
//   m_grid[currCell.y][currCell.x].setMazeStatus(SEARCHED);
   getCell(loc.y, loc.x)->setMazeStatus(CURRENT);
//   m_grid[loc.y][loc.x].setMazeStatus(CURRENT);
   currCell = loc;
   ++nodesVisited;
   
   onNodesVisitedChanged();
//   cerr << ";moveCurrent\n";
   // TODO:  update m_noVisited counter

   return 1;
}
VectorXY MazeGenerationManager::getNextCellCoordinates()
{
	return getCurrentCell()->getCoordinates() + Directions::getDirectionVector(nextDirection);
}
std::shared_ptr<Room> MazeGenerationManager::getCurrentRoom()
{
	std::shared_ptr<Room> room = getCurrentCell()->room.lock();
	return room;
}