[nostalgia/player] Turn player back into test sandbox
This commit is contained in:
parent
8fa47e961d
commit
ce34d450b9
@ -10,10 +10,11 @@
|
|||||||
|
|
||||||
using namespace nostalgia;
|
using namespace nostalgia;
|
||||||
|
|
||||||
|
static int spriteX{};
|
||||||
|
static int spriteY{};
|
||||||
static bool s_paused = false;
|
static bool s_paused = false;
|
||||||
static ox::Optional<scene::Scene> s_scene;
|
|
||||||
|
|
||||||
static int updateHandler(turbine::Context&) noexcept {
|
static int sceneUpdateHandler(turbine::Context&) noexcept {
|
||||||
constexpr auto sleepTime = 16;
|
constexpr auto sleepTime = 16;
|
||||||
if (s_paused) {
|
if (s_paused) {
|
||||||
return sleepTime;
|
return sleepTime;
|
||||||
@ -22,7 +23,7 @@ static int updateHandler(turbine::Context&) noexcept {
|
|||||||
return sleepTime;
|
return sleepTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyEventHandler(turbine::Context &tctx, turbine::Key key, bool down) noexcept {
|
static void sceneKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool down) noexcept {
|
||||||
if (down) {
|
if (down) {
|
||||||
if (key == turbine::Key::Alpha_Q) {
|
if (key == turbine::Key::Alpha_Q) {
|
||||||
turbine::requestShutdown(tctx);
|
turbine::requestShutdown(tctx);
|
||||||
@ -32,14 +33,87 @@ static void keyEventHandler(turbine::Context &tctx, turbine::Key key, bool down)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[maybe_unused]]
|
||||||
|
static int testUpdateHandler(turbine::Context &tctx) noexcept {
|
||||||
|
auto &cctx = *turbine::applicationData<core::Context>(tctx);
|
||||||
|
constexpr auto sleepTime = 16;
|
||||||
|
if (s_paused) {
|
||||||
|
return sleepTime;
|
||||||
|
}
|
||||||
|
int xmod = 0;
|
||||||
|
int ymod = 0;
|
||||||
|
if (buttonDown(tctx, turbine::Alpha_D) || buttonDown(tctx, turbine::GamePad_Right)) {
|
||||||
|
xmod = 2;
|
||||||
|
} else if (buttonDown(tctx, turbine::Alpha_A) || buttonDown(tctx, turbine::GamePad_Left)) {
|
||||||
|
xmod = -2;
|
||||||
|
}
|
||||||
|
if (buttonDown(tctx, turbine::Alpha_S) || buttonDown(tctx, turbine::GamePad_Down)) {
|
||||||
|
ymod = 2;
|
||||||
|
} else if (buttonDown(tctx, turbine::Alpha_W) || buttonDown(tctx, turbine::GamePad_Up)) {
|
||||||
|
ymod = -2;
|
||||||
|
}
|
||||||
|
if (!xmod && !ymod) {
|
||||||
|
spriteX += 1;
|
||||||
|
}
|
||||||
|
spriteX += xmod;
|
||||||
|
spriteY += ymod;
|
||||||
|
constexpr ox::StringView sprites = "nostalgia";
|
||||||
|
for (unsigned i = 0; i < sprites.len(); ++i) {
|
||||||
|
auto const c = static_cast<unsigned>(sprites[i] - ('a' - 1));
|
||||||
|
core::setSprite(cctx, i, {
|
||||||
|
.enabled = true,
|
||||||
|
.x = spriteX + 8 * (static_cast<int>(i) + 1),
|
||||||
|
.y = spriteY,
|
||||||
|
.tileIdx = c,
|
||||||
|
.priority = 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return sleepTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[maybe_unused]]
|
||||||
|
static void testKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool down) noexcept {
|
||||||
|
if (down) {
|
||||||
|
if (key == turbine::Key::Alpha_Q) {
|
||||||
|
turbine::requestShutdown(tctx);
|
||||||
|
} else if (key == turbine::Key::Alpha_P) {
|
||||||
|
s_paused = !s_paused;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[[maybe_unused]]
|
||||||
|
static ox::Error runTest(turbine::Context &tctx) {
|
||||||
|
constexpr ox::FileAddress TileSheetAddr = ox::StringLiteral("/TileSheets/Charset.ng");
|
||||||
|
constexpr ox::FileAddress PaletteAddr = ox::StringLiteral("/Palettes/Chester.npal");
|
||||||
|
oxRequireM(cctx, core::init(tctx));
|
||||||
|
turbine::setApplicationData(tctx, cctx.get());
|
||||||
|
oxRequire(tsStat, turbine::rom(tctx)->stat(PaletteAddr));
|
||||||
|
oxReturnError(core::loadSpriteTileSheet(*cctx, TileSheetAddr, PaletteAddr));
|
||||||
|
oxReturnError(core::initConsole(*cctx));
|
||||||
|
core::puts(*cctx, 10, 9, "DOPENESS!!!");
|
||||||
|
turbine::setUpdateHandler(tctx, testUpdateHandler);
|
||||||
|
turbine::setKeyEventHandler(tctx, testKeyEventHandler);
|
||||||
|
//core::setBgStatus(*cctx, 1, true);
|
||||||
|
//core::setBgStatus(*cctx, 2, true);
|
||||||
|
//core::setBgStatus(*cctx, 3, true);
|
||||||
|
return turbine::run(tctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[maybe_unused]]
|
||||||
|
static ox::Error runScene(turbine::Context &tctx) {
|
||||||
|
constexpr ox::FileAddress SceneAddr = ox::StringLiteral("/Scenes/Chester.nscn");
|
||||||
|
oxRequireM(cctx, core::init(tctx));
|
||||||
|
oxRequire(scn, keel::readObj<scene::SceneStatic>(keelCtx(tctx), SceneAddr));
|
||||||
|
turbine::setUpdateHandler(tctx, sceneUpdateHandler);
|
||||||
|
turbine::setKeyEventHandler(tctx, sceneKeyEventHandler);
|
||||||
|
scene::Scene const scene(*scn);
|
||||||
|
oxReturnError(scene.setupDisplay(*cctx));
|
||||||
|
return turbine::run(tctx);
|
||||||
|
}
|
||||||
|
|
||||||
ox::Error run(ox::UniquePtr<ox::FileSystem> &&fs) noexcept {
|
ox::Error run(ox::UniquePtr<ox::FileSystem> &&fs) noexcept {
|
||||||
oxRequireM(tctx, turbine::init(std::move(fs), "Nostalgia"));
|
oxRequireM(tctx, turbine::init(std::move(fs), "Nostalgia"));
|
||||||
oxRequireM(cctx, core::init(*tctx));
|
return runTest(*tctx);
|
||||||
constexpr ox::FileAddress SceneAddr = ox::StringLiteral("/Scenes/Chester.nscn");
|
|
||||||
oxRequire(scn, keel::readObj<scene::SceneStatic>(keelCtx(*tctx), SceneAddr));
|
|
||||||
turbine::setUpdateHandler(*tctx, updateHandler);
|
|
||||||
turbine::setKeyEventHandler(*tctx, keyEventHandler);
|
|
||||||
s_scene.emplace(*scn);
|
|
||||||
oxReturnError(s_scene->setupDisplay(*cctx));
|
|
||||||
return turbine::run(*tctx);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user