]> Dogcows Code - chaz/yoink/blobdiff - src/GameLayer.cc
big batch of changes
[chaz/yoink] / src / GameLayer.cc
index a80946f6f5ff68fd393ad165734871eaa7ba8cf7..a37f175801e8e38e280dfa857f9798724fd2c3b6 100644 (file)
@@ -27,6 +27,7 @@
 *******************************************************************************/
 
 #include <Moof/Engine.hh>
+#include <Moof/Exception.hh>
 #include <Moof/Log.hh>
 #include <Moof/Math.hh>
 #include <Moof/OpenGL.hh>
 #endif
 
 
+
+Mf::Scalar GameLayer::getZCoord(const Mf::Vector2& position) const
+{
+       Mf::Scalar z;
+
+       mScript.getGlobalTable().pushField("GetZCoord");
+       mScript.push(position[0]);
+       mScript.push(position[1]);
+       mScript.call(2, 1);
+       mScript.getTop().get(z);
+       mScript.pop();
+
+       return z;
+}
+
+void GameLayer::loadSceneLoader()
+{
+       std::string loaderPath = Scene::getPath("loader");
+       if (loaderPath == "")
+       {
+               throw Mf::Exception(Mf::ErrorCode::RESOURCE_NOT_FOUND, "loader");
+       }
+
+       Mf::Script::Status status = mScript.doFile(loaderPath);
+       if (status != Mf::Script::SUCCESS)
+       {
+               std::string str;
+               mScript[-1].get(str);
+
+               Mf::logScript("%s", str.c_str());
+               throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR, str.c_str());
+       }
+
+       mScript.getGlobalTable().pushField("scenes");
+       mScript.getTop().get(mSceneList);
+       if (mSceneList.size() == 0)
+       {
+               Mf::logScript("no variable `scenes' within loader");
+               throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR, "no scenes to load");
+       }
+}
+
+void GameLayer::advanceScene()
+{
+       if (mSceneList.size() != 0)
+       {
+               mScene = Scene::alloc(mSceneList[0]);
+               mSceneList.erase(mSceneList.begin());
+               mScene->load(mScript);
+       }
+}
+
+
 GameLayer::GameLayer() :
-       mMusic("BeatTheCube"),
+       mMusic("NightFusionIntro"),
        mPunchSound("Thump")
 {
        mMusic.setLooping(true);
        mMusic.enqueue("NightFusionLoop");
        mMusic.stream();
 
+       loadSceneLoader();
+       advanceScene();                         // load the first scene
+
        mHeroine = Heroine::alloc();
        mHeroine->animation.startSequence("FlyDiagonallyUp");
 
        Mf::Scalar a[6] = {0.0, 1.5, -0.5, 3.0, -2.0, 1.0};
        mInterp.init(a, 2.0, Mf::Interpolator::OSCILLATE);
 
-       mScene = Scene::alloc("Classic");
-
        setProjection();
 
        mHud = Hud::alloc();
@@ -75,7 +130,7 @@ void GameLayer::update(Mf::Scalar t, Mf::Scalar dt)
        mScene->checkForCollision(*mHeroine);
 
        mCamera.setPosition(Mf::Vector3(-mHeroine->getState().position[0],
-                               -mHeroine->getState().position[1], -256));
+                               -mHeroine->getState().position[1], -10));
        //mCamera.lookAt(Mf::promote(mHeroine->getState().position));
 
        //Mf::Vector3 heroinePosition = Mf::promote(mHeroine->getState().position);
@@ -99,6 +154,7 @@ void GameLayer::draw(Mf::Scalar alpha) const
 
        mScene->drawIfVisible(alpha, mCamera.getFrustum());
 
+       mHeroine->setZCoord(getZCoord(mHeroine->getState().position));
        mHeroine->draw(alpha);
 }
 
@@ -150,7 +206,7 @@ void GameLayer::setProjection()
 
 void GameLayer::setProjection(Mf::Scalar width, Mf::Scalar height)
 {
-       mCamera.setProjection(cml::rad(60.0), width / height, 32.0, 2500.0);
+       mCamera.setProjection(cml::rad(60.0), width / height, 1.0, 200.0);
 }
 
 
This page took 0.02203 seconds and 4 git commands to generate.