Compare commits

...

2 Commits

Author SHA1 Message Date
9c631d3d9a undo 2025-07-08 10:40:56 -04:00
2eead14b8e segfault test fix 2025-07-08 10:40:26 -04:00
2 changed files with 12 additions and 6 deletions

View File

@@ -9,8 +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(fishAssetPairs[asset_index].image), : Entity(asset_index % 2 == 0), image(getFishAssetPairs()[asset_index].image),
mask(fishAssetPairs[asset_index].mask), mask(getFishAssetPairs()[asset_index].mask),
speed(Random::floatInRange(0.25f, 2.25f)) { speed(Random::floatInRange(0.25f, 2.25f)) {
const auto &aquarium = Aquarium::getInstance(); const auto &aquarium = Aquarium::getInstance();
@@ -45,7 +45,7 @@ void Fish::randomizeMask() {
} }
int Fish::getRandomAssetIndex() { int Fish::getRandomAssetIndex() {
return Random::intInRange(0, static_cast<int>(fishAssetPairs.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

@@ -4,7 +4,8 @@
#include "../SpriteUtils.h" #include "../SpriteUtils.h"
#include <vector> #include <vector>
const std::vector<AssetPair> fishAssets = { inline const std::vector<AssetPair>& getFishAssets() {
static const std::vector<AssetPair> fishAssets = {
{ {
{ {
R"(???\??)", R"(???\??)",
@@ -100,6 +101,11 @@ const std::vector<AssetPair> fishAssets = {
R"( 6 3 77 4 1)", R"( 6 3 77 4 1)",
R"(6661111111311311111 )", R"(6661111111311311111 )",
}}}; }}};
return fishAssets;
}
inline const std::vector<AssetPair> fishAssetPairs = inline const std::vector<AssetPair>& getFishAssetPairs() {
createBidirectionalAssets(fishAssets); static const std::vector<AssetPair> fishAssetPairs =
createBidirectionalAssets(getFishAssets());
return fishAssetPairs;
}