*******************************************************************************/
#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();
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);
mScene->drawIfVisible(alpha, mCamera.getFrustum());
+ mHeroine->setZCoord(getZCoord(mHeroine->getState().position));
mHeroine->draw(alpha);
}
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);
}