From 12f76ddd5a1f535c404227174e9c03ff1d3732e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Wed, 4 Mar 2015 15:52:28 +0100 Subject: [PATCH] Added a trigger that resets the player when his z value is below 15. --- data/levels/Level1.xml | 11 ++++++----- data/levels/scripts/resetPlayer.lua | 17 +++++++++++++++++ level.cc | 8 +++++++- level.hh | 2 ++ loader.cc | 1 + 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 data/levels/scripts/resetPlayer.lua diff --git a/data/levels/Level1.xml b/data/levels/Level1.xml index 76335e2..2b937a8 100644 --- a/data/levels/Level1.xml +++ b/data/levels/Level1.xml @@ -11776,18 +11776,19 @@ 105 20 - - + resetPlayer + false 0 - 0 + -100000 0 - - - 1.0 + 100015 false 0 - - + resetPlayer.lua 0 - 0 + 105 0 diff --git a/data/levels/scripts/resetPlayer.lua b/data/levels/scripts/resetPlayer.lua new file mode 100644 index 0000000..4428ee6 --- /dev/null +++ b/data/levels/scripts/resetPlayer.lua @@ -0,0 +1,17 @@ +local global = require( "global" ) +if(global.triggeredResetPlayer == nil) then + global.triggeredResetPlayer = false +end +function trigger(objectToChange) + if(global.triggeredResetPlayer == false) then + if(not level) then + print("No level found in Lua!") + return + end + + level:resetPlayer() + + --global.triggeredResetPlayer = true + print("reset player") + end +end diff --git a/level.cc b/level.cc index 394922b..d8ba583 100644 --- a/level.cc +++ b/level.cc @@ -38,6 +38,7 @@ void Level::load() { .addFunction("deleteObject", &Level::deleteObject) .addFunction("getObjectCount", &Level::getPhysicsObjectsVectorSize) .addFunction("moveObject", &Level::moveObject) + .addFunction("resetPlayer", &Level::resetPlayer) .endClass(); //Push the level to Lua as a global variable luabridge::push(luaState, this); @@ -180,7 +181,12 @@ void Level::deleteObject(int objectIndex){ void Level::resetPlayer(){ Loader loader = Loader(); glm::vec3 newPosition = loader.reloadPlayerPosition(xmlFilePath, this); - //TODO cameraCenter.setPosition(newPosition); + physics.forceMove(newPosition, playerIndex); + physics.forceMoveCamera(newPosition + glm::vec3(1,0,0)); +} + +void Level::setPlayerIndex(int index){ + playerIndex = index; } void Level::setStrength(float strength) { diff --git a/level.hh b/level.hh index 1062013..40f2976 100644 --- a/level.hh +++ b/level.hh @@ -56,6 +56,7 @@ class Level { lua_State* getLuaState(); Terrain* getTerrain(); void resetPlayer(); + void setPlayerIndex(int index); private: lua_State* luaState=nullptr; std::vector objects; @@ -66,6 +67,7 @@ class Level { glm::vec4 fogColour; Light directionalLight; Object* cameraCenter; + int playerIndex; Object* skydome; Physics physics; Camera camera; diff --git a/loader.cc b/loader.cc index d70b40f..2864707 100644 --- a/loader.cc +++ b/loader.cc @@ -259,6 +259,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa if(compositionType == 20){ level->setCameraCenter(object); + level->setPlayerIndex(objectIdentifier[1]); } }//objectData found }//finding the objectData