[nostalgia/player] Add PC controls and Bullock integration

This commit is contained in:
2023-02-01 22:48:26 -06:00
parent 231f460668
commit cd28fee8fd
3 changed files with 33 additions and 12 deletions
+21 -12
View File
@@ -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) {
core::shutdown(ctx);
if (down) {
if (key == core::Key::Alpha_Q) {
core::shutdown(ctx);
} else if (key == core::Key::Alpha_P) {
paused = !paused;
}
}
}