From 79faa2edea0cae13b7ef0d975d7a288c99574557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Wed, 4 Mar 2015 18:10:49 +0100 Subject: [PATCH] Added 'Safepoints' to the resetPlayer script. --- data/levels/scripts/openFirstDoor.lua | 4 ++-- data/levels/scripts/openSecondDoor1.lua | 10 +--------- data/levels/scripts/openSecondDoor2.lua | 10 +--------- data/levels/scripts/openSecondDoor3.lua | 10 +--------- data/levels/scripts/openSecondDoor4.lua | 1 + data/levels/scripts/resetPlayer.lua | 15 +++++++++++++-- level.cc | 9 +++++++-- level.hh | 1 + 8 files changed, 27 insertions(+), 33 deletions(-) diff --git a/data/levels/scripts/openFirstDoor.lua b/data/levels/scripts/openFirstDoor.lua index 001f8d6..44d95f4 100644 --- a/data/levels/scripts/openFirstDoor.lua +++ b/data/levels/scripts/openFirstDoor.lua @@ -15,7 +15,7 @@ function trigger(objectToChange) local strength = 100 local xPos = 17.5 - local yPos = 33 + local yPos = 33.0 local zPos = 81.5 level:moveObject(objectToChange, strength, xPos, yPos, zPos) @@ -35,7 +35,7 @@ function triggerUndo(objectToChange) local strength = 100 local xPos = 17.5 - local yPos = 25 + local yPos = 25.0 local zPos = 81.5 level:moveObject(objectToChange, strength, xPos, yPos, zPos) diff --git a/data/levels/scripts/openSecondDoor1.lua b/data/levels/scripts/openSecondDoor1.lua index 7baccc5..15e7308 100644 --- a/data/levels/scripts/openSecondDoor1.lua +++ b/data/levels/scripts/openSecondDoor1.lua @@ -22,15 +22,7 @@ function trigger(objectToChange) global.triggeredOpenSecondDoor1 = true if(global.triggeredOpenSecondDoor1 == true and global.triggeredOpenSecondDoor2 == true and global.triggeredOpenSecondDoor3 == true and global.triggeredOpenSecondDoor4 == true) then - if(global.openSecondDoorCounter == 4) then - local strength = 100 - local xPos = -81.5 - local yPos = 33 - local zPos = 4.5 - level:moveObject(objectToChange, strength, xPos, yPos, zPos) - else - global.triggeredOpenSecondDoor1Undo = false - end + global.triggeredOpenSecondDoor1Undo = false end print("openSecondDoor1") diff --git a/data/levels/scripts/openSecondDoor2.lua b/data/levels/scripts/openSecondDoor2.lua index f1de38e..b7ca74b 100644 --- a/data/levels/scripts/openSecondDoor2.lua +++ b/data/levels/scripts/openSecondDoor2.lua @@ -22,15 +22,7 @@ function trigger(objectToChange) global.triggeredOpenSecondDoor2 = true if(global.triggeredOpenSecondDoor1 == true and global.triggeredOpenSecondDoor2 == true and global.triggeredOpenSecondDoor3 == true and global.triggeredOpenSecondDoor4 == true) then - if(global.openSecondDoorCounter == 4) then - local strength = 100 - local xPos = -81.5 - local yPos = 33 - local zPos = 4.5 - level:moveObject(objectToChange, strength, xPos, yPos, zPos) - else - global.triggeredOpenSecondDoor2Undo = false - end + global.triggeredOpenSecondDoor2Undo = false end print("openSecondDoor2") diff --git a/data/levels/scripts/openSecondDoor3.lua b/data/levels/scripts/openSecondDoor3.lua index 0da7adf..16f2116 100644 --- a/data/levels/scripts/openSecondDoor3.lua +++ b/data/levels/scripts/openSecondDoor3.lua @@ -22,15 +22,7 @@ function trigger(objectToChange) global.triggeredOpenSecondDoor3 = true if(global.triggeredOpenSecondDoor1 == true and global.triggeredOpenSecondDoor2 == true and global.triggeredOpenSecondDoor3 == true and global.triggeredOpenSecondDoor4 == true) then - if(global.openSecondDoorCounter == 4) then - local strength = 100 - local xPos = -81.5 - local yPos = 33 - local zPos = 4.5 - level:moveObject(objectToChange, strength, xPos, yPos, zPos) - else - global.triggeredOpenSecondDoor3Undo = false - end + global.triggeredOpenSecondDoor3Undo = false end print("openSecondDoor3") diff --git a/data/levels/scripts/openSecondDoor4.lua b/data/levels/scripts/openSecondDoor4.lua index 9c2c98b..e1143b2 100644 --- a/data/levels/scripts/openSecondDoor4.lua +++ b/data/levels/scripts/openSecondDoor4.lua @@ -28,6 +28,7 @@ function trigger(objectToChange) local yPos = 33 local zPos = 4.5 level:moveObject(objectToChange, strength, xPos, yPos, zPos) + global.openedSecondDoor = true else global.triggeredOpenSecondDoor4Undo = false end diff --git a/data/levels/scripts/resetPlayer.lua b/data/levels/scripts/resetPlayer.lua index 4428ee6..30969c2 100644 --- a/data/levels/scripts/resetPlayer.lua +++ b/data/levels/scripts/resetPlayer.lua @@ -8,8 +8,19 @@ function trigger(objectToChange) print("No level found in Lua!") return end - - level:resetPlayer() + if(global.triggeredOpenFirstDoor == true) then + if(global.openedSecondDoor == true) then + if(global.triggeredOpenThirdDoor == true) then + level:movePlayer(-169.5,22.5,58.5) + else + level:movePlayer(-78.5,22.5,4.5) + end + else + level:movePlayer(17.5,22.5,87.0) + end + else + level:resetPlayer() + end --global.triggeredResetPlayer = true print("reset player") diff --git a/level.cc b/level.cc index 90c3ba4..cb34369 100644 --- a/level.cc +++ b/level.cc @@ -39,6 +39,7 @@ void Level::load() { .addFunction("getObjectCount", &Level::getPhysicsObjectsVectorSize) .addFunction("moveObject", &Level::moveObject) .addFunction("resetPlayer", &Level::resetPlayer) + .addFunction("movePlayer", &Level::movePlayer) .endClass(); //Push the level to Lua as a global variable luabridge::push(luaState, this); @@ -188,8 +189,12 @@ void Level::deleteObject(int objectIndex){ void Level::resetPlayer(){ Loader loader = Loader(); glm::vec3 newPosition = loader.reloadPlayerPosition(xmlFilePath, this); - physics.forceMove(newPosition, playerIndex); - physics.forceMoveCamera(newPosition + glm::vec3(1,0,0)); + physics.forcePlayer(newPosition); +} + +void Level::movePlayer(float xPosition, float yPosition, float zPosition){ + glm::vec3 newPosition = glm::vec3(xPosition, yPosition, zPosition); + physics.forcePlayer(newPosition); } void Level::setPlayerIndex(int index){ diff --git a/level.hh b/level.hh index 6e60bbf..43e9157 100644 --- a/level.hh +++ b/level.hh @@ -57,6 +57,7 @@ class Level { lua_State* getLuaState(); Terrain* getTerrain(); void resetPlayer(); + void movePlayer(float xPosition, float yPosition, float zPosition); void setPlayerIndex(int index); private: lua_State* luaState=nullptr;