Ejemplo n.º 1
0
	void TriggerExplosion ( Texture* tex, GLfloat x, GLfloat y, GLfloat Blastradius )	{
		cout<<"TriggerExplosion: ExplosionsList.size()="<<ExplosionsList.size() <<endl;
		bStartshaking = true;
		//exit(50);
//		int i;

		cout<<"------------->explosion() called"<<endl;
		//add new element to the map
		if ( ExplosionsList.empty() ) ExplosionsList[0]=explosion();
		else ExplosionsList[ ( ExplosionsList.rbegin() )->first+1]=explosion();
		cout<<"------------->explosion() call finished"<<endl;
		//exit(0);

		ExplosionsList[ExplosionsList.size()-1].iterateSheets = true;
		ExplosionsList[ExplosionsList.size()-1].animationTimer.Start();
		ExplosionsList[ExplosionsList.size()-1].Load ( tex, 4, 4 );
		ExplosionsList[ExplosionsList.size()-1].Scale ( Blastradius/30.0 );

//		for ( i=0; i < ExplosionsList.size(); i++ )	{
		ExplosionsList[ExplosionsList.size()-1].x = x;
		ExplosionsList[ExplosionsList.size()-1].y = y;
		ExplosionsList[ExplosionsList.size()-1].Active = true;
		ExplosionsList[ExplosionsList.size()-1].CurrentFrame = 0;
		ExplosionsList[ExplosionsList.size()-1].startTicks = Timer[0].GetTicks();
		cout<<"setting speed"<<endl;
		ExplosionsList[ExplosionsList.size()-1].setAnimationSpeed ( 16.0f );
//		}
		cout<<"explosion at ("<<ExplosionsList[ExplosionsList.size()-1].x<<","<<ExplosionsList[ExplosionsList.size()-1].y<<")"<<endl;

	}
Ejemplo n.º 2
0
int msg_mines (int n, int msg, int z) {		// space mines
	int sh, x, y;
	switch (msg) {
		case msg_update:
			objs[n].count = (objs[n].count + 1)&3; return (1);
		case msg_draw:
			sh = 0xf00 + 18 + objs[n].count/2;
			drawshape (&gamevp, sh, objs[n].x, objs[n].y); break;
		case msg_touch:
			switch (objs[z].kind) {
				case obj_player:
					if (class_cnt(class_shield)==0) {
						p_hit (2); snd_play (1,5);
						x = objs[n].x - 11; y = objs[n].y - 9;
						addobj (obj_explode3, x, y, 0, 0);
						explosion (objs[n].x, objs[n].y, 5);
						text ("You hit an enemy space mine!",0);
						killobj (n);
						}; break;
				case obj_shield:
					addobj (obj_explode2, objs[n].x, objs[n].y, 0, 0);
					explosion (objs[n].x, objs[n].y, 5);
					text ("Your shield was destroyed by a space mine",0);
					killobj (n); killobj (z); snd_play (1,5);
				};
		}; return (0);
	};
Ejemplo n.º 3
0
	void AddExplosion ( Texture* tex )	{
		cout<<"AddExplosion"<<endl;
		exit ( 0 );

		//add new element to the map
		if ( ExplosionsList.empty() ) ExplosionsList[0]=explosion();
		else ExplosionsList[ ( ExplosionsList.rbegin() )->first+1]=explosion();

		ExplosionsList[ExplosionsList.size()-1].iterateSheets = true;
		ExplosionsList[ExplosionsList.size()-1].setAnimationSpeed ( 0.0f );
		ExplosionsList[ExplosionsList.size()-1].animationTimer.Start();
		ExplosionsList[ExplosionsList.size()-1].Load ( tex, 4, 4 );
		ExplosionsList[ExplosionsList.size()-1].Scale ( 2 );
		ExplosionsList[ExplosionsList.size()-1].Active = false;
	}
