add input delay

This commit is contained in:
2025-07-08 13:18:16 -04:00
parent 348b687bd9
commit 5bae9a07af
4 changed files with 13 additions and 8 deletions

View File

@@ -87,7 +87,7 @@ void Aquarium::redraw() {
entities_need_sorting = true; entities_need_sorting = true;
} }
// Add new entities (only if we have them) // Add new entities if we have them
if (!newEntities.empty()) { if (!newEntities.empty()) {
// Reserve space to minimize reallocations // Reserve space to minimize reallocations
entities.reserve(entities.size() + newEntities.size()); entities.reserve(entities.size() + newEntities.size());

View File

@@ -9,7 +9,8 @@ std::unordered_map<char, char> Fish::color_map;
Fish::Fish() : Fish(getRandomAssetIndex()) {} Fish::Fish() : Fish(getRandomAssetIndex()) {}
Fish::Fish(int asset_index) Fish::Fish(int asset_index)
: Entity(asset_index % 2 == 0), image(getFishAssetPairs()[asset_index].image), : Entity(asset_index % 2 == 0),
image(getFishAssetPairs()[asset_index].image),
mask(getFishAssetPairs()[asset_index].mask), mask(getFishAssetPairs()[asset_index].mask),
speed(Random::floatInRange(0.25f, 2.25f)) { speed(Random::floatInRange(0.25f, 2.25f)) {
@@ -45,7 +46,8 @@ void Fish::randomizeMask() {
} }
int Fish::getRandomAssetIndex() { int Fish::getRandomAssetIndex() {
return Random::intInRange(0, static_cast<int>(getFishAssetPairs().size()) - 1); return Random::intInRange(0,
static_cast<int>(getFishAssetPairs().size()) - 1);
} }
void Fish::update() noexcept { x += moving_right ? speed : -speed; } void Fish::update() noexcept { x += moving_right ? speed : -speed; }

View File

@@ -1,4 +1,3 @@
// SpriteUtils.h - Unified mirroring for all asset types
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <string> #include <string>

View File

@@ -22,10 +22,14 @@ int main(int argc, char *argv[]) {
while (true) { while (true) {
aquarium.redraw(); aquarium.redraw();
int ch = getch(); int ch = getch();
if (ch == 'q') if (ch != ERR) {
break; if (ch == 'q')
if (ch == 'r') break;
aquarium.resize(); if (ch == 'r')
aquarium.resize();
flushinp();
usleep(100000);
}
} }
return 0; return 0;