mobility.hpp 1.6 KB
Newer Older
louiz’'s avatar
louiz’ committed
1 2 3
#ifndef MOBILITY_COMPONENT_HPP_INCLUDED
#define MOBILITY_COMPONENT_HPP_INCLUDED

4
#include <world/direction.hpp>
louiz’'s avatar
louiz’ committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <world/components.hpp>
#include <fixmath/fix16.hpp>
#include <world/path.hpp>

#include <cstdint>

class Location;
class World;

class Mobility: public Component
{
public:
  static const ComponentType component_type = ComponentType::Mobility;

  Mobility(const Fix16& speed);
  ~Mobility() = default;
  void tick(Entity*, World*) override final;
  Fix16 get_speed() const;
23
  void set_speed(const Fix16& speed);
24 25 26 27
  /**
   * Given a path, change the location and cut down the path (if we moved
   * enough) to follow that path
   */
louiz’'s avatar
louiz’ committed
28
  void follow_path(Path& path, World* world, Location* location);
29 30 31 32 33 34
  /**
   * Move the location towards the given goal. Doesn't do any pathfinding or
   * collision handling, just moves unconditionally in the right direction.
   *
   * The goal is reached if after this function, the location's position == goal.
   */
35 36
  Fix16 move_towards(const Position& goal, Location* location);
  Fix16 move_towards(const Position& goal, Location* location, Fix16 speed);
37 38 39 40 41
  /**
   * Get the angle of the entity that has this mobility, based on the latest
   * movement done.
   */
  Fix16 get_angle() const;
42 43 44 45 46
  /**
   * Get the one of the 8 cardinal directions, based on the last movement’s
   * angle
   */
  Direction get_direction() const;
louiz’'s avatar
louiz’ committed
47 48
private:
  Fix16 speed;
49
  Vec2 last_movement;
louiz’'s avatar
louiz’ committed
50 51 52 53 54 55 56 57 58

  Mobility(const Mobility&) = delete;
  Mobility(Mobility&&) = delete;
  Mobility& operator=(const Mobility&) = delete;
  Mobility& operator=(Mobility&&) = delete;
};


#endif /* MOBILITY_COMPONENT_HPP_INCLUDED */