コード例 #1
0
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);
	}
}
コード例 #2
0
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();
}
コード例 #3
0
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);
	}
}
コード例 #4
0
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();
}
コード例 #5
0
ファイル: Menu.cpp プロジェクト: nian0601/Spaceshooter
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();
}
コード例 #6
0
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();
}
コード例 #7
0
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);
	}
}
コード例 #8
0
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();
}
コード例 #9
0
MissionManager::MissionManager(Level& aLevel, Entity& aPlayer, const std::string& aFileToReadFrom)
	: myLevel(aLevel)
	, myPlayer(aPlayer)
	, myMissions(16)
	, myCurrentMission(0) 
	, myMissionsNotOrder(16)
	, myAllowedToStartNextMission(true)
	, myEndEventsActive(false)
{
	PostMaster::GetInstance()->Subscribe(eMessageType::EVENT_QUEUE_EMPTY, this);
	XMLReader reader;
	reader.OpenDocument(aFileToReadFrom);

	tinyxml2::XMLElement* element = reader.ForceFindFirstChild("root");

	for (element = reader.ForceFindFirstChild(element, "missionContainer"); element != nullptr;
		element = reader.FindNextElement(element, "missionContainer"))
	{
		int missionIndex = -1;
		reader.ForceReadAttribute(element, "index", missionIndex);

		MissionContainer* mission = new MissionContainer(myLevel, myPlayer, reader, element);
		mission->SetIndex(missionIndex);
		myMissionsNotOrder.Add(mission);
	}
	reader.CloseDocument();

	int currentIndex = 0;
	while (myMissions.Size() != myMissionsNotOrder.Size())
	{
		int prevIndex = currentIndex;
		for (int i = 0; i < myMissionsNotOrder.Size(); ++i)
		{
			if (myMissionsNotOrder[i]->GetIndex() == currentIndex)
			{
				++currentIndex;
				myMissions.Add(myMissionsNotOrder[i]);
				break;
			}
		}
		DL_ASSERT_EXP(prevIndex == currentIndex - 1, "Mission index " + std::to_string(currentIndex) + " not found.");
	}
}
コード例 #10
0
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();
}
コード例 #11
0
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();
}
コード例 #12
0
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);
	}
}
コード例 #13
0
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);
	}
}
コード例 #14
0
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();
}
コード例 #15
0
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));
	//}
}
コード例 #16
0
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();
}
コード例 #17
0
void LevelFactory::LoadDifficults()
{
	XMLReader reader;
	reader.OpenDocument("Data/Setting/SET_difficulty.xml");
	tinyxml2::XMLElement* rootElement = reader.ForceFindFirstChild("root");
	int index = 0;
	for (tinyxml2::XMLElement* e = reader.ForceFindFirstChild(rootElement); e != nullptr; e = reader.FindNextElement(e))
	{
		DL_ASSERT_EXP(index < static_cast<int>(eDifficult::_COUNT), "You are trying to add more difficults than there should be.");
		if (std::strcmp(e->Name(), "Difficult") == 0)
		{
			Difficult newDifficult;
			std::string diffType;
			reader.ForceReadAttribute(e, "type", diffType);
			reader.ForceReadAttribute(e, "multiplier", newDifficult.myMultiplier);
			reader.ForceReadAttribute(e, "defendHealthMulitplier", newDifficult.myHealthMultiplier);

			if (diffType == "Easy")
			{
				newDifficult.myType = eDifficult::EASY;
			}
			else if (diffType == "Normal")
			{
				newDifficult.myType = eDifficult::NORMAL;
			}
			else if (diffType == "Hard")
			{
				newDifficult.myType = eDifficult::HARD;
			}

			myDifficults.Insert(index++,newDifficult);
		}
	}
	reader.CloseDocument();
}
コード例 #18
0
MissionContainer::MissionContainer(Level& aLevel, Entity& aPlayer, XMLReader& aReader, tinyxml2::XMLElement* aElement)
	: Mission(aReader, aElement)
	, myRequiredMissions(8)
	, myOptionalMissions(8)
	, myRequiredActiveMissions(8)
	, myOptionalActiveMissions(8)
	, myEndingMissions(8)
{
	PostMaster::GetInstance()->Subscribe(eMessageType::EVENT_QUEUE_EMPTY, this);

	CU::GrowingArray<Mission*> unorderedRequiredMissions(8);
	CU::GrowingArray<Mission*> unorderedOptionalMissions(8);

	for (tinyxml2::XMLElement* element = aReader.ForceFindFirstChild(aElement, "mission"); element != nullptr;
		element = aReader.FindNextElement(element, "mission"))
	{
		std::string type;
		aReader.ForceReadAttribute(element, "type", type);
		type = CU::ToLower(type);
		int missionIndex = -1;
		aReader.ForceReadAttribute(element, "index", missionIndex);
		bool required;
		aReader.ForceReadAttribute(element, "required", required);

		Mission* mission = nullptr;
		if (type == "waypoint")
		{
			mission = new WaypointMission(aLevel, aPlayer, aReader, element);
		}
		else if (type == "killx")
		{
			mission = new KillXEnemiesMission(aLevel, aReader, element);
		}
		else if (type == "killxabort")
		{
			mission = new KillXEnemiesAbortMission(aLevel, aReader, element);
		}
		else if (type == "killall")
		{
			mission = new KillAllMission(aLevel, aReader, element);
		}
		else if (type == "killallabort")
		{
			mission = new KillAllAbortMission(aLevel, aReader, element);
		}
		else if (type == "survival")
		{
			mission = new SurvivalMission(aReader, element);
		}
		else if (type == "survivalabort")
		{
			mission = new SurvivalAbortMission(aReader, element);
		}
		else if (type == "defend")
		{
			mission = new DefendMission(aReader, element, false);
		}
		else if (type == "defendabort")
		{
			mission = new DefendMission(aReader, element, true);
		}
		else if (type == "killstructures")
		{
			mission = new KillStructureMission(aReader, element);
		}

		DL_ASSERT_EXP(mission != nullptr, "Missiontype not recognized: " + type);

		mission->SetIndex(missionIndex);

		if (required == true)
		{
			unorderedRequiredMissions.Add(mission);
		}
		else
		{
			unorderedOptionalMissions.Add(mission);
			PostMaster::GetInstance()->SendMessage<LevelScoreMessage>(LevelScoreMessage(eLevelScoreMessageType::OPTIONAL_MISSION_ADDED));
		}
	}

	DL_ASSERT_EXP(unorderedRequiredMissions.Size() > 0, "Need a required mission in missioncontainer");

	SortCopy(myRequiredMissions, unorderedRequiredMissions);
	SortCopy(myOptionalMissions, unorderedOptionalMissions);
	

	for (int i = 0; i < myRequiredMissions.Size(); ++i)
	{
		myRequiredActiveMissions.Add(myRequiredMissions[i]);
	}

	for (int i = 0; i < myOptionalMissions.Size(); ++i)
	{
		myOptionalActiveMissions.Add(myOptionalMissions[i]);
	}
}
コード例 #19
0
ファイル: Menu.cpp プロジェクト: nian0601/Spaceshooter
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();
}