// // entity.cxx // engine // // Created by Sam Jaffe on 5/20/19. // Copyright © 2019 Sam Jaffe. All rights reserved. // #include "game/engine/entity.hpp" #include #include "game/engine/serial.hpp" #include "game/engine/time.hpp" #include "game/graphics/material.hpp" using namespace engine; static unsigned int next_id() { static unsigned int id{0}; return ++id; } entity::entity(Json::Value const & json) : identity(next_id()), in_scene(), last_position({-1, -1}), velocity(to_vec2(json["velocity"])), acceleration(), angular_velocity(0.f), render_info(to_object(json)), frame_index(0), frame_texture_coords({make_vector(0.f, 0.f)}), scale(json["size"].asFloat()), collides_with(0), collides_as(0) { render_info.location.size *= scale; render_info.frame.origin = frame_texture_coords[frame_index]; } void entity::update(tick const & tk) { last_position = render_info.location.origin; float delta = tk.since.count(); auto delta_pos = velocity * delta; render_info.location.origin += delta_pos; render_info.points.ll += delta_pos; render_info.points.lr += delta_pos; render_info.points.ur += delta_pos; render_info.points.ul += delta_pos; velocity += acceleration * delta; // render_info.angle += angular_velocity * delta; }