void LevelFactory::LoadPlayer() { myCurrentLevel->myPlayer = new Entity(eEntityType::PLAYER, *myCurrentLevel->myScene, Prism::eOctreeType::PLAYER); myCurrentLevel->myPlayer->AddComponent<GUIComponent>(); myCurrentLevel->myPlayer->AddComponent<GraphicsComponent>()->Init("Data/Resource/Model/Player/SM_Cockpit.fbx" , "Data/Resource/Shader/S_effect_pbl.fx", myCurrentLevel->myPlayer->GetComponent<GUIComponent>()->GetCockpitOrientation()); myCurrentLevel->myPlayer->AddComponent<InputComponent>()->Init(*myCurrentLevel->myInputWrapper); myCurrentLevel->myPlayer->AddComponent<ShootingComponent>(); myCurrentLevel->myPlayer->AddComponent<CollisionComponent>()->Init(7.5f); myCurrentLevel->myPlayer->AddComponent<PhysicsComponent>()->Init(1, { 0, 0, 0 }); myCurrentLevel->myPlayer->AddComponent<SoundComponent>(); //myCurrentLevel->myPlayer->GetComponent<ShootingComponent>()->AddWeapon(myCurrentLevel->myWeaponFactory->GetWeapon("W_gun_machine_level_1")); // replace these with UpgradeWeapon later //myCurrentLevel->myPlayer->GetComponent<ShootingComponent>()->AddWeapon(myCurrentLevel->myWeaponFactory->GetWeapon("W_gun_shotgun_level_1")); //myCurrentLevel->myPlayer->GetComponent<ShootingComponent>()->AddWeapon(myCurrentLevel->myWeaponFactory->GetWeapon("W_gun_rocket_launcher_level_1")); XMLReader reader; reader.OpenDocument("Data/Setting/SET_player.xml"); int health = 0; bool invulnerable = false; reader.ReadAttribute(reader.FindFirstChild("life"), "value", health); reader.ReadAttribute(reader.FindFirstChild("life"), "invulnerable", invulnerable); myCurrentLevel->myPlayer->AddComponent<HealthComponent>()->Init(health, invulnerable); float timeBeforeRecharging = 0.f; float chargeRate = 0.f; reader.ReadAttribute(reader.FindFirstChild("shield"), "timeBeforeRecharching", timeBeforeRecharging); reader.ReadAttribute(reader.FindFirstChild("shield"), "chargeRate", chargeRate); myCurrentLevel->myPlayer->AddComponent<ShieldComponent>()->Init(timeBeforeRecharging, chargeRate); myCurrentLevel->myCollisionManager->Add(myCurrentLevel->myPlayer->GetComponent<CollisionComponent>(), eEntityType::PLAYER); //myCurrentLevel->myCamera = new Prism::Camera(myCurrentLevel->myPlayer->myOrientation); float maxMetersToEnemies = 0; reader.ReadAttribute(reader.ForceFindFirstChild("maxdistancetoenemiesinGUI"), "meters", maxMetersToEnemies); myCurrentLevel->myPlayer->GetComponent<GUIComponent>()->Init(maxMetersToEnemies); myCurrentLevel->myPlayer->SetName("player"); std::string particlePath; reader.ReadAttribute(reader.FindFirstChild("particle"), "src", particlePath); myCurrentLevel->myPlayer->AddComponent<ParticleEmitterComponent>()->Init(particlePath); myCurrentLevel->myPlayer->GetComponent<ParticleEmitterComponent>()->GetEmitter()->ShouldLive(true); reader.CloseDocument(); reader.OpenDocument("Data/Resource/Model/Player/SM_cockpit_glass_a.xml"); reader.ForceReadAttribute(reader.ForceFindFirstChild(reader.ForceFindFirstChild("root"), "radius") , "value", myCurrentLevel->myCockpitRadius); reader.CloseDocument(); Prism::ModelProxy* tempModel = Prism::Engine::GetInstance()->GetModelLoader()->LoadModel( "Data/Resource/Model/Player/SM_cockpit_glass_a.fbx", "Data/Resource/Shader/S_effect_glass.fx"); myCurrentLevel->myGlassCockpit = new Prism::Instance(*tempModel, *myCurrentLevel->myPlayer->GetComponent<GUIComponent>()->GetCockpitOrientation() , Prism::eOctreeType::PLAYER, myCurrentLevel->myCockpitRadius); }
void WeaponFactory::LoadWeapon(const std::string& aWeaponFilePath) { XMLReader weaponDocument; weaponDocument.OpenDocument(aWeaponFilePath); tinyxml2::XMLElement* weaponElement; tinyxml2::XMLElement* rootElement = weaponDocument.FindFirstChild("root"); if (rootElement == nullptr) { weaponElement = weaponDocument.FindFirstChild("Weapon"); } else { weaponElement = weaponDocument.FindFirstChild(rootElement, "Weapon"); } WeaponDataType weaponDataType; weaponDataType.myBulletsPerShot = 1; weaponDataType.myIsHoming = false; weaponDocument.ForceReadAttribute(weaponElement, "name", weaponDataType.myType); for (tinyxml2::XMLElement* e = weaponDocument.FindFirstChild(weaponElement); e != nullptr; e = weaponDocument.FindNextElement(e)) { if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("cooldown").c_str()) == 0) { weaponDocument.ForceReadAttribute(e, "value", weaponDataType.myCoolDownTime); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("spread").c_str()) == 0) { weaponDocument.ForceReadAttribute(e, "value", weaponDataType.mySpread); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("bulletsPerShot").c_str()) == 0) { weaponDocument.ForceReadAttribute(e, "value", weaponDataType.myBulletsPerShot); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("position").c_str()) == 0) { weaponDocument.ForceReadAttribute(e, "x", weaponDataType.myPosition.myX); weaponDocument.ForceReadAttribute(e, "y", weaponDataType.myPosition.myY); weaponDocument.ForceReadAttribute(e, "z", weaponDataType.myPosition.myZ); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("bullet").c_str()) == 0) { weaponDocument.ForceReadAttribute(e, "type", weaponDataType.myBulletType); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("homing").c_str()) == 0) { weaponDocument.ForceReadAttribute(e, "bool", weaponDataType.myIsHoming); weaponDocument.ForceReadAttribute(e, "turnRate", weaponDataType.myHomingTurnRateModifier); } } myWeaponsTypes.insert(std::pair<std::string, WeaponDataType>(weaponDataType.myType, weaponDataType)); weaponDocument.CloseDocument(); }
Menu::Menu(const std::string& aXMLPath, int aLevelID) : myButtons(8) , myMainMenu(false) , myRenderCenter(false) , myLevelID(aLevelID) , myIsOptionsMenu(false) { XMLReader reader; reader.OpenDocument(aXMLPath); std::string background; std::string crosshair; CU::Vector2<float> crosshairSize; tinyxml2::XMLElement* menuElement = reader.FindFirstChild("menu"); reader.ReadAttribute(menuElement, "mainMenu", myMainMenu); reader.ForceReadAttribute(reader.ForceFindFirstChild(menuElement, "background"), "path", background); reader.ReadAttribute(reader.ForceFindFirstChild(menuElement, "background"), "sizeX", myBackgroundSize.x); reader.ReadAttribute(reader.ForceFindFirstChild(menuElement, "background"), "sizeY", myBackgroundSize.y); reader.ReadAttribute(reader.ForceFindFirstChild(menuElement, "background"), "renderCenter", myRenderCenter); reader.ForceReadAttribute(reader.ForceFindFirstChild(menuElement, "crosshair"), "path", crosshair); reader.ForceReadAttribute(reader.ForceFindFirstChild(menuElement, "crosshair"), "sizeX", crosshairSize.x); reader.ForceReadAttribute(reader.ForceFindFirstChild(menuElement, "crosshair"), "sizeY", crosshairSize.y); myCrosshair = new Prism::Sprite(crosshair, crosshairSize, crosshairSize / 2.f); myScreenSize = { float(Prism::Engine::GetInstance()->GetWindowSize().x), float(Prism::Engine::GetInstance()->GetWindowSize().y) }; if (myBackgroundSize.x != 0 && myBackgroundSize.y != 0) { myBackground = new Prism::Sprite(background, myBackgroundSize, myBackgroundSize / 2.f); } else { myBackground = new Prism::Sprite(background, myScreenSize, myScreenSize / 2.f); } tinyxml2::XMLElement* buttonElement = reader.FindFirstChild(menuElement, "button"); for (; buttonElement != nullptr; buttonElement = reader.FindNextElement(buttonElement)) { Button* newButton = nullptr; int id = -1; reader.ReadAttribute(buttonElement, "ID", id); if (id >= 0) { newButton = new LevelButton(reader, buttonElement, myLevelID); } else { newButton = new Button(reader, buttonElement, myLevelID); } myButtons.Add(newButton); } reader.CloseDocument(); }
void WeaponFactory::LoadProjectile(const std::string& aProjectileFilePath) { XMLReader projectileDocument; projectileDocument.OpenDocument(aProjectileFilePath); tinyxml2::XMLElement* projectileElement; tinyxml2::XMLElement* rootElement = projectileDocument.FindFirstChild("root"); if (rootElement == nullptr) { projectileElement = projectileDocument.FindFirstChild("Projectile"); } else { projectileElement = projectileDocument.FindFirstChild(rootElement, "Projectile"); } ProjectileDataType projectileType; projectileType.myCollision = -1.f; projectileDocument.ForceReadAttribute(projectileElement, "type", projectileType.myType); for (tinyxml2::XMLElement* e = projectileDocument.FindFirstChild(projectileElement); e != nullptr; e = projectileDocument.FindNextElement(e)) { if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("Entity").c_str()) == 0) { if (e->Attribute("type") != nullptr) { projectileDocument.ForceReadAttribute(e, "type", projectileType.myEntityType); } else { projectileDocument.ForceReadAttribute(e, "name", projectileType.myEntityType); } } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("maxAmount").c_str()) == 0) { projectileDocument.ForceReadAttribute(e, "value", projectileType.myMaxBullet); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("speed").c_str()) == 0) { projectileDocument.ForceReadAttribute(e, "value", projectileType.mySpeed); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("collision").c_str()) == 0) { projectileDocument.ForceReadAttribute(e, "value", projectileType.myCollision); } } myProjectileTypes.insert(std::pair<std::string, ProjectileDataType>(projectileType.myType, projectileType)); projectileDocument.CloseDocument(); }
void LevelFactory::ReadLevelSettings() { XMLReader reader; std::string settingsPath = "Data/Level/Level0" + std::to_string(myCurrentID - 1) + "/L_level_0" + std::to_string(myCurrentID - 1) + "_settings.xml"; reader.OpenDocument(settingsPath); myAmbientHue = { 0.f, 0.f, 0.f, 0.f }; std::string firstWeapon = ""; std::string secondWeapon = ""; std::string thirdWeapon = ""; reader.ReadAttribute(reader.FindFirstChild("startWeapon"), "first", firstWeapon); reader.ReadAttribute(reader.FindFirstChild("startWeapon"), "second", secondWeapon); reader.ReadAttribute(reader.FindFirstChild("startWeapon"), "third", thirdWeapon); if (firstWeapon != "") { myCurrentLevel->myPlayer->GetComponent<ShootingComponent>()->UpgradeWeapon(myCurrentLevel->myWeaponFactory->GetWeapon(firstWeapon), 0); // replace these with UpgradeWeapon later } if (secondWeapon != "") { myCurrentLevel->myPlayer->GetComponent<ShootingComponent>()->UpgradeWeapon(myCurrentLevel->myWeaponFactory->GetWeapon(secondWeapon), 1); } if (thirdWeapon != "") { myCurrentLevel->myPlayer->GetComponent<ShootingComponent>()->UpgradeWeapon(myCurrentLevel->myWeaponFactory->GetWeapon(thirdWeapon), 2); } tinyxml2::XMLElement* skipableElement = reader.FindFirstChild("skipable"); if (skipableElement != nullptr) { myCurrentLevel->myIsSkipable = true; } reader.ReadAttribute(reader.FindFirstChild("Ambient"), "r", myAmbientHue.r); reader.ReadAttribute(reader.FindFirstChild("Ambient"), "g", myAmbientHue.g); reader.ReadAttribute(reader.FindFirstChild("Ambient"), "b", myAmbientHue.b); myAmbientHue.r = myAmbientHue.r / 255.f; myAmbientHue.g = myAmbientHue.g / 255.f; myAmbientHue.b = myAmbientHue.b / 255.f; myCurrentLevel->myPlayer->GetComponent<GUIComponent>()->UpdateWeapons(); reader.CloseDocument(); }
void LevelFactory::LoadPowerups(XMLReader& aReader, tinyxml2::XMLElement* aLevelElement) { for (tinyxml2::XMLElement* entityElement = aReader.FindFirstChild(aLevelElement, "powerup"); entityElement != nullptr; entityElement = aReader.FindNextElement(entityElement, "powerup")) { Entity* newEntity = new Entity(eEntityType::POWERUP, *myCurrentLevel->myScene, Prism::eOctreeType::STATIC); tinyxml2::XMLElement* powerUpElement = aReader.ForceFindFirstChild(entityElement, "position"); CU::Vector3<float> powerUpPosition; aReader.ForceReadAttribute(powerUpElement, "X", powerUpPosition.x); aReader.ForceReadAttribute(powerUpElement, "Y", powerUpPosition.y); aReader.ForceReadAttribute(powerUpElement, "Z", powerUpPosition.z); newEntity->myOriginalOrientation.SetPos(powerUpPosition*10.f); newEntity->myOrientation = newEntity->myOriginalOrientation; powerUpElement = aReader.ForceFindFirstChild(entityElement, "type"); std::string powerUp; aReader.ForceReadAttribute(powerUpElement, "powerup", powerUp); myCurrentLevel->myEntityFactory->CopyEntity(newEntity, powerUp); newEntity->GetComponent<PowerUpComponent>()->SetPlayer(myCurrentLevel->myPlayer); myCurrentLevel->myCollisionManager->Add(newEntity->GetComponent<CollisionComponent>(), eEntityType::POWERUP); myCurrentLevel->myEntities.Add(newEntity); } }
void LevelFactory::LoadLevelListFromXML(const std::string& aXMLPath) { myLevelPaths.clear(); XMLReader reader; reader.OpenDocument(aXMLPath); std::string levelPath = ""; int ID = 0; int lastID = ID - 1; tinyxml2::XMLElement* levelElement = reader.FindFirstChild("level"); for (; levelElement != nullptr; levelElement = reader.FindNextElement(levelElement)) { lastID = ID; reader.ForceReadAttribute(levelElement, "ID", ID); reader.ForceReadAttribute(levelElement, "path", levelPath); myLevelPaths[ID] = levelPath; if (ID - 1 != lastID) { DL_ASSERT("[LevelFactory] Wrong ID-number in levelList.xml! The numbers should be counting up, in order."); } if (myCurrentID >= 10) { DL_ASSERT("[LevelFactory] Can't handle level ID with two digits."); } } reader.CloseDocument(); }
void LevelFactory::LoadTriggers(XMLReader& aReader, tinyxml2::XMLElement* aLevelElement) { for (tinyxml2::XMLElement* entityElement = aReader.FindFirstChild(aLevelElement, "trigger"); entityElement != nullptr; entityElement = aReader.FindNextElement(entityElement, "trigger")) { myCurrentLevel->AddTrigger(aReader, entityElement); } }
void EntityFactory::LoadEntites(const std::string& aEntityRootPath, float aDifficultScale) { myDifficultScale = aDifficultScale; XMLReader rootDocument; rootDocument.OpenDocument(aEntityRootPath); tinyxml2::XMLElement* rootElement = rootDocument.FindFirstChild("root"); WATCH_FILE(aEntityRootPath, EntityFactory::ReloadEntity); for (tinyxml2::XMLElement* e = rootDocument.FindFirstChild(rootElement); e != nullptr; e = rootDocument.FindNextElement(e)) { std::string entityPath = ""; rootDocument.ForceReadAttribute(e, "src", entityPath); if (entityPath != "") { //#ifdef _DEBUG // XMLReader entityReader; // entityReader.OpenDocument(entityPath); // tinyxml2::XMLElement* entityElement; // tinyxml2::XMLElement* rootElement = entityReader.FindFirstChild("root"); // if (rootElement == nullptr) // { // entityElement = entityReader.FindFirstChild("Entity"); // } // else // { // entityElement = entityReader.FindFirstChild(rootElement, "Entity"); // } // // std::string entityName; // entityReader.ForceReadAttribute(entityElement, "name", entityName); // myEntityTags[entityName] = entityPath; // entityReader.CloseDocument(); //#else LoadEntity(entityPath, aDifficultScale); WATCH_FILE(entityPath, EntityFactory::ReloadEntity); //#endif } } rootDocument.CloseDocument(); }
void ParticleSystemData::Load(const std::string& aFilePath) { myEmitterData.Init(4); myOrientations.Init(4); myTimeStamps.Init(4); XMLReader xmlDoc; xmlDoc.OpenDocument(aFilePath); XMLElement emitterElement = xmlDoc.FindFirstChild(); emitterElement = emitterElement->FirstChildElement("Emitter"); while (emitterElement != nullptr) { XMLElement dataElement = emitterElement->FirstChildElement("Name"); std::string emitterName = dataElement->GetText(); dataElement = emitterElement->FirstChildElement("Time"); float time; dataElement->QueryFloatText(&time); dataElement = emitterElement->FirstChildElement("Position"); Vector3<float> position; position.x = dataElement->FloatAttribute("x"); position.y = dataElement->FloatAttribute("y"); position.z = dataElement->FloatAttribute("z"); dataElement = emitterElement->FirstChildElement("Rotation"); Vector3<float> rotation; rotation.x = dataElement->FloatAttribute("x"); rotation.y = dataElement->FloatAttribute("y"); rotation.z = dataElement->FloatAttribute("z"); Matrix44<float> orientation; orientation *= Matrix44<float>::CreateRotateAroundX(rotation.x); orientation *= Matrix44<float>::CreateRotateAroundY(rotation.y); orientation *= Matrix44<float>::CreateRotateAroundZ(rotation.z); orientation.SetTranslation(position); myEmitterData.Add(emitterName); myOrientations.Add(orientation); myTimeStamps.Add(time); emitterElement = emitterElement->NextSiblingElement("Emitter"); } }
void BulletManager::LoadFromFactory(WeaponFactory* aWeaponFactory, EntityFactory* aEntityFactory, const std::string& aProjectileList) { XMLReader rootDocument; rootDocument.OpenDocument(aProjectileList); tinyxml2::XMLElement* rootElement = rootDocument.FindFirstChild("root"); for (tinyxml2::XMLElement* e = rootDocument.FindFirstChild(rootElement); e != nullptr; e = rootDocument.FindNextElement(e)) { std::string projectilePath = ""; rootDocument.ForceReadAttribute(e, "src", projectilePath); if (projectilePath != "") { LoadProjectile(aWeaponFactory, aEntityFactory, projectilePath); } } rootDocument.CloseDocument(); }
void WeaponFactory::LoadProjectiles(const std::string& aRootFilePath) { XMLReader rootDocument; rootDocument.OpenDocument(aRootFilePath); tinyxml2::XMLElement* rootElement = rootDocument.FindFirstChild("root"); WATCH_FILE(aRootFilePath, WeaponFactory::ReloadWeapon); for (tinyxml2::XMLElement* e = rootDocument.FindFirstChild(rootElement); e != nullptr; e = rootDocument.FindNextElement(e)) { std::string projectilePath = ""; rootDocument.ForceReadAttribute(e, "src", projectilePath); if (projectilePath != "") { LoadProjectile(projectilePath); WATCH_FILE(projectilePath, WeaponFactory::ReloadWeapon); } } rootDocument.CloseDocument(); }
void LevelFactory::LoadProps(XMLReader& aReader, tinyxml2::XMLElement* aLevelElement) { for (tinyxml2::XMLElement* entityElement = aReader.FindFirstChild(aLevelElement, "prop"); entityElement != nullptr; entityElement = aReader.FindNextElement(entityElement, "prop")) { Entity* newEntity = new Entity(eEntityType::PROP, *myCurrentLevel->myScene, Prism::eOctreeType::STATIC); std::string propType; aReader.ForceReadAttribute(entityElement, "propType", propType); myCurrentLevel->myEntityFactory->CopyEntity(newEntity, propType); newEntity->AddComponent<PropComponent>()->Init("", ""); FillDataPropOrDefendable(aReader, entityElement, newEntity); } }
ConversationManager::ConversationManager(const std::string& aXmlPath) : myCurrent(nullptr) { XMLReader reader; reader.OpenDocument(aXmlPath); tinyxml2::XMLElement* element = reader.ForceFindFirstChild("root"); tinyxml2::XMLElement* timeElement = reader.FindFirstChild(element, "conversationTime"); float conversationTime = 3.f; if (timeElement != nullptr) { reader.ReadAttribute(timeElement, "value", conversationTime); } for (element = reader.FindFirstChild(element, "conversation"); element != nullptr; element = reader.FindNextElement(element, "conversation")) { std::string name; reader.ForceReadAttribute(element, "name", name); name = CU::ToLower(name); myConversations[name] = new Conversation(name, reader, element, conversationTime); } reader.CloseDocument(); //tinyxml2::XMLElement* element = aReader.ForceFindFirstChild(aElement, "conversation"); //for (tinyxml2::XMLElement* element = aReader.ForceFindFirstChild(aElement, "sentence"); element != nullptr; // element = aReader.FindNextElement(aElement, "sentence")) //{ // std::string text; // aReader.ForceReadAttribute(element, "text", text); // mySentences.Add(new Sentence(text)); //} }
void LevelFactory::LoadDefendables(XMLReader& aReader, tinyxml2::XMLElement* aLevelElement, float aDifficultScale) { for (tinyxml2::XMLElement* entityElement = aReader.FindFirstChild(aLevelElement, "defendable"); entityElement != nullptr; entityElement = aReader.FindNextElement(entityElement, "defendable")) { Entity* newEntity = new Entity(eEntityType::DEFENDABLE, *myCurrentLevel->myScene, Prism::eOctreeType::STATIC); std::string propType; aReader.ForceReadAttribute(entityElement, "propType", propType); myCurrentLevel->myEntityFactory->CopyEntity(newEntity, propType); int difficultHealth = int(newEntity->GetComponent<HealthComponent>()->GetHealth() * aDifficultScale); newEntity->GetComponent<HealthComponent>()->Init(difficultHealth); std::string defendName; aReader.ForceReadAttribute(entityElement, "defendName", defendName); defendName = CU::ToLower(defendName); newEntity->AddComponent<PropComponent>()->Init(defendName, ""); FillDataPropOrDefendable(aReader, entityElement, newEntity); } }
void LoadingScreen::ReadXML() { CU::Vector2<float> windowSize = { float(Prism::Engine::GetInstance()->GetWindowSize().x), float(Prism::Engine::GetInstance()->GetWindowSize().y) }; XMLReader reader; reader.OpenDocument("Data/Menu/MN_loading_screen.xml"); tinyxml2::XMLElement* rootElement = reader.ForceFindFirstChild("root"); for (tinyxml2::XMLElement* screenElement = reader.FindFirstChild(rootElement, "screen"); screenElement != nullptr; screenElement = reader.FindNextElement(screenElement, "screen")) { std::string aSpritePath = ""; int levelID = 0; reader.ForceReadAttribute(reader.FindFirstChild(screenElement, "ID"), "value", levelID); if (levelID != myScreens.Size()) { DL_ASSERT("[LoadingScreen] Wrong ID-number in MN_loading_screen.xml! The numbers should be counting up, in order, starting from 0."); } std::string aRotatingThingPath = ""; std::string aRotatingThingPath2 = ""; reader.ForceReadAttribute(reader.FindFirstChild(screenElement, "background"), "path", aSpritePath); reader.ForceReadAttribute(reader.FindFirstChild(screenElement, "rotatingThing"), "path", aRotatingThingPath); reader.ForceReadAttribute(reader.FindFirstChild(screenElement, "rotatingThing2"), "path", aRotatingThingPath2); Screen* newScreen = new Screen(); newScreen->myBackground = new Prism::Sprite(aSpritePath, { windowSize.y * 2.f, windowSize.y }, windowSize / 2.f); newScreen->myRotatingThing = new Prism::Sprite(aRotatingThingPath, { 256.f, 256.f }, { 128.f, 128.f }); newScreen->myRotatingThing2 = new Prism::Sprite(aRotatingThingPath2, { 256.f, 256.f }, { 128.f, 128.f }); tinyxml2::XMLElement* textElement = reader.FindFirstChild(screenElement, "text"); TimedMessage newMessage; newMessage.myCurrentTime = 0.f; reader.ForceReadAttribute(textElement, "value", newMessage.myMessage); reader.ForceReadAttribute(textElement, "time", newMessage.myMaxTime); newScreen->myMessages.Add(newMessage); myScreens.Add(newScreen); } reader.CloseDocument(); }
void LevelFactory::LoadDirectionalLights(XMLReader& aReader, tinyxml2::XMLElement* aLevelElement) { for (tinyxml2::XMLElement* entityElement = aReader.FindFirstChild(aLevelElement, "directionallight"); entityElement != nullptr; entityElement = aReader.FindNextElement(entityElement, "directionallight")) { tinyxml2::XMLElement* directionalElement = aReader.ForceFindFirstChild(entityElement, "rotation"); Prism::DirectionalLight* newDirLight = new Prism::DirectionalLight(); CU::Vector3<float> lightDirection; aReader.ForceReadAttribute(directionalElement, "X", lightDirection.x); aReader.ForceReadAttribute(directionalElement, "Y", lightDirection.y); aReader.ForceReadAttribute(directionalElement, "Z", lightDirection.z); CU::Matrix44<float> orientation; CU::GetOrientation(orientation, lightDirection); CU::Vector3<float> direction(0.f, 0.f, 1.f); direction = direction * orientation; newDirLight->SetDir(direction); //newDirLight->SetOrientation(orientation); //newDirLight->SetDir(lightDirection); directionalElement = aReader.ForceFindFirstChild(entityElement, "color"); CU::Vector4<float> lightColor; aReader.ForceReadAttribute(directionalElement, "R", lightColor.myR); aReader.ForceReadAttribute(directionalElement, "G", lightColor.myG); aReader.ForceReadAttribute(directionalElement, "B", lightColor.myB); aReader.ForceReadAttribute(directionalElement, "A", lightColor.myA); newDirLight->SetColor(lightColor); myDirectionalLights.Add(newDirLight); } }
Menu::Menu(const std::string& aXMLPath) : myButtons(8) , myMainMenu(false) , myRenderCenter(false) , myLevelID(-1) , myCredits(nullptr) { XMLReader reader; reader.OpenDocument(aXMLPath); std::string background; std::string crosshair; CU::Vector2<float> crosshairSize; if (aXMLPath == "Data/Menu/MN_ingame_menu.xml") { myIsOptionsMenu = true; } else { myIsOptionsMenu = false; } if (aXMLPath == "Data/Menu/MN_credits.xml") { myCredits = new Prism::Sprite("Data/Resource/Texture/Menu/Credits/T_credits.dds", { 1024.f, 1024.f }, { 512.f, 512.f }); } tinyxml2::XMLElement* menuElement = reader.FindFirstChild("menu"); reader.ReadAttribute(menuElement, "mainMenu", myMainMenu); reader.ForceReadAttribute(reader.ForceFindFirstChild(menuElement, "background"), "path", background); reader.ReadAttribute(reader.ForceFindFirstChild(menuElement, "background"), "sizeX", myBackgroundSize.x); reader.ReadAttribute(reader.ForceFindFirstChild(menuElement, "background"), "sizeY", myBackgroundSize.y); reader.ReadAttribute(reader.ForceFindFirstChild(menuElement, "background"), "renderCenter", myRenderCenter); reader.ForceReadAttribute(reader.ForceFindFirstChild(menuElement, "crosshair"), "path", crosshair); reader.ForceReadAttribute(reader.ForceFindFirstChild(menuElement, "crosshair"), "sizeX", crosshairSize.x); reader.ForceReadAttribute(reader.ForceFindFirstChild(menuElement, "crosshair"), "sizeY", crosshairSize.y); myCrosshair = new Prism::Sprite(crosshair, crosshairSize, crosshairSize / 2.f); myScreenSize = { float(Prism::Engine::GetInstance()->GetWindowSize().x), float(Prism::Engine::GetInstance()->GetWindowSize().y) }; if (myBackgroundSize.x != 0 && myBackgroundSize.y != 0) { myBackground = new Prism::Sprite(background, myBackgroundSize, myBackgroundSize / 2.f); } else { myFullscreenBackgroundSize = { myScreenSize.y * 2.f, myScreenSize.y }; myBackground = new Prism::Sprite(background, myFullscreenBackgroundSize, myFullscreenBackgroundSize / 2.f); } tinyxml2::XMLElement* buttonElement = reader.FindFirstChild(menuElement, "button"); for (; buttonElement != nullptr; buttonElement = reader.FindNextElement(buttonElement)) { Button* newButton = nullptr; int id = -1; reader.ReadAttribute(buttonElement, "ID", id); if (id >= 0) { newButton = new LevelButton(reader, buttonElement, id); } else { newButton = new Button(reader, buttonElement, -1); } myButtons.Add(newButton); } reader.CloseDocument(); }
void BulletManager::LoadProjectile(WeaponFactory* aWeaponFactory, EntityFactory* aEntityFactory, const std::string& aProjectilePath) { std::string projectileLoaderType; XMLReader rootDocument; rootDocument.OpenDocument(aProjectilePath); tinyxml2::XMLElement* projectileElement; tinyxml2::XMLElement* rootElement = rootDocument.FindFirstChild("root"); if (rootElement == nullptr) { projectileElement = rootDocument.FindFirstChild("Projectile"); } else { projectileElement = rootDocument.FindFirstChild(rootElement, "Projectile"); } rootDocument.ForceReadAttribute(projectileElement, "type", projectileLoaderType); rootDocument.CloseDocument(); BulletData* bulletData = new BulletData; ProjectileDataType projectileDataType = aWeaponFactory->GetProjectile(projectileLoaderType); bulletData->myMaxBullet = projectileDataType.myMaxBullet; bulletData->mySpeed = projectileDataType.mySpeed; bulletData->myPlayerBulletCounter = 0; bulletData->myPlayerBullets.Init(bulletData->myMaxBullet); bulletData->myPlayerBulletComponents.Init(bulletData->myMaxBullet); for (int i = 0; i < bulletData->myMaxBullet; i++) { Entity* newEntity = new Entity(eEntityType::PLAYER_BULLET, myScene, Prism::eOctreeType::NOT_IN_OCTREE); aEntityFactory->CopyEntity(newEntity, projectileDataType.myEntityType); newEntity->GetComponent<GraphicsComponent>()->SetPosition({ 0, 0, 0 }); bulletData->myPlayerBulletComponents.Add(newEntity->GetComponent<BulletComponent>()); bulletData->myPlayerBullets.Add(newEntity); } bulletData->myEnemyBulletCounter = 0; bulletData->myEnemyBullets.Init(bulletData->myMaxBullet); bulletData->myEnemyBulletComponents.Init(bulletData->myMaxBullet); for (int i = 0; i < bulletData->myMaxBullet; i++) { Entity* newEntity = new Entity(eEntityType::ENEMY_BULLET, myScene, Prism::eOctreeType::NOT_IN_OCTREE); aEntityFactory->CopyEntity(newEntity, projectileDataType.myEntityType); newEntity->GetComponent<GraphicsComponent>()->SetPosition({ 0, 0, 0 }); if (projectileDataType.myCollision > 0) { newEntity->GetComponent<CollisionComponent>()->SetCollisionRadius(projectileDataType.myCollision); } bulletData->myEnemyBulletComponents.Add(newEntity->GetComponent<BulletComponent>()); bulletData->myEnemyBullets.Add(newEntity); } bulletData->myType = ConvertToBulletEnum(projectileDataType.myType); if (bulletData->myType == eBulletType::COUNT) { std::string errorMessage = "[BulletManager] No bullet with name " + projectileDataType.myType; DL_ASSERT(errorMessage.c_str()); } DeleteWeaponData(myBulletDatas[static_cast<int>(bulletData->myType)]); myBulletDatas[static_cast<int>(bulletData->myType)] = bulletData; }
void EntityFactory::LoadEntity(const std::string& aEntityPath, float aDifficultScale) { XMLReader entityDocument; entityDocument.OpenDocument(aEntityPath); EntityData newEntity(*myDummyScene); tinyxml2::XMLElement* entityElement; tinyxml2::XMLElement* rootElement = entityDocument.FindFirstChild("root"); if (rootElement == nullptr) { entityElement = entityDocument.FindFirstChild("Entity"); } else { entityElement = entityDocument.FindFirstChild(rootElement, "Entity"); } std::string entityName = ""; entityDocument.ForceReadAttribute(entityElement, "name", entityName); if (myEntities.find(entityName) != myEntities.end()) { std::string errorMessage = "[EntityFactory] Entity there is already a object named " + entityName; DL_ASSERT(errorMessage.c_str()); } newEntity.myEntity->SetName(entityName); if (entityName != "E_projectile_enemy_fast") { aDifficultScale = 1.f; } else { aDifficultScale = aDifficultScale; } ENTITY_LOG("Load entity %s starting", entityName.c_str()); for (tinyxml2::XMLElement* e = entityDocument.FindFirstChild(entityElement); e != nullptr; e = entityDocument.FindNextElement(e)) { std::string childName = e->Name(); if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("GraphicsComponent").c_str()) == 0) { LoadGraphicsComponent(newEntity, entityDocument, e); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("AIComponent").c_str()) == 0) { LoadAIComponent(newEntity, entityDocument, e); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("ShootingComponent").c_str()) == 0) { LoadShootingComponent(newEntity, entityDocument, e); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("CollisionComponent").c_str()) == 0) { LoadCollisionComponent(newEntity, entityDocument, e, eCollisionType::NORMAL); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("PlanetCollisionComponent").c_str()) == 0) { LoadCollisionComponent(newEntity, entityDocument, e, eCollisionType::PLANET); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("PhysicsComponent").c_str()) == 0) { LoadPhysicsComponent(newEntity, entityDocument, e); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("BulletComponent").c_str()) == 0) { LoadBulletComponent(newEntity, entityDocument, e, aDifficultScale); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("HealthComponent").c_str()) == 0) { LoadHealthComponent(newEntity, entityDocument, e); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("PowerUpComponent").c_str()) == 0) { LoadPowerUpComponent(newEntity, entityDocument, e); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("ParticleEmitterComponent").c_str()) == 0) { LoadParticleEmitterComponent(newEntity, entityDocument, e); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("StreakEmitterComponent").c_str()) == 0) { LoadStreakEmitterComponent(newEntity, entityDocument, e); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("rotate").c_str()) == 0) { bool rotate; entityDocument.ReadAttribute(e, "value", rotate); newEntity.myEntity->SetShouldRotate(rotate); entityDocument.ReadAttribute(e, "xAxis", rotate); newEntity.myEntity->SetShouldRotateX(rotate); entityDocument.ReadAttribute(e, "yAxis", rotate); newEntity.myEntity->SetShouldRotateY(rotate); entityDocument.ReadAttribute(e, "zAxis", rotate); newEntity.myEntity->SetShouldRotateZ(rotate); } else if (std::strcmp(CU::ToLower(e->Name()).c_str(), CU::ToLower("SoundComponent").c_str()) == 0) { LoadSoundComponent(newEntity, entityDocument, e); ENTITY_LOG("Entity %s loaded %s", entityName.c_str(), e->Name()); } else { std::string errorMessage = "[EntityFactory]: Entity could not find the component " + static_cast<std::string>(e->Name()); DL_ASSERT(errorMessage.c_str()); } } if (entityName != "") { myEntities.insert(std::pair<std::string, EntityData>(entityName, newEntity)); ENTITY_LOG("Load entity %s ending", entityName.c_str()); } else { DL_ASSERT("[EntityFactory]: Entity could not be created missing a name."); } entityDocument.CloseDocument(); }