X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FGameLayer.cc;h=a37f175801e8e38e280dfa857f9798724fd2c3b6;hp=a80946f6f5ff68fd393ad165734871eaa7ba8cf7;hb=8a1acac01b444dccf8b57cedf08392ada2e473c1;hpb=bffc879fc8ee8167bb123310d39fad4e2f426ffd diff --git a/src/GameLayer.cc b/src/GameLayer.cc index a80946f..a37f175 100644 --- a/src/GameLayer.cc +++ b/src/GameLayer.cc @@ -27,6 +27,7 @@ *******************************************************************************/ #include +#include #include #include #include @@ -39,22 +40,76 @@ #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); }