Ejemplo n.º 4
0
int16_t shot_collision(void)
{
	int16_t x, y;
	x = shot.pos.x >> UNITS_X_SHIFT;
	y = shot.pos.y >> UNITS_Y_SHIFT;
	
	//bottom, left, right
	if(	y >= FIELD_Y + FIELD_HEIGHT
	||	x < FIELD_X || x >= FIELD_X + FIELD_WIDTH)
	{
		return 1;
	}
	
	//players
	if(player_hit(&player1, x, y) || player_hit(&player2, x, y))	{ return 1; }
	
	//terrain
	if(y >= terrain[x - FIELD_X])
	{
		explosion(x, y);
		//TODO update terrain
		return 1;
	}
	
	return 0;
}
Ejemplo n.º 5
0
void PlayerUnit::hitAction(IEnemyBullet* enemyBullet){
	if(collision){
		--stock;
		explosion();
		PlaySound(SoundMng.get(SE_PE01));
	}
}
Ejemplo n.º 6
0
void Ball::advance(int phase)
{
    if (!phase)
        return;
    else if (collidesWithItem(gun1))
    {
        emit hit(x(), y(), 1, numOfDamage);
        scene()->removeItem(this);
        delete this;
    }
    else if (collidesWithItem(gun2))
    {
        emit hit(x(), y(), 2, numOfDamage);
        scene()->removeItem(this);
        delete this;
    }
    else if (y() > horizon - 5)
    {
        emit explosion(x(), radius, numOfDamage);
        scene()->removeItem(this);
        delete this;
    }
    else
    {
        double newX = t * vX + resis * t * t/2;
        double newY = t * vY - t * t;
        newY = newY * (- 1);
        setPos(startX + newX, startY + newY);
        t = t + 0.3;

        rotate(1);


    }
}
Ejemplo n.º 7
0
void Enemy::destory( )
{

	if(hp <= 0){

		//explosion effect  flame
		auto effect = Effect::CreateEffect( );
		effect->explosion(gameStage, this->getPosition( ));

		//explosion effect of particle


		auto config = Config::getInstance( );
		if(config->geteffectState( ))
		{
			SimpleAudioEngine::getInstance( )->playEffect( ship_explode_effect0 );
		}
	
		config->setScore( config->getScore( ) + score );

		//log("current get score is :%d",config->getScore  () );
	
		this->unschedule(schedule_selector( Enemy::fire ) );
		this->removeFromParent( );
	}
}
Ejemplo n.º 8
0
TriggerSettingsRocket* SceneNadia::getLaserRocket(float hue, float hueChange) {
	
	TriggerSettingsRocket& ts = *new TriggerSettingsRocket();
	
	RocketSettings& rocketSettings = *new RocketSettings();
	
	rocketSettings.startSpeedMin = 800;
	rocketSettings.startSpeedMax = 900;
	rocketSettings.drag = 0.96;
	rocketSettings.gravity.y = 100;
	rocketSettings.setLifeTime(1.7);
	
	ParticleSystemSettings laserTrails = getLaserParticles(hue, hueChange);
	ParticleSystemSettings trails = getTrailParticles(hue, hueChange);
	
	laserTrails.sizeStartMin = 8;
	laserTrails.sizeStartMax = 10;
	laserTrails.sizeChangeRatio = 0; 
	laserTrails.shimmerMin = 1;
	laserTrails.emitInheritVelocity = 1;
	laserTrails.drag = rocketSettings.drag;
	laserTrails.gravity = rocketSettings.gravity;
	
	laserTrails.lifeMin = laserTrails.lifeMax = rocketSettings.getLifeTime();

		
	laserTrails.emitCount = 1;
	laserTrails.emitMode = PARTICLE_EMIT_BURST;
	trails.emitLifeTime = rocketSettings.getLifeTime();
	
	ParticleSystemSettings explosion(laserTrails);
	explosion.emitDelay = rocketSettings.getLifeTime();
	explosion.emitCount = 15;
	explosion.speedMax = 500;
	explosion.speedMin = 800;
	explosion.directionZVar = 180;
	explosion.sizeStartMin = 1;
	explosion.sizeStartMax = 1;
	explosion.lifeMin = 0.3;
	explosion.lifeMin = 0.5;
	explosion.drag = 0.9;
	explosion.hueChange = 0;
	explosion.brightnessEnd = 0; 
	
	
	//explosion.emitDelay = trails.emitLifeTime;
	
	rocketSettings.addParticleSystemSetting(laserTrails);
	//rocketSettings.addParticleSystemSetting(trails);
	rocketSettings.addParticleSystemSetting(explosion);
	
	ts.addRocketSettings(&rocketSettings);
	
	ts.rechargeSettings = TriggerRechargeSettings::medium;
	
	return &ts;
	
}
Ejemplo n.º 9
0
	void AddExplosion(const char texture[])	{
		//cout<<"AddExplosion"<<endl;
		ExplosionsList.push_back(explosion());
		ExplosionsList[ExplosionsList.size()-1].iterateSheets = true;
		ExplosionsList[ExplosionsList.size()-1].setAnimationSpeed(0.0f);
		ExplosionsList[ExplosionsList.size()-1].animationTimer.Start();
		ExplosionsList[ExplosionsList.size()-1].Load(texture, 4, 4);
		ExplosionsList[ExplosionsList.size()-1].Scale(2);
		ExplosionsList[ExplosionsList.size()-1].Active = false;
	}
Ejemplo n.º 10
0
int Player::hit(int damage){

  if(!active) return 0;
  
  active = 0;
  
  explosion(x,y,300);
  //lives--;
  score/=2;
  
}
Ejemplo n.º 11
0
static void
cexplosion (unsigned char *message, int size)
{
  int             x, y, type, letter, n;
  GETSHORT (message, x);
  GETSHORT ((message + 2), y);
  GETCHAR ((message + 4), type);
  GETCHAR ((message + 5), letter);
  GETCHAR ((message + 6), n);
  explosion (x, y, type, letter, n);
}
Ejemplo n.º 12
0
int msg_shield (int n, int msg, int z) {
	int sh;
	switch (msg) {
		case msg_update:
			if (objs[n].count2 >= 240)
				objs[n].count = (objs[n].count + 1)&3;
			move_obj (n, objs[0].x-2, objs[0].y-2);
			if (++objs[n].count2==340) killobj (n); return (1);
		case msg_draw:
			sh = 0x804 + objs[n].count/2;
			drawshape (&gamevp, sh, objs[n].x, objs[n].y); break;
		case msg_touch:
			switch (objs[z].kind) {
				case obj_enemy1:
				case obj_enemy2:
				case obj_enemy3:
				case obj_enemy4:
				case obj_enemy5:
				case obj_enemy6:
				case obj_enemy7:
				case obj_enemy8:
				case obj_enemy9:
				case obj_enemya:
				case obj_enemyb:
				case obj_enemyc:
				case obj_enemyd:
				case obj_enemye:
				case obj_enemyf:
				case obj_enemyg:
				case obj_enemyh:
				case obj_enemyi:
				case obj_enemyj:
				case obj_enemyk:
					snd_play (1,7);
					if (objs[z].count3 < 1) {
						killobj (z);
						}
					else {
						objs[z].xd = -objs[z].xd;
						objs[z].yd = -objs[z].yd;
						}; break;
				case obj_bullet2:
				case obj_spinner:
				case obj_laser:
					snd_play (1,7);
					explosion (objs[z].x, objs[z].y, 5);
					killobj (z);
				};
		}; return (0);
	};
