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

View File

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