entity.cxx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // entity.cxx
  3. // engine
  4. //
  5. // Created by Sam Jaffe on 5/20/19.
  6. // Copyright © 2019 Sam Jaffe. All rights reserved.
  7. //
  8. #include "game/engine/entity.hpp"
  9. #include <json/json.h>
  10. #include "game/engine/serial.hpp"
  11. #include "game/engine/time.hpp"
  12. #include "game/graphics/material.hpp"
  13. using namespace engine;
  14. static unsigned int next_id() {
  15. static unsigned int id{0};
  16. return ++id;
  17. }
  18. entity::entity(Json::Value const & json)
  19. : identity<entity>(next_id()), in_scene(), last_position({-1, -1}),
  20. velocity(to_vec2(json["velocity"])), acceleration(),
  21. angular_velocity(0.f), render_info_(to_object(json)), frame_index(0),
  22. frame_texture_coords({make_vector(0.f, 0.f)}),
  23. scale(json["size"].asFloat()), collides_with(0), collides_as(0) {
  24. render_info_.location.size *= scale;
  25. render_info_.frame.origin = frame_texture_coords[frame_index];
  26. }
  27. void entity::update(float delta) {
  28. last_position = render_info_.location.origin;
  29. auto delta_pos = velocity * delta;
  30. render_info_.location.origin += delta_pos;
  31. render_info_.points.ll += delta_pos;
  32. render_info_.points.lr += delta_pos;
  33. render_info_.points.ur += delta_pos;
  34. render_info_.points.ul += delta_pos;
  35. velocity += acceleration * delta;
  36. // render_info.angle += angular_velocity * delta;
  37. }
  38. void entity::collide(entity const &) {}