Ejemplo n.º 13
0
static void astdelux_sound_update(int param, INT16 *buffer, int length)
{
	int samplerate = Machine->sample_rate;

    while( length-- > 0)
	{
		int sum = 0;

		sum += explosion(samplerate) / 2;
		sum += thrust(samplerate) / 2;

		*buffer++ = sum;
	}
}
Ejemplo n.º 14
0
void CRoleSprite::hurt(int iHarm)
{
	if(m_pSprite->isVisible() == false) return;
	m_iHp -= iHarm;
	if(m_iHp <= 0)
	{
		m_pSprite->setVisible(false);
		m_pSprite->stopAllActions();
		this->unscheduleAllSelectors();
		m_iLife--;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Music/Explosion.mp3");
		explosion();
	}
}
Ejemplo n.º 15
0
void RPG_ExplosionManager::CreateExplosion(hkvVec3 const& center, RPG_ExplosionType_e type, float const strength, float const radius, float const length, hkvVec3 const& direction)
{
#if (HK_CONFIG_THREAD == HK_CONFIG_MULTI_THREADED) && !(HAVOK_FORCE_SINGLETHREADED)  // Will be on PC, PS3 etc.
  hkpWorld* world = vHavokPhysicsModule::GetInstance()->GetPhysicsWorld();
  world->lock();
#endif  

  RPG_Explosion explosion(center, type, strength, radius, length, direction);
  m_explosions.Append(explosion);

#if (HK_CONFIG_THREAD == HK_CONFIG_MULTI_THREADED) && !(HAVOK_FORCE_SINGLETHREADED)  // Will be on PC, PS3 etc.
  world->unlock();
#endif
}
Ejemplo n.º 16
0
int16_t player_hit(Player* player, int16_t x, int16_t y)
{
	if(	x < player->pos.x || x >= player->pos.x + 3
	||	y < player->pos.y || y >= player->pos.y + 2)	{ return 0; }
	
	explosion(x, y);
	draw_player(player);
	player->hull -= SHOT_DAMAGE;
	draw_stats(player);
	term_setpos(MSG_X, MSG_Y + 1);
	printstr("hit player ");
	printch(player->id);
	return 1;
}
Ejemplo n.º 17
0
    void MissileBoss::OnType(char c, bool *hit, bool *phraseFinished)
    {
        *hit = m_phrase.OnType(c, GAME.GetTime());
        *phraseFinished = m_phrase.Finished();

        if (*phraseFinished) {
            GAME.MakeCharAvail(m_phrase.GetStartChar());
            --m_health;
            if (m_health > 0) {
                m_phrase.Reset(GAME.GetPhrase(PhraseBook::PL_MEDIUM));
            } else {
                ExplosionPtr explosion(new Explosion(m_origin, ColourRGBA::White()));
                GAME.AddEffect(explosion);
            }
        }
    }
