Example #1
0
void Physics::update(float dt) {
  // update stuff
  p.update(dt, *this);
  box.update(dt, *this);
  for (int i=0; i<enemies.size(); ++i) enemies[i].update(dt, *this);
  for (int i=0; i<bullets.size(); ++i) bullets[i].update(dt);
  for (int i=0; i<explosions.size(); ++i) explosions[i].update(dt);
  
  // collide stuff
  for (int i=0; i<bullets.size(); ++i) {  // level - bullet
    if (l.collidesWith(bullets[i]) || outsideBounds(bullets[i])) {
      if (bullets[i].explosive) explosions.push_back(Explosion(bullets[i].pos.x, bullets[i].pos.y));
      bullets.erase(bullets.begin() + i);
    }
  }
  for (int i=0; i<enemies.size(); ++i) { // player - enemy
    if (p.collidesWith(enemies[i])) {
      p.dead = true;
      break;
    }
  }
  for (int b=0; b<explosions.size(); ++b) // explosion - enemy
    for (int e=0; e<enemies.size(); ++e)
      if (explosions[b].collidesWith(enemies[e]))
        enemies.erase(enemies.begin() + e);
  
  for (int i=0; i<bullets.size(); ++i) {  // check bullet death
    if (bullets[i].dead) {
      bullets.erase(bullets.begin() + i);
      --i;
    }
  } 
  for (int i=0; i<explosions.size(); ++i) { // check explosion death
    if (explosions[i].dead) {
      explosions.erase(explosions.begin() + i);
      --i;
    }
  }
  
        
  for (int b=0; b<bullets.size(); ++b) { // bullet - enemy
    for (int e=0; e<enemies.size(); ++e) {
      if (bullets[b].collidesWith(enemies[e]) ) {
        if (bullets[b].explosive) explosions.push_back(Explosion(bullets[b].pos.x, bullets[b].pos.y));
        enemies[e].hurt(bullets[b].damadge);
        if (enemies[e].dead) enemies.erase(enemies.begin() + e);
        bullets.erase(bullets.begin() + b);
        --b;
        break;
      }
    }
  }

}
Example #2
0
void ObjMine::Refresh()
{
  // the mine is now out of the map
  // or it's a fake mine that has already exploded!
  if (!is_active) {
    timeout_sound.Stop();
    escape_time = 0;
    return;
  }

  // try to detect a character near the mine
  if (!animation) {
    Detection();
  } else {
    image->Update();

    // the timeout is finished !!
    if (attente < GameTime::GetInstance()->ReadSec()) {
      is_active = false;
      timeout_sound.Stop();
      if (!fake)
        Explosion();
      else
        FakeExplosion();

      if (launcher != NULL)
        launcher->SignalProjectileTimeout();
    }
  }
}
Example #3
0
PopUp::PopUp(sf::Font font,std::string message,sf::Vector2f position,sf::Vector2f size,int time)
{
	_font = new sf::Font;
	wantsToDie = false;
	_time = time;
	*_font = font;
	_text.setFont(*_font);
	_text.setString(message);
	trigger = 0;
	
	_shape.setSize(size);
	_text.setCharacterSize(size.y*0.5f);
	_shape.setPosition(position);
	_text.setPosition(position);
	_text.setColor(sf::Color::Black);
	_shape.setOutlineThickness(2.0f);
	_shape.setOutlineColor(sf::Color::Black);
	
	float ratiox = _shape.getGlobalBounds().width/_text.getGlobalBounds().width;
	float ratioy = _shape.getGlobalBounds().height/_text.getGlobalBounds().height;
	ratioy*=0.5f;
	_text.setScale(ratiox,ratioy);
	delay = 0.15f;

	_explosions.push_back(Explosion(sf::Vector2f(_shape.getPosition().x+_shape.getSize().x*0.5f,_shape.getPosition().y+_shape.getSize().y*0.5f)));
	
}
Example #4
0
void Player::die()
{
	setDead(true);
	deathTimeStamp = glutGet(GLUT_ELAPSED_TIME);
	parent->killAllEntities();
	Explosion e = Explosion(parent, location, "resources/particle.png", 100, 70);
	livesRemaining--;
}
Example #5
0
void CDynWater::AddExplosion(const float3& pos, float strength, float size)
{
	if(pos.y>size || size < 8)
		return;

	GML_STDMUTEX_LOCK(water); // AddExplosion

	explosions.push_back(Explosion(pos,std::min(size*20,strength),size));
}
Example #6
0
void Bomb::update(gdl::Clock &clock)
{
  this->time -= clock.getElapsed();
  if (this->time <= 0)
    {
      this->used = false;
      throw Explosion();
    }
}
Example #7
0
void Field::step() {
	--counter_;
	if (gameOver_ && counter_ <= 0 && !blocks_.empty()) {
		counter_ = 5;
		std::vector<Block>::iterator randomBlock = blocks_.begin() + std::uniform_int_distribution<int>(0, blocks_.size()-1)(random);
		explosions_.push_back(Explosion(*randomBlock, 1));
		blocks_.erase(randomBlock);
	}
	if (!gameOver_) {
		control_->step();
		linesCleared = 0;
		if (counter_ <= 0) {
			ResetCounter();
			if (!tetromino_->MoveDown()) {
				if (delay_) {
					NewTetromino();
					delay_ = false;
				} else {
					counter_ = 30; // Wait 0.3 seconds so that it's possible to move blocks below others
					delay_ = true;
				}
			} else {
				delay_ = false;
			}
		}
		tetromino_->Step();
		if (control_->Check(control::Drop)) {
			tetromino_->drop();
			NewTetromino();
		}
		if (control_->Check(control::Down)) {
			if (downKeyReleased_ && counter_ > 7) {
				counter_ = 7;
			}
		} else {
			downKeyReleased_ = true;
		}
	}

	for (auto& b : blocks_) {
		b.step();
	}

	if ((level_ + 1) * 10 <= lines_) {
		++level_;
	}

	for (auto& e : explosions_) {
		e.Step();
	}
	explosions_.erase(std::remove_if(explosions_.begin(), explosions_.end(), [](const Explosion& e) {
		return e.isFinished();
	}), explosions_.end());
}
Example #8
0
bool PopUp::draw(sf::RenderWindow &window)
{

	if(_timer2.getElapsedTime().asSeconds()>delay && trigger == 0)
	{
		_explosions.push_back(Explosion(sf::Vector2f(_shape.getPosition().x+_shape.getSize().x,_shape.getPosition().y+_shape.getSize().y*0.5f)));
		trigger = 1;
		_timer2.restart();
	}
	if(_timer2.getElapsedTime().asSeconds()>delay && trigger == 1)
	{
		_explosions.push_back(Explosion(sf::Vector2f(_shape.getPosition().x,_shape.getPosition().y+_shape.getSize().y*0.5f)));
	_timer2.restart();
	trigger = 3;
	}
	if(_timer2.getElapsedTime().asSeconds()>delay && trigger == 3)
	{

	}


	if(_timer.getElapsedTime().asSeconds()>_time && time != 0)
	{
		wantsToDie = true;
		return wantsToDie;
	}

	for(int i = 0; i < _explosions.size();i++)
	{
		if(_explosions[i].update())
			_explosions[i].draw(window);
		else
			_explosions.erase(_explosions.begin()+i);
	}

	window.draw(_shape);
	window.draw(_text);

	return wantsToDie;
	
}
Example #9
0
void Enemy::Damage( int damage, bool magic, Player* source ) {
    _hp -= std::max( damage, 0 );
    if ( damage > 0 )
        PlaySoundRandom( Lib::SOUND_ENEMY_HIT );

    if ( _hp <= 0 && !IsDestroyed() ) {
        PlaySoundRandom( _destroySound );
        if ( source && GetScore() > 0 )
            source->AddScore( GetScore() );
        if ( _explodeOnDestroy )
            Explosion();
        else
            Explosion( 0, 4, true, Vec2f( GetPosition() ) );
        OnDestroy( damage >= Player::BOMB_DAMAGE );
        Destroy();
    } else if ( !IsDestroyed() ) {
        if ( damage > 0 )
            PlaySoundRandom( Lib::SOUND_ENEMY_HIT );
        _damaged = damage >= Player::BOMB_DAMAGE ? 25 : 1;
    }
}
Example #10
0
//Post-step: Ammo free
static void ammoFree( cpSpace *space, cpShape *shape, void *unused) {
    cpBody *body = cpShapeGetBody(shape);
    Bullet *ammo = (Bullet*)cpBodyGetUserData(body);
    //cpVect pos = cpBodyGetPosition(Body);
    //printf("body->p: %f %f \n", Body->p.x, Body->p.y);
    //printf("Position: %f %f \n",pos.x,pos.y);
    //ammo->explosion(Body->p.x - 59, Body->p.y - 59);
//    for(int i=0; i < EXPLOSION_MAXIMUM_SPRITES; i++)
//        if( !explosionCheck[i] )
//            explosionSet(i, Body->p.x - 59, Body->p.y - 59);
    Explosion(body->p.x - 59, body->p.y -59);
    printf("Post step free");
    ammo->destroy();
}
Example #11
0
void Field::removeLine(const int y, const int numberOfLines) {
	auto end = blocks_.end();
	for (auto it = blocks_.begin(); it != end; ++it) {
		if (it->getY() == y) {
			explosions_.push_back(Explosion(*it, numberOfLines));
			blocks_.erase(it);
			return removeLine(y, numberOfLines);
		}
	}
	for (auto it = blocks_.begin(); it != end; ++it) {
		if (it->getY() > y) {
			it->setY(it->getY() - 1);
			it->setAnimationY(it->getAnimationY() + 1);
		}
	}
	++lines_;
	--maxY_;
}
Example #12
0
	void ManagerModel::AddExplosion(Vec2 startPosition, Model::EntityType entity) {
		Explosion *explosion = DBG_NEW Explosion();
		explosion->OnInit(this);
		explosion->mPos = startPosition;
		if (entity == ENTITY_ASTEROID) {
			explosion->mScale /= 1.5;
		} else if (entity == ENTITY_PLAYER) {
			explosion->mScale *= 2;
		} else if (entity == ENTITY_ENEMIEBOSS) {
			explosion->mScale *= 3;
		}
		mEntities.push_back(explosion);

		for (auto *view : mViews) {
			view->OnExplosionSpawned((Explosion*)explosion);
			view->PlayExplosionSoundEffect((Explosion*)explosion);
		}
	}
Example #13
0
void CluzookaCluster::Refresh()
{
#ifdef CLUSTERS_SPAWN_CLUSTERS
  if (m_recursion_depth > 1) {
    uint time = GameTime::GetInstance()->Read();
    Double flying_time = ( Double )( time - begin_time );

    if ( flying_time >= m_time_before_spawn )
    {
        DoSpawn();
        Explosion();
        return;
    };
  };
#endif

  WeaponProjectile::Refresh();
// no SetRotation needed as images are balls :)
  //image->SetRotation_rad(GetSpeedAngle());
}
Example #14
0
void Feld::klick(){
    if (this->isEnabled()){
	if(legen){
		Mine = true;
		this->setText("M");
		this->setEnabled(false);
	}else{
            this ->setEnabled(false);
            aktiv = false;
		if(Mine){
			emit Explosion();
                        this->setText("X");
		}else{
                        this->setText(QString::number(Anzahl));
                        emit notExplosion(Anzahl, this->pos());

		}

	}
    }
}
Example #15
0
void DrawTargets(void)											// Draws The Targets (Needs To Be Seperate)
{
	glLoadIdentity();											// Reset The Modelview Matrix
	glTranslatef(0.0f,0.0f,-10.0f);								// Move Into The Screen 20 Units
	for (int loop=0; loop<level; loop++)						// Loop Through 9 Objects
	{
		glLoadName(loop);										// Assign Object A Name (ID)
		glPushMatrix();											// Push The Modelview Matrix
		glTranslatef(object[loop].x,object[loop].y,object[loop].distance);		// Position The Object (x,y)
		if (object[loop].hit)									// If Object Has Been Hit
		{
			Explosion(loop);									// Draw An Explosion
		}
		else													// Otherwise
		{
			glRotatef(object[loop].spin,0.0f,0.0f,1.0f);		// Rotate The Object
			Object(size[object[loop].texid].w,size[object[loop].texid].h,object[loop].texid);	// Draw The Object
		}
		glPopMatrix();											// Pop The Modelview Matrix
	}
}
Example #16
0
void ExplosionList::addExplosion (int x, int y) {
    explosions_.push_back(Explosion(x, y));
}
Example #17
0
void CStuff::CheckCollisions ()																					// Kollisionen prüfen
{
	list<CExplosion>::iterator ItExpl;
	list<CShot> *ShotList = m_pPlayer->GetShotList();
	list<CShot>::iterator ItShot;
	// Liste für Terrainobjekte laden

	list<CBombo>::iterator ItBombo = m_BomboList.begin();
	list<CSpider>::iterator ItSpid = m_SpiderList.begin();
	list<CStachelstein>::iterator ItStac = m_StachelsteinList.begin();
	// Für weitere Monsterlisten Iteratoren erzeugen und auf Start setzen

	// Player
	for (ItExpl = m_ExplosionList.begin(); ItExpl != m_ExplosionList.end(); ItExpl++)
		if (CkRect(m_pPlayer->GetRect(), ItExpl->GetRect()))
			m_pPlayer->DoDamage(ItExpl->GetX(), ItExpl->GetY(), 5);
	// Terrain durchforsten
	// Player

	// Bombos
	while (ItBombo != m_BomboList.end())
	{
		for (ItExpl = m_ExplosionList.begin(); ItExpl != m_ExplosionList.end(); ItExpl++)
			if (CkRect(ItBombo->GetRect(), ItExpl->GetRect()))
				ItBombo->DoDamage(ItExpl->GetX(), ItExpl->GetY(), 5);
		for (ItShot = ShotList->begin(); ItShot != ShotList->end(); ItShot++)
			if (CkRect(ItBombo->GetRect(), ItShot->GetRect()))
			{
				ItBombo->DoDamage(0.5f, 1);
				ItShot->SetAlive(false);
			}
		if (m_pPlayer->IsAttack())
			if (CkRect(m_pPlayer->GetAttackRect(), ItBombo->GetRect()))
				ItBombo->DoDamage(m_pPlayer->GetX(), m_pPlayer->GetY(), 2);
		if (ItBombo->GetMode() == 5)
		{
			ItBombo->SetAlive(false);
			CExplosion Explosion(static_cast<int>(ItBombo->GetX()-77.0f), static_cast<int>(ItBombo->GetY()-75.0f));
			m_ExplosionList.push_back(Explosion);
		}
		if (ItBombo->IsAlive())
			ItBombo++;
		else ItBombo = m_BomboList.erase(ItBombo);
	}
	// Bombos

	// Stachelsteine
	while (ItStac != m_StachelsteinList.end())
	{
		for (ItExpl = m_ExplosionList.begin(); ItExpl != m_ExplosionList.end(); ItExpl++)
			if (CkRect(ItStac->GetRect(), ItExpl->GetRect()))
				ItStac->DoDamage(ItExpl->GetX(), ItExpl->GetY(), 5);
		for (ItShot = ShotList->begin(); ItShot != ShotList->end(); ItShot++)
			if (CkRect(ItStac->GetRect(), ItShot->GetRect()))
			{
				ItStac->DoDamage(0.5f, 1);
				ItShot->SetAlive(false);
			}
		if (m_pPlayer->IsAttack())
			if (CkRect(m_pPlayer->GetAttackRect(), ItStac->GetRect()))
				ItStac->DoDamage(m_pPlayer->GetX(), m_pPlayer->GetY(), 2);
		if (ItStac->IsAlive())
			ItStac++;
		else ItStac = m_StachelsteinList.erase(ItStac);
	}
	// Stachelsteine

	// Hexaspiders
	while (ItSpid != m_SpiderList.end())
	{
		for (ItExpl = m_ExplosionList.begin(); ItExpl != m_ExplosionList.end(); ItExpl++)
			if (CkRect(ItSpid->GetRect(), ItExpl->GetRect()))
				ItSpid->DoDamage(ItExpl->GetX(), ItExpl->GetY(), 5);
		for (ItShot = ShotList->begin(); ItShot != ShotList->end(); ItShot++)
			if (CkRect(ItSpid->GetRect(), ItShot->GetRect()))
			{
				ItSpid->DoDamage(0.5f, 1);
				ItShot->SetAlive(false);
			}
		if (m_pPlayer->IsAttack())
			if (CkRect(m_pPlayer->GetAttackRect(), ItSpid->GetRect()))
				ItSpid->DoDamage(m_pPlayer->GetX(), m_pPlayer->GetY(), 2);
		if (ItSpid->IsAlive())
			ItSpid++;
		else ItSpid = m_SpiderList.erase(ItSpid);
	}
	// Hexaspiders

	/*list <CTile>::iterator ItTile4;
	for (ItTile4=tiles4.begin(); ItTile4!=tiles4.end(); ItTile4++)
	{
		if (CkRect(ItTile4->GetRect(), m_pPlayer->GetRect())==true)
		{
			m_pPlayer->ProcessMoving(-255.0f);
		}
	}*/

}
Example #18
0
Projectile::~Projectile()
{
	Explosion e = Explosion(parent, location, "resources/particle.png", 7, 4);
}
Example #19
0
void Grenade::think(const double elapsedTime)
{
	//Run entity think routines.
	Entity::think(elapsedTime);

	//Check if Grenade lifetime is over.
	if(mLifeTimer.getElapsedTime() > ttl)
	{
		game->getEntityManager()->add(New Explosion(mPosition,3.0f));
		setShouldDelete(true);
	}

	mVelocity.Y -= 0.001;

	if(mPosition.Y < -1.f)
	{
		mVelocity.Y = -mVelocity.Y;
		mVelocity.Y *= GRENADE_DAMPING;

		//if(abs(mVelocity.Y) > 0.01f)
			//game->getSoundEngine()->play3DSound(game->getResourceManager()->get("squishsound"), mPosition, 3.0, randomFloat(0.75,1.25));

		if(rotator < 0)
		{
			rotator += 5;

			if(rotator > 0)
			{
				rotator = 0;
			}
		}
		else if(rotator > 0)
		{
			rotator -= 5;

			if(rotator < 0)
				rotator = 0;
		}

		game->getSoundEngine()->play3DSound(game->getResourceManager()->get("grenade_clink"), mPosition, 0.8f, randomFloat(0.75,1.25));
	}

	if(game->getCurrentMap()->getTile(int(mPosition.X + mVelocity.X), int(mPosition.Z)).type == TYPE_WALL)
	{
		mVelocity.X = -mVelocity.X;

		mVelocity *= GRENADE_DAMPING;

		game->getSoundEngine()->play3DSound(game->getResourceManager()->get("grenade_clink"), mPosition, 0.8f, randomFloat(0.75,1.25));

	}
	if(game->getCurrentMap()->getTile(int(mPosition.X), int(mPosition.Z + mVelocity.Z)).type == TYPE_WALL)
	{
		mVelocity.Z = -mVelocity.Z;

		mVelocity *= GRENADE_DAMPING;

		game->getSoundEngine()->play3DSound(game->getResourceManager()->get("grenade_clink"), mPosition, 0.8f, randomFloat(0.75,1.25));
	}

	//Add velocity to current position.
	mPosition += mVelocity;

	mpAnim->setRotation(mpAnim->getRotation() + rotator);

	if(mVoice)
		mVoice->setPosition(mPosition);
}
Example #20
0
void GameScreen::createExplosion(glm::vec3 const& position, float size, float duration, bool removeBlocks)
{
	// Add new explosion
	explosions.push_back(Explosion(position, glm::vec2(size), duration));
	// Limit explosion sounds to one per frame
	if (explosionsThisFrame < 1)
	{
		game->getSoundManager()->playSound("Sounds/bombexplosion.mp3", position, 30.f);
	}
	explosionsThisFrame++;

	// Find all bombs within the explosion radius
	Bomb::id_set nearbyBombs;
	glm::vec2 groundPos(glm::swizzle<glm::X, glm::Z>(position));
	getNearbyBombs(groundPos, size * 0.5f, nearbyBombs);
	BOOST_FOREACH(Bomb::id const& id, nearbyBombs)
	{
		// Only deal with the players own bombs
		if (id.first == myID)
		{
			Bomb& bomb = myEntities[id.second];
			if (bomb.isAlive())
			{
				Packet::ptr packet(new Packet13RemoveBomb(myID, id.second, true));
				client->write(packet);

				bomb.setIsAlive(false);
			}
		}
	}
	
	// Blow up blocks
	if (removeBlocks)
	{
		float blockExplosionRadius = size * 0.8f;

		glm::vec2 bPos = groundPos - glm::vec2(0.5f);

		glm::ivec2 minPos(glm::floor(bPos - glm::vec2(blockExplosionRadius)));
		glm::ivec2 maxPos(glm::ceil(bPos + glm::vec2(blockExplosionRadius)));

		minPos = glm::max(minPos, 0);
		maxPos = glm::min(maxPos, blockMap.getSize() - glm::ivec2(1));

		std::vector<glm::ivec2> blocks;

		// For every block in a square...
		for (int x = minPos.x; x <= maxPos.x; x++)
		{
			for (int y = minPos.y; y <= maxPos.y; y++)
			{
				glm::ivec2 oPos(x, y);

				Block::ptr block = blockMap.getBlock(oPos);			

				if (block && block->isDestructible() && glm::distance(glm::vec2(oPos), bPos) < blockExplosionRadius)
				{
					blocks.push_back(oPos);
				}
			}
		}

		// If any block to remove was found...
		if (!blocks.empty())
		{
			Packet::ptr packet(new Packet14RemoveBlocks(blocks));
			client->write(packet);
		}
	}

	// Give score for every explosion close to the opponents base
	if (glm::distance(position, opponentBasePos) < size * 0.5f)
	{
		scoreThisFrame += BASE_POINTS_PER_BOMB;
	}
}
Example #21
0
void Polecat::Refresh()
{
  if (m_energy == 0) {
    Explosion();
    return;
  }
  int tmp = GetMSSinceTimeoutStart();
  if (cfg.timeout && tmp > 1000 * (GetTotalTimeout())) {
    if (!last_fart_time) {
      std::string txt = Format(_("%s has done something for the environment, he has not ordered the polecat to fart."),
             ActiveCharacter().GetName().c_str());
      Weapon::Message(txt);
    }
    SignalTimeout();
  }

  Double norm, angle;
  if (last_fart_time && last_fart_time + TIME_BETWEEN_FART < GameTime::GetInstance()->Read()) {
    Fart();
  }

  //When we hit the ground, jump !
  if(!IsMoving() && !FootsInVacuum()) {
    // Limiting number of rebound to avoid desync
    if(last_rebound_time + TIME_BETWEEN_REBOUND > GameTime::GetInstance()->Read()) {
      image->SetRotation_rad(0.0);
      return;
    }
    last_rebound_time = GameTime::GetInstance()->Read();
    MSG_DEBUG("weapon.polecat", "Jump ! (time = %d)", last_rebound_time);
    //If the GNU is stuck in ground -> change direction
    int x = GetX();
    int y = GetY();
    if(x == save_x && y == save_y)
      m_sens = -m_sens;
    save_x = x;
    save_y = y;

    //Do the jump
    norm = RandomSync().GetDouble(1.0, 2.0);
    PutOutOfGround();
    SetSpeedXY(Point2d(m_sens * norm , -norm * THREE));
  }
  //Due to a bug in the physic engine
  //sometimes, angle==infinite (according to gdb) ??
  GetSpeed(norm, angle);

  angle = RestrictAngle(angle) * ONE_HALF;
  bool flipped = m_sens == -1;
  if (flipped) {
    if (angle > 0)
      angle -= HALF_PI;
    else
      angle += HALF_PI;
  }

  image->SetRotation_rad(angle);
  image->SetFlipped(flipped);
  image->Scale(ONE, ONE);
  image->Update();
}
Example #22
0
void EnemyList::checkCollisions(PlayerProjectiles& playerProjectiles)
{
	for (unsigned int i = 0; i < enemyList.size(); i++)
	{
		Point enemy(enemyList[i].getCompX(), enemyList[i].getCompY());
		for (unsigned int j = 0; j < playerProjectiles.getSize(); j++)
		{
			Bullet* b = playerProjectiles.getBullet(j);
			Point bulPoint(b->getX(), b->getY());
			if (enemyList[i].enemyType == 0 && Collision().checkCollision(playerProjectiles.getVector()[j].box, enemy, 0.97))
			{
				b->destroy();
				enemyList[i].enemyHP--;
				Explosion explosion;
				if (enemyList[i].enemyHP <= 0)
				{
					enemyList[i].destroyed = true;
					if (enemyList[i].enemyType == 0)
					{
						explosion = Explosion(enemyList[i].compX, enemyList[i].compY, 1, explosionTextureID);
					}
					else
					{
						explosion = Explosion(enemyList[i].compX, enemyList[i].compY, 2, explosionTextureID);
					}
					
					explosionList.addExplosion(explosion);
				}
			}
			else if (enemyList[i].enemyType == 1 && Collision().isIntersect(enemyList[i].box,
				enemy,
				b->box,
				bulPoint,
				28,
				minTransDist))
			{
				b->destroy();
				enemyList[i].enemyHP--;
				if (enemyList[i].enemyHP <= 0)
				{
					enemyList[i].destroyed = true;
					Explosion explosion(enemyList[i].compX, enemyList[i].compY, 1, explosionTextureID);
					explosionList.addExplosion(explosion);
				}
			}
		}

		for (unsigned int j = 0; j < enemyList.size(); j++)
		{
			Point p2(enemyList[j].getCompX(), enemyList[j].getCompY());
			if (i != j && Collision().isIntersect(enemyList[i].box, enemy, enemyList[j].box, p2, 28, minTransDist))
			{
				if (enemyList[i].enemyType == 1)
				{
					enemyList[j].setMinTransDist(minTransDist.pointX, minTransDist.pointY);
				}
				else if (enemyList[j].enemyType == 1)
				{
					enemyList[i].setMinTransDist(minTransDist.pointX, minTransDist.pointY);
				}
				else
				{
					enemyList[i].setMinTransDist(minTransDist.pointX * 0.5, minTransDist.pointY * 0.5);
					enemyList[j].setMinTransDist(-minTransDist.pointX * 0.5, -minTransDist.pointY * 0.5);
				}
			}
		}

		Point playerPos(playerShipX, playerShipY);
		//std::cout << playerPos.pointX << "\t" << playerPos.pointY << "\t" << enemy.pointX << "\t" << enemy.pointY << std::endl;
		BoundingQuad lineBox(playerPos, playerPos, enemy, enemy);
		bool result = true;
		for (unsigned int j = 0; j < asteroidMapListRef->asteroidField.size(); j++)
		{
			Point p2(asteroidMapListRef->asteroidField[j].getRoidX(), asteroidMapListRef->asteroidField[j].getRoidY());
			if (Collision().isIntersect(enemyList[i].box, 
				enemy,
				asteroidMapListRef->asteroidField[j].box, 
				p2,
				28,
				minTransDist))
			{
				enemyList[i].setMinTransDist(minTransDist.pointX * 2, minTransDist.pointY * 2);
				enemyList[i].turnAround();
			}
			if (!Collision().hasLineOfSight(enemy, playerPos, lineBox, asteroidMapListRef->asteroidField[j].box, p2, 28))
			{
				result = false;
			}
		}
		enemyList[i].setLOS(result);
	}

	for (unsigned int i = 0; i < playerProjectiles.getSize(); i++)
	{
		Bullet* b = playerProjectiles.getBullet(i);
		Point p1(b->getX(), b->getY());
		
		for (unsigned int j = 0; j < asteroidMapListRef->asteroidField.size(); j++)
		{
			Point p2(asteroidMapListRef->asteroidField[j].getRoidX(), asteroidMapListRef->asteroidField[j].getRoidY());
			if (Collision().isIntersect(b->box, p1, asteroidMapListRef->asteroidField[j].box, p2, 40, minTransDist))
			{
				Explosion explosion(b->box.pointsN[2].pointX, b->box.pointsN[2].pointY, 0.3, explosionTextureID);
				explosionList.addExplosion(explosion);
				b->destroyed = true;
			}
		}
	}
}
Example #23
0
OrangeEnemy::~OrangeEnemy()
{
	Explosion e = Explosion(parent, location, "resources/orangeParticle.png");
	parent->addToHighScore(25);
}
Example #24
0
void jugar(void){
     
     //rutina asteroides
     
     gotoxy(x,y); printf("%c",2);
     gotoxy(xx,yy); printf("%c",2);
     gotoxy(x1,y1); printf("%c",2);
     gotoxy(x2,y2); printf("%c",2);
     gotoxy(x3,y3); printf("%c",2);
     gotoxy(x4,y4); printf("%c",2);
     gotoxy(x5,y5); printf("%c",2);
     gotoxy(x6,y6); printf("%c",2);
     gotoxy(x7,y7); printf("%c",2);
     gotoxy(x8,y8); printf("%c",2);
     Sleep(70);
     
     gotoxy(x,y); printf(" ");
     gotoxy(xx,yy); printf(" ");
     gotoxy(x1,y1); printf(" ");
     gotoxy(x2,y2); printf(" ");
     gotoxy(x3,y3); printf(" ");
     gotoxy(x4,y4); printf(" ");
     gotoxy(x5,y5); printf(" ");
     gotoxy(x6,y6); printf(" ");
     gotoxy(x7,y7); printf(" ");
     gotoxy(x8,y8); printf(" ");
     if(y > 20){
          
          y=4;
          x= (rand() % 70) + 6;
          }
     if(yy > 20){
          
          yy=4;
          xx= (rand() % 70) + 6;
          }
     if(y1 > 20){
          
          y1=4;
          x1= (rand() % 70) + 6;
          }
     if(y2 > 20){
          
          y2=4;
          x2= (rand() % 70) + 6;
          }
     if(y3 > 20){
          
          y3=4;
          x3= (rand() % 70) + 6;
          }
          
     if(y4 > 20){
          
          y4=4;
          x4= (rand() % 70) + 6;
          }     
     if(y5 > 20){
          
          y5=4;
          x5= (rand() % 70) + 6;
          }
     
     if(y6 > 20){
          
          y6=4;
          x6= (rand() % 70) + 6;
          }
     
     if(y7 > 20){
          
          y7=4;
          x7= (rand() % 70) + 6;
          }
     
     if(y8 > 20){
          
          y8=4;
          x8= (rand() % 70) + 6;
          }
     
     
     
     
     //Mover avion
     if(kbhit()){
                 unsigned char tecla = getch();
                 
                 switch(tecla){
                               case IZQUIERDA:
                                    if(ix>4){
                                            
                                            gotoxy(ix,iy);puts(borrar_avion);
                                            gotoxy(ix,iy+1);puts(borrar_avion);
                                            gotoxy(ix,iy+2);puts(borrar_avion);
                                            ix-=2;

                                            gotoxy(ix,iy);puts(avion_l1);
                                            gotoxy(ix,iy+1);puts(avion_l2);
                                            gotoxy(ix,iy+2);puts(avion_l3);

                                            }
                                            break;
                                case DERECHA:
                                     if (ix<70){
                                            
                                            gotoxy(ix,iy);puts(borrar_avion);
                                            gotoxy(ix,iy+1);puts(borrar_avion);
                                            gotoxy(ix,iy+2);puts(borrar_avion);
                                            ix+=2;

                                            gotoxy(ix,iy);puts(avion_l1);
                                            gotoxy(ix,iy+1);puts(avion_l2);
                                            gotoxy(ix,iy+2);puts(avion_l3);

                                               }
                               break;
                               
                               }//switch
     }//if
     
     //Golpes asteroides
     
     if((x>ix && x<ix+6 && y==iy-1)||(xx>ix && xx<ix+6 && yy==iy-1)||(x1>ix && x1<ix+6 && y1==iy-1)||(x2>ix && x2<ix+6 && y2==iy-1)||(x3>ix && x3<ix+6 && y3==iy-1)||(x4>ix && x4<ix+6 && y4==iy-1)||(x5>ix && x5<ix+6 && y5==iy-1)||(x6>ix && x6<ix+6 && y6==iy-1)||(x7>ix && x7<ix+6 && y7==iy-1)||(x8>ix && x8<ix+6 && y8==iy-1)){
              Corazones --;
              Barra_salud(Corazones);
              printf("\a");
              }
     
     gotoxy(ix,iy);puts(avion_l1);
     gotoxy(ix,iy+1);puts(avion_l2);
     gotoxy(ix,iy+2);puts(avion_l3);
     
     if(!Corazones){
                    Num_vidas--;
                    vidas(Num_vidas);
                    Explosion();
                    Corazones = 3;
                    Barra_salud(Corazones);
                  }
     
     y++;
     yy++;
     y1++;
     y2++;
     y3++;
     y4++;
     y5++;
     y6++;
     y7++;
     y8++;     
     
     }