[nostalgia/player] Add PC controls and Bullock integration
This commit is contained in:
parent
231f460668
commit
cd28fee8fd
@ -24,6 +24,7 @@ target_link_libraries(
|
||||
nostalgia
|
||||
NostalgiaWorld
|
||||
NostalgiaCore
|
||||
OxLogConn
|
||||
)
|
||||
|
||||
install(
|
||||
|
@ -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 <nostalgia/core/core.hpp>
|
||||
@ -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<unsigned>(s[i] - ('a' - 1));
|
||||
core::setSprite(ctx, i, spriteX + 8 * (static_cast<int>(i) + 1), spriteY, c);
|
||||
for (unsigned i = 0; i < sprites.len(); ++i) {
|
||||
const auto c = static_cast<unsigned>(sprites[i] - ('a' - 1));
|
||||
core::setSprite(ctx, i, spriteX + 8 * (static_cast<int>(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) {
|
||||
if (down) {
|
||||
if (key == core::Key::Alpha_Q) {
|
||||
core::shutdown(ctx);
|
||||
} else if (key == core::Key::Alpha_P) {
|
||||
paused = !paused;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,23 @@
|
||||
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <ox/logconn/logconn.hpp>
|
||||
|
||||
#include <nostalgia/core/core.hpp>
|
||||
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user