Beispiel #1
0
// Idle callback
// Para controlar el tiempo
void Idle_cb() {
  static unsigned int lt=0;
  int dt = glutGet(GLUT_ELAPSED_TIME) - lt;
  if(dt > 60) {
    
    // Convierte AvionAng de grados a radianes
    double ang=AvionAng*PI/180.0;
    
    if ( teclado.Salir() ) {
      exit( EXIT_SUCCESS );
    }
    if ( teclado.Adelante() ) {
      AvionX-=5*sin(ang);
      AvionY+=5*cos(ang);
    }
    if ( teclado.Atras() ) {
      AvionX+=5*sin(ang);
      AvionY-=5*cos(ang);
    }
    if ( teclado.Izquierda() ) {
      AvionAng+=2;
    }
    if ( teclado.Derecha() ) {
      AvionAng-=2;
    }
    
    lt = glutGet(GLUT_ELAPSED_TIME);
    glutPostRedisplay();
  }
}
Beispiel #2
0
void Avion::Mover(int dt,Teclado& teclado)
{
	if(isDead)
	{
		//Mostrar explosion
	}
	else
	{
	  fx[0]->Actualizar();
	  fx[2]->Actualizar();

	  if(isFired)
	  {
		MetrallaX += velMetralla_x;
		MetrallaY += velMetralla_y;
		
		incxMetralla += velMetralla_x;
		incyMetralla += velMetralla_y;

		if(abs(incyMetralla) > 1000 || abs(incxMetralla) > 1000)
		{
			isFired = false;
			MetrallaX = 0;
			MetrallaY = 0;
			incyMetralla = 0;
			incxMetralla = 0;
		}

		double ang1=(AngMetralla)*PI/180.0;
		
		fx[1]->SetPosicion(MetrallaX+20*cosf(ang1)+sinf(ang1),MetrallaY+20*sinf(ang1)-cosf(ang1));
		fx[1]->Actualizar();
		
		fx[1]->SetPosicion(MetrallaX-12*cosf(ang1)+sinf(ang1),MetrallaY-12*sinf(ang1)-cosf(ang1));		
		fx[1]->Actualizar();

		if(!fx[1]->GetActivo()) 
		{
			fx[1]->ToggleActivo();
		}

	  }
	  else
	  {
		  fx[1]->Actualizar();
	  }

	  lightY++;
	  if(lightY > 20.0)
		  lightY = 0.0;

	  //Convierte AvionAng de grados a radianes
	  double ang=AvionAng*PI/180.0;

	  if(teclado.Adelante())
	  {
		 isReady =  true;
	  }

	  if(isReady)	  
	  {
		  // double sin(double ang); // Calcula el seno de ang medido en radianes
		  if(teclado.Atras()) //Turbo
		  {
			  AvionX-=12*sin(ang);
			  AvionY+=12*cos(ang);
			  lightY +=5;
			  isTurbo = true;
		  }
		  else
		  {
			  AvionX-=3*sin(ang);
			  AvionY+=3*cos(ang);
			  isTurbo = false;
		  }
	  }

	  /*if(teclado.Atras())
	  {
		AvionX+=5*sin(ang);
		AvionY-=5*cos(ang);
	  }*/

	  if(teclado.IzquierdaAux())
	  {
		AvionAng+=2;
	  }

	  if(teclado.DerechaAux())
	  {
		AvionAng-=2;		
	  }

	  if(!isFired && teclado.Disparar())
	  {
		  if(fx[1]->GetActivo()) 
		  {
			fx[1]->ToggleActivo();
		  }

		  isFired = true;		
		  AngMetralla = AvionAng;

		  double ang3=(AngMetralla)*PI/180.0;
		  ang3 += PI/2;

		  MetrallaX = AvionX+cos(ang3)*20;
		  MetrallaY = AvionY+sin(ang3)*20;
		  		 
		  velMetralla_x = 18*cos(ang3);
		  velMetralla_y = 18*sin(ang3);
		 
	  }

	  if(isTurbo)
	  { 
		if(!fx[0]->GetActivo()) 
		{
			fx[0]->ToggleActivo();
		}		
	  }
	  else
	  {
		if(fx[0]->GetActivo()) 
		{
			fx[0]->ToggleActivo();
		}
	  }
	  if(fx[0]->GetActivo())
	  {
		fx[0]->SetPosicion(AvionX,AvionY);				 
	  }

	  if(fx[2]->GetActivo())
	  {
		fx[2]->SetPosicion(AvionX,AvionY);				 
	  }
	}
}
Beispiel #3
0
void
Dios::Update()
{
	Teclado *teclado = Juego::GetInstance()->GetTeclado();
	AddPoder(0.01f);

	core::vector3df pos = nodo->getPosition();

	if ( diosIzquierdo )
	{
		if ( teclado->KeyDown(irr::EKEY_CODE::KEY_KEY_Z) )
		{
			if(poder[0]>0)
			{
				this->partida->CrearDisparo(pos,poder[0],1,this);
				poder[0]=0;
				poder[1]=poder[1]/1.2;
				poder[2]=poder[2]/1.2;
			}
		}
		else if ( teclado->KeyDown(irr::EKEY_CODE::KEY_KEY_X) )
		{
			if(poder[0]>0)
			{
				this->partida->CrearDisparo(pos,poder[1],2,this);
				poder[1]=0;
				poder[0]=poder[0]/1.2;
				poder[2]=poder[2]/1.2;
			}
		}
		if ( teclado->KeyDown(irr::EKEY_CODE::KEY_KEY_C) )
		{
			if(poder[0]>0)
			{
				this->partida->CrearDisparo(pos,poder[2],3,this);
				poder[2]=0;
				poder[0]=poder[0]/1.2;
				poder[1]=poder[1]/1.2;
			}
		}

		if ( teclado->Key(irr::EKEY_CODE::KEY_KEY_Q) )
		{
			pos.X += 0.2f ;
		}
		else if ( teclado->Key(irr::EKEY_CODE::KEY_KEY_A) )
		{
			pos.X -= 0.2f ;
		}
	}
	else
	{
		if ( teclado->KeyDown(irr::EKEY_CODE::KEY_NUMPAD1) )
		{
			if(poder[0]>0)
			{
				this->partida->CrearDisparo(pos,poder[0],1,this);
				poder[0]=0;
				poder[1]=poder[1]/1.2;
				poder[2]=poder[2]/1.2;
			}
		}
		if ( teclado->KeyDown(irr::EKEY_CODE::KEY_NUMPAD2) )
		{
			if(poder[0]>0)
			{
				this->partida->CrearDisparo(pos,poder[1],2,this);
				poder[1]=0;
				poder[0]=poder[0]/1.2;
				poder[2]=poder[2]/1.2;
			}
		}
		if ( teclado->KeyDown(irr::EKEY_CODE::KEY_NUMPAD3) )
		{
			if(poder[0]>0)
			{
				this->partida->CrearDisparo(pos,poder[2],3,this);
				poder[2]=0;
				poder[0]=poder[0]/1.2;
				poder[1]=poder[1]/1.2;
			}
		}

		if ( teclado->Key(irr::EKEY_CODE::KEY_UP) )
		{
			pos.X += 0.2f ;
		}
		else if ( teclado->Key(irr::EKEY_CODE::KEY_DOWN) )
		{
			pos.X -= 0.2f ;
		}
	}

	// Comprobamos que no nos salimos de la pantalla
	if ( pos.X < -25.0f )
	{
		pos.X = -25.0f ;
	}
	else if ( pos.X > 25.0f )
	{
		pos.X = 25.0f ;
	}

	nodo->setPosition(pos);
}
Beispiel #4
0
//------------------------------------------------------------
void inicializa() {
  // GLUT
  glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);// pide color RGB y double buffering
  glutInitWindowSize(w,h); glutInitWindowPosition(10,10);
  glutCreateWindow("TP N°3 - Nahuel Lattessi"); // crea el main window

  // declara los callbacks, los que (aun) no se usan (aun) no se declaran
  glutDisplayFunc(Display_cb);
  glutReshapeFunc(Reshape_cb);
  //glutKeyboardFunc(Keyboard_cb);
  //glutSpecialFunc(Special_cb);
  teclado.Iniciar();
  glutIdleFunc(Idle_cb);

  // OpenGL
  //glClearColor(0.01f,0.01f,0.01f,1.f); // color de fondo
  // Activo el zbuffer
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
  glDepthRange(0.0, 1.0);
  glClearDepth(1.0);
  
  // Inicializo texturas
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glGenTextures(5,texid);
  
  // Textura1 = 1D // Stripe
  makeStripeImage();
  glBindTexture(GL_TEXTURE_1D, texid[0]);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_DECAL);
  glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, stripeImageWidth, 0, GL_RGBA, GL_UNSIGNED_BYTE, stripeImage);
  
  // Textura2 = 2D // Check
  makeCheckImage();
  glBindTexture(GL_TEXTURE_2D, texid[1]);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, otherImage);
    
  // Textura3 = 2D // Pasto
  glBindTexture(GL_TEXTURE_2D, texid[2]);
  mipmap_ppm("Assets/grass.ppm");
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  
  // Textura4 = 2D // Cubo
  glBindTexture(GL_TEXTURE_2D, texid[3]);
  mipmap_ppm("Assets/cubo.ppm");
  
  // Textura5 // Spry para el ala
  glBindTexture(GL_TEXTURE_2D, texid[4]);
  mipmap_ppm("Assets/Spry.ppm");

  // las operaciones subsiguientes se aplican a la matriz de modelado GL_MODELVIEW
  glMatrixMode(GL_MODELVIEW); glLoadIdentity();
}
Beispiel #5
0
//------------------------------------------------------------
void inicializa() {
  // GLUT
  glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);// pide color RGB y double buffering
  glutInitWindowSize(w,h); glutInitWindowPosition(10,10);
  glutCreateWindow("Ejemplo Avion"); // crea el main window

  // declara los callbacks, los que (aun) no se usan (aun) no se declaran
  glutDisplayFunc(Display_cb);
  glutReshapeFunc(Reshape_cb); 
  glutSpecialFunc(Special_cb);
  glutIdleFunc(Idle_cb);  //Idle

  teclado.Iniciar();

  // OpenGL

  //Z-Buffer
  glEnable(GL_DEPTH_TEST);
  glDepthFunc( GL_LEQUAL );
  glDepthRange(0.0, 1.0);
  glClearDepth(1.0);

  glEnable(GL_NORMALIZE); // para que el scaling no moleste
  glDisable(GL_AUTO_NORMAL); // para nurbs??
  glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset (1,1); // coplanaridad
  glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH);

  glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
  glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
  glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);

  glShadeModel(GL_SMOOTH);

  // transparencias
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);  

  //glClearColor(0.23f,0.20f,0.01f,1.f); // color de fondo
  glClearColor(0.01f,0.01f,0.01f,1.f);
  
   // direccion de los poligonos
  glFrontFace(GL_CCW); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);  
  glCullFace(GL_BACK); // se habilita por objeto (cerrado o abierto)


   // textura
  // textura1
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glGenTextures(3,texid);

  glBindTexture(GL_TEXTURE_2D, texid[0]);
  mipmap_ppm("cubo.ppm");
  
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

 /* glEnable(GL_TEXTURE_2D);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);*/
  
  //Textura 2
  glBindTexture(GL_TEXTURE_2D, texid[1]);
  mipmap_ppm("grass.ppm");
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    

  glBindTexture(GL_TEXTURE_2D, texid[2]);
  mipmap_ppm("pista.ppm");
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 


  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  // las operaciones subsiguientes se aplican a la matriz de modelado GL_MODELVIEW
  glMatrixMode(GL_MODELVIEW); glLoadIdentity();

}
Beispiel #6
0
void Idle_cb() 
{
  
  static unsigned int lt=0;  	
  
  int dt = glutGet(GLUT_ELAPSED_TIME) - lt;
  
  if(dt > 60) 
  {

	  if(isFired)
	  {
		incyMetralla+=8;
		if(incyMetralla < 0 || incyMetralla > h)
			isFired = false;
	  }

	  lightY++;
	  if(lightY > 20.0)
		  lightY = 0.0;

	// Convierte AvionAng de grados a radianes
	  double ang=AvionAng*PI/180.0;
	  
	  if(teclado.Salir())
	  {
		  exit(EXIT_SUCCESS);
	  }
	  
	  if(teclado.Adelante())
	  {
		// double sin(double ang); // Calcula el seno de ang medido en radianes
		AvionX-=5*sin(ang);
		AvionY+=5*cos(ang);		
	  }

	  if(teclado.Atras())
	  {
		AvionX+=5*sin(ang);
		AvionY-=5*cos(ang);
	  }

	  if(teclado.IzquierdaAux())
	  {
		AvionAng+=2;
	  }

	  if(teclado.DerechaAux())
	  {
		AvionAng-=2;		
	  }

	  if(!isFired && teclado.Disparar())
	  {
		  isFired = true;		
		  MetrallaX = AvionX;
		  MetrallaY = AvionY;
		  incxMetralla = -sin(AvionAng);
		  incyMetralla = cos(AvionAng);			  
		  AngMetralla = AvionAng;
	  }

	  lt = glutGet(GLUT_ELAPSED_TIME);	
	  glutPostRedisplay();
  }
}