fissh

termios terminal aquarium. demo at ssh://fish@kloet.net
Download | Log | Files | Refs

Bubble.cpp (677B)


      1 #include "Bubble.h"
      2 
      3 Bubble::Bubble(float x, float y) : Entity(x, y) {
      4   current_image.resize(1);
      5   current_mask.resize(1);
      6   updateFrame();
      7 }
      8 
      9 void Bubble::update() noexcept {
     10   --y;
     11   ++lifetime;
     12   updateFrame();
     13 }
     14 
     15 void Bubble::updateFrame() {
     16   int frameIndex = std::min(lifetime / FRAMES_PER_ANIMATION, MAX_FRAME_INDEX);
     17   current_image[0] = BUBBLE_FRAMES[frameIndex];
     18   current_mask[0] = BUBBLE_COLOR;
     19 }
     20 
     21 // Waterline collision
     22 bool Bubble::shouldBeRemoved() const noexcept { return y < 10; }
     23 
     24 // Bubbles don't create replacements
     25 std::unique_ptr<Entity> Bubble::createReplacement() const { return nullptr; }
     26 
     27 int Bubble::getPreferredLayer() const noexcept { return 5; }