From 6a02161b3797357455d955fe27600a9366cb18d9 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 2 Aug 2022 01:32:46 -0500 Subject: [PATCH] [nostalgia/player] Make sprites in demo scene auto-scroll --- src/nostalgia/player/app.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/nostalgia/player/app.cpp b/src/nostalgia/player/app.cpp index 487740a0..5fa3ae51 100644 --- a/src/nostalgia/player/app.cpp +++ b/src/nostalgia/player/app.cpp @@ -6,24 +6,31 @@ using namespace nostalgia; -static unsigned spriteX = 72; -static unsigned spriteY = 64; +static int spriteX = 72; +static int spriteY = 64; static int updateHandler(core::Context *ctx) noexcept { + int xmod = 0; + int ymod = 0; if (core::buttonDown(ctx, core::GamePad_Right)) { - spriteX += 2; + xmod = 2; } else if (core::buttonDown(ctx, core::GamePad_Left)) { - spriteX -= 2; + xmod = -2; } if (core::buttonDown(ctx, core::GamePad_Down)) { - spriteY += 2; + ymod = 2; } else if (core::buttonDown(ctx, core::GamePad_Up)) { - spriteY -= 2; + ymod = -2; } + if (!xmod && !ymod) { + spriteX += 2; + } + spriteX += xmod; + spriteY += ymod; constexpr auto s = "nostalgia"; for (unsigned i = 0; s[i]; ++i) { const auto c = static_cast(s[i] - ('a' - 1)); - core::setSprite(ctx, i, spriteX + 8 * (i + 1), spriteY, c); + core::setSprite(ctx, i, static_cast(spriteX) + 8 * (i + 1), static_cast(spriteY), c); } return 16; }