Example #1
0
void Enemy4::logic(vector<Bala*>bullets, SDL_Surface *screen, Player *player)
{
   for(int x=0;x<bullets.size();x++)
   {
     if((((bullets[x]->getx()>= this->getx())&& (bullets[x]->getx()<= this->getx()+10)) ||
        ((bullets[x]->getx()+10 >= this->getx())&& (bullets[x]->getx()+10 <= this->getx()+10))) &&
        (((bullets[x]->gety() >= this->gety()) && (bullets[x]->gety() <= this->gety()+20)) ||
        ((bullets[x]->gety()+20 >= this->gety()) && (bullets[x]->gety()+20 <= this->gety()+20))))
    {
      this->vida-=5;
      player->score+=5;
    }
   }

 for(int x=0;x<this->bullets.size();x++)
   {
     if((((this->bullets[x]->getx()>= player->getx())&& (this->bullets[x]->getx()<= player->getx()+10)) ||
        ((this->bullets[x]->getx()+10 >= player->getx())&& (this->bullets[x]->getx()+10 <= player->getx()+10))) &&
        (((this->bullets[x]->gety() >= player->gety()) && (this->bullets[x]->gety() <= player->gety()+20)) ||
        ((this->bullets[x]->gety()+20 >= player->gety()) && (this->bullets[x]->gety()+20 <= player->gety()+20))))
    {
      player->vida-=0.5;
    }
   }

    x-=5;
    if(x<-100)
        x=1000;

    disparar(screen);
}
Example #2
0
void Magnetman::actualizarMaquinaEstados(real deltaT)
{
	reflejos += deltaT;

	switch(estadoMagnetman)
	{
		case CORRIENDO:
		{
			if(!puedeCorrer())
			{
				virar();
				estadoMagnetman = QUIETO;		
			}	
			break;
		}
		case SALTANDO:
		{
			if(reflejos >= REFLEJOS && disparos)
			{
				reflejos = 0;

				Megaman *megaman = obtenerMundo().obtenerMegamanCercano(obtenerPosicion());

				b2Vec2 vista = megaman->obtenerPosicion()-obtenerPosicion();

				if(b2Dot(vista,Cuerpo::versorIzquierda) > 0)
					modificarOrientacion(izquierda);
				else 
					modificarOrientacion(derecha);

				disparar(megaman->obtenerPosicion()-obtenerPosicion());
				disparos--;
			}

			if(puedeSaltar())
				estadoMagnetman = QUIETO;
			break;
		}
		case QUIETO:
		{
			
			real aleatorio = numeroAleatorio(0,1);
			
			if(aleatorio > 0.6)
			{
				saltar();
				estadoMagnetman = SALTANDO;
				disparos = CANTDISPAROS;
			}
			else
			{
				correr();
				estadoMagnetman = CORRIENDO;
			}

			reflejos = 0;
			break;
		}
	}

	#ifndef compiling_server
	/*Es mas preciso cambiarlo de esta forma que una vez por cambio de la maquina de estados.*/

	if(estaEnElAire())
		cambiar(&animacion_saltando);
	else
		cambiar(&animacion_corriendo);
	#endif
}
Example #3
0
void Sparkman::actualizarMaquinaEstados(real deltaT)
{
	if(!megaman || !obtenerMundo().existeMegaman(IDTarget))
	{
		megaman = obtenerMundo().obtenerMegamanCercano(obtenerPosicion());
		IDTarget = megaman->obtenerID();
	}

	reflejos += deltaT;

	switch(estadoSparkman)
	{
		case DISPARANDO:
		{
			orientacion = obtenerOrientacion();
	
			b2Vec2 vista = megaman->obtenerPosicion()-obtenerPosicion();

			if(b2Dot(vista,Cuerpo::versorIzquierda) > 0)
				modificarOrientacion(izquierda);
			else 
				modificarOrientacion(derecha);

			disparar(megaman->obtenerPosicion()-obtenerPosicion());

			estadoSparkman = QUIETO;
			
			break;
		}
		case SALTANDO:
		{
			if(reflejos >= TIEMPOCORRIENDO)
			{
				reflejos = 0;
				dejarCorrer();
			}

			if(puedeSaltar())
				estadoSparkman = QUIETO;
			break;
		}
		case QUIETO:
		{
			
			real aleatorio = numeroAleatorio(0,1);

			modificarOrientacion(orientacion);
			
			if(puedeCorrer())
			{

				if(aleatorio < 0.5)
				{
					correr();
					saltar();
					estadoSparkman = SALTANDO;
				}
				else
				{
					estadoSparkman = DISPARANDO;
				}
			}
			else
			{
				virar();
				orientacion = obtenerOrientacion();
			}

			reflejos = 0;
			break;
		}
	}

	#ifndef compiling_server
	/*Es mas preciso cambiarlo de esta forma que una vez por cambio de la maquina de estados.*/

	if(estaEnElAire())
		cambiar(&animacion_saltando);
	else
		cambiar(&animacion_corriendo);
	#endif
}