commit 8b70203eb22797ce60840adff85ef6ca3559474a
parent 754643ba2253abf2bcb716fbe6514aefb4ca836d
Author: amrfti <andrew@kloet.net>
Date: Tue, 8 Jul 2025 09:30:11 -0400
fix segfault
Diffstat:
7 files changed, 126 insertions(+), 69 deletions(-)
diff --git a/Makefile b/Makefile
@@ -36,9 +36,5 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.$(SRC_EXT)
clean:
rm -rf $(OBJ_DIR) $(BIN_DIR)
-# Run the program
-run: $(EXEC)
- ./$(EXEC)
-
# Phony targets
.PHONY: all clean run
diff --git a/src/Entity.cpp b/src/Entity.cpp
@@ -58,9 +58,6 @@ void Entity::draw() const {
bool Entity::shouldBeRemoved() const noexcept {
const auto &aquarium = Aquarium::getInstance();
- if (moving_right) {
- return x > static_cast<float>(aquarium.getWidth());
- } else {
- return (x + static_cast<float>(getWidth())) < 0;
- }
+ // unsigned nonsense
+ return x < -static_cast<int>(getWidth()) || x > aquarium.getWidth();
}
diff --git a/src/Entity.h b/src/Entity.h
@@ -29,7 +29,7 @@ public:
float getX() const noexcept { return x; }
float getY() const noexcept { return y; }
- virtual size_t getWidth() const noexcept { return getImage()[0].length(); }
+ virtual int getWidth() const noexcept { return getImage()[0].length(); }
size_t getId() const noexcept { return entity_id; }
virtual void update() noexcept = 0;
diff --git a/src/Fish.cpp b/src/Fish.cpp
@@ -16,14 +16,15 @@ Fish::Fish(int asset_index)
const auto &aquarium = Aquarium::getInstance();
y = Random::intInRange(static_cast<int>(image.size()) + 6,
aquarium.getHeight() - static_cast<int>(image.size()));
- x = moving_right ? -20.0f : static_cast<float>(aquarium.getWidth());
+ x = moving_right ? -this->getWidth()
+ : static_cast<float>(aquarium.getWidth());
randomizeMask();
}
void Fish::randomizeMask() {
- // Clear and rebuild color map with fresh random colors each time
+ // Clear and rebuild color map with random colors each time
color_map.clear();
- color_map['4'] = 'W'; // White is always '4'
+ color_map['4'] = 'W'; // White is always '4' for eyes
// Assign random colors to digits 1-3, 5-9
for (char digit = '1'; digit <= '9'; ++digit) {
diff --git a/src/Whale.cpp b/src/Whale.cpp
@@ -6,7 +6,7 @@
Whale::Whale() : Whale(getRandomDirection()) {}
Whale::Whale(int asset_index)
- : Entity((asset_index = 0)), frames(whaleAssets[asset_index].frames),
+ : Entity((asset_index == 0)), frames(whaleAssets[asset_index].frames),
mask(whaleAssets[asset_index].mask), speed(WHALE_SPEED) {
const auto &aquarium = Aquarium::getInstance();
diff --git a/src/assets/CastleAssets.h b/src/assets/CastleAssets.h
@@ -9,14 +9,32 @@ struct CastleAsset {
};
inline CastleAsset castleAsset = {
- {R"( T~~)", R"( |)", R"( /^\)",
- R"( / \)", R"( _ _ _ / \ _ _ _)",
- R"([ ]_[ ]_[ ]/ _ _ \[ ]_[ ]_[ ])", R"(|_=__-_ =_|_[ ]_[ ]_|_=-___-__|)",
- R"( | _- = | =_ = _ |= _= |)", R"( |= -[] |- = _ = |_-=_[] |)",
- R"( | =_ |= - ___ | =_ = |)", R"( |= []- |- /| |\ |=_ =[] |)",
- R"( |- =_ | =| | | | |- = - |)", R"( |_______|__|_|_|_|__|_______|)"},
- {R"( RR)", R"()", R"( yyy)",
- R"( y y)", R"( y y)",
- R"( y y)", R"()", R"()", R"()", R"( yyy)",
- R"( yy yy)", R"( y y y y)",
- R"( yyyyyyy)"}};
+ {
+ R"( T~~)",
+ R"( |)",
+ R"( /^\)",
+ R"( / \)",
+ R"( _ _ _ / \ _ _ _)",
+ R"([ ]_[ ]_[ ]/ _ _ \[ ]_[ ]_[ ])",
+ R"(|_=__-_ =_|_[ ]_[ ]_|_=-___-__|)",
+ R"( | _- = | =_ = _ |= _= |)",
+ R"( |= -[] |- = _ = |_-=_[] |)",
+ R"( | =_ |= - ___ | =_ = |)",
+ R"( |= []- |- /| |\ |=_ =[] |)",
+ R"( |- =_ | =| | | | |- = - |)",
+ R"( |_______|__|_|_|_|__|_______|)"},
+ {
+ R"( RR)",
+ R"()",
+ R"( yyy)",
+ R"( y y)",
+ R"( y y)",
+ R"( y y)",
+ R"()",
+ R"()",
+ R"()",
+ R"( yyy)",
+ R"( yy yy)",
+ R"( y y y y)",
+ R"( yyyyyyy)"}
+};
diff --git a/src/assets/WhaleAssets.h b/src/assets/WhaleAssets.h
@@ -1,5 +1,6 @@
#pragma once
#include "../Entity.h"
+#include "../SpriteUtils.h"
#include <vector>
struct WhaleAsset {
@@ -7,47 +8,91 @@ struct WhaleAsset {
std::vector<std::string> mask;
};
-inline const std::vector<WhaleAsset> whaleAssets = {
- {{{{R"()", R"()", R"()", R"( .-----.)", R"( .' `.)",
- R"(,????/ (o) \)", R"(\`._/ ,__)"},
- {R"()", R"()", R"( :)", R"( .-----.)",
- R"( .' `.)", R"(,????/ (o) \)",
- R"(\`._/ ,__)"},
- {R"()", R"( :)", R"( :)", R"( .-----.)",
- R"( .' `.)", R"(,????/ (o) \)",
- R"(\`._/ ,__)"},
- {R"( . .)", R"( -:-)", R"( :)",
- R"( .-----.)", R"( .' `.)", R"(,????/ (o) \)",
- R"(\`._/ ,__)"},
- {R"( . .)", R"( .-.-.)", R"( :)",
- R"( .-----.)", R"( .' `.)", R"(,????/ (o) \)",
- R"(\`._/ ,__)"},
- {R"( . .)", R"( '.-:-.')", R"( ' : ')",
- R"( .-----.)", R"( .' `.)", R"(,????/ (o) \)",
- R"(\`._/ ,__)"},
- {R"()", R"( .- -.)", R"( ; : ;)", R"( .-----.)",
- R"( .' `.)", R"(,????/ (o) \)",
- R"(\`._/ ,__)"},
- {R"()", R"()", R"( ; ;)", R"( .-----.)",
- R"( .' `.)", R"(,????/ (o) \)",
- R"(\`._/ ,__)"}},
- {R"( C C)", R"( CCCCCCC)", R"( C C C)", R"()",
- R"()", R"( W)", R"()"}},
- {{{R"()", R"()", R"()", R"( .-----.)", R"( .' `.)",
- R"( / (o) \????)", R"((__, \_.'/)"},
- {R"()", R"()", R"( :)", R"( .-----.)", R"( .' `.)",
- R"( / (o) \????)", R"((__, \_.'/)"},
- {R"()", R"( :)", R"( :)", R"( .-----.)",
- R"( .' `.)", R"( / (o) \????)", R"((__, \_.'/)"},
- {R"( . .)", R"( -:-)", R"( :)", R"( .-----.)",
- R"( .' `.)", R"( / (o) \????)", R"((__, \_.'/)"},
- {R"( . .)", R"( .-.-.)", R"( :)", R"( .-----.)",
- R"( .' `.)", R"( / (o) \????)", R"((__, \_.'/)"},
- {R"( . .)", R"( '.-:-.')", R"( ' : ')", R"( .-----.)",
- R"( .' `.)", R"( / (o) \????)", R"((__, \_.'/)"},
- {R"()", R"( .- -.)", R"( ; : ;)", R"( .-----.)",
- R"( .' `.)", R"( / (o) \????)", R"((__, \_.'/)"},
- {R"()", R"()", R"( ; ;)", R"( .-----.)", R"( .' `.)",
- R"( / (o) \????)", R"((__, \_.'/)"}},
- {R"( C C)", R"( CCCCCCC)", R"( C C C)", R"()", R"()",
- R"( W)", R"()"}}}};
+const WhaleAsset whale = {
+ {
+ {
+ R"( )",
+ R"()",
+ R"()",
+ R"( .-----. )",
+ R"( .' `. )",
+ R"(,????/ (o) \)",
+ R"(\`._/ ,__)"
+ },
+ {
+ R"( )",
+ R"()",
+ R"( : )",
+ R"( .-----. )",
+ R"( .' `. )",
+ R"(,????/ (o) \)",
+ R"(\`._/ ,__)"
+ },
+ {
+ R"( )",
+ R"( : )",
+ R"( : )",
+ R"( .-----. )",
+ R"( .' `. )",
+ R"(,????/ (o) \)",
+ R"(\`._/ ,__)"
+ },
+ {
+ R"( . . )",
+ R"( -:- )",
+ R"( : )",
+ R"( .-----. )",
+ R"( .' `. )",
+ R"(,????/ (o) \)",
+ R"(\`._/ ,__)"
+ },
+ {
+ R"( . . )",
+ R"( .-.-. )",
+ R"( : )",
+ R"( .-----. )",
+ R"( .' `. )",
+ R"(,????/ (o) \)",
+ R"(\`._/ ,__)"
+ },
+ {
+ R"( . . )",
+ R"( '.-:-.' )",
+ R"( ' : ' )",
+ R"( .-----. )",
+ R"( .' `. )",
+ R"(,????/ (o) \)",
+ R"(\`._/ ,__)"
+ },
+ {
+ R"( )",
+ R"( .- -. )",
+ R"( ; : ; )",
+ R"( .-----. )",
+ R"( .' `. )",
+ R"(,????/ (o) \)",
+ R"(\`._/ ,__)"
+ },
+ {
+ R"( )",
+ R"( )",
+ R"( ; ; )",
+ R"( .-----. )",
+ R"( .' `. )",
+ R"(,????/ (o) \)",
+ R"(\`._/ ,__)"
+ }
+ },
+ {
+ R"( C C )",
+ R"( CCCCCCC )",
+ R"( C C C )",
+ R"()",
+ R"()",
+ R"( W )",
+ R"()"
+ }
+};
+
+inline const std::vector<WhaleAsset> whaleAssets =
+ createBidirectionalFramedAssets(whale);