Bomb::NormalBomb::NormalBomb() { this->ctor(NormalBomb_o); TimerComponent *timer = new TimerComponent(NORMAL_BOMB_TIMER); timer->AssignEntity(this); this->AddComponent(timer); PhysicComponent *physic = new PhysicComponent(0.5); physic->AssignEntity(this); this->AddComponent(physic); MeshComponent *graphic = new MeshComponent(MODEL, new std::string("bombe"), new std::string(MODELPATH"bombe/bombe.fbx"), BombMeshInit, BombMeshDraw, G_Renderer); graphic->AssignEntity(this); this->AddComponent(graphic); ExplodeComponent *explode = new ExplodeComponent(NORMAL_BOMB_POWER, NORMAL_BOMB_SIZE); explode->AssignEntity(this); this->AddComponent(explode); this->_isDestroy = true; // AudioComponent AudioComponent* audio = new AudioComponent(Event::COMMON); audio->AssignEntity(this); this->AddComponent(audio); _sound = new std::string("explosion"); _soundpath = new std::string(SOUNDPATH"BOMB_01.wav"); audio->AddSound(_soundpath, _sound); }
bool Bomb::NormalBomb::IsDone() { if (this->HasComponent(Timer_c)) { TimerComponent *timer = static_cast<TimerComponent *>(this->GetComponent(Timer_c)); return timer->IsDone(); } return false; }
Bomb::ClassicMode::ClassicMode() { this->ctor(ClassicMode_o); this->_isDestroy = false; TimerComponent *timer = new TimerComponent(180); timer->AssignEntity(this); this->AddComponent(timer); }
void Bomb::NormalBomb::Update() { EventTreatment(); if (this->HasComponent(Timer_c) && !this->_isDestroy) { TimerComponent *timer = static_cast<TimerComponent *>(this->GetComponent(Timer_c)); timer->Update(); if (timer->IsDone() && !this->_isDestroy) this->Destroy(); } }
void TimerSystem::update(Register ®, const double dt) { HandleManager* handleManager = reg.getHandleManager(); GameObjectManager* gameObjectManager = reg.getGameObjectManager(); GameObjectList gameObjectList = gameObjectManager->getGameObjectsWithComponents(componentList); GameObject* gameObject; TimerComponent* timerComponent; for (gameObject = gameObjectList.next(); gameObject; gameObject = gameObjectList.next()) { timerComponent = gameObject->getComponent<TimerComponent>(*handleManager, TIMER_COMPONENT); if (timerComponent) { timerComponent->tick(dt); } } }
void Bomb::ClassicMode::Update() { if (G_GameSettings->gamemode == Settings::SURVIVAL && IsOnlyOnePlayer()) this->Destroy(); else if (this->HasComponent(Timer_c) && !this->_isDestroy) { TimerComponent *timer = static_cast<TimerComponent *>(this->GetComponent(Timer_c)); timer->Update(); if (timer->IsDone() && !this->_isDestroy && G_GameSettings->gamemode != Settings::SURVIVAL) this->Destroy(); } this->SaveScore(); }
PlayerState* PlayerFireBallState::processRealTimeInput(sf::Time dt, const sf::RenderWindow& renderWindow) { SpiritCoreComponent* spiritCoreComp = nullptr; if (mPlayer->hasComp<SpiritCoreComponent>()) spiritCoreComp = mPlayer->comp<SpiritCoreComponent>(); if (!mRightMouseReleased && !sf::Mouse::isButtonPressed(sf::Mouse::Right)) { mRightMouseReleased = true; mMouseLastPos = sf::Vector2f(renderWindow.mapPixelToCoords(sf::Mouse::getPosition(renderWindow))); CreateNewEntityEvent::Ptr createEntitiesEvent(new CreateNewEntityEvent()); sf::Vector2f playerWorldPos = mPlayer->comp<TransformableComponent>()->getWorldPosition(true); BoxCollisionComponent* boxComp = mPlayer->comp<BoxCollisionComponent>(); sf::Vector2f playerBoxSize(boxComp->mBoundingRect.width, boxComp->mBoundingRect.height); QueueEntityScriptData::EngineInitializeFunc initializeFunc; sf::Vector2f dirToMouse = Utility::unitVector(sf::Vector2f(renderWindow.mapPixelToCoords( sf::Mouse::getPosition(renderWindow))) - playerWorldPos); playerWorldPos += sf::Vector2f((playerBoxSize.x + 10.f) * dirToMouse.x, (playerBoxSize.y + 10.f) * dirToMouse.y); //sf::Time additionalTime(sf::seconds(mCurrentTimeBuff)); float currentTimeBuff = mCurrentTimeBuff; initializeFunc = [dirToMouse, playerWorldPos, currentTimeBuff](Entity* newEntity){ newEntity->comp<VelocityComponent>()->setVelocity(dirToMouse); newEntity->comp<TransformableComponent>()->setPosition(playerWorldPos); TimerComponent* timerComp = newEntity->comp<TimerComponent>(); sf::Time originalTime = timerComp->getTimeLimitTimer("FireBall_Time"); newEntity->comp<TimerComponent>()->setNewTimeLimitToTimer("FireBall_Time", originalTime.asSeconds() + currentTimeBuff); }; createEntitiesEvent->queueEntityFromEngine("Sky", scriptDir + "FireBallScript.lua", "FireBall", &initializeFunc); EventManager::getInstance()->queueEvent(std::move(createEntitiesEvent)); return nullptr; } if (!mRightMouseReleased) return nullptr; sf::Vector2f finalVelo; if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) finalVelo.y = -1.f; if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) finalVelo.x = -1.f; if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) finalVelo.y = 1.f; if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) finalVelo.x = 1.f; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)){ VelocityComponent* veloComp = mPlayer->comp<VelocityComponent>(); if (finalVelo == sf::Vector2f()) finalVelo = veloComp->getFacingDirection() * -1.f; return new PlayerSideStepState(mPlayer, finalVelo, mPlayerStateTable); } if (finalVelo != sf::Vector2f()) return new PlayerIdleState(mPlayer, mPlayerStateTable); return nullptr; }