diff --git a/src/nostalgia/player/CMakeLists.txt b/src/nostalgia/player/CMakeLists.txt index a474ec12..c6997d69 100644 --- a/src/nostalgia/player/CMakeLists.txt +++ b/src/nostalgia/player/CMakeLists.txt @@ -24,6 +24,7 @@ target_link_libraries( nostalgia NostalgiaWorld NostalgiaCore + OxLogConn ) install( diff --git a/src/nostalgia/player/app.cpp b/src/nostalgia/player/app.cpp index a1a192ab..b1a51c43 100644 --- a/src/nostalgia/player/app.cpp +++ b/src/nostalgia/player/app.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #include @@ -8,18 +8,24 @@ using namespace nostalgia; static int spriteX = 72; static int spriteY = 64; +static ox::StringView sprites = "nostalgia"; +static bool paused = false; static int updateHandler(core::Context *ctx) noexcept { + constexpr auto sleepTime = 16; + if (paused) { + return sleepTime; + } int xmod = 0; int ymod = 0; - if (core::buttonDown(ctx, core::Alpha_D) || core::buttonDown(ctx, core::GamePad_Right)) { + if (buttonDown(ctx, core::Alpha_D) || buttonDown(ctx, core::GamePad_Right)) { xmod = 2; - } else if (core::buttonDown(ctx, core::Alpha_A) || core::buttonDown(ctx, core::GamePad_Left)) { + } else if (buttonDown(ctx, core::Alpha_A) || buttonDown(ctx, core::GamePad_Left)) { xmod = -2; } - if (core::buttonDown(ctx, core::Alpha_S) || core::buttonDown(ctx, core::GamePad_Down)) { + if (buttonDown(ctx, core::Alpha_S) || buttonDown(ctx, core::GamePad_Down)) { ymod = 2; - } else if (core::buttonDown(ctx, core::Alpha_W) || core::buttonDown(ctx, core::GamePad_Up)) { + } else if (buttonDown(ctx, core::Alpha_W) || buttonDown(ctx, core::GamePad_Up)) { ymod = -2; } if (!xmod && !ymod) { @@ -27,17 +33,20 @@ static int updateHandler(core::Context *ctx) noexcept { } spriteX += xmod; spriteY += ymod; - constexpr ox::StringView s = "nostalgia"; - for (unsigned i = 0; s[i]; ++i) { - const auto c = static_cast(s[i] - ('a' - 1)); - core::setSprite(ctx, i, spriteX + 8 * (static_cast(i) + 1), spriteY, c); + for (unsigned i = 0; i < sprites.len(); ++i) { + const auto c = static_cast(sprites[i] - ('a' - 1)); + core::setSprite(ctx, i, spriteX + 8 * (static_cast(i) + 1), spriteY, c, 0, 0, 0); } - return 16; + return sleepTime; } static void keyEventHandler(core::Context *ctx, core::Key key, bool down) noexcept { - if (down && key == core::Key::Alpha_Q) { - core::shutdown(ctx); + if (down) { + if (key == core::Key::Alpha_Q) { + core::shutdown(ctx); + } else if (key == core::Key::Alpha_P) { + paused = !paused; + } } } diff --git a/src/nostalgia/player/main.cpp b/src/nostalgia/player/main.cpp index 2ad0d708..533fa89f 100644 --- a/src/nostalgia/player/main.cpp +++ b/src/nostalgia/player/main.cpp @@ -2,12 +2,23 @@ * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. */ +#include + #include #include "app.hpp" static ox::Error run(int argc, const char **argv) noexcept { ox::trace::init(); +#ifdef DEBUG + ox::LoggerConn loggerConn; + const auto loggerErr = loggerConn.initConn("Nostalgia Player"); + if (loggerErr) { + oxErrf("Could not connect to logger: {} ({}:{})\n", toStr(loggerErr), loggerErr.file, loggerErr.line); + } else { + ox::trace::setLogger(&loggerConn); + } +#endif if (argc < 2) { oxErr("Please provide path to project directory or OxFS file.\n"); return OxError(1);