| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- //
- // scene.cpp
- // engine
- //
- // Created by Sam Jaffe on 9/2/16.
- //
- #include "game/engine/scene.hpp"
- #include "game/engine/entity.hpp"
- #include "game/engine/events.hpp"
- #include "game/engine/game_dispatch.hpp"
- #include "game/graphics/renderer.hpp"
- #include "game/math/common.hpp"
- using namespace engine;
- scene::~scene() {}
- void scene::update(float delta) {
- for (auto & ent : entities) {
- ent.update(delta);
- }
- for (auto & pair : colliders) {
- auto & collidable = collidables[pair.first];
- for (auto & ent : pair.second) {
- for (auto & hit : collidable) {
- if (math::intersects(ent->render_info().points,
- hit->render_info().points)) {
- ent->collide(*hit);
- }
- }
- }
- }
- }
- void scene::render() {
- for (auto & ent : entities) {
- renderer->draw(ent.render_info());
- }
- }
- void scene::handle_key_event(event::key_event evt) {
- if (evt.type & event::PRESSED_MASK && evt.key == keys::QUIT) {
- dispatch_.lock()->quit();
- }
- }
- void scene::handle_mouse_event(event::mouse_event evt) {}
- math::vec2 scene::size() const { return local_scene_dimension_; }
- key_binding const & scene::keys() const { return keys_; }
|