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

View File

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