decouple waterline from entity

This commit is contained in:
2025-05-22 20:30:51 -04:00
committed by laugos
parent 614ada45fd
commit 7dc41bdb2a
2 changed files with 10 additions and 16 deletions

View File

@@ -5,25 +5,21 @@
#include <algorithm> #include <algorithm>
#include <ncurses.h> #include <ncurses.h>
Waterline::Waterline() { Waterline::Waterline() : x(0), y(5) {
std::vector<std::string> baseShape = { shape = {
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", "^^^^ ^^^ ^^^ ^^^ ^^^^ ", "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", "^^^^ ^^^ ^^^ ^^^ ^^^^ ",
"^^^^ ^^^^ ^^^ ^^ ", "^^ ^^^^ ^^^ ^^^^^^ "}; "^^^^ ^^^^ ^^^ ^^ ", "^^ ^^^^ ^^^ ^^^^^^ "};
int seg_len = baseShape[0].size(); const size_t width = Aquarium::getInstance().getWidth();
int repeat = Aquarium::getInstance().getWidth() / seg_len + 1; for (auto &line : shape) {
const std::string original = line;
for (auto &line : baseShape) { while (line.size() < width) {
std::string original = line;
while (line.size() < Aquarium::getInstance().getWidth()) {
line += original; line += original;
} }
} }
shape = std::move(baseShape);
y = 5;
} }
void Waterline::draw() { void Waterline::draw() const {
for (size_t i = 0; i < shape.size(); ++i) { for (size_t i = 0; i < shape.size(); ++i) {
Aquarium::getInstance().drawToBackBuffer(i + y, x, 0, shape[i], Aquarium::getInstance().drawToBackBuffer(i + y, x, 0, shape[i],
std::string(shape[i].size(), 'c')); std::string(shape[i].size(), 'c'));
@@ -42,9 +38,6 @@ void Waterline::update() {
} }
void Waterline::shiftString(std::string &str, int direction) { void Waterline::shiftString(std::string &str, int direction) {
if (str.empty() || (direction != 1 && direction != -1))
return;
if (direction == 1) { if (direction == 1) {
std::rotate(str.rbegin(), str.rbegin() + 1, str.rend()); std::rotate(str.rbegin(), str.rbegin() + 1, str.rend());
} else { } else {

View File

@@ -1,13 +1,14 @@
#pragma once #pragma once
#include "Entity.h" #include "Entity.h"
class Waterline : public Entity { class Waterline {
private: private:
size_t x, y;
std::vector<std::string> shape; std::vector<std::string> shape;
void shiftString(std::string &, int direction); void shiftString(std::string &, int direction);
public: public:
Waterline(); Waterline();
void draw(); void draw() const;
void update(); void update();
}; };