refactor bubble
This commit is contained in:
@@ -2,25 +2,17 @@
|
||||
#include "Aquarium.h"
|
||||
#include <ncurses.h>
|
||||
|
||||
Bubble::Bubble(float x, float y) : Entity() {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
Bubble::Bubble(size_t x, size_t y) : x(x), y(y) {}
|
||||
|
||||
void Bubble::update() {
|
||||
--y;
|
||||
++lifetime;
|
||||
}
|
||||
|
||||
void Bubble::update() { y -= 1; }
|
||||
|
||||
void Bubble::draw() {
|
||||
lifetime++;
|
||||
|
||||
// Determine the frame based on lifetime
|
||||
int frameNumber = lifetime / 9;
|
||||
if (frameNumber > 2)
|
||||
frameNumber = 2;
|
||||
|
||||
char frame = bubbleChars[frameNumber];
|
||||
|
||||
std::string line(1, frame);
|
||||
std::string colorLine(1, 'c');
|
||||
|
||||
Aquarium::getInstance().drawToBackBuffer(y, x, 0, line, colorLine);
|
||||
void Bubble::draw() const {
|
||||
static const std::string colorString(1, BUBBLE_COLOR);
|
||||
// Clamp frame index
|
||||
int frameIndex = std::min(lifetime / FRAMES_PER_ANIMATION, MAX_FRAME_INDEX);
|
||||
Aquarium::getInstance().drawToBackBuffer(y, x, 0, BUBBLE_FRAMES[frameIndex],
|
||||
colorString);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user