refactor castle
This commit is contained in:
@@ -1,39 +1,24 @@
|
|||||||
#include "Castle.h"
|
#include "Castle.h"
|
||||||
#include "Aquarium.h"
|
#include "Aquarium.h"
|
||||||
|
#include "assets/CastleAssets.h"
|
||||||
|
|
||||||
const std::vector<std::string> Castle::image = {
|
Castle::Castle()
|
||||||
R"( T~~ )", R"( | )",
|
: x(Aquarium::getInstance().getWidth() - 32),
|
||||||
R"( /^\ )", R"( / \ )",
|
y(Aquarium::getInstance().getHeight() - 13), image(castleAsset.image),
|
||||||
R"( _ _ _ / \ _ _ _ )", R"([ ]_[ ]_[ ]/ _ _ \[ ]_[ ]_[ ])",
|
mask(castleAsset.mask) {}
|
||||||
R"(|_=__-_ =_|_[ ]_[ ]_|_=-___-__|)", R"( | _- = | =_ = _ |= _= | )",
|
|
||||||
R"( |= -[] |- = _ = |_-=_[] | )", R"( | =_ |= - ___ | =_ = | )",
|
|
||||||
R"( |= []- |- /| |\ |=_ =[] | )", R"( |- =_ | =| | | | |- = - | )",
|
|
||||||
R"( |_______|__|_|_|_|__|_______| )"};
|
|
||||||
|
|
||||||
const std::vector<std::string> Castle::mask = {
|
void Castle::draw() const {
|
||||||
R"( RR )", R"( )",
|
auto &aquarium = Aquarium::getInstance();
|
||||||
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 )"};
|
|
||||||
|
|
||||||
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) {
|
for (size_t i = 0; i < image.size(); ++i) {
|
||||||
std::string currentLine;
|
std::string currentLine;
|
||||||
std::string colorLine;
|
std::string colorLine;
|
||||||
|
currentLine.reserve(image[i].size());
|
||||||
|
colorLine.reserve(image[i].size());
|
||||||
|
|
||||||
// Iterate over characters in the current line
|
// Iterate over characters in the current line
|
||||||
for (size_t j = 0; j < image[i].size(); ++j) {
|
for (size_t j = 0; j < image[i].size(); ++j) {
|
||||||
char ch = image[i][j];
|
char ch = image[i][j];
|
||||||
if (ch == '?')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
char colorChar = 'K'; // default to black
|
char colorChar = 'K'; // default to black
|
||||||
if (i < mask.size() && j < mask[i].size() && mask[i][j] != ' ')
|
if (i < mask.size() && j < mask[i].size() && mask[i][j] != ' ')
|
||||||
@@ -44,9 +29,6 @@ void Castle::draw() {
|
|||||||
colorLine += colorChar;
|
colorLine += colorChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
Aquarium::getInstance().drawToBackBuffer(y + i, x, 0, currentLine,
|
aquarium.drawToBackBuffer(y + i, x, 0, currentLine, colorLine);
|
||||||
colorLine);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Castle::update() { return; }
|
|
||||||
|
|||||||
14
src/Castle.h
14
src/Castle.h
@@ -1,14 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Entity.h"
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class Castle : public Entity {
|
class Castle {
|
||||||
private:
|
private:
|
||||||
static const std::vector<std::string> image;
|
const size_t x, y;
|
||||||
static const std::vector<std::string> mask;
|
const std::vector<std::string> image;
|
||||||
|
const std::vector<std::string> mask;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Castle();
|
Castle();
|
||||||
|
void draw() const;
|
||||||
void draw();
|
|
||||||
void update();
|
|
||||||
};
|
};
|
||||||
|
|||||||
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