refactor castle
This commit is contained in:
@@ -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; }
|
||||
|
||||
14
src/Castle.h
14
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;
|
||||
};
|
||||
|
||||
38
src/CastleAssets.h
Normal file
38
src/CastleAssets.h
Normal file
@@ -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)"}}
|
||||
};
|
||||
38
src/assets/CastleAssets.h
Normal file
38
src/assets/CastleAssets.h
Normal file
@@ -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)"}};
|
||||
Reference in New Issue
Block a user