X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FGameLayer.cc;h=0ed249c8af964ffffd1bd009c21592350459280e;hp=3f5a7a869fb2dd8d13e6da4671d82f78d474f47d;hb=b357615aba1dbde81e3c6999366604e6001010a7;hpb=246d7d6e4386b686327163d621c7c8b398b7d479 diff --git a/src/GameLayer.cc b/src/GameLayer.cc index 3f5a7a8..0ed249c 100644 --- a/src/GameLayer.cc +++ b/src/GameLayer.cc @@ -42,25 +42,10 @@ #endif - -Mf::Scalar GameLayer::getZCoord(const Mf::Vector2& position) const -{ - Mf::Scalar z; - - mState.script.getGlobalTable().pushField("GetZCoord"); - mState.script.push(position[0]); - mState.script.push(position[1]); - mState.script.call(2, 1); - mState.script.getTop().get(z); - mState.script.pop(); - - return z; -} - void GameLayer::loadSceneLoader() { mState.script.importStandardLibraries(); - importLogPrintFunction(mState.script); + importLogFunctions(mState.script); std::string loaderPath = Scene::getPath("loader"); if (loaderPath == "") @@ -101,6 +86,18 @@ void GameLayer::advanceScene() throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR, str); } + + mState.script.getGlobalTable().pushField("Event"); + if (mState.script[-1].isTable()) + { + mState.script[-1].pushField("Think"); + mState.script.set("Think", Mf::Script::REGISTRY); + mState.script.pop(2); + } + else + { + mState.script.pop(); + } } } @@ -121,11 +118,14 @@ GameLayer::GameLayer() : loadSceneLoader(); advanceScene(); // load the first scene + mThinkTimer.init(boost::bind(&GameLayer::thinkTimer, this), + 0.1, Mf::Timer::REPEAT); + mState.heroine = Heroine::alloc(); - mState.heroine->animation.startSequence("FlyDiagonallyUp"); + mState.heroine->animation.startSequence("GreenDiamond"); Mf::Scalar a[6] = {0.0, 1.5, -0.5, 3.0, -2.0, 1.0}; - mState.interp.init(a, 2.0, Mf::Interpolator::OSCILLATE); + mState.interp.init(a, 5.0, Mf::Interpolator::OSCILLATE); setProjection(); } @@ -155,12 +155,19 @@ void GameLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt) mState.scene->checkForCollision(*mState.heroine); mState.camera.setPosition(Mf::Vector3(-mState.heroine->getState().position[0], - -mState.heroine->getState().position[1], -9)); + -mState.heroine->getState().position[1], -6)); //mState.camera.lookAt(Mf::promote(mState.heroine->getState().position)); mRay.point = mState.heroine->getState().position; } +void GameLayer::thinkTimer() +{ + mState.script.getRegistryTable().pushField("Think"); + if (mState.script[-1].isFunction()) mState.script.call(); + else mState.script.pop(); +} + void GameLayer::rayTimer() { @@ -186,9 +193,9 @@ void GameLayer::rayTimer() { hits.front().normal.normalize(); mRay.solve(point, hits.front().distance); - Mf::logDebug << "scene: d = " << hits.front().distance << std::endl; - Mf::logDebug << " P = " << point << std::endl; - Mf::logDebug << " n = " << hits.front().normal << std::endl; + Mf::logInfo << "scene: d = " << hits.front().distance << std::endl; + Mf::logInfo << " P = " << point << std::endl; + Mf::logInfo << " n = " << hits.front().normal << std::endl; } } @@ -205,7 +212,6 @@ void GameLayer::draw(Mf::Engine& engine, Mf::Scalar alpha) const mState.scene->drawIfVisible(alpha, mState.camera.getFrustum()); - mState.heroine->setZCoord(getZCoord(mState.heroine->getState().position)); mState.heroine->draw(alpha); mRay.draw(); @@ -242,6 +248,12 @@ bool GameLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event) cml::rad(-10.0)); return true; } + else if (event.key.keysym.sym == SDLK_r) + { + loadSceneLoader(); + advanceScene(); + return true; + } return mState.heroine->handleEvent(event); case SDL_KEYUP: