*
**************************************************************************/
-#include "../config.h"
+#include "config.h"
#include <stdexcept>
#include <moof/log.hh>
#include <moof/math.hh>
+#include <moof/mesh.hh>
#include <moof/opengl.hh>
#include <moof/settings.hh>
#include <moof/video.hh>
void GameLayer::loadSceneLoader()
{
- state_.script.import_standard_libraries();
+ state_.script.import_safe_standard_libraries();
moof::log::import(state_.script);
+ moof::mesh::import(state_.script, "yoink");
+ moof::sound::import(state_.script, "yoink");
- std::string path("loader");
- if (!moof::resource::find(path))
+ std::string path = moof::resource::find_file("scenes/loader.lua");
+ if (path.empty())
{
throw std::runtime_error("cannot find scene loader script");
}
state_.script.top().get(state_.sceneList);
if (state_.sceneList.size() == 0)
{
- throw std::runtime_error("no variable `scenes' in script loader.");
+ throw std::runtime_error("no variable `scenes' in script loader");
}
}
state_.script.registry().set_field();
}
state_.script.pop();
+
+ table = state_.script.globals().push_field("Event");
+ if (table.is_table())
+ {
+ table.push_field("Draw");
+ state_.script.registry().set_field("Draw");
+ }
+ state_.script.pop();
}
}
GameLayer::GameLayer()
{
- moof::log_info("about to load sound resource...");
- music_ = moof::resource::load("sounds/NightFusionIntro.ogg");
- if (music_)
- {
- music_->loop(true);
- music_->enqueue("NightFusionLoop");
- }
- else moof::log_error("music not loaded");
+ music_.queue("NightFusionIntro");
+ music_.loop(true);
+ music_.queue("NightFusionLoop");
+ music_.position(moof::vector3(10.0, 5.0, 0.0));
- //music_->position(moof::vector3(10.0, 5.0, 0.0));
-
- mThinkTimer.init(boost::bind(&GameLayer::thinkTimer, this),
- 0.1, moof::timer::repeat);
+ punch_sound_.sample("Thump");
state_.heroine = Heroine::alloc();
state_.heroine->animation.startSequence("FlyDiagonallyUp");
{
bool isMute = false;
settings().get("nomusic", isMute);
- if (!isMute) music_->play();
+ music_.play();
loadSceneLoader();
advanceScene(settings()); // load the first scene
mRay.point = state_.heroine->state().position;
- moof::view::update(t, dt);
-}
-
-void GameLayer::thinkTimer()
-{
state_.script.registry().push_field("Think");
if (state_.script[-1].is_function()) state_.script.call();
- else state_.script.pop();
-}
+ else state_.script.pop();
+ moof::view::update(t, dt);
+}
void GameLayer::rayTimer()
{
if (!state_.scene) return;
state_.camera.upload_to_gl(alpha);
+ float pos[] = {state_.heroine->state().position[0],
+ state_.heroine->state().position[1], 0.0f, 1.0f};
+ glLightfv(GL_LIGHT0, GL_POSITION, pos);
+
// DRAW THE SCENE
- moof::texture::reset_binding();
+ moof::image::reset_binding();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- state_.scene->draw_if_visible(alpha, state_.camera.frustum());
+ //state_.scene->draw_if_visible(alpha, state_.camera.frustum());
+
+ size_t meh = 23;
+ state_.script.push(meh);
+ state_.script.pop();
+
+ state_.script.registry().push_field("Draw");
+ if (state_.script[-1].is_function())
+ {
+ moof::script::status result = state_.script.call();
+ if (result != moof::script::success)
+ {
+ std::string str;
+ state_.script[-1].get(str);
+ throw std::runtime_error("script error: " + str);
+ }
+ }
+ else state_.script.pop();
+
state_.heroine->draw(alpha);
mRay.draw();
{
state_.heroine->animation.startSequence("Flattened");
moof::log_info("thump!");
- //mPunchSound.play();
+ punch_sound_.play();
return true;
}
else if (event.key.keysym.sym == SDLK_m)
{
- music_->toggle();
+ music_.toggle();
return true;
}
else if (event.key.keysym.sym == SDLK_PAGEUP)