#include "Seaweed.h" #include "Aquarium.h" #include "Random.h" #include "defs.h" #include Seaweed::Seaweed() : x(Random::intInRange(0, Aquarium::getInstance().getWidth())), y(Aquarium::getInstance().getHeight()), height(Random::intInRange(SEAWEED_MIN_HEIGHT, SEAWEED_MAX_HEIGHT)), speed(Random::floatInRange(0.1f, 0.3f)), lifetime(Random::intInRange(SEAWEED_MIN_LIFETIME, SEAWEED_MAX_LIFETIME)) { } void Seaweed::update() noexcept { frame += speed; if (frame >= 1.0f) { pattern_flipped = !pattern_flipped; frame -= 1.0f; } --lifetime; } void Seaweed::draw() const { auto &aquarium = Aquarium::getInstance(); std::string line(1, '\0'); std::string colorLine(1, 'g'); for (size_t i = 0; i < height; ++i) { // Determine character and position for this segment const bool use_left = (i % 2 == 0) ^ pattern_flipped; const char ch = use_left ? PATTERN_LEFT : PATTERN_RIGHT; const int drawX = static_cast(x) + (use_left ? 0 : 1); const int drawY = y - static_cast(i); line[0] = ch; aquarium.drawToBackBuffer(drawY, drawX, 0, line, colorLine); } }