Example #1
0
bool HoldableItemProtection::use( void )
{
	Event *event;

	if ( _owner && !multiplayerManager.checkFlag( MP_FLAG_NO_POWERUPS ) )
	{
		if ( !_owner->isSubclassOf( Player ) )
			return false;

		Powerup *powerup;
		Player *player;

		player = (Player *)_owner;

		powerup = Powerup::CreatePowerup( "Protection", "models/item/powerup_protection.tik", player );

		event = new Event( EV_Item_SetAmount );
		event->AddFloat( 15.0f );
		powerup->ProcessEvent( event );

		if ( powerup )
		{
			player->setPowerup( powerup );
			return true;
		}
	}

	return false;
}
Example #2
0
Powerup *Powerup::CreatePowerup( const str &className, const str &modelName, Sentient *sentient )
{
	str fullname;
	SpawnArgs args;
	ClassDef *cls;
	Powerup *powerup;


	fullname = "Powerup";
	fullname += className;

	args.setArg( "classname", fullname.c_str() );

	cls = args.getClassDef();

	if ( !cls )
		return NULL;

	if ( !checkInheritance( &Powerup::ClassInfo, cls ) )
		return NULL;

	powerup = (Powerup *)cls->newInstance();

	if ( !powerup )
		return NULL;

	powerup->init( modelName, sentient );

	return powerup;
}
Example #3
0
//=============================================================================================================
void Game::AddPowerup(const D3DXVECTOR2 pos)
{
	if( !GameVariables::EnablePowerups )
		return;

	int prob = rand() % 200;

	// 10% esély h lesz egyáltalán powerup
	if( prob >= 180 )
	{
		Powerup power;

		power.Initialize(*game);
		power.Image = &atlas1["powerup"];
		power.SetPosition(pos);
		power.Speed = background.Speed * 0.5f;

		powerups.push_back(power);

		if( prob >= 180 && prob < 188 )
			powerups.rbegin()->apply.connect(this, &Game::rapidfire_apply);
		else if( prob >= 188 && prob < 196 )
			powerups.rbegin()->apply.connect(this, &Game::twincannons_apply);
		else if( prob >= 196 && prob < 198 )
			powerups.rbegin()->apply.connect(this, &Game::extrahealth_apply);
		else if( prob >= 198 && prob < 200 )
			powerups.rbegin()->apply.connect(this, &Game::extrashield_apply);
		else
			std::cout << "Impossible powerup...\n";
	}
}
Example #4
0
void Player::contact(Entity* e) {
  //not exactly elegant, but oh well.
  if(e->getType() == ET_ENTITY || e->getType() == ET_SPACESHIP_A || e->getType() == ET_SPACESHIP_B || e->getType() == ET_SPACESHIP_C || e->getType() == ET_SPACESHIP_D) {
    if(e->isDead()) { //if it's dead, we don't care about this collision
      return;
    }
    
    applyDamage(e->getCollisionDamage()); //apply collision damage to player
    e->setHealth(0); //kill entity

    _game->getGameplayScreen()->addScore(50);
    _game->getGameplayScreen()->addEnemyShot();

    _game->getGameplayScreen()->getEntityManager()->deleteEntity(e->getId(), true); //schedule deletion
  }

  if(e->getType() == ET_POWERUP) {
    Powerup* powerup = static_cast <Powerup*> (e);
    std::string powerupType = powerup->getPowerupType();

    if(powerupType == "hp") {
      _game->getGameplayScreen()->addHealth(100);
    } else if(powerupType == "score") {
      _game->getGameplayScreen()->addScore(50);
    } else if(powerupType == "dmg") {
      applyDamage(50);
    }

    powerup->setHealth(0);
  }
}
Example #5
0
/**
* Static constructor with position and index. Objects should be created with
* this method once dynamic level loading is implemented.
*
* @param	pos	The initial position in world coordinates
* @param	i	The index in the list of power-up metadata
*
* @return  An autoreleased physics object
*/
Powerup* Powerup::create(const Vec2& pos, const PowerupType& t, int i) {
	Powerup* p = new (std::nothrow) Powerup();
	if (p && p->init(pos, t, i)) {
		p->autorelease();
		return p;
	}
	CC_SAFE_DELETE(p);
	return nullptr;
};
Example #6
0
void LevelScreen::ReceiveMessage(Message* m)
{
    if(m->GetMessageName() == "FoodConsumed")
    {
        std::stringstream ss;
        
        m_highscoreCounter += m_snake->getPointMultiplicator();
        
        ss << std::setfill('0') << std::setw(4) << m_highscoreCounter;
        
        m_highscore->SetDisplayString(ss.str());
    }
    else if(m->GetMessageName() == "PowerupConsumed")
    {
        std::stringstream ss;
        m_highscoreCounter += m_snake->getPointMultiplicator();
        ss << std::setfill('0') << std::setw(4) << m_highscoreCounter;
        
        Powerup* powerup = static_cast<Powerup*>(m->GetSender());
        
        if(powerup != NULL)
        {
            m_popupText->SetColor(1.f, 1.f, 1.f);
            m_popupText->SetDisplayString(powerup->getDescription());
            m_popupText->ChangeColorTo(Color(1.0,0.0,0.0), 5.0, true, "HidePopup");
            theWorld.Add(m_popupText, kUILayer);
        }
    }
    else if(m->GetMessageName() == "HidePopup")
    {
        theWorld.Remove(m_popupText);
    }
    else if(m->GetMessageName() == "EnterPressed")
    {
        theSwitchboard.UnsubscribeFrom(this, "EnterPressed");
        theSwitchboard.Broadcast(new Message("ShowMenu"));
    }
    else if(m->GetMessageName() == "ObstacleHit")
    {
        theWorld.Remove(m_popupText);
        m_snake->stop();
                
        TextActor* gameOver = new TextActor("popup", "GAME OVER");
        gameOver->SetPosition(-4.8f, 4.0f);
        gameOver->SetColor(1.f, 1.f, 1.f);
        
        TextActor* hitEnterText = new TextActor("standard", "Hit [Enter] to get back to menu...");
        hitEnterText->SetPosition(-8.8f, 0.0f);
        hitEnterText->SetColor(1.f, 1.f, 1.f);
        
        addRenderable(gameOver, kUILayer);
        addRenderable(hitEnterText, kUILayer);
        
        theSwitchboard.SubscribeTo(this, "EnterPressed");
    }
}
Example #7
0
void Ship::onCollide( Object* collided_with ) {
    if( collided_with->get_type() == T_POWERUP ) {
        std::cout<<"ShipC"<<std::endl;
        Powerup* powerup = (Powerup*)collided_with;
        weapons_upgrade();
        powerup->die();
    }
    else
        MovingObject::onCollide( collided_with );
}
Example #8
0
bool Player::Update()
{

	int controlEvent = CONTROL_EVENT_DO_NOTHING;
	bool playerMoved = FALSE;

	controlEvent = this->theController->GetControlEvent();
	this->Update(controlEvent);


	if (this->theController->IsDropBombPressed())
	{
		int x = 3;
		if( 
			(bombDropCoundownTimer <= 0) &&
			!IsCollisionWithBomb() && 
			(numAllowedBombs > numBombsDropped)
		  )
		{
			this->numBombsDropped++;
			controlEvent = CONTROL_EVENT_DROP_BOMB;
			this->Update(controlEvent);
			bombDropCoundownTimer = bombDropCoundownTimerInitialValue;

		}
	}

	if(bombDropCoundownTimer > 0)
	{
		bombDropCoundownTimer--;
	}


	Powerup * aPowerup = IsCollisionWithPowerup();
	if(aPowerup)
	{
		aPowerup->Activate(this);
		Universe::RemovePowerup(aPowerup );
		delete aPowerup;
		Sound::PlaySound(Sound::pickup_powerup_sound);
	}



	bool collisionWithExplosion = ExplosionPart::IsGameObjectInAnyExplosionPart(this);
	if(collisionWithExplosion)
	{
		this->playerState = PLAYER_STATE_DEAD;
		Sound::PlaySound(Sound::player_dies_sound);
	}
	return collisionWithExplosion;

}
Example #9
0
/**
 * This function assumes this powerup has already been removed from the powerup 
 * effect queue. If another PowerupShrinkRay is in the queue then allow that one 
 * to stop the effect.
 */
void PowerupShrinkRay::StopEffect(u8 player)
{
  for (int i = 0; i < MAX_POWERUP_EFFECTS; ++i)
  {
    Powerup *powerup = g_players[player].gameData.powerupEffects[i];
    if (powerup && powerup->GetPowerupId() == powerupId)
    {
      return;
    }
  }
  
  g_players[player].gameData.powerupData.playfieldScale = 0;
}
Example #10
0
void Powerup::givePlayerItem( Player *player )
{
	Powerup *powerup;
	const char *modelName;

	modelName = gi.NameForNum( edict->s.modelindex );

	if ( !modelName )
		return;

	powerup = Powerup::CreatePowerup( item_name, modelName, player );

	Event *event = new Event( EV_Item_SetAmount );
	event->AddFloat( amount );
	powerup->ProcessEvent( event );

	player->setPowerup( powerup );
}
Example #11
0
void powerup(const CCommand &args)
{
	CBasePlayer *player = ToBasePlayer (UTIL_GetCommandClient ()); 
	if (!player)
	{
		return;
	}
	Vector org;
	Vector forward;

	AngleVectors (player->EyeAngles (), &forward);
	VectorMA (player->GetAbsOrigin () + Vector (0, 0, 36), 80, forward, org);

	Powerup *p = (Powerup *)CreateEntityByName ("da_powerup");
	p->random = true;
	p->type = 0;
	p->delay = 10;
	p->Spawn ();
	p->SetAbsOrigin (org);
}
Example #12
0
Powerup *  Player::IsCollisionWithPowerup()
{
	BOB * playerBOB = this->GetTheCollisionBob();
	POWERUP_VECTOR::iterator theIterator;
	POWERUP_VECTOR & theBombs = Universe::GetPowerups();

	for(	theIterator = theBombs.begin();
		theIterator != theBombs.end();
		theIterator++
		)
	{
		Powerup * next = *theIterator;
		BOB * nextBOB = next->GetBlitterObject()->getTheBOB();
		boolean collision = Collision_BOBS_Half_Overlap(playerBOB,nextBOB);

		if(collision)
		{
			return next;
		}

	}
	return 0;
}
Example #13
0
bool Bullet::collideBullet(Bullet bullets[], Comet comets[], int bSize, int cSize, SpaceShip &ship, int curRound, Powerup powerup, Powerup powerups[], int pSize)
{
	int i;
	int j;
	for(i = 0; i < bSize; i++)
	{
		if(bullets[i].live)
		{
			for(j = 0; j < cSize; j++)
			{
				if(comets[j].live)
				{
					if( (bullets[i].x - bullets[i].boundX) < (comets[j].x + comets[j].boundx) &&
						(bullets[i].x + bullets[i].boundX) > (comets[j].x - comets[j].boundx) &&
						(bullets[i].y - bullets[i].boundY) < (comets[j].y + comets[j].boundy) &&
						(bullets[i].y + bullets[i].boundY) > (comets[j].y - comets[j].boundy))
					{
						
						bullets[i].live = !bullets[i].live;
						comets[j].live = !comets[j].live;
						ship.score += curRound *5 * 10;

						if (powerup.startPowerUp(powerups, pSize))
						{
							for (int l; l < 0; l++)
							{
								if (powerups[l].live)
								{
									powerups[l].x = bullets[i].x;
									powerups[l].y = bullets[i].y;
								}
							}
						}
						return true;
					}else{
						return false;
					}
				}
				
			}
		}
		
	}

}
Example #14
0
//---------------------------------------------------------
void GameSession::Update(float dt)
{
    GameObjectList::iterator list1;
    for(list1=m_activeObj.begin();list1!=m_activeObj.end();++list1)
    {
        GameObj* temp = *list1;
        //update logic and positions
        if((*list1)->m_active)
        {
            (*list1)->Update(dt);
            Vector3 clippedPos = (*list1)->getPosition();
            Clip(clippedPos);
            (*list1)->setPosition(clippedPos);
        }
        else continue;
        
        //check for collisions
        if((*list1)->m_collisionFlags != GameObj::OBJ_NONE)
        {
            GameObjectList::iterator list2;
            for(list2=m_activeObj.begin();list2!=m_activeObj.end();++list2)
            {
                //the first obj may have already collided with something, making it inactive
                if(!(*list1)->m_active)
                    continue;

                //don't collide with yourself
                if(list1 == list2)
                    continue;
                
                if((*list2)->m_active    && 
                    ((*list1)->m_collisionFlags & (*list2)->m_type) && 
                    (*list1)->IsColliding(*list2)) 
                {
                    (*list1)->DoCollision((*list2));
                }
            }
        }
        if(list1==m_activeObj.end()) break;
    }
    
    //get rid of inactive objects
    GameObjectList::iterator end    = m_activeObj.end();
    GameObjectList::iterator newEnd = remove_if(m_activeObj.begin(),m_activeObj.end(),RemoveNotActive);
    if(newEnd != end)
        m_activeObj.erase(newEnd,end);

    //check for no main ship, respawn
    if(m_mainShip == NULL || m_respawnTimer>=0.0f)
    {
        m_respawnTimer-=dt;
        if(m_respawnTimer<0.0f)
        {
            m_mainShip = new Ship;
            if(m_mainShip)
            { 
                PostGameObj(m_mainShip);
                m_humanControl->SetShip(m_mainShip);
                m_AIControl->SetShip(m_mainShip);
            }
        }
    }

    //occasionally spawn a powerup
    m_powerupTimer-=dt;
    if(m_powerupTimer <0.0f)
    {
        m_powerupTimer = randflt()*6.0f + 4.0f;
        Powerup* pow = new Powerup;
        if(pow)
        {
            Vector3 pos;

            pos.x= randflt()*m_screenW; 
            pos.y= randflt()*m_screenH; 
            pos.z= 0;
            pow->setPosition(pos);

            Vector3 vel;

            vel.x= randflt()*40 - 20; 
            vel.y= randflt()*40 - 20;
            vel.z= 0;
            pow->setVelocity(vel);

            PostGameObj(pow);
        }
    }

    //check for additional life bonus each 10K points
    if(m_score >= m_bonusScore)
    {
        m_numLives++;
        m_bonusScore += BONUS_LIFE_SCORE;
    }
    
    //check for finished wave
    if(!m_numAsteroids)
    {
        m_waveNumber++;
        WaveOver();
    }

    //check for finished game, and reset
    if(!m_numLives)
        GameOver();

    m_humanControl->Update(dt);

    //update AI control, if turned on
    if(m_AIOn)
        m_AIControl->Update(dt);
}
Example #15
0
	void GameLogic::update(float delta)
	{
		if(running)
		{
			// update platforms
			for (auto &platform : *level->getPlatforms())
			{
				platform->update(delta);

				// check for landings
				// landing = they intersect and the player is high enough
				if (platform->getSprite().getGlobalBounds().intersects(player->getSprite().getGlobalBounds())
					&& player->getY() + player->getSprite().getGlobalBounds().height < platform->getY() + platform->getSprite().getGlobalBounds().height)
				{
					if (player->isFalling()) player->land(platform->getY());
					landedPlatform = platform;
					platform->startFall();
				}
			}

			// update level
			level->update(player->getY(), delta);

			// update player
			player->update(delta);

			// check for powerup collision
			std::vector<Powerup*>::iterator powerupIt = level->getPowerups()->begin();
			while (powerupIt != level->getPowerups()->end())
			{
				Powerup* powerup = *powerupIt;

				if (powerup->getSprite().getGlobalBounds().intersects(player->getSprite().getGlobalBounds()))
				{
					std::cout << "got powerup " << powerup->getType() << "\n";
					player->applyPowerup(powerup->getType());
					powerupIt = level->getPowerups()->erase(powerupIt);
				}
				else {
					++powerupIt;
				}
			}

			// update falling hazards
			std::vector<FallingHazard*>::iterator hazardIt = level->getFallingHazards()->begin();
			while (hazardIt != level->getFallingHazards()->end())
			{
				FallingHazard* hazard = *hazardIt;
				hazard->update(delta);
				// check collision
				if (hazard->getCircle().getGlobalBounds().intersects(player->getSprite().getGlobalBounds()))
				{
					hazardIt = level->getFallingHazards()->erase(hazardIt);
					if (!player->immune){
						player->hitByRock(hazard->getVy());
						manager->queueEvent(&hazardEvent);
					}
				} else {
					++hazardIt;
				}
				
			}

			std::vector<Fireball*>::iterator fireballIt = level->getFireballs()->begin();
			while (fireballIt != level->getFireballs()->end())
			{
				Fireball* fireball= *fireballIt;
				fireball->update(delta);

				// check collision
				if (fireball->getCircle().getGlobalBounds().intersects(player->getSprite().getGlobalBounds()))
				{
					fireballIt = level->getFireballs()->erase(fireballIt);
					if (!player->immune){
						if (player->life != 0){
							player->hitByFire();
							manager->queueEvent(&hazardEvent);
						}
						else{
							player->die();
							manager->queueEvent(&gameOver);
						}
					}
				}
				else {
					++fireballIt;
				}
			}

			// move player with platform
			if (player->landed)
			{
				player->stickToPlatform(delta, landedPlatform->getVelocityX(), landedPlatform->getVelocityY());
			}

			// check for death by lava
			if (player->getY() > level->getLavaY())
			{
				if (player->alive)
				{
					manager->queueEvent(&gameOver);
					player->die();
				}
			}
		}
	}
Example #16
0
bool Enemy::check_collision(Projectile *p)
{
    if(p->x > _x && p->x < _x + _w &&
       p->y > _y && p->y < _y + _h)
    {
        --_health;

        _w -= ((_tier - 1 < 1 ? 2 : (_tier - 1) * 2) + 1);
        _h -= (_tier + 1);

        if(_w < 16)  _w = 16;
        if(_h < 16)  _h = 16;

        ParticleSystem *_hit_psys;

        if(_health > 0)
        {
            if(Mix_PlayChannel(-1, _hit_sound, 0) == -1)
            {
                std::cout << "Unable to play sound: " << Mix_GetError() << std::endl;
            }

            _hit_psys = new ParticleSystem(_x + _w / 2, _y + _h / 2, 10, 0.0001f, (((double) rand()) / RAND_MAX) * 360, 20, 5, 1.0f, 0.0f, 0.0f, 600, 4, true);
        }
        else
        {
            int r = (((double) rand()) / RAND_MAX) * 10 / _tier / 1.5;
            // std::cout << "r = " << r << " vs. " << (int) (10 / _tier / 2) << std::endl;
            if(r == (int) (10 / _tier / 2))
            {
                POWERUP_TYPE t = POWERUP_SPEED;

                r = (((double) rand()) / RAND_MAX) * 3;
                int d;
                if(r == 1)
                {
                    t = POWERUP_PROJECTILE_SPEED;
                    d = 10;
                }
                else if(r == 2)
                {
                    t = POWERUP_SPEED;
                    d = 10;
                }
                else
                {
                    t = POWERUP_TRIPLESHOT;
                    d = 20;
                }
                Powerup *p = new Powerup(t, _x, _y, 32, 32, d, 4);
                p->start();
                PowerupManager::register_powerup(p);
            }

            if(Mix_PlayChannel(-1, _dead_sound, 0) == -1)
            {
                std::cout << "Unable to play sound: " << Mix_GetError() << std::endl;
            }

            _hit_psys = new ParticleSystem(_x + _w / 2, _y + _h / 2, 20, 0.0001f, 0, 360, 100, 1.0f, 0.0f, 0.0f, 400, 4, true);
        }
        _hit_psys->start();
        ParticleManager::register_system(_hit_psys);

        return true;
    }

    return false;
}
Example #17
0
 /** Sets a new powerup. */
 void setPowerup (PowerupManager::PowerupType t, int n)
                                  { m_powerup.set(t, n); }
Example #18
0
 /** Returns the number of powerups. */
 int            getNumPowerup       () const { return m_powerup.getNum(); }