void EnemyBossRedBullet::derivedUpdate() { float time = lifetimer.getElapsedTime().asSeconds(); if(time > 2.5f) { auto impact = GameGlobals::get()->impact; auto position = getTransform->getPosition(); auto color = getRenderer->getColor(); impact->setColor(color); impact->setScale(1.75f, 2.45f + (thor::random(0, 10) >= 9 ? 1.6f : 0.f)); impact->setPosition(position); impact->emit(1); destroyEntity(); return; } if(m_speed < 150.f) { m_speed += std::max(0.f, time * time - 0.01f) * 7.f; } if(time <= 0.6f) { auto player = GameGlobals::get()->player; float targetAngle = sz::getAngle(getTransform->getPosition(), player->getTransform->getPosition()); m_angle += sz::angleDiff(m_angle, targetAngle) / 25.f; } getPhysics->setRotation(sz::toDegrees(m_angle)); }
void EntityManager::destroyEntitiesByTag( const std::string &tag){ CTagEntityMng::TVId lent = getTagMng().getEntitiesByTag( tag); for ( std::size_t ind =0; ind< lent.size(); ind++) { destroyEntity( lent[ind]); getTagMng().unregisterTagForEntity( lent[ind], tag); } }
//! //! Destructor of the Model2SceneNode class. //! Model2SceneNode::~Model2SceneNode () { destroyEntity(); destroyAllAttachedMovableObjects(m_sceneNode); OgreTools::destroyResourceGroup(m_oldResourceGroupName); emit viewNodeUpdated(); DEC_INSTANCE_COUNTER }
void EnemyHeavyBullet::derivedUpdate() { float time = lifetimer.getElapsedTime().asSeconds(); if(time > 2.7f) { destroyEntity(); } m_speed += std::max(0.f, time * time - 0.01f) * 25.f; }
bool Bomb::spread() { int x = 0, y = 0; x = _distanceCovered; y = _distanceCovered; while ((_vec.x + x) < _distance + _vec.x) { if (_spreadRight && (_spreadRight = destroyEntity(glm::vec2(_vec.x + x, _vec.y)))) _fireList.push_back(new Fire(glm::vec2(_vec.x + x, _vec.y))); if (_spreadLeft && (_spreadLeft = destroyEntity(glm::vec2(_vec.x - x, _vec.y)))) _fireList.push_back(new Fire(glm::vec2(_vec.x - x, _vec.y))); ++x; if (_spreadTop && (_spreadTop = destroyEntity(glm::vec2(_vec.x, _vec.y + y)))) _fireList.push_back(new Fire(glm::vec2(_vec.x, _vec.y + y))); if (_spreadDown && (_spreadDown = destroyEntity(glm::vec2(_vec.x, _vec.y - y)))) _fireList.push_back(new Fire(glm::vec2(_vec.x, _vec.y - y))); ++y; } _distanceCovered = x - 1; return true; }
ChunkBase::~ChunkBase() { destroyEntity(); destroyPhysicsBody(); removeMesh(); if (mVertices != 0) { delete[] mVertices; } if (mIndices != 0) { delete[] mIndices; } }
void PlayerBullet::derivedUpdate() { float time = lifetimer.getElapsedTime().asSeconds(); float scale = std::max(0.25f, 0.6f - time * 5.f); getComponent<sz::Transform>()->setScale(scale, scale); if(time > 2.7f) { destroyEntity(); } if(m_speed < 220.f) m_speed += std::max(0.f, time * time - 0.005f) * 25.f; //m_speed += (150.f - m_speed) * Time.delta / 3.f; }
void EntityManager::unlockEntityDestruction() { mDestructionLocked = false; for (auto ID : mEntitiesToRemove) destroyEntity(ID); mEntitiesToRemove.clear(); for (auto& pair : mComponentsToRemove) { for (auto componentType : pair.second) { removeComponentFromEntity(pair.first, componentType); } } }
//------------------------------------------------------------------------------------- PyObject* Base::pyDestroyEntity() { if(isDestroyed()) { PyErr_Format(PyExc_Exception, "%s::destroy: %d is destroyed!\n", getScriptName(), getID()); PyErr_PrintEx(0); S_Return; } if(creatingCell_ || cellMailbox_ != NULL) { PyErr_Format(PyExc_Exception, "%s::destroy: id:%i has cell! creatingCell=%s\n", this->getScriptName(), this->getID(), creatingCell_ ? "true" : "false"); PyErr_PrintEx(0); } else destroyEntity(); S_Return; }
//! //! //! \return True, if successful loading of ogre mesh //! False, otherwise. //! bool Model2SceneNode::loadMesh () { // destroy an existing OGRE entity for the mesh destroyEntity(); QString filename = getStringValue("Geometry File"); if (filename == "") { Log::debug(QString("Geometry file has not been set yet. (\"%1\")").arg(m_name), "Model2SceneNode::loadMesh"); return false; } // check if the file exists if (!QFile::exists(filename)) { Log::error(QString("Mesh file \"%1\" not found.").arg(filename), "Model2SceneNode::loadMesh"); return false; } // split the absolute filename to path and base filename int lastSlashIndex = filename.lastIndexOf('/'); QString path = ""; if (lastSlashIndex > -1) { path = filename.mid(0, lastSlashIndex); filename = filename.mid(lastSlashIndex + 1); } if (!filename.endsWith(".mesh")) { Log::error("The geometry file has to be an OGRE mesh file.", "Model2SceneNode::loadMesh"); return false; } // destroy old resource group and generate new one QString resourceGroupName = QString::fromStdString(createUniqueName("ResourceGroup_" + filename + "_Model2SceneNode")); OgreTools::destroyResourceGroup(m_oldResourceGroupName); m_oldResourceGroupName = resourceGroupName; OgreTools::createResourceGroup(resourceGroupName, path); // recreating the entity createEntity(m_name, filename); Log::info(QString("Mesh file \"%1\" loaded.").arg(filename), "Model2SceneNode::loadMesh"); return true; }
//----------------------------------------------------------------------- void SceneDecoratorExtern::_notifyStop (void) { if (mSubnode && mParentTechnique->getParentSystem()) { Ogre::SceneNode* sceneNode = mParentTechnique->getParentSystem()->getParentSceneNode(); Ogre::SceneNode::ChildNodeIterator it = sceneNode->getChildIterator(); unsigned int i = 0; while (it.hasMoreElements()) { Ogre::SceneNode* child = static_cast<Ogre::SceneNode*>(it.getNext()); if (child == mSubnode) { mSubnode->detachAllObjects(); sceneNode->removeAndDestroyChild(i); mSubnode = 0; } ++i; } destroyEntity(); } }
RaduisControlet::~RaduisControlet(){ destroyEntity(); }
void Game::processNetworkEvents() { sf::Lock guard(_clientsMutex); for(auto it = _clients.begin(); it != _clients.end();++it) { book::Client* client = *it; book::packet::NetworkEvent* msg; while(client and client->pollEvent(msg)) { switch(msg->type()) { case book::FuncIds::IdDisconnected : { it = _clients.erase(it); --it; delete client; client = nullptr; }break; case book::FuncIds::IdLogOut : { it = _clients.erase(it); --it; client->getTeam()->remove(client); onLogOut(client); client = nullptr; }break; case book::FuncIds::IdRequestCreateEntity : { book::packet::RequestCreateEntity* event = static_cast<book::packet::RequestCreateEntity*>(msg); sf::Lock gameGuard(_teamMutex); short int entityType = event->getType(); int gold = client->getTeam()->getGold(); sf::Vector2i coord = event->getCoord(); for(book::EntityType::Info& info : book::EntityType::informations) { if(info.makeAs == entityType and gold >= info.cost and _byCoords[coord].size() == 0) { book::MakeAs makeAs = book::getMakeAs(info.makeAs); if(makeAs != nullptr) { createEntity(coord,client->getTeam(),makeAs); client->getTeam()->addGold(-info.cost); } } } }break; case book::FuncIds::IdRequestDestroyEntity : { book::packet::RequestDestroyEntity* event = static_cast<book::packet::RequestDestroyEntity*>(msg); unsigned int id = event->getId(); if(entities.isValid(id)) { sf::Lock gameGuard(_teamMutex); CompTeam::Handle team = entities.getComponent<CompTeam>(id); if(team.isValid()) { if(team->_team->id() == client->getTeam()->id()) { destroyEntity(id); } } } }break; default : break; } } } }
void EntityManager::destoryAllEntities() { while (countEntities() != 0) { destroyEntity(entityArray[0].uid); } }
entid_t EntityMgr::createEntity(const char * type, entid_t idParent, Object * param) { if (NULL==type) throw Exception("core: Invalid entity type [NULL]"); if (-1!=idParent) checkId(idParent); // Get component ComponentMgr * comgr = SingleComponentMgr::getInstance(); IComponent * c = comgr->getComponentForType(type); // Try to create entity EntityBase * e = NULL; try { // Find creator const EntityTypeInfo * t = c->getTypeInfo(); for (; t && t->typeName; ++t) { if (stricmp(t->typeName, type)==0) { if (t->creator==NULL) break; e = t->creator(); break; } } if (NULL==e) throw Exception("core: Unable to find entity creator"); } catch(const Exception& e) { SingleCore::getInstance()->logMessage("core: Exception while creating entity '%s' -->>\n%s", type, (const char*)e); throw; } catch(...) { SingleCore::getInstance()->logMessage("core: Unknown exception while creating entity '%s'", type); throw; } if (e==NULL) throw Exception("core: Error creating entity %s", type); // Find type chunk if the one exists; if not, create it typeid_t typeId = -1; MapTypeId::const_iterator it=mapTypeId.find(type); if (it==mapTypeId.end()) { typeId = createChunkType(c, type); mapTypeId[type]=typeId; } else typeId = it->second; // Add entity information entid_t id = createChunkEntity(e, typeId); chunkType[typeId].instances.push_back(id); if (-1!=idParent) { EntityChunk& ecParent=chunkEntity[idParent]; ecParent.children.back()=id; ecParent.children.push_back(-1); const_cast<const entid_t*&>(ecParent.entity->childId) = &ecParent.children[0]; } EntityChunk& ec = chunkEntity[id]; const_cast<entid_t&>(e->entityId) = id; const_cast<entid_t&>(e->parentId) = idParent; const_cast<const entid_t*&>(e->childId) = &ec.children[0]; const_cast<ICore*&>(e->icore) = SingleCore::getInstance(); // Try to init entity bool init=false; try { e->entityInit(param); init=true; } catch(const Exception& e) { SingleCore::getInstance()->logMessage("core: Exception in %s::entityInit() -->>\n%s", type, (const char*)e); destroyEntity(id); throw; } catch(...) { SingleCore::getInstance()->logMessage("core: Unknown exception in %s::entityInit()", type); destroyEntity(id); throw; } // Notify subscribers that entity has been created TrigEntityLife::Param trigParam; trigParam.eid = id; trigParam.lifeTime = entityCreated; trigParam.param = param; trigParam.entityType = chunkType[chunkEntity[id].typeId].name; getCore()->activate(TrigEntityLife::tid,&trigParam); return id; }
LinearControlet::~LinearControlet(){ destroyEntity(); }
void EntityManager::destroyEntity(Entity *entity) { destroyEntity(entity->getId()); }
OrientationControlet::~OrientationControlet(){ destroyEntity(); }
RotateControlet::~RotateControlet(){ destroyEntity(); }
void bossControllerUpdate(Controller* c, Entity* e, Iwbtg* iw, float dt) { ControllerBoss* b = &c->boss; if(b->triggered) { if(!b->initialized) { b->initialized = true; // Take the first action in the queue if(!bossIsActionQueueEmpty(b)) { b->actionQueue[0].initialized = false; bossAddActiveAction(b, &b->actionQueue[0]); } } for(int i = 0; i < MAX_ACTIONS_PER_BOSS; ++i) { BossAction* a = b->activeActions[i]; if(a == 0) continue; a->time += dt; switch(a->type) { case BossActionType_wait: if(a->time > a->wait.time) bossRemoveActiveAction(b, a); break; case BossActionType_move: if(!a->initialized) { a->move.start = e->position; a->initialized = true; } e->position = vector2fLerp(a->move.start, a->move.destination, inOutEase(clamp(a->time / a->move.time, 0, 1))); if(a->time >= a->move.time) bossRemoveActiveAction(b, a); break; case BossActionType_projectileBurst: { BossActionProjectileBurst* pb = &a->projectileBurst; if(!a->initialized) pb->shotTimer = 0; pb->shotTimer += dt; // TODO: do something a little smarter here so that // if two shots occur on the same frame, their positions // are correctly seperated from each other. if(pb->shotTimer > pb->interval) { soundPlay(assetsGetSound(&iw->game, "bossShoot"), 0.2); while(pb->shotTimer > pb->interval) { for(int i = 0; i < pb->count; ++i) { Entity* p = createEntity(iw, pb->projectileEntityType, e->position.x + (e->sprite.size.x / 2), e->position.y + (e->sprite.size.y / 2)); p->position.x -= (p->sprite.size.x / 2); p->position.y -= (p->sprite.size.y / 2); p->velocity = speedDirectionToVector2f(pb->speed, pb->direction + ((360 / pb->count) * i)); } pb->direction += pb->rotation; pb->shotTimer -= pb->interval; } } if(a->time > pb->interval * pb->repeat) bossRemoveActiveAction(b, a); } break; case BossActionType_playMusic: musicPlay(a->playMusic.music, 0.7, &iw->game); bossRemoveActiveAction(b, a); break; case BossActionType_projectileRandomSpray: if(a->time > a->projectileRandomSpray.time) bossRemoveActiveAction(b, a); BossActionProjectileRandomSpray* pb = &a->projectileRandomSpray; Entity* p = createEntity(iw, pb->projectileEntityType, e->position.x + (e->sprite.size.x / 2), e->position.y + (e->sprite.size.y / 2)); p->position.x -= (p->sprite.size.x / 2); p->position.y -= (p->sprite.size.y / 2); pb->previousDirection += (12 * 7); //pb->previousDirection = (randomfBetween(0, 360)); p->velocity = speedDirectionToVector2f(pb->speed, pb->previousDirection + randomfBetween(-12, 12)); pb->soundCounter++; if(pb->soundCounter > 1) { pb->soundCounter = 0; soundPlay(assetsGetSound(&iw->game, "bossShoot"), 0.1); } break; case BossActionType_projectileAimed: { BossActionProjectileAimed* pa = &a->projectileAimed; Entity* p = createEntity(iw, pa->projectileEntityType, e->position.x + (e->sprite.size.x / 2), e->position.y + (e->sprite.size.y / 2)); p->position.x -= (p->sprite.size.x / 2); p->position.y -= (p->sprite.size.y / 2); float direction = vector2fDirection( vector2fAdd(e->position, v2f(e->sprite.size.x / 2, e->sprite.size.y / 2)), vector2fAdd(iw->player.position, v2f(16, 16))) * (180 / PI); p->velocity = speedDirectionToVector2f(pa->speed, direction); soundPlay(assetsGetSound(&iw->game, "bossShoot"), 0.1); bossRemoveActiveAction(b, a); } break; default: bossRemoveActiveAction(b, a); printf("Warning: Tried to perform boss action that has not been implemented!\n"); break; } if(!a->initialized) a->initialized = true; } // TODO: Make this into a loop so multiple actions can start per frame. if(!bossIsActionBlocking(b) && iw->state != GameState_gameOver) bossNextAction(b); if(b->health <= 0) { if(iw->boss == e) iw->boss = 0; createEntity(iw, EntityType_warp, 480 - 64, 540 - 256); musicPlayOnce(assetsGetMusic(&iw->game, "bossDefeatedMusic"), 0.7, &iw->game); destroyEntity(e); } } }
void RigidControlet::rebuildEntity(){ destroyEntity(); createEntity(); }