Exemplo n.º 1
0
/************************************************************
This is where all of glutDisplayFunc() is handled
**************************************************************/
void drawScene()
{
									
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);

	ALint play;
	printMaze();
	
	
	glPushMatrix();	
		glTranslatef(startX,startY,0.0f);
		if(danger(mines,startX,startY) == true)
		{
			glColor3f(1.0f,0.0f,0.0f);
			alGetSourcei(Sources[2], AL_SOURCE_STATE, &play);
            alSourcefv(Sources[2], AL_POSITION, SourcePos[2] );
            alSourcePlay(Sources[2]);
				
		}else
		{
			glColor3f(1.0f,1.0f,0.0f);
		}
		
		glutSolidSphere(0.5,20,20);
	glPopMatrix();
	

		if(primitive == 1)
		{
			for(int row = 0; row < ROWMAX;row++)
			{
				for(int col = 0; col < COLMAX;col++)
				{		
					if(mines[col][row] == '*')
					{
						glPushMatrix();
							glBegin(GL_QUADS);
							glColor3f(1.0f, 0.0f, 1.0f);
							glVertex3f(col+0.5,row+0.5,1.0f);				// Top Right Of The Quad (Bottom)
							glVertex3f(col-0.5,row+0.5,1.0f);					// Top Left Of The Quad (Bottom)
							glVertex3f(col-0.5,row-0.5,1.0f);						// Bottom Left Of The Quad (Bottom)
							glVertex3f(col+0.5,row-0.5,1.0f);					// Bottom Right Of The Quad (Bottom)
							glEnd();
						glPopMatrix();

					}
				}
			}
		}

	glutSwapBuffers();

}
Exemplo n.º 2
0
void protect (char *pass, char *nome) {
  if (valid(pass))
    danger(nome);
}
Exemplo n.º 3
0
void car::adapt(std::vector<car>& way,double time,int num)
{
	std::vector<car> left,front,right;
	double frontmin=1000;
	int fp=0;
#if ACCIEDENT==1
	if(rand()%100000<1||broken)
	{
		speed=0;
		broken=1;
		return;
	}
#endif
	//
	//We assume the car has been sort before

	for(int i=num+1;i<way.size() && way[i].location-location<distance();i++)
	{
		car c=way[i];

		if(c.lane==this->lane)
		{
			front.push_back(c);
			if(c.speed<frontmin)
				frontmin=c.speed;
		}

		if(c.lane==this->lane+1&&(c.location-this->location)<distance() )
			left.push_back(c);
		if(c.lane==this->lane-1&&(c.location-this->location)<distance() )
			right.push_back(c);
	}
	if(front.size()>0)
	{
		car &fron=front[0];
		dangercol=danger(fron);
		bra=1;
	}
	else
		bra=0;
	/*
	for(int i=num-1;i>=0 && fabs(way[i].location-location)<side;i--)
	{
		car c=way[i];

		if(c.lane==this->lane+1&&(c.location-this->location)<side)
			left.push_back(c);
		if(c.lane==this->lane-1&&(c.location-this->location)<side)
			right.push_back(c);
	}
	*/
	if (front.size()>0&& (frontmin<=maxspeed) )
	{
		if(frontmin<1e-2)
		{
#ifdef RIGHTSYS
			if(lane<MAXLANE-1)
				lane++;
			else
				speed=0;
#else
			if(lane>0)
				lane--;
			else
				speed=0;
#endif
			return;
		}
		if(lane<MAXLANE-1&&left.size()==0&&fabs(lasw-time)>SWITCHTIME)
		{
			lane++;
			fp=1;
			lasw=time;
			speed+=5;
			if(speed>maxspeed)
				speed=maxspeed;
			return;
		}
		speed=frontmin;
		return;
	}
	if(front.size()>1)
	{
		if(lane<MAXLANE-1&&left.size()==0)
		{
			lane++;
			lasw=time;
			speed+=5;
			if(speed>maxspeed)
				speed=maxspeed;
			return;
		}
		else if(lane>0&&right.size()==0)
		{
			lane--;
			lasw=time;
			return;
		}
		else
		{
			speed-=10;
			if(speed<0)
				speed=0;
			return;
		}

	}

	if((lane>1||(lane>0 &&rand()%500<1) )&&right.size()==0&&fp!=1&&fabs(lasw-time)>SWITCHTIME)
	{
		lasw=time;
		lane--;
		return;
	}
	if(lane>0&&right.size()!=0&&speed<maxspeed)
	{
		speed+=5;
		return;
	}
	if(front.size()==0&&(speed<maxspeed*0.7||mind>70000))
	{
		speed+=5;
		if(speed>maxspeed)
			speed=maxspeed;
		return;
	}
	if(mind<80001&&speed>0.7*maxspeed)
		speed-=10;
	if(speed>maxspeed)
		speed=maxspeed;
}