Ejemplo n.º 18
0
position Pacman::premove(long unsigned int dt){
	double deslocamento = dt * .003f;
	position dest = position(_xcoord, _ycoord);	//Posição final da simulação
	if(_isDead){
		explosion(dt);
		return dest;
	}
	if(_up)
		((_ycoord + deslocamento > 7) ? (dest = position(_xcoord, 7)):(dest = position(_xcoord, _ycoord + deslocamento)));
	else if(_down)
		((_ycoord - deslocamento < -7) ? (dest = position(_xcoord, -7)):(dest = position(_xcoord, _ycoord - deslocamento)));
	else if(_left)
		((_xcoord - deslocamento < -12) ? (dest = position(-12, _ycoord)):(dest = position(_xcoord - deslocamento, _ycoord)));
	else if(_right)
		((_xcoord + deslocamento > 12) ? (dest = position(12, _ycoord)):(dest = position(_xcoord + deslocamento, _ycoord)));
	return  dest;
}
Ejemplo n.º 19
0
template<> void Bullet<bad>::update(){

  if(!active) return;
  draw();
  x += xv;
  y += yv;
  
  if(out_of_bounds()) active = 0; else
  if(player_contact()){
    player.hit(1);
    explosion(x,y,rand()%13+7);
    active = 0;
    return;
  }
  draw();
  
}
Ejemplo n.º 20
0
void WordAggregator::parse (std::string& words, FrequencyMap& _map)
{
    std::string wordset[WORDSET_ARRAY_SIZE];
    Explosion explosion(words);
    explosion.explode(' ', wordset);

    /* Iterate through all the words in the wordset. */
    for (int w=0; w < WORDSET_ARRAY_SIZE; w++)
    {
        if (wordset[w] == "") break;
        bool found = !(_map.find(wordset[w]) == _map.end());
        bool add = (!found && !library->find(wordset[w]));
        if (found || add)
        {
            _map[wordset[w]]++;
        }
    }
}
Ejemplo n.º 21
0
static void asteroid_sound_update(int param, INT16 *buffer, int length)
{
	int samplerate = Machine->sample_rate;

    while( length-- > 0 )
	{
		int sum = 0;

		sum += explosion(samplerate) / 7;
		sum += thrust(samplerate) / 7;
		sum += thump(samplerate) / 7;
		sum += saucer(samplerate) / 7;
		sum += saucerfire(samplerate) / 7;
		sum += shipfire(samplerate) / 7;
		sum += life(samplerate) / 7;

        *buffer++ = sum;
	}
}
Ejemplo n.º 22
0
void Assignment1::Init()
{
	// Init VBO here
	glClearColor(0.0f, 0.7f, 1.0f, 0.0f);
	//enable depth test 
	glEnable(GL_DEPTH_TEST);

	rotateAngle = 1;
	translateX = 1;
	scaleAll = 1;
	flyBack = 1;
	cloudMovement = 1;
	explosionRotation = 1;
	explosionSize = 1;
	sizeValue;
	//Generate a default VAO for now 
	glGenVertexArrays(1, &m_vertexArrayID);
	glBindVertexArray(m_vertexArrayID);

	//generate buffers
	glGenBuffers(NUM_GEOMETRY, &m_vertexBuffer[0]);
	glGenBuffers(NUM_GEOMETRY, &m_colorBuffer[0]);

	landScape();
	clouds();
	sun();
	explosion();
	cactus();

	//Load vertex and fragment shaders
	m_programID = LoadShaders(
		"Shader//TransformVertexShader.vertexshader",
		//"Shader//SimpleVertexShader.vertexshader",
		"Shader//SimpleFragmentShader.fragmentshader"
		);

	//Get a handle for our "MVP" uniform
	m_parameters[U_MVP] = glGetUniformLocation(m_programID, "MVP");
	// Use our shader
	glUseProgram(m_programID);

}
Ejemplo n.º 23
0
template<> void Bullet<good>::update(){
  
  if(!active) return;
  draw();
  x += xv;
  y += yv;
  
  if(out_of_bounds()) active = 0; else 
  if(Entity* e = enemy_contact(1)){
  
    e->hit(1);
    explosion(x,y,rand()%13+7);
    active = 0;
    return;
    
  }  
  
  draw();
  
}
Ejemplo n.º 24
0
void Game::updateInsects() {
	//insect kamikaze ship rotation, movement, boundaries, bullet and ship collision
	for (int i = 0; i < insectKamikazeFleet.size(); i++) {
		findRotation(insectKamikazeFleet[i].x, insectKamikazeFleet[i].y, playerShip.x, playerShip.y, insectKamikazeFleet[i].rotation);
		insectKamikazeFleet[i].vx = cos(insectKamikazeFleet[i].rotation) * insectKamikazeFleet[i].speed;
		insectKamikazeFleet[i].vy = sin(insectKamikazeFleet[i].rotation) * insectKamikazeFleet[i].speed;
		insectKamikazeFleet[i].x += insectKamikazeFleet[i].vx;
		insectKamikazeFleet[i].y += insectKamikazeFleet[i].vy;
		insectKamikazeFleet[i].frameExposure++;
		if (insectKamikazeFleet[i].frameExposure > 4) {
			insectKamikazeFleet[i].frame++;
			insectKamikazeFleet[i].frameExposure = 0;
			if (insectKamikazeFleet[i].frame > 14) insectKamikazeFleet[i].frame = 0;
		}

		if (insectKamikazeFleet[i].x + (ENEMYDIMENSION * INSECTSCALE) / 2 > RIGHTBOUNDARY) insectKamikazeFleet[i].x = RIGHTBOUNDARY - (ENEMYDIMENSION * INSECTSCALE) / 2;
		else if (insectKamikazeFleet[i].x - (ENEMYDIMENSION * INSECTSCALE) / 2 < LEFTBOUNDARY) insectKamikazeFleet[i].x = LEFTBOUNDARY + 5;
		if (insectKamikazeFleet[i].y + (ENEMYDIMENSION * INSECTSCALE) / 2 > LOWERBOUNDARY) insectKamikazeFleet[i].y = LOWERBOUNDARY - (ENEMYDIMENSION * INSECTSCALE) / 2;
		else if (insectKamikazeFleet[i].y - (ENEMYDIMENSION * INSECTSCALE) / 2 < UPPERBOUNDARY) insectKamikazeFleet[i].y = UPPERBOUNDARY + 5;

		if (insectKamikazeFleet[i].ifHit) {
			insectKamikazeFleet[i].framesSinceHit++;
			if (insectKamikazeFleet[i].framesSinceHit > FRAMESPERFLASH) {
				insectKamikazeFleet[i].framesSinceHit = 0;
				insectKamikazeFleet[i].ifHit = false;
			}
		}
	}

	for (int k = 0; k < insectKamikazeFleet.size(); k++) {
		for (int i = 0; i < AMOUNTOFVECTORS; i++) {
			for (int j = 0; j < arrayOfVectors[i].size(); j++) {
				if (arrayOfVectors[i].at(j).x > insectKamikazeFleet[k].x - (ENEMYDIMENSION * INSECTSCALE) / 2 &&
					arrayOfVectors[i].at(j).x < insectKamikazeFleet[k].x + (ENEMYDIMENSION * INSECTSCALE) / 2 &&
					arrayOfVectors[i].at(j).y > insectKamikazeFleet[k].y - (ENEMYDIMENSION * INSECTSCALE) / 2 &&
					arrayOfVectors[i].at(j).y < insectKamikazeFleet[k].y + (ENEMYDIMENSION * INSECTSCALE) / 2) {
					arrayOfVectors[i].erase(arrayOfVectors[i].begin() + j);
					insectKamikazeFleet[k].lives -= BULLETDAMAGE;	
					if (insectKamikazeFleet[k].lives <= 0) {
						createExplosion(explosion(), insectKamikazeFleet[k].x, insectKamikazeFleet[k].y, insectKamikazeFleet[k].rotation, 0.55f, 0, 255, 0);
						insectKamikazeFleet.erase(insectKamikazeFleet.begin() + k);
						totalInsectKillsLevel++;
						break;
					}
					else {
						insectKamikazeFleet[k].ifHit = true;
						insectKamikazeFleet[k].framesSinceHit = 0;
					}
				}
			}
		}
	}

	/*




	Make function that takes in x,y of bullet/weapon and ship, full width and height of both bullet and ship, What type of ship,
	will make much easier to change other stuff then.







	*/


	for (int k = 0; k < insectKamikazeFleet.size(); k++) {
		for (int i = 0; i < missileVector.size(); i++) {
			if (missileVector[i].x > insectKamikazeFleet[k].x - (ENEMYDIMENSION * INSECTSCALE) / 2 &&
				missileVector[i].x < insectKamikazeFleet[k].x + (ENEMYDIMENSION * INSECTSCALE) / 2 &&
				missileVector[i].y > insectKamikazeFleet[k].y - (ENEMYDIMENSION * INSECTSCALE) / 2 &&
				missileVector[i].y < insectKamikazeFleet[k].y + (ENEMYDIMENSION * INSECTSCALE) / 2) {
				missileVector.erase(missileVector.begin() + i);
				insectKamikazeFleet[k].lives -= MISSILEDAMAGE;
				if (insectKamikazeFleet[k].lives <= 0) {		
					createExplosion(explosion(), insectKamikazeFleet[k].x, insectKamikazeFleet[k].y, insectKamikazeFleet[k].rotation, 0.55f, 0, 255, 0);
					insectKamikazeFleet.erase(insectKamikazeFleet.begin() + k);
					totalInsectKillsLevel++;
					break;
				}
				else {
					insectKamikazeFleet[k].ifHit = true;
					insectKamikazeFleet[k].framesSinceHit = 0;
				}
			}
		}
	}
}
Ejemplo n.º 25
0
void Game::updateEnemyShip1s() {
	//rotation, movement, boundaries, bullet and ship collision
	for (int i = 0; i < enemyShipFleet.size(); i++) {
		findRotation(enemyShipFleet[i].x, enemyShipFleet[i].y, playerShip.x, playerShip.y, enemyShipFleet[i].rotation);
		enemyShipFleet[i].x += enemyShipFleet[i].vx;
		enemyShipFleet[i].y += enemyShipFleet[i].vy;

		/*
		**************************************************************************************************************

		changes to try(change direction somehow if boundary hit) Talking about enemyship1 (which he is called from now on to avoid ambiguity with the insect with just enemyship itself):
		1. Make his y = x * x
		2. y = x * x * x, log(x) sqrt(x), sin(x) etc
		3. his y = cos(rotation) and x = y * y
		4. find circle formula (based on centre maybe)
		5. semi circle
		6. form function which takes distance close to player and works dynamic circle  which changes every frame if player moves. Then try semi circle. Work it maybe with angles, or maybe just come circumference follower
		7. Finally work some way finally after doing all that to make him avoid his fellow teammates ships which will be hard.
		Function that takes in x and y of every teammate within 200-400 pixels and moves in a direction away from them but towards you if possible. Have them go slow so they can easily plan in a group mentality kinda way?
		Maybe have them eventually just go fast and slow. They slow down when clsoe to an enemy ship and eventually move away. They maybe never get too close to an enemy ship because they slow down same with yours.
		8. And separate point as to how it will look if you do eventually collide off an enemy ship. Maybe just bounce off and lose health so player avoids hitting them then.
		9. make them go in a parade kinda way. or a big s towards you and instead of avoiding you maybe enemyship1s also eventually crash into you but take their time about it.
		left all the way then small or mediumu turn towards right
		*/

		if (enemyShipFleet[i].x + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 > RIGHTBOUNDARY) enemyShipFleet[i].x = RIGHTBOUNDARY - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
		else if (enemyShipFleet[i].x - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 < LEFTBOUNDARY) enemyShipFleet[i].x = LEFTBOUNDARY + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
		if (enemyShipFleet[i].y + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 > LOWERBOUNDARY) {
			enemyShipFleet[i].y = LOWERBOUNDARY - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
			enemyShipFleet[i].vy *= -1;
		}
		else if (enemyShipFleet[i].y - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 < UPPERBOUNDARY) {
			enemyShipFleet[i].y = UPPERBOUNDARY + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
			enemyShipFleet[i].vy *= -1;
		}
		if (enemyShipFleet[i].ifHit) {
			enemyShipFleet[i].framesSinceHit++;
			if (enemyShipFleet[i].framesSinceHit > FRAMESPERFLASH) {
				enemyShipFleet[i].framesSinceHit = 0;
				enemyShipFleet[i].ifHit = false;
			}
		}
	}

	for (int k = 0; k < enemyShipFleet.size(); k++) {
		for (int i = 0; i < AMOUNTOFVECTORS; i++) {
			for (int j = 0; j < arrayOfVectors[i].size(); j++) {
				if (arrayOfVectors[i].at(j).x > enemyShipFleet[k].x - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
					arrayOfVectors[i].at(j).x < enemyShipFleet[k].x + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
					arrayOfVectors[i].at(j).y > enemyShipFleet[k].y - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
					arrayOfVectors[i].at(j).y < enemyShipFleet[k].y + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2) {
					arrayOfVectors[i].erase(arrayOfVectors[i].begin() + j);
					enemyShipFleet[k].lives -= BULLETDAMAGE;
					if (enemyShipFleet[k].lives <= 0) {
						createExplosion(explosion(), enemyShipFleet[k].x, enemyShipFleet[k].y, enemyShipFleet[k].rotation, 0.6f, rand() % 255, rand() % 255, rand() % 255);
						for (int a = 0; a < pShipTargets.size(); a++) {
							;//if (pShipTargets[a].ship == &enemyShipFleet[k]) pShipTargets.erase(pShipTargets.begin() + a);
						}			
						enemyShipFleet.erase(enemyShipFleet.begin() + k);
						totalEnemyShipKillsLevel++;
						break;
					}
					else {
						enemyShipFleet[k].ifHit = true;
						enemyShipFleet[k].framesSinceHit = 0;
					}
				}
			}
		}
	}

	for (int k = 0; k < enemyShipFleet.size(); k++) {
		for (int i = 0; i < missileVector.size(); i++) {
			if (missileVector[i].x > enemyShipFleet[k].x - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
				missileVector[i].x < enemyShipFleet[k].x + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
				missileVector[i].y > enemyShipFleet[k].y - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
				missileVector[i].y < enemyShipFleet[k].y + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2) {
				missileVector[i].target = NULL;
				missileVector.erase(missileVector.begin() + i);
				enemyShipFleet[k].lives -= MISSILEDAMAGE;
				if (enemyShipFleet[k].lives <= 0) {
					createExplosion(explosion(), enemyShipFleet[k].x, enemyShipFleet[k].y, enemyShipFleet[k].rotation, 0.6f, 255, 255, 255);
					for (int a = 0; a < pShipTargets.size(); a++) {
						if (pShipTargets[a].ship == &enemyShipFleet[k]) {
							//pShipTargets[a].ship = NULL;
							//pShipTargets.erase(pShipTargets.begin() + a);
							noOfLockedOn--;
							break;
						}
					}
					//pShipTargets[k].ship = NULL;
					pShipTargets.erase(pShipTargets.begin() + k); //on the way to getting there. Fixes killing 1 guy and another green lock on showing hmm ///wont work with insects
					enemyShipFleet.erase(enemyShipFleet.begin() + k);
					for (int i = 0; i < pShipTargets.size(); i++) {
						pShipTargets[i].ship = &enemyShipFleet[i];
					}
					totalEnemyShipKillsLevel++;
					break;
				}
				else {
					enemyShipFleet[k].ifHit = true;
					enemyShipFleet[k].framesSinceHit = 0;
				}
			}
		}
	}

	if (frameCount % 60 == 0 && enemyShipFleet.size() > 0) createBullet(false);
}
Ejemplo n.º 26
0
void world::spawn_explosion(const nya_math::vec3 &pos,float radius)
{
    m_explosions.push_back(explosion(pos, radius));
}
Ejemplo n.º 27
0
void MainWindow::timerEvent ( QTimerEvent * event ){

    // ----------- partie personnage
    if (gravity<0){
        personnage->setCurrentH(personnage->getCurrentH()+1);
        if(personnage->getCurrentH()>= personnage->getMaxH() || collisionTest(0,-1)){
            gravity = baseGravity;
            personnage->setCurrentH(0);
        }
        else{
            personnage->setCurrentS(6);
            personnage->immobile();
        }

    }
    else if(collisionTest(0,1)){
        if(gravity == 1)
            personnage->setCurrentS(4); //LANDING
        gravity = 0;
    }
    else {
        gravity = baseGravity;
        personnage->setCurrentS(3); // FALLING
        personnage->immobile();
    }

    int x = 0;
    if(gravity == 0 && controleur->getStateKeys(0))
        tryJump();

    if(controleur->getStateKeys(2)){
        if (personnage->tryDropBombe()){
            // ajouter un truc du style personnage->hasBonusBombe()
            ajouterBombe(personnage->getX()+personnage->getLargeur()/2,personnage->getY()+ personnage->getHauteur());
            controleur->setPressed(Qt::Key_Down,false);
        }
    }

    if(controleur->getStateKeys(1)){
        x +=- 1;
        personnage->courireG();
    }
    else if(controleur->getStateKeys(3)){
        x += 1;
        personnage->courireD();
    }

    if(x == 0 && gravity == 0 /*&& personnage->getCurrentS() != 3*/)
        personnage->immobile();

    // TODO ? asscocier les bombes au joueur, soit avec le trigger du Joueur, soir en ayant bombes[NumJ][bombes]
    if(/*personnage->hasBonusTrigger == trigger &&*/controleur->getStateKeys(4)){
        triggerAll();
        controleur->setPressed(Qt::Key_Space,false);
    }

    tryMove(0,gravity);
    tryMove(x,0);


    // ----------- partie bombes
    int tmpSizeB = bombes.size();
    for(int i = 0; i<tmpSizeB; i++){
        if(bombes[i]->isExploding()){
            explosion(bombes[i],0,0);
            explosion(bombes[i],0,1);
            explosion(bombes[i],0,-1);
            explosion(bombes[i],1,0);
            explosion(bombes[i],-1,0);


        }
        if(bombes[i]->hasExploded()){
            int tmpSizeE = bombes[i]->getExplosions().size();
            for(int j = 0; j< tmpSizeE; j++)
                scene->removeItem(bombes[i]->getExplosions().at(j));
            scene->removeItem((bombes[i])->getPicture());
            bombes.remove(i);
            tmpSizeB--;
            personnage->decrNbBombe();
        }
    }

}
Ejemplo n.º 28
0
int main(int argc, char *argv[])
{
	
	SDL_Event event;
	bool done = false;
	float lastFrameTicks = 0.0f;
	float ball_angle = 0.0f;
	srand(time(NULL));

	Matrix projectionMatrix;
	Matrix viewMatrix;
	Setup(&displayWindow, &projectionMatrix);

	std::vector<Entity*> entities;
	std::vector<DrawSpriteText> text;
	std::vector<Entity*> enemy_bullets;
	std::vector<DrawSpriteText> title_text;

	GLuint space_sheet = LoadTexture("sheet.png", GL_RGBA);
	GLuint fontsheet = LoadTexture("font1.png", GL_RGBA);
	GLuint bg = LoadTexture("darkPurple.png", GL_RGB);

	Entity* newEnt;
	for (size_t x = 0; x < 11; ++x){
		for (size_t y = 0; y < 4; ++y){
			
			switch (y){
			case 0:
				newEnt = new Entity(space_sheet, 1024.0f, 423.0f, 728.0f, 93.0f, 84.0f, 0.5f);

				break;
			case 1:
				newEnt = new Entity(space_sheet, 1024.0f, 425.0f, 468.0f, 93.0f, 84.0f, 0.5f);
				break;
			default:
				newEnt = new Entity(space_sheet, 1024.0f, 425.0f, 384.0f, 93.0f, 84.0f, 0.5f);
				break;
			}
			
			newEnt->x = (-6.22 + newEnt->width/2 * 11) + (x * (newEnt->width + 0.15));
			newEnt->y = ((3.5 - newEnt->height * 2) - newEnt->height/2 ) - (y * (newEnt->height + 0.2));
			entities.push_back(newEnt);
		}
	}

	for (size_t i = 0; i < entities.size(); ++i){
		points.push_back(std::make_pair(entities[i]->x, entities[i]->y));
	}
	
	Entity player(space_sheet, 1024.0f, 211.0f, 941.0f, 99.0f, 75.0f, 0.5);
	player.y = -3.5 + 0.1 + player.height/2;

	Entity player_bullet(space_sheet, 1024.0f, 843.0f, 789.0f, 13.0f, 57.0f, 0.5);
	player_bullet.x = 7.0;
	
	for (size_t i = 0; i < ENEMY_BULLETS; ++i){
		newEnt = new Entity(space_sheet, 1024.0f, 843.0f, 789.0f, 13.0f, 57.0f, 0.5);
		newEnt->x = 7.0;
		enemy_bullets.push_back(newEnt);
	}

	Entity explosion(space_sheet, 1024.0f, 737.0f, 613.0f, 37.0f, 37.0f, 0.5);
	explosion.x = 7.0;

	DrawSpriteText Life(fontsheet, "LIFE", 0.5, 0);
	Life.y = 3.0f;
	Life.x = 1.0f;
	text.push_back(Life);

	for (size_t i = 0; i < MAX_LIVES; ++i){
		newEnt = new Entity(space_sheet, 1024.0f, 211.0f, 941.0f, 99.0f, 75.0f, 0.5);
		newEnt->y = 3.0f;
		newEnt->x = 1.2f + newEnt->width*3 + ((newEnt->width + 0.1)*i);
		entities.push_back(newEnt);
	}

	DrawSpriteText Title(fontsheet, "Press Enter to Start", 0.5, 0);
	Title.x = -4.7;
	title_text.push_back(Title);

	ShaderProgram program(RESOURCE_FOLDER"vertex_textured.glsl", RESOURCE_FOLDER"fragment_textured.glsl");

	glUseProgram(program.programID);
	
	while (!done) {
		
		float ticks = (float)SDL_GetTicks() / 1000.0f;
		float elapsed = ticks - lastFrameTicks;
		lastFrameTicks = ticks;
		

		float fixedElapsed = elapsed;
		program.setProjectionMatrix(projectionMatrix);
		program.setViewMatrix(viewMatrix);

		switch (state){
		case(STATE_TITLE) :
			TitleProcessEvents(&event,&done);
			TitleRender(&program,title_text);
			break;
		case(STATE_GAME):
			GameProcessEvents(&event, &done, elapsed, entities, player_bullet, player);
			if (fixedElapsed > FIXED_TIMESTEP * MAX_TIMESTEPS){
				fixedElapsed = FIXED_TIMESTEP * MAX_TIMESTEPS;
			}
			while (fixedElapsed >= FIXED_TIMESTEP){
				fixedElapsed -= FIXED_TIMESTEP;
				GameUpdate(FIXED_TIMESTEP, entities, enemy_bullets, player_bullet, explosion, player);
			}
			GameUpdate(fixedElapsed, entities, enemy_bullets, player_bullet, explosion, player);
			GameRender(&program, entities, enemy_bullets, text, player_bullet, explosion, player);
			break;
		}
		
	}
	for (size_t i = 0; i < entities.size(); ++i){
		delete entities[i];
	}

	SDL_Quit();
	return 0;
}
Ejemplo n.º 29
0
void Bullet::collide(){
    if(collision(this,ally)){
        alive = false;
        explosion(s.getPosition(),allies,BulletExplosionSize+(s.getScale().x/2000),BulletExplosionDamage);
    }
}
Ejemplo n.º 30
0
int main() {
	const int spd = 16;
	for (int x=0;x<41;++x) {
		angles_y[x] = (spd*cos(PI/180*(x-20+90)));
		angles_x[x] = (spd*sin(PI/180*(x-20+90)));
	}
	
    allegro_init();
    install_keyboard();
    install_timer();
   
    LOCK_VARIABLE(speed_counter);
    LOCK_FUNCTION(increment_speed_counter);
    install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
   
    const int width = 1024;
    const int height = 768;
   
    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, width, height, 0, 0);
    set_alpha_blender();
	
    BITMAP* buffer = create_bitmap(width, height);
    
    //BITMAP* image3 = load_bitmap("./sprites/chopper3.tga", 0);
    BITMAP* image2 = load_bitmap("./sprites/chopper.tga", 0);
    BITMAP* image = load_bitmap("./sprites/chopper2.tga", 0);
    
    BITMAP* background = load_bitmap("./sprites/background.bmp", 0);
    
    BITMAP* image_sphere = load_bitmap("./sprites/sphere1.tga", 0);
    BITMAP* image_sphere2 = load_bitmap("./sprites/sphere2.tga", 0);
    
    BITMAP* image_shot = load_bitmap("./sprites/shot.tga", 0);
    
    BITMAP* image_explosion[17];
    
    image_explosion[0] = load_bitmap("./sprites/exp_frame_0.tga", 0);
    image_explosion[1] = load_bitmap("./sprites/exp_frame_1.tga", 0);
    image_explosion[2] = load_bitmap("./sprites/exp_frame_2.tga", 0);
    image_explosion[3] = load_bitmap("./sprites/exp_frame_3.tga", 0);
    image_explosion[4] = load_bitmap("./sprites/exp_frame_4.tga", 0);
    image_explosion[5] = load_bitmap("./sprites/exp_frame_5.tga", 0);
    image_explosion[6] = load_bitmap("./sprites/exp_frame_6.tga", 0);
    image_explosion[7] = load_bitmap("./sprites/exp_frame_7.tga", 0);
    image_explosion[8] = load_bitmap("./sprites/exp_frame_8.tga", 0);
    image_explosion[9] = load_bitmap("./sprites/exp_frame_9.tga", 0);
    image_explosion[10] = load_bitmap("./sprites/exp_frame_10.tga", 0);
    image_explosion[11] = load_bitmap("./sprites/exp_frame_11.tga", 0);
    image_explosion[12] = load_bitmap("./sprites/exp_frame_12.tga", 0);
    image_explosion[13] = load_bitmap("./sprites/exp_frame_13.tga", 0);
    image_explosion[14] = load_bitmap("./sprites/exp_frame_14.tga", 0);
    image_explosion[15] = load_bitmap("./sprites/exp_frame_15.tga", 0);
    image_explosion[16] = load_bitmap("./sprites/exp_frame_16.tga", 0);
	
	std::vector<helicopter> heli;
    heli.push_back(helicopter(image_explosion, 17,image->w,  image->h,  40,  40, 0, 0,   0, gravity / 2, 0.8, 0.5));
    heli.push_back(helicopter(image_explosion, 17,image2->w, image2->h, 720, 40, 0, 0,   0, gravity / 2, 0.8, 0.5));
    //heli.push_back(helicopter(image_explosion, 17,image3->w, image3->h, 350, 200, 0, 100, 0, gravity / 2, 0.8, 0.5));
    heli[0].flip = !heli[0].flip;
    
    srand(time(NULL));
    
    std::vector<ball> spheres;
	for (int x=0;x<10;++x) 
		spheres.push_back(
			ball(
				image_sphere->w,
				image_sphere->h,
				(double)((int)rand()%(SCREEN_W-image_sphere->w)),
				(double)((int)rand()%(SCREEN_H-image_sphere->h)),
				(double)((int)rand()%60),
				(double)((int)rand()%60),
				0.0,
				gravity * 2,
				0.95,
				0.95));
	
	std::vector<explosion> explosions;
	
    while (!key[KEY_ESC]) {
        while (speed_counter > 0) {
        	heli[1].get_input(key[KEY_UP], key[KEY_DOWN], key[KEY_LEFT], key[KEY_RIGHT], true);
        	heli[0].get_input(key[KEY_W], key[KEY_S], key[KEY_A], key[KEY_D], true);
        	//heli[2].get_input(key[KEY_Y], key[KEY_H], key[KEY_G], key[KEY_J], true);
        	
        	for (unsigned int x=0;x<heli.size();++x) {
            	if (!(heli[x].health>0))explosions.push_back(explosion(image_explosion, 17, (int)heli[x].pos_x, (int)heli[x].pos_y, rand()%(heli[x].size_x*2), rand()%(heli[x].size_y*2)));
        		heli[x].update_phys();
        	}
            
            for (unsigned int x=0;x<spheres.size();++x) {
            	spheres[x].update_phys();
            }
            	
            for (unsigned int x=0;x<explosions.size();++x)
            	if (explosions[x].alive)
            		explosions[x].update_frame();
            	else
            		explosions.erase(explosions.begin()+x);
            
            for (unsigned int x=0;x<heli.size();++x)
				for (unsigned int y=0;y<spheres.size();++y)
					if (check_collision(spheres[y], heli[x])) {
						heli[x].explode((heli[x].pos_x - spheres[y].pos_x)+heli[x].speed_x, (heli[x].pos_y - spheres[y].pos_y)+heli[x].speed_y, 1);
						spheres[y].explode((spheres[y].pos_x - heli[x].pos_x)+spheres[y].speed_x, (spheres[y].pos_y - heli[x].pos_y)+spheres[y].speed_y);
						if (heli[x].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[x].pos_x, (int)heli[x].pos_y, heli[x].size_x, heli[x].size_y));
						explosions.push_back(explosion(image_explosion, 17, (int)spheres[y].pos_x, (int)spheres[y].pos_y));
					}
            
            for (unsigned int x=0;x<spheres.size();++x)
            	for (unsigned int y=x+1;y<spheres.size();++y)
					if (check_collision(spheres[x], spheres[y])) {
						spheres[x].explode((spheres[x].pos_x - spheres[y].pos_x)+spheres[x].speed_x, (spheres[x].pos_y - spheres[y].pos_y)+spheres[x].speed_y);
						spheres[y].explode((spheres[y].pos_x - spheres[x].pos_x)+spheres[y].speed_x, (spheres[y].pos_y - spheres[x].pos_y)+spheres[y].speed_y);
						explosions.push_back(explosion(image_explosion, 17, (int)spheres[x].pos_x, (int)spheres[x].pos_y));
						explosions.push_back(explosion(image_explosion, 17, (int)spheres[y].pos_x, (int)spheres[y].pos_y));
					}
            
            if (check_collision(heli[0], heli[1])) {
            	heli[0].explode((heli[0].pos_x - heli[1].pos_x)+heli[0].speed_x, (heli[0].pos_y - heli[1].pos_y)+heli[0].speed_y, 5);
            	heli[1].explode((heli[1].pos_x - heli[0].pos_x)+heli[1].speed_x, (heli[1].pos_y - heli[0].pos_y)+heli[1].speed_y, 5);
            	if (heli[0].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[0].pos_x, (int)heli[0].pos_y, heli[0].size_x, heli[0].size_y));
            	if (heli[1].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[1].pos_x, (int)heli[1].pos_y, heli[1].size_x, heli[1].size_y));
            }
            
            for (unsigned int x=0;x<heli.size();++x) {
            	for (unsigned int y=0;y<heli[x].shots.size();++y) {
            		for (unsigned int z=0;z<heli.size();++z)
            			if (z!=x)
            				if (check_collision(heli[x].shots[y], heli[z])) {
            					heli[z].explode((heli[z].pos_x - heli[x].shots[y].pos_x)+heli[z].speed_x, (heli[z].pos_y - heli[x].shots[y].pos_y)+heli[z].speed_y,10);
            					if (heli[z].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[z].pos_x, (int)heli[z].pos_y));
            				}
            		for (unsigned int z=0;z<spheres.size();++z)
            			if (check_collision(heli[x].shots[y], spheres[z])) {
							spheres[z].explode((spheres[z].pos_x - heli[x].shots[y].pos_x)+spheres[z].speed_x, (spheres[z].pos_y - heli[x].shots[y].pos_y)+spheres[z].speed_y);
							explosions.push_back(explosion(image_explosion, 17, (int)spheres[z].pos_x, (int)spheres[z].pos_y));
							if (z==0) {
								spheres.erase(spheres.begin());
								spheres.push_back(ball(image_sphere->w,image_sphere->h,(double)((int)rand()%(SCREEN_W-image_sphere->w)),(double)((int)rand()%(SCREEN_H-image_sphere->h)),(double)((int)rand()%60),(double)((int)rand()%60),0.0,gravity * 2,0.95,0.95));
								heli[x].health += 50;
							}
						}
            	}
            	for (unsigned int y=x+1;y<heli.size();++y)
            		if (check_collision(heli[x], heli[y])) {
            			heli[x].explode((heli[x].pos_x - heli[y].pos_x)+heli[x].speed_x, (heli[x].pos_y - heli[y].pos_y)+heli[x].speed_y,10);
            			if (heli[x].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[x].pos_x, (int)heli[x].pos_y));
            			heli[y].explode((heli[y].pos_x - heli[x].pos_x)+heli[y].speed_x, (heli[y].pos_y - heli[x].pos_y)+heli[y].speed_y,10);
            			if (heli[y].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[y].pos_x, (int)heli[y].pos_y));
            		}
            }
            
            speed_counter--;
        }
        
		blit(background, buffer, 0, 0, 0, 0, width, height);
		
		for (unsigned int x=0;x<spheres.size();++x) {
			if (x==0)
				spheres[x].draw(buffer, image_sphere2);
			else
				spheres[x].draw(buffer, image_sphere);
		}
			
        heli[0].draw(buffer, image, image_shot);
        heli[1].draw(buffer, image2, image_shot);
        //heli[2].draw(buffer, image3, image_shot);
        
        draw_health(buffer, 10, 10, heli[0].health);
        draw_health(buffer, SCREEN_W-110, 10, heli[1].health);
        //draw_health(buffer, SCREEN_W/2, 10, heli[2].health);
        
        for (unsigned int x=0;x<explosions.size();++x)
        	explosions[x].draw(buffer);
		
        blit(buffer, screen, 0, 0, 0, 0, width, height);
        clear_bitmap(buffer);
    }
   
    destroy_bitmap(buffer);
    
   
    return 0;
}