initial commit
This commit is contained in:
41
src/Seaweed.cpp
Normal file
41
src/Seaweed.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "Seaweed.h"
|
||||
#include "Aquarium.h"
|
||||
#include "Random.h"
|
||||
#include "defs.h"
|
||||
#include <ncurses.h>
|
||||
|
||||
Seaweed::Seaweed() : Entity() {
|
||||
speed = Random::floatInRange(0.1f, 0.3f);
|
||||
height = Random::intInRange(SEAWEED_MIN_HEIGHT, SEAWEED_MAX_HEIGHT);
|
||||
x = Random::intInRange(0, Aquarium::getInstance().getWidth());
|
||||
y = Aquarium::getInstance().getHeight() - 1;
|
||||
lifetime = Random::intInRange(SEAWEED_MIN_LIFETIME, SEAWEED_MAX_LIFETIME);
|
||||
}
|
||||
|
||||
void Seaweed::update() {
|
||||
frame += speed;
|
||||
if (frame >= 1.0f) {
|
||||
std::swap(pattern[0], pattern[1]);
|
||||
frame -= 1.0f;
|
||||
}
|
||||
--lifetime;
|
||||
}
|
||||
|
||||
void Seaweed::draw() {
|
||||
std::string line;
|
||||
std::string colorLine;
|
||||
|
||||
for (int i = 0; i < height; ++i) {
|
||||
line.clear();
|
||||
char ch = (pattern[i % 2] == '(') ? '(' : ')';
|
||||
|
||||
// Adjust x and y based on the pattern
|
||||
int drawX = (ch == '(') ? x : x + 1;
|
||||
int drawY = y - i;
|
||||
|
||||
line.push_back(ch);
|
||||
colorLine.push_back('g');
|
||||
|
||||
Aquarium::getInstance().drawToBackBuffer(drawY, drawX, 0, line, colorLine);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user