void PowerUpInterface::updateState() { if( GameConfig::game_powerups == false ) { return; } if ( NetworkState::status == _network_state_server ) { if( regen_timer.count() ) { generatePowerUp(); } } for (PowerUpList::iterator i = powerup_list.begin(); i != powerup_list.end(); /* empty */) { PowerUp* powerup = *i; if(powerup->life_cycle_state == _power_up_lifecycle_state_inactive) { delete powerup; i = powerup_list.erase(i); } else { powerup->updateState(); i++; } } }
bool Wallbreaker::checkBrick(Entity& entity, int i, int j, const sf::Vector2f& old_pos) { if (i >= 0 && i < LevelManager::NB_BRICK_LINES && j >= 0 && j < LevelManager::NB_BRICK_COLS) { Brick& brick = m_level.getBrick(i, j); if (brick.isActive()) { entity.onBrickHit(brick, old_pos); if (!brick.isActive()) { // Randomly create a new power-up if (math::rand(0, 9) == 0) { PowerUp* powerup = PowerUp::createRandom(); powerup->setPosition(brick.getPosition()); addEntity(powerup); } // Update remaining bricks counter --m_remaining_bricks; m_hud.setBrickCount(m_remaining_bricks); // Upgrade score ++m_score; m_hud.setScore(m_score); if (m_score > Settings::highscore) { Settings::highscore = m_score; m_hud.setHighscore(Settings::highscore); } } return true; } } return false; }
void PowerUpInterface::offloadGraphics( SpriteSorter &sorter ) { if( GameConfig::game_powerups == false ) { return; } PowerUpList::iterator i; for(i=powerup_list.begin(); i!=powerup_list.end(); i++) { PowerUp* powerup = *i; powerup->offloadGraphics(sorter); } }
PowerUp* PowerUp::create() { PowerUp* powerUpNode = new PowerUp; if (powerUpNode->init()) { powerUpNode->autorelease(); return powerUpNode; } else { CC_SAFE_DELETE(powerUpNode); return nullptr; } return powerUpNode; }
void Idle::Execute(Tank* pTank) { PowerUp *nearestPowerUp = pTank->findNearestPowerUp(); Tank *nearestTarget = pTank->findNearestTarget(); if (nearestPowerUp != NULL && nearestTarget != NULL) { if (pTank->getTankPosition().distance(nearestPowerUp->getPowerUpPosition()) < pTank->getTankPosition().distance(nearestTarget->getTankPosition())) { pTank->GetFSM()->changeState(SeekTarget::Instance()); } } else { //pTank->GetFSM()->changeState(SeekPowerUp::Instance()); } }
void EntityManager::createPowerup(char* path, btTransform &trans, int type) { btScalar mass = btScalar(0.f); PowerUp* pup = new PowerUp(); pup->SetType(type); pup->initRenderObject(path); //Taking this out for a bit; doesn't need to be a trimesh really //btCollisionShape* triMesh = sFactory.createStaticTriangleMesh(pup->renderObject); btScalar radius = 2.5f; btCollisionShape* sphereMesh = sFactory.createSphere(radius); pup->initPhysicsObject(sphereMesh, mass, trans); addPowerUp(pup); Physics::Inst()->addEntity(*pup); }
void EndlessWorld::extendFlat() { //flat cpVect verts[] = { cpv(koniec - dodatek - G_odlegloscmiedzyBramkami, -2000), cpv(koniec - dodatek - G_odlegloscmiedzyBramkami, 0), cpv(koniec, 0), cpv(koniec, -2000), }; cpSpaceRemoveStaticShape(gravitySpace, floor); floor = cpPolyShapeNew(floorBody, 4, verts, cpvzero); floor->e = 0;//elastycznosc; floor->u = 0.1f;//friction floor->collision_type = COLLISIONTYPEFLOOR; cpShapeSetLayers(floor, CPFLOORCOLIDER); cpSpaceAddStaticShape(gravitySpace, floor); flatsprite->setTextureRect(Rect(verts[0].x, verts[1].y, abs(verts[3].x), flatsprite->getTexture()->getContentSize().height)); bottomSpr->setPositionX(koniec - dodatek - G_odlegloscmiedzyBramkami); //chkpts if (isEndless()) { for (int i = koniec - dodatek; i <= koniec; i += G_odlegloscmiedzyBramkami) { auto chkpt = Chcekpoint::create(this, &orderedOpponents, R_SPRITE_checkpoint); chkpt->setPosition(i, floor->bb.t); modifyGate(chkpt); rotationLayer->addChild(chkpt); } } //POWERUPS for (int j = koniec - dodatek + G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar); j <= koniec; j += G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar)) { int wysokosc = 2.5f * Sprite::createWithSpriteFrameName(R_Box[1])->getContentSize().height; PowerUp *pwrup = PowerUp::create(&orderedOpponents); pwrup->setPosition(Vec2(j, floor->bb.t + wysokosc)); rotationLayer->addChild(pwrup); } }
void EndlessWorld::setMinGates(int number) { minliczbabramek = number; int bramki = minliczbabramek; if (isEndless()) bramki = G_endlessGateNumber; for (int i = 1; i <= bramki; i++) { auto chkpt = Chcekpoint::create(this, &orderedOpponents, R_SPRITE_checkpoint); chkpt->setPosition(floor->bb.l + i*G_odlegloscmiedzyBramkami, floor->bb.t); rotationLayer->addChild(chkpt); if (i == minliczbabramek) chkpt->setIsLast(true); modifyGate(chkpt); } //POWER UPY for (int odl = G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar); odl <= koniec; odl += G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar)) { int wysokosc = 2.5f * Sprite::createWithSpriteFrameName(R_Box[1])->getContentSize().height; PowerUp *pwrup = PowerUp::create(&orderedOpponents); pwrup->setPosition(Vec2(odl, floor->bb.t + wysokosc)); rotationLayer->addChild(pwrup); } }
void PowerUp::dropRandom(const sf::Vector2f& position) { PowerUp* powerup = new PowerUp((Type) math::rand(0, PowerUp::_COUNT - 1)); powerup->setPosition(position); EntityManager::getInstance().addEntity(powerup); }
void Player::onCollision(PowerUp& powerup) { switch (powerup.getType()) { // timed bonus case PowerUp::DOUBLE_SHOT: if (bonus_[T_DOUBLESHOT] == 0) m_weapon.setMultiply(2); bonus_[T_TRISHOT] = 0; bonus_[T_DOUBLESHOT] += TIMED_BONUS_DURATION; m_panel.activeAttackPowerUp(bonus_[T_DOUBLESHOT], powerup.getType()); break; case PowerUp::TRIPLE_SHOT: if (bonus_[T_TRISHOT] == 0) m_weapon.setMultiply(3); bonus_[T_DOUBLESHOT] = 0; bonus_[T_TRISHOT] += TIMED_BONUS_DURATION; m_panel.activeAttackPowerUp(bonus_[T_TRISHOT], powerup.getType()); break; case PowerUp::SPEED: if (bonus_[T_SPEED] == 0) { m_speed *= BONUS_SPEED_FACTOR; m_smoke_emitter.createParticles(120); } bonus_[T_SPEED] += TIMED_BONUS_DURATION; m_panel.activeSpeedPowerUp(bonus_[T_SPEED]); break; // immediate bonus case PowerUp::REPAIR: if (getHP() < m_max_hp) m_panel.setHP(updateHP(1)); break; case PowerUp::FULL_REPAIR: setHP(m_max_hp); m_panel.setHP(m_max_hp); m_powerup_emitter.setPosition(getCenter()); m_powerup_emitter.createParticles(50); break; case PowerUp::SHIELD: if (m_shield < m_max_shield) setShield(m_shield + 1); break; case PowerUp::FULL_SHIELD: setShield(m_max_shield); m_panel.setShield(m_max_shield); m_powerup_emitter.setPosition(getCenter()); m_powerup_emitter.createParticles(50); break; case PowerUp::ICECUBE: if (m_icecubes < MAX_ICECUBES) m_panel.setIcecubes(++m_icecubes); break; case PowerUp::MISSILE: if (m_missiles < MAX_MISSILES) m_panel.setMissiles(++m_missiles); break; default: break; } powerup.kill(); MessageSystem::write(powerup.getDescription(), powerup.getPosition()); SoundSystem::playSound("power-up.ogg"); }
void PowerUpSpawner::addPowerUp(Powerup powerUpInfo) { if (powerUpInfo.id.compare("ExtraPoints") == 0) { if (powerUpInfo.cantidad <= 0) return; int textureID = m_textureHelper->stringToInt(powerUpInfo.id); int step = (m_stageSize - Game::Instance()->getGameHeight()) / powerUpInfo.cantidad; for(int i = 0; i < powerUpInfo.cantidad; ++i) { PowerUpSpawnInfo powerUpSpawnInfo; int pointsValue = getRandomPointsValue(); PowerUp* powerUp = new ExtraPointsPU(pointsValue); int posX = Random::getRange(0, Game::Instance()->getGameWidth() - powerUpInfo.ancho); int posY = Random::getRange(0, (Game::Instance()->getGameHeight() - (Game::Instance()->getGameHeight()/5))); powerUp->load(posX, posY, powerUpInfo.ancho, powerUpInfo.alto, textureID, powerUpInfo.frames); powerUpSpawnInfo.powerUpToSpawn = powerUp; int randomStagePosition = Random::getRange((i * step) - (step/50), ((i + 1) * step) + (step/50)); if (randomStagePosition < 0) randomStagePosition = 0; if (randomStagePosition > m_stageSize) randomStagePosition = m_stageSize; powerUpSpawnInfo.stagePosition = randomStagePosition; powerUpSpawnInfo.posX = posX; powerUpSpawnInfo.posY = posY; //printf("Extra Points Power Up en posicion %d \n", randomStagePosition); m_powerUpsToSpawn.push_back(powerUpSpawnInfo); } } if (powerUpInfo.id.compare("BombPU") == 0) { if (powerUpInfo.cantidad <= 0) return; int textureID = m_textureHelper->stringToInt(powerUpInfo.id); int step = (m_stageSize - Game::Instance()->getGameHeight()) / powerUpInfo.cantidad; for(int i = 0; i < powerUpInfo.cantidad; ++i) { PowerUpSpawnInfo powerUpSpawnInfo; PowerUp* powerUp = new BombPU(); int posX = Random::getRange(0, Game::Instance()->getGameWidth() - powerUpInfo.ancho); int posY = Random::getRange(0, (Game::Instance()->getGameHeight() - (Game::Instance()->getGameHeight()/4))); powerUp->load(posX, posY, powerUpInfo.ancho, powerUpInfo.alto, textureID, powerUpInfo.frames); powerUpSpawnInfo.powerUpToSpawn = powerUp; int randomStagePosition = Random::getRange((i * step) - (step/50), ((i + 1)* step) + (step/50)); if (randomStagePosition < 0) randomStagePosition = 0; if (randomStagePosition > m_stageSize) randomStagePosition = m_stageSize; powerUpSpawnInfo.stagePosition = randomStagePosition; powerUpSpawnInfo.posX = posX; powerUpSpawnInfo.posY = posY; //printf("Bomb Power Up en posicion %d \n", randomStagePosition); m_powerUpsToSpawn.push_back(powerUpSpawnInfo); } } if (powerUpInfo.id.compare("DualWeaponPU") == 0) { if (powerUpInfo.cantidad <= 0) return; int textureID = m_textureHelper->stringToInt(powerUpInfo.id); int step = (m_stageSize - Game::Instance()->getGameHeight()) / powerUpInfo.cantidad; for(int i = 0; i < powerUpInfo.cantidad; ++i) { PowerUpSpawnInfo powerUpSpawnInfo; PowerUp* powerUp = new DualWeaponPU(); int posX = Random::getRange(0, Game::Instance()->getGameWidth() - powerUpInfo.ancho); int posY = Random::getRange(0, (Game::Instance()->getGameHeight() - (Game::Instance()->getGameHeight()/4))); powerUp->load(posX, posY, powerUpInfo.ancho, powerUpInfo.alto, textureID, powerUpInfo.frames); powerUpSpawnInfo.powerUpToSpawn = powerUp; int randomStagePosition = Random::getRange((i * step) - (step/50), ((i + 1) * step) + (step/50)); if (randomStagePosition < 0) randomStagePosition = 0; if (randomStagePosition > m_stageSize) randomStagePosition = m_stageSize; powerUpSpawnInfo.stagePosition = randomStagePosition; powerUpSpawnInfo.posX = posX; powerUpSpawnInfo.posY = posY; //printf("Bomb Power Up en posicion %d \n", randomStagePosition); m_powerUpsToSpawn.push_back(powerUpSpawnInfo); } } if (powerUpInfo.id.compare("SecondaryPow") == 0) { if (powerUpInfo.cantidad <= 0) return; int textureID = m_textureHelper->stringToInt(powerUpInfo.id); int step = (m_stageSize - Game::Instance()->getGameHeight()) / powerUpInfo.cantidad; for(int i = 0; i < powerUpInfo.cantidad; ++i) { PowerUpSpawnInfo powerUpSpawnInfo; PowerUp* powerUp = new SecondaryShipsPU(); int posX = Random::getRange(0, Game::Instance()->getGameWidth() - powerUpInfo.ancho); int posY = Random::getRange(0, (Game::Instance()->getGameHeight() - (Game::Instance()->getGameHeight()/4))); powerUp->load(posX, posY, powerUpInfo.ancho, powerUpInfo.alto, textureID, powerUpInfo.frames); powerUpSpawnInfo.powerUpToSpawn = powerUp; int randomStagePosition = Random::getRange((i * step) - (step/50), ((i + 1) * step) + (step/50)); if (randomStagePosition < 0) randomStagePosition = 0; if (randomStagePosition > m_stageSize) randomStagePosition = m_stageSize; powerUpSpawnInfo.stagePosition = randomStagePosition; powerUpSpawnInfo.posX = posX; powerUpSpawnInfo.posY = posY; //printf("Bomb Power Up en posicion %d \n", randomStagePosition); m_powerUpsToSpawn.push_back(powerUpSpawnInfo); } } }