entity.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // entity.hpp
  3. // engine
  4. //
  5. // Created by Sam Jaffe on 5/20/19.
  6. // Copyright © 2019 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <json/forwards.h>
  10. #include "game/engine/engine_fwd.hpp"
  11. #include "game/graphics/graphics_fwd.h"
  12. #include "game/graphics/object.hpp"
  13. #include "game/util/identity.hpp"
  14. namespace engine {
  15. class collidable : identity<collidable> {
  16. public:
  17. collidable(graphics::object const & obj);
  18. collidable(Json::Value const & json, graphics::manager const & mgr);
  19. virtual void collide(collidable const &) {}
  20. graphics::object const & render_info() const { return render_info_; }
  21. protected:
  22. // A mix of position and graphics info
  23. graphics::object render_info_;
  24. };
  25. class entity : public collidable {
  26. public:
  27. // TODO: Extract this out?
  28. entity(Json::Value const & json, graphics::manager const & mgr);
  29. void update(float delta);
  30. private:
  31. // The scene that owns this object
  32. std::weak_ptr<scene> in_scene;
  33. // Position info
  34. math::vec2 last_position{{-1, -1}};
  35. math::vec2 velocity;
  36. math::vec2 acceleration{{0, 0}};
  37. float angular_velocity{0.f};
  38. // Graphics info
  39. std::size_t frame_index{0};
  40. std::vector<math::vec2> frame_texture_coords;
  41. float scale{1.f};
  42. collision_t collides_with;
  43. collision_t collides_as;
  44. };
  45. }