Example #1
0
/*!
  In \a phase 0, increment the missile's age and return if
  the missile has expired. If not, move the missile based
  on its current position and velocity. Then get the its
  list of colliding sprites and traverse the list. When a
  rock is found in the list, mark both the rock and the
  missile dead and return.

  In phase 1, if the missile is marked dead, delete it;
  \internal
 */
void KMissile::advance(int phase)
{
    if (phase == 0) {
	if (dying())
	    markDead();
	else
	    incrementAge();
	if (isDead())
	    return;
	KSprite::advance(phase);
        QList<QGraphicsItem*> hits = collidingItems();
        QList<QGraphicsItem*>::iterator i;
        for (i=hits.begin(); i!=hits.end(); ++i) {
	    if ((*i)->type() > ID_Base) {
		KSprite* sprite = (KSprite*)(*i);
		if (sprite->isRock()) {
		    sprite->markDead();
		    markDead();
		    break;
		}
	    }
        }
    }
    else if (isDead() || dying())
	delete this;
}
void CollisionManager::checkEnemyPlayerBulletCollision(
        const std::vector<GameObject *> &objects) {
    for(unsigned int i = 0; i < objects.size(); i++) {
        auto pObject = objects[i];
        
        for(unsigned int j = 0; j < 
                TheBulletHandler::Instance()->getPlayerBullets().size(); j++) {
            if(pObject->type() != std::string("Enemy") || !pObject->updating()) {
                continue;
            }
            
            auto pRect1 = std::make_shared<SDL_Rect>();
            pRect1->x = pObject->getPosition().getX();
            pRect1->y = pObject->getPosition().getY();
            pRect1->w = pObject->getWidth();
            pRect1->h = pObject->getHeight();
            
            auto pPlayerBullet = TheBulletHandler::Instance()->
                getPlayerBullets()[j];
            
            auto pRect2 = std::make_shared<SDL_Rect>();
            pRect2->x = pPlayerBullet->getPosition().getX();
            pRect2->y = pPlayerBullet->getPosition().getY();
            pRect2->w = pPlayerBullet->getWidth();
            pRect2->h = pPlayerBullet->getHeight();
            
            if(RectRect(pRect1, pRect2)) {
                if(!pObject->dying() && !pPlayerBullet->dying()) {
                    pPlayerBullet->collision();
                    pObject->collision();
                }                
            }            
        }
    }
}
Example #3
0
/*!
  In phase 0, advance the rock's image and move the rock
  according to its current poisition and velocity.

  In phase 1, if the rock has been marked dead, then it
  has collided with the ship. Break it into smaller rocks.
  Then destroy the original rock.
  \internal
 */
void KMediumRock::advance(int phase)
{
    if (!isDead()) {
	if (!phase) {
	    KRock::advanceImage();
	    KSprite::advance(phase);
	}
    }
    if (phase && (isDead() || dying())) {
	if (!dying())
	    destroy();
	delete this;
    }
}
Example #4
0
/*!
  This function is only called by \l QGraphicsScene::advance().

  The shield's position is always computed from the ship's
  position, so the shield is not moved here. Neither is the
  shield destroyed here, because the shield is meant to
  exist for as long as the ship exists. The only thing that
  happens here is that in \a phase 1 the shield is either
  shown or hidden depending on whether it is marked as
  being up or not.

  The shield is created when the ship is created. The shield
  is deleted when the ship is deleted.

  \internal
 */
void KShield::advance(int phase)
{
    if ((phase == 0) && dying())
	markDead();
    else if (phase == 1) {
	if (isDead() || dying()) {
	    delete this;
	    return;
	}
	if (isUp())
	    show();
	else
	    hide();
    }
}
Example #5
0
/*!
  In phase 0, age the exhaust and mark it dead if it has
  expired. Also advance the exhaust image and move the
  exhaust with the ship.

  In phase 1, if the exhaust has been marked dead,
  destroy it.
  \internal
 */
