| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //
- // entity.cxx
- // engine
- //
- // Created by Sam Jaffe on 5/20/19.
- // Copyright © 2019 Sam Jaffe. All rights reserved.
- //
- #include "game/engine/entity.hpp"
- #include <json/json.h>
- #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<entity>(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(float delta) {
- last_position = render_info_.location.origin;
- 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;
- }
- void entity::collide(entity const &) {}
|