diff --git a/Makefile b/Makefile index 78e859c..2d4ffdf 100644 --- 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 index 389588f..0b97388 100644 --- 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(aquarium.getWidth()); - } else { - return (x + static_cast(getWidth())) < 0; - } + // unsigned nonsense + return x < -static_cast(getWidth()) || x > aquarium.getWidth(); } diff --git a/src/Entity.h b/src/Entity.h index 0e18c0a..b11f976 100644 --- 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 index 53bc13a..30bb7b2 100644 --- 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(image.size()) + 6, aquarium.getHeight() - static_cast(image.size())); - x = moving_right ? -20.0f : static_cast(aquarium.getWidth()); + x = moving_right ? -this->getWidth() + : static_cast(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 index 0ef56eb..c30d7e9 100644 --- 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 index 581a977..0007a27 100644 --- 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 index fbc658f..aa1efad 100644 --- a/src/assets/WhaleAssets.h +++ b/src/assets/WhaleAssets.h @@ -1,5 +1,6 @@ #pragma once #include "../Entity.h" +#include "../SpriteUtils.h" #include struct WhaleAsset { @@ -7,47 +8,91 @@ struct WhaleAsset { std::vector mask; }; -inline const std::vector 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 whaleAssets = + createBidirectionalFramedAssets(whale);