fissh

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

Ship.cpp (723B)


      1 #include "Ship.h"
      2 #include "../assets/ShipAssets.h"
      3 #include "../core/Aquarium.h"
      4 #include "../utils/Random.h"
      5 
      6 Ship::Ship() : Ship(getRandomDirection()) {}
      7 
      8 Ship::Ship(int asset_index)
      9     : Entity(asset_index == 0), image(getShipAssets()[asset_index].image),
     10       mask(getShipAssets()[asset_index].mask), speed(SHIP_SPEED) {
     11 
     12   const auto &aquarium = Aquarium::getInstance();
     13   y = 0;
     14   if (moving_right) {
     15     x = -static_cast<float>(image[0].length());
     16   } else {
     17     x = static_cast<float>(aquarium.getWidth());
     18   }
     19 }
     20 
     21 int Ship::getRandomDirection() { return Random::intInRange(0, 1); }
     22 
     23 void Ship::update() noexcept { x += moving_right ? speed : -speed; }
     24 
     25 int Ship::getPreferredLayer() const noexcept { return 9; }