commit 4e0fcff66e7a58c5b2479bf1ec85e93693adcdd2
parent d4871e8f36f9e8a828822530bdb7b19acc2c3433
Author: amrfti <andrew@kloet.net>
Date: Thu, 22 May 2025 20:53:41 -0400
refactor castle
Diffstat:
4 files changed, 93 insertions(+), 35 deletions(-)
diff --git a/src/Castle.cpp b/src/Castle.cpp
@@ -1,39 +1,24 @@
#include "Castle.h"
#include "Aquarium.h"
+#include "assets/CastleAssets.h"
-const std::vector<std::string> Castle::image = {
- R"( T~~ )", R"( | )",
- R"( /^\ )", R"( / \ )",
- R"( _ _ _ / \ _ _ _ )", R"([ ]_[ ]_[ ]/ _ _ \[ ]_[ ]_[ ])",
- R"(|_=__-_ =_|_[ ]_[ ]_|_=-___-__|)", R"( | _- = | =_ = _ |= _= | )",
- R"( |= -[] |- = _ = |_-=_[] | )", R"( | =_ |= - ___ | =_ = | )",
- R"( |= []- |- /| |\ |=_ =[] | )", R"( |- =_ | =| | | | |- = - | )",
- R"( |_______|__|_|_|_|__|_______| )"};
+Castle::Castle()
+ : x(Aquarium::getInstance().getWidth() - 32),
+ y(Aquarium::getInstance().getHeight() - 13), image(castleAsset.image),
+ mask(castleAsset.mask) {}
-const std::vector<std::string> Castle::mask = {
- 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 )"};
+void Castle::draw() const {
+ auto &aquarium = Aquarium::getInstance();
-Castle::Castle() : Entity() {
- x = Aquarium::getInstance().getWidth() - 32;
- y = Aquarium::getInstance().getHeight() - 13;
-}
-
-void Castle::draw() {
for (size_t i = 0; i < image.size(); ++i) {
std::string currentLine;
std::string colorLine;
+ currentLine.reserve(image[i].size());
+ colorLine.reserve(image[i].size());
// Iterate over characters in the current line
for (size_t j = 0; j < image[i].size(); ++j) {
char ch = image[i][j];
- if (ch == '?')
- continue;
char colorChar = 'K'; // default to black
if (i < mask.size() && j < mask[i].size() && mask[i][j] != ' ')
@@ -44,9 +29,6 @@ void Castle::draw() {
colorLine += colorChar;
}
- Aquarium::getInstance().drawToBackBuffer(y + i, x, 0, currentLine,
- colorLine);
+ aquarium.drawToBackBuffer(y + i, x, 0, currentLine, colorLine);
}
}
-
-void Castle::update() { return; }
diff --git a/src/Castle.h b/src/Castle.h
@@ -1,14 +1,14 @@
#pragma once
-#include "Entity.h"
+#include <string>
+#include <vector>
-class Castle : public Entity {
+class Castle {
private:
- static const std::vector<std::string> image;
- static const std::vector<std::string> mask;
+ const size_t x, y;
+ const std::vector<std::string> image;
+ const std::vector<std::string> mask;
public:
Castle();
-
- void draw();
- void update();
+ void draw() const;
};
diff --git a/src/CastleAssets.h b/src/CastleAssets.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <string>
+#include <vector>
+
+using CastleAsset =
+ std::pair<std::vector<std::string>, std::vector<std::string>>;
+
+inline std::vector<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)"}}
+};
diff --git a/src/assets/CastleAssets.h b/src/assets/CastleAssets.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <string>
+#include <vector>
+
+struct CastleAsset {
+ std::vector<std::string> image;
+ std::vector<std::string> mask;
+};
+
+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)"}};