void KExhaust::advance(int phase)
{
    if (phase == 0) {
	if (dying())
	    markDead();
	else
	    incrementAge();
	if (isDead())
	    return;
	advanceImage();
	KSprite::advance(phase);
    }
    else if (isDead() || dying())
	delete this;
}
void CollisionManager::checkPlayerEnemyBulletCollision(Player* pPlayer) {
    auto pRect1 = std::make_shared<SDL_Rect>();
    pRect1->x = pPlayer->getPosition().getX();
    pRect1->y = pPlayer->getPosition().getY();
    pRect1->w = pPlayer->getWidth();
    pRect1->h = pPlayer->getHeight();
    
    for(unsigned int i = 0; i < 
            TheBulletHandler::Instance()->getEnemyBullets().size(); i++) {
        auto pEnemyBullet = TheBulletHandler::Instance()->getEnemyBullets()[i];
        
        auto pRect2 = std::make_shared<SDL_Rect>();
        pRect2->x = pEnemyBullet->getPosition().getX();
        pRect2->y = pEnemyBullet->getPosition().getY();
        
        pRect2->w = pEnemyBullet->getWidth();
        pRect2->h = pEnemyBullet->getHeight();
        
        if(RectRect(pRect1, pRect2)) {
            if(!pPlayer->dying() && !pEnemyBullet->dying()) {
                pEnemyBullet->collision();
                pPlayer->collision();
            }
        }
    }
}
Example #7
0
void ItemEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
  if (itemType == ItemBossHeart && !game().getCurrentMap()->isCleared()) return;

  PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity);

  if (collideWithEntity(entity))
  {
    if (playerEntity != NULL && !playerEntity->isDead())
    {
      if (isMerchandise)
      {
        playerEntity->setItemToBuy(this);
      }
      else if (canBePickedUp())
      {
        playerEntity->acquireItem(itemType);

        if (isMerchandise) playerEntity->pay(getPrice());

        dying();

        if (!items[itemType].generatesStance)
          new MagnetEntity(x, y, playerEntity, itemType);
      }
    }
  }
}
Example #8
0
int
main(int argc, char *argv[])
{
	int ch;

	emotion = fear = speed = 1;

	while ((ch = getopt(argc, argv, "f")) != -1) {
		switch (ch) {
		case 'f':
			speed <<= 1;
			break;
		}
	}

	concerned();
	sleep(1);
	afraid();
	sleep(1);
	feared();
	sleep(1);
	dying();

	sleep(1);

	printf("\n");
	fflush(stdout);
	warnx("all life functions terminated");
	return 0;
}
void Boss::die(){
    //sequence to 10 random explosion
    stopAllActions();
    Vector<FiniteTimeAction*> explosions;
    for(int i = 0; i < 22; i++)
    {
        auto expl = CallFunc::create(this, callfunc_selector(Boss::createRandomExplosion));
        auto delay = DelayTime::create(i*0.15);
        auto seq = Sequence::create(delay, expl, nullptr);
        explosions.pushBack(seq);
    }
    auto giantExpl = Spawn::create(explosions);
    Vector<FiniteTimeAction*> explosions2;
    for(int i = 0; i < 15; i++)
    {
        auto expl = CallFunc::create(this, callfunc_selector(Boss::createRandomExplosion));
        explosions2.pushBack(expl);
    }
    auto giantExpl2 = Spawn::create(explosions2);
    auto callDead = CallFunc::create(this, callfunc_selector(Boss::dead));
    auto final = Sequence::create(giantExpl, giantExpl2, callDead,nullptr);
    runAction(final);
    dying();
    
}
Example #10
0
/*!
  In phase 0, age the powerup sprite and move it
  based on its current position and velocity.

  In phase 1, if the powerup has been marked for
  being applied to the ship, increase the ship's
  fire power.
  \internal
 */
void KShootPowerup::advance(int phase)
{
    if (phase == 0) {
	if (dying())
	    markDead();
	else
	    incrementAge();
	KSprite::advance(phase);
    }
    else {
	if (apply() && ship_)
	    ship_->incrementFirePower();
	if (isDead() || dying())
	    delete this;
    }
}
Example #11
0
void SausageEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
  if (!isDying && !isAgonising && collideWithEntity(entity))
  {
    if (entity->getType() == ENTITY_PLAYER || entity->getType() == ENTITY_BOLT )
    {
      PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity);
      BoltEntity* boltEntity = dynamic_cast<BoltEntity*>(entity);

      if (playerEntity != NULL && !playerEntity->isDead()) dying();

      else if (boltEntity != NULL && !boltEntity->getDying() && boltEntity->getAge() > 0.05f) collideWithBolt(boltEntity);
    }
    else // collision with other enemy ?
    {
      if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX)
      {
        if (this != entity)
        {
          EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity);
          if (enemyEntity->canCollide()) collideWithEnemy(enemyEntity);
        }
      }
    }
  }
}
Example #12
0
void PlayerServer::injury(int point, Attribute attribute, std::unique_ptr<Card> &card, PlayerServer *source, bool fromChain)
{
	TRIEV(t_PreInjury, &point, &attribute, &card, &source);
	if (point > 0) {
		
		WriteBuffer wb;
		uint8_t pt = (uint8_t)point;
		uint8_t attr = attribute;
		wb << this->position << pt << attr;
		GAME->notify(100, Notify_Injury, wb);
		setHp(hp - point);
		if (hp <= 0) {
			dying(source);
		}
		TRIEV(t_Injuried, &point, &attribute, &card, &source);
		if (!fromChain && chained && attribute != Attribute_None) {
			if(this->alive)
				this->setChained(false);
			int8_t pos = game->currentPosition;
			do 
			{
				PlayerServer* player = static_cast<PlayerServer*>(game->players[pos]);
				if (player->alive && player->chained) {
					player->injury(point, attribute, card, source, true);
					if(player->alive)
						player->setChained(false);
				}
				pos++;
				if (pos >= (int8_t)game->players.size()) {
					pos = 0;
				}
			} while (pos != game->currentPosition);
		}
	}
}
Example #13
0
DrawerPolyline::~DrawerPolyline()
{
    emit dying(this);

    if (m_vtkPolydata)
    {
        m_vtkPolydata->Delete();
    }

    if (m_vtkPoints)
    {
        m_vtkPoints->Delete();
    }

    if (m_vtkCellArray)
    {
        m_vtkCellArray->Delete();
    }

    if (m_vtkActor)
    {
        m_vtkActor->Delete();
    }
    if (m_vtkBackgroundActor)
    {
        m_vtkBackgroundActor->Delete();
    }
    if (m_vtkMapper)
    {
        m_vtkMapper->Delete();
    }
}
Example #14
0
/*!
  In phase 0, age the powerup sprite and move it
  based on its current position and velocity.

  In phase 1, if the powerup has been marked for
  being applied to the ship, increase the ship's
  power level.
  \internal
 */
void KEnergyPowerup::advance(int phase)
{
    if (phase == 0) {
	if (dying())
	    markDead();
	else
	    incrementAge();
	KSprite::advance(phase);
    }
    else {
	if (apply() && ship_)
	    ship_->increasePowerLevel(FUEL_POWERUP_BONUS);
	if (isDead() || dying())
	    delete this;
    }
}
Example #15
0
BugEditDialog::BugEditDialog(Bug *b, QWidget *parent, Qt::WFlags flags)
	: QDialog(parent, flags), bug(b)
{
	ui.setupUi(this);

	connect(bug, SIGNAL(dying()), this, SLOT(close()));
	connect(bug, SIGNAL(dying()), this, SLOT(deleteLater()));

	ui.procPage->setProcessor(&bug->get_processor());
	ui.dnaPage->setBug(bug);

	connect(bug, SIGNAL(changed()), ui.procPage, SLOT(updateInfo()));
	connect(bug, SIGNAL(changed()), ui.dnaPage, SLOT(updateInfo()));

	setAttribute(Qt::WA_QuitOnClose, false);
	setAttribute(Qt::WA_DeleteOnClose, true);
}
Example #16
0
int emittable::remove_watcher(watcher *w, MSGID msgid) {
	if (dying()) { ASSERT(false); return NBR_EINVAL; }
	watch_entry *tmp = reinterpret_cast<watch_entry *>(w);
	command *e = m_cl.alloc<watch_entry*, const bool>(tmp, false);
	TRACE("allocate command object %p %u\n", e, e->m_type);
	if (!e) { return NBR_EMALLOC; }
	e->set_respond_msgid(msgid);
	return add_command(e);
}
Example #17
0
/*!
  This function is called by QGraphicsScene::advance().
  It is called twice for each item at each animation step,
  first with \a phase = 0, and then with \a phase = 1.

  In phase 0, each item moves itself. In phase 1, each item
  that is responsible for handling collisions detects its
  collisions and handles them.

  Note: Each subclass of this base class must implement
  advance() and call this function when \a phase == 0.
  \internal
 */
void
KSprite::advance(int phase)
{
    if (phase == 0) {
	if (dying())
	    markDead();
	if ((vx_ != 0.0) || (vy_ != 0.0)) {
	    moveBy(vx_,vy_);
	    wrap();
	}
    }
}
Example #18
0
/*!
  In phase 0, advance the rock's image and move the rock
  according to its current poisition and velocity.

  In phase 1, if the rock has been marked dead, then it
  has collided with the ship. Destroy the rock. Sometimes
  create a powerup in its place.
  \internal
 */
void KSmallRock::advance(int phase)
{
    if (!isDead()) {
	if (!phase) {
	    KRock::advanceImage();
	    KSprite::advance(phase);
	}
    }
    if (phase && (isDead() || dying())) {
        view_->reportRockDestroyed(10);
	if (!dying()) {
	    KPowerup* new_pup = KPowerup::create();
	    if (new_pup) {
		double r = (0.5 - randDouble()) * 4.0;
		new_pup->setPos(x(),y());
		new_pup->setVelocity(velocityX()+r,velocityY()+r);
		new_pup->show();
	    }
	}
	delete this; // Don't do anything after deleting me.
    }
}
void RockMissileEntity::collideWall()
{
  if (rockType == 1 && !hasCollided)
  {
    hasCollided = true;
    if (collisionDirection == DIRECTION_RIGHT || collisionDirection == DIRECTION_LEFT) velocity.x = -velocity.x;
    else velocity.y = -velocity.y;
  }
  else
  {
    dying();
  }
}
Example #20
0
void ItemEntity::buy()
{
  if (canBePickedUp() && isMerchandise)
  {
    game().getPlayer()->acquireItem(itemType);
    game().getPlayer()->pay(getPrice());
    game().getPlayer()->setItemToBuy(NULL);

    dying();

    if (!items[itemType].generatesStance)
      new MagnetEntity(x, y, game().getPlayer(), itemType);
  }
}
Example #21
0
   void
 ActiveMonitor::closeEvent(QCloseEvent * e)
 {
   QWidget::closeEvent(e);
   emit(dying(this));
 }
void GiantSlimeEntity::animate(float delay)
{
  slimeTimer -= delay;
  if (slimeTimer <= 0.0f)
  {
    slimeTypeEnum slimeType = SlimeTypeStandard;
    if (game().isAdvancedLevel())
    {
      slimeType =  (slimeTypeEnum)(slimeType + rand() % 3);
    }
    switch (slimeCounter)
    {
    case 0:
      new SlimeEntity(TILE_WIDTH * 1.5f, TILE_HEIGHT * 1.5f, slimeType, true);
      break;
    case 1:
      new SlimeEntity(TILE_WIDTH * (MAP_WIDTH - 2) + TILE_WIDTH * 0.5f, TILE_HEIGHT * 1.5f, slimeType, true);
      break;
    case 2:
      new SlimeEntity(TILE_WIDTH * (MAP_WIDTH - 2) + TILE_WIDTH * 0.5f, TILE_HEIGHT * (MAP_HEIGHT - 2) + TILE_HEIGHT * 0.5f, slimeType, true);
      break;
    case 3:
      new SlimeEntity(TILE_WIDTH * 1.5f, TILE_HEIGHT * (MAP_HEIGHT - 2) + TILE_HEIGHT * 0.5f, slimeType, true);
      break;
    }
    slimeTimer = 7.0f;
    slimeCounter ++;
    if (slimeCounter == 4) slimeCounter = 0;
  }

  if (age <= 0.0f)
  {
    age += delay;
    return;
  }
  EnemyEntity::animate(delay);
  if (specialState[SpecialStateIce].active) delay *= specialState[SpecialStateIce].param1;

  timer -= delay;
  if (timer <= 0.0f)
  {
    if (state == 0) // walking
    {
      counter--;
      if (counter >= 0)
      {
        timer = 0.5f;
        if (hp <= hpMax / 4)
          creatureSpeed = GIANT_SLIME_SPEED * 1.4f;
        if (hp <= hpMax / 2)
          creatureSpeed = GIANT_SLIME_SPEED * 1.2f;
        else
          creatureSpeed = GIANT_SLIME_SPEED;

        setVelocity(Vector2D(x, y).vectorTo(game().getPlayerPosition(), GIANT_SLIME_SPEED ));
      }
      else
      {
        int r = rand() % 3;
        if (r == 0) changeToState(1);
        else if (r == 1) changeToState(3);
        else changeToState(5);
      }
    }
    else if (state == 1) // waiting for jumping
    {
      changeToState(2);
    }
    else if (state == 2) // jumping
    {
      changeToState(8);
    }
    else if (state == 3)
    {
      changeToState(4);
    }
    else if (state == 4) // walking
    {
      counter--;
      if (counter >= 0)
      {
        if (hp <= hpMax / 4)
          timer = missileDelay * 0.6f;
        if (hp <= hpMax / 2)
          timer = missileDelay * 0.8f;
        else
          timer = missileDelay;
        fire();
      }
      else
      {
        changeToState(8);
      }
    }
    else if (state == 5)
    {
      changeToState(6);
    }
    else if (state == 6)  // jump
    {
      changeToState(7); // fall
    }
    else if (state == 7)  // jump
    {
    }
    else if (state == 8)  // jump
    {
      changeToState(0); // fall
    }
  }

  if (state == 0) // walking
  {
    frame = ((int)(age * 2.0f)) % 2;
  }
  else if (state == 1 || state == 5) // waiting to jump
  {
    if (timer < 0.25f)
      frame = 1;
    else
      frame = 0;
  }
  else if (state == 2)  // jumping
  {
    hVelocity -= 700.0f * delay;

    h += hVelocity * delay;

    if (h <= 0.0f)
    {
      if (hp <= 0)
        dying();
      else
      {
        h = 0.0f;
        if (isFirstJumping)
        {
          isFirstJumping = false;
          hVelocity = 160.0f;
          SoundManager::getInstance().playSound(SOUND_SLIME_IMAPCT);
        }
        else
        {
          SoundManager::getInstance().playSound(SOUND_SLIME_IMAPCT_WEAK);
          viscosity = 0.96f;
          changeToState(0);
        }
      }
    }
    if (hVelocity > 0.0f) frame = 2;
    else frame = 0;
  }
  else if (state == 6) // ultra jump
  {
    if (h < 2000)
      h += hVelocity * delay;
  }
  else if (state == 7) // ultra jump
  {
    if (!isFalling && timer <= 2.2f)
    {
      isFalling = true;
      x = game().getPlayer()->getX();
      y = game().getPlayer()->getY();
      // to prevent collisions
      float x0 = TILE_WIDTH + 1;
      float xf = TILE_WIDTH * (MAP_WIDTH - 1) - 1;
      float y0 = TILE_HEIGHT + 1;
      float yf = TILE_HEIGHT * (MAP_HEIGHT - 1) - 1;

      calculateBB();

      if (boundingBox.left < x0) x += (x0 - boundingBox.left);
      else if (boundingBox.left + boundingBox.width > xf) x -= (boundingBox.left + boundingBox.width - xf);

      if (boundingBox.top < y0) y += (y0 - boundingBox.top);
      else if (boundingBox.top + boundingBox.height > yf) y -= (boundingBox.top + boundingBox.height - yf);
    }
    if (timer < 2.3f)
    {
      h += hVelocity * delay;
      if (h <= 0)
      {
        h = 0;
        changeToState(8);
        game().makeShake(0.8f);
        SoundManager::getInstance().playSound(SOUND_CYCLOPS_IMPACT);
      }
    }
  }

  if (state == 6 && timer < 0.5f)
  {
    int fade = timer * 512;
    if (fade < 0) fade = 0;
    sprite.setColor(sf::Color(255, 255, 255, fade));
  }
  else if (state == 7 && timer < 1.5f)
    sprite.setColor(sf::Color(255, 255, 255, 255));
  else if (state == 7 && timer < 2.0f)
    sprite.setColor(sf::Color(255, 255, 255, (2.0f - timer) * 512));
  else if (state == 7)
    sprite.setColor(sf::Color(255, 255, 255, 0));

  isMirroring = (frame == 2) && (velocity.x < 0.0f);
  z = y + 26;
}
Example #23
0
/*!
  The advance function does quite a lot for the ship sprite.
  In \a phase 0, if the ship is marked dead, just return. If
  not, move the ship using its current position and velocity.
  Then get the list of all collisions with the ship and run
  through the list.

  If the ship collides with a rock, then if the shield is
  up, destroy the rock. If the shiled is down (normal), mark
  the ship dead and return.

  If the ship collides with a powerup, then if the shield is
  up, mark the powerup destroyed. If the shield is not up,
  apply the powerup to the ship.

  In phase 1, if the ship is marked dead, explode the ship,
  delete it, and return. Otherwise, handle ship rotation,
  breaking, ship velocity, an teleporting. also update the
  image if the ship is rotating, and the exhaust image, if
  the engine is on. If the shiled is up, handle its image
  and age. Finally, in phase one, handle the firing of the
  missiles.
  \internal
 */
void KShip::advance(int phase)
{
    if (phase == 0) {
	if (dying())
	    markDead();
	if (isDead() || teleport_)
	    return;
	KSprite::advance(phase);
	QList<QGraphicsItem*> hits = ship_->collidingItems();
	QList<QGraphicsItem*>::Iterator i;
	for (i=hits.begin(); i!=hits.end(); ++i) {
	    if ((*i)->type() <= ID_Base)
		continue;
	    KSprite* sprite = (KSprite*)(*i);
	    if (sprite->isRock()) {
		if (shield_->isUp()) {
		    /*
		      The ship hit a rock with the shield up.
		      The rock is marked for death, which will
		      cause it to break up or just disappear in
		      in phase 1.

		      The shield's strength is reduced by an
		      amount commensurate with the rock size.
		      If the strength goes to 0, the shield
		      will be dropped in phase 1.
		     */
		    sprite->markDead();
		    int s = 1;
		    if (sprite->isLargeRock())
			s = 3;
		    else if (sprite->isMediumRock())
			s = 2;
		    int pl = s * (SHIELD_HIT_COST - (shield_->strength()*2));
		    shield_->reduceStrength(s);
		    reducePowerLevel(pl);
		}
		else {
		    /*
		      The ship hit a rock with the shield down.
		      Mark the ship dead and return. The ship
		      will be exploded in phase 1.
		     */
                    view_->setCanPause(false);
		    markDead();
		    shield_->markDead();
		    return;
		}
	    }
	    else if (sprite->isPowerup()) {
		if (shield_->isUp()) {
		    sprite->markDead();
		}
		else {
		    /*
		      The ship hit a powerup with the shield down.
		      Mark the powerup for apply. It will be applied
		      to the ship in phase 1, if the ship survives.
		      Also mark the powerup dead, ie consumed.
		     */
		    sprite->markApply();
		    sprite->markDead();
		    return;
		}
	    }
            else if (powerLevel() <= EMPTY_SHIP_POWER_LEVEL) {
                ship_->markDead();
                shield_->markDead();
            }
	}
    }
    else { // phase 1
	if (isDead() || dying()) {
	    explode(); // shatters the ship into spinning fragments.
	    delete this;
	    return;
	}
	if (rotateSlow_)
	    rotateSlow_--;

	if (rotateLeft_) {
	    angleIndex_ -= rotateSlow_ ? 1 : rotationRate_;
	    if (angleIndex_ < 0)
		angleIndex_ = SHIP_STEPS-1;
	    angle_ = angleIndex_ * PI_X_2 / SHIP_STEPS;
	    cosangle_ = cos(angle_);
	    sinangle_ = sin(angle_);
	}

	if (rotateRight_) {
	    angleIndex_ += rotateSlow_ ? 1 : rotationRate_;
	    if (angleIndex_ >= SHIP_STEPS)
		angleIndex_ = 0;
	    angle_ = angleIndex_ * PI_X_2 / SHIP_STEPS;
	    cosangle_ = cos(angle_);
	    sinangle_ = sin(angle_);
	}

	if (isBraking()) {
	    stopEngine();
	    stopRotation();
	    if ((fabs(dx_) < 2.5) && (fabs(dy_) < 2.5)) {
		dx_ = 0.0;
		dy_ = 0.0;
		setVelocity(dx_,dy_);
		releaseBrakes();
	    }
	    else {
		double motionAngle = atan2(-dy_,-dx_);
		if (angle_ > M_PI)
		    angle_ -= PI_X_2;
		double angleDiff = angle_ - motionAngle;
		if (angleDiff > M_PI)
		    angleDiff = PI_X_2 - angleDiff;
		else if (angleDiff < -M_PI)
		    angleDiff = PI_X_2 + angleDiff;
		double fdiff = fabs(angleDiff);
		if (fdiff > 0.08) {
		    if (angleDiff > 0)
			rotateLeft_ = true;
		    else if (angleDiff < 0)
			rotateRight_ = true;
		    if (fdiff > 0.6)
			rotationRate_ = brakeForce() + 1;
		    else if (fdiff > 0.4)
			rotationRate_ = 2;
		    else
			rotationRate_ = 1;

		    if (rotationRate_ > 5)
			rotationRate_ = 5;
		}
		else if ((fabs(dx_)>1) || (fabs(dy_)>1)) {
		    startEngine();
		    // we'll make braking a bit faster
		    dx_ += cosangle_/6 * (brakeForce() - 1);
		    dy_ += sinangle_/6 * (brakeForce() - 1);
		    reducePowerLevel(BRAKE_ON_COST);
		    KExhaust::add(ship_->x() + 10 - cosangle_*11,
				  ship_->y() + 10 - sinangle_*11,
				  dx_-cosangle_,
				  dy_-sinangle_,
				  brakeForce()+1);
		}
	    }
	}
	else if (engineIsOn()) {
	    /*
	      The ship has a terminal velocity, but trying
	      to go faster still uses fuel (can go faster
	      diagonally - don't care).
	    */
	    double thrustx = cosangle_/8;
	    double thrusty = sinangle_/8;
	    if (fabs(dx_ + thrustx) < MAX_SHIP_SPEED)
		dx_ += thrustx;
	    if (fabs(dy_ + thrusty) < MAX_SHIP_SPEED)
		dy_ += thrusty;
	    setVelocity(dx_,dy_);
	    reducePowerLevel(5);
	    KExhaust::add(x() + 10 - cosangle_*10,
			  y() + 10 - sinangle_*10,
			  dx_-cosangle_,
			  dy_-sinangle_,
			  3);
	}

	setImage(angleIndex_ >> 1);

	if (teleport_) {
	    int ra = rand() % 10;
	    if(ra == 0)
		ra += rand() % 20;
	    int xra = ra * 60 + ((rand() % 20) * (rand() % 20));
	    int yra = ra * 50 - ((rand() % 20) * (rand() % 20));
	    setPos(xra,yra);
	    teleport_ = false;
	    if (teleportCount_ > 0) {
		--teleportCount_;
		view_->markVitalsChanged();
	    }
	    wrap();
	}

	if (shield_->isUp()) {
	    /*
	      The shield's position always depends on the
	      ship's position.
	     */
	    static int sf = 0;
	    sf++;
	    if (sf % 2)
		shield_->advanceImage();
	    shield_->setPos(x()-5,y()-5);
	    shield_->show();
	}

	if (isShooting()) {
	    int maxMissiles = firePower_ + 2;
	    if (canShoot() && (KMissile::missiles() < maxMissiles)) {
		KMissile* missile = new KMissile();
		missile->setMaximumAge(12);
		missile->setPos(11 + x() + cosangle_ * 11,
				11 + y() + sinangle_ * 11);
		missile->setVelocity(dx_ + cosangle_ * MISSILE_SPEED,
				     dy_ + sinangle_ * MISSILE_SPEED);
		missile->show();
		reducePowerLevel(1);
		view_->reportMissileFired();
		int delay = 5 - firePower_;
		if (delay < 0)
		    delay = 0;
		delayShooting(delay); // delay firing next missile.
	    }
	    decrementNextShotDelay();
	}
    }
}
Example #24
0
DrawerBitmap::~DrawerBitmap()
{
    emit dying(this);
}
Example #25
0
void BaseCreatureEntity::prepareDying()
{
  dying();
}
Example #26
0
void BaseCreatureEntity::dyingFromAge()
{
  dying();
}
void LargeSlimeEntity::animate(float delay)
{
  if (age <= 0.0f)
  {
    age += delay;
    return;
  }
  EnemyEntity::animate(delay);
  if (specialState[SpecialStateIce].active) delay *= specialState[SpecialStateIce].param1;

  timer -= delay;
  frame = 0;
  if (timer <= 0.0f)
  {
    if (state == 0) // walking
    {
      counter--;
      if (counter >= 0)
      {
        timer = 0.5f;
        if (hp <= hpMax / 4)
          creatureSpeed = GIANT_SLIME_SPEED * 1.4f;
        if (hp <= hpMax / 2)
          creatureSpeed = GIANT_SLIME_SPEED * 1.2f;
        else
          creatureSpeed = GIANT_SLIME_SPEED;

        setVelocity(Vector2D(x, y).vectorTo(game().getPlayerPosition(), GIANT_SLIME_SPEED ));
      }
      else
      {
        int r = rand() % 2;
        if (r == 0) changeToState(1);
        else changeToState(3);
      }
    }
    else if (state == 1) // waiting for jumping
    {
      changeToState(2);
    }
    else if (state == 2) // jumping
    {
      changeToState(8);
    }
    else if (state == 3)
    {
      changeToState(4);
    }
    else if (state == 4) // walking
    {
      counter--;
      if (counter >= 0)
      {
        if (hp <= hpMax / 4)
          timer = missileDelay * 0.6f;
        if (hp <= hpMax / 2)
          timer = missileDelay * 0.8f;
        else
          timer = missileDelay;
        fire();
      }
      else
      {
        changeToState(8);
      }
    }
    else if (state == 8)  // jump
    {
      changeToState(0); // fall
    }
  }

  if (state == 0) // walking
  {
    frame = ((int)(age * 2.0f)) % 2;
  }
  else if (state == 1 || state == 5) // waiting to jump
  {
    if (timer < 0.25f)
      frame = 1;
    else
      frame = 0;
  }
  else if (state == 2)  // jumping
  {
    hVelocity -= 700.0f * delay;

    h += hVelocity * delay;

    if (h <= 0.0f)
    {
      if (hp <= 0)
        dying();
      else
      {
        h = 0.0f;
        if (isFirstJumping)
        {
          isFirstJumping = false;
          hVelocity = 160.0f;
          SoundManager::getInstance().playSound(SOUND_SLIME_IMAPCT);
        }
        else
        {
          SoundManager::getInstance().playSound(SOUND_SLIME_IMAPCT_WEAK);
          viscosity = 0.96f;
          changeToState(0);
        }
      }
    }
    if (hVelocity > 0.0f) frame = 2;
    else frame = 0;
  }

  isMirroring = (frame == 2) && (velocity.x < 0.0f);
  frame += baseFrame;

  z = y + 26;
}
   void
 SingleServerConfigDialog::slotFinished()
 {
   emit(dying(this));
 }