From 75440f919f331a07e3584de63fa77da22bdd7398 Mon Sep 17 00:00:00 2001 From: Steffen Date: Sat, 17 Jan 2015 14:07:12 +0100 Subject: [PATCH] Added the option to define initial position constraints in the Level.xml file. --- converter/converter.cc | 30 ++++++++++++++++++++++++------ level.cc | 26 +++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/converter/converter.cc b/converter/converter.cc index 11c83bf..199789e 100644 --- a/converter/converter.cc +++ b/converter/converter.cc @@ -98,14 +98,32 @@ Converter::Converter(std::string level){ //Create global physics parameters XMLElement* physics = doc->NewElement("physics"); - XMLElement* friction = doc->NewElement("friction"); - XMLElement* strength = doc->NewElement("strength"); - friction->SetText("0.9"); - strength->SetText("100.0"); - physics->InsertEndChild(friction); - physics->InsertEndChild(strength); + XMLElement* playerFriction = doc->NewElement("friction"); + XMLElement* playerStrength = doc->NewElement("strength"); + playerFriction->SetText("0.9"); + playerStrength->SetText("100.0"); + physics->InsertEndChild(playerFriction); + physics->InsertEndChild(playerStrength); doc->InsertEndChild(physics); + //create positionConstraint Dummy + XMLElement* positionConstraint = doc->NewElement("positionConstraint"); + XMLElement* positionConstraintObjectNum = doc->NewElement("objectNum"); + XMLElement* positionConstraintXPos = doc->NewElement("xPosition"); + XMLElement* positionConstraintYPos = doc->NewElement("yPosition"); + XMLElement* positionConstraintZPos = doc->NewElement("zPosition"); + XMLElement* positionConstraintStrength = doc->NewElement("strength"); + positionConstraintObjectNum->SetText("0"); + positionConstraintXPos->SetText("0.0"); + positionConstraintYPos->SetText("0.0"); + positionConstraintZPos->SetText("0.0"); + positionConstraintStrength->SetText("100.0"); + positionConstraint->InsertEndChild(positionConstraintObjectNum); + positionConstraint->InsertEndChild(positionConstraintXPos); + positionConstraint->InsertEndChild(positionConstraintYPos); + positionConstraint->InsertEndChild(positionConstraintZPos); + positionConstraint->InsertEndChild(positionConstraintStrength); + doc->InsertEndChild(positionConstraint); }else{ dst << src.rdbuf(); XMLElement* thisComposition = doc->FirstChildElement("composition"); diff --git a/level.cc b/level.cc index adba222..97e1ad7 100644 --- a/level.cc +++ b/level.cc @@ -387,7 +387,31 @@ void Level::load() { } } } - } + }//triggers + + //load positionConstraints + composition = doc->FirstChildElement("composition"); + for(; composition; composition=composition->NextSiblingElement("composition")){ + XMLElement* positionConstraint = composition->FirstChildElement("positionConstraint"); + for(; positionConstraint; positionConstraint=positionConstraint->NextSiblingElement("positionConstraint")){ + float xPos, yPos, zPos, strength; + int objectNum, idGreen, idBlue, objectIndex; + errorCheck(positionConstraint->FirstChildElement("xPosition")->QueryFloatText(&xPos)); + errorCheck(positionConstraint->FirstChildElement("yPosition")->QueryFloatText(&yPos)); + errorCheck(positionConstraint->FirstChildElement("zPosition")->QueryFloatText(&zPos)); + errorCheck(positionConstraint->FirstChildElement("strength")->QueryFloatText(&strength)); + errorCheck(positionConstraint->FirstChildElement("objectNum")->QueryIntText(&objectNum)); + errorCheck(composition->FirstChildElement("idGreen")->QueryIntText(&idGreen)); + errorCheck(composition->FirstChildElement("idBlue")->QueryIntText(&idBlue)); + for (unsigned int i = 0; i