From 90b9831d6fb89feedeec63cb392c4535c5df60fe Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 24 Feb 2019 12:30:40 -0500 Subject: Started state machine The "--editor" flag can be passed to the program to start it in editor mode, which is currently nothing. The Renderer class was removed here, as each state basically needs to do its own rendering. However, refactoring to make this more elegant will probably occur in the future. --- src/simulation.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/simulation.cpp') diff --git a/src/simulation.cpp b/src/simulation.cpp index a43a4e8..317e010 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -233,6 +233,49 @@ void Simulation::tick( } } +void Simulation::render(SDL_Renderer* ren) +{ + for (size_t y = 0; y < level_.getSize().h(); y++) + { + for (size_t x = 0; x < level_.getSize().w(); x++) + { + int val = 255 - level_.at(x, y) * 10; + + SDL_SetRenderDrawColor(ren, val, val, val, 255); + + SDL_Rect rect { + static_cast(x * TILE_SIZE.w()), + static_cast(y * TILE_SIZE.h()), + TILE_SIZE.w(), + TILE_SIZE.h() + }; + + SDL_RenderFillRect(ren, &rect); + } + } + + constexpr Layer renderOrder[] = { Layer::track, Layer::object }; + + ranges::for_each( + ranges::view::for_each( + renderOrder, + [&] (Layer layer) { + return entityRange() | views::isOnLayer(layer); + }), + [&] (const Entity& entity) { + SDL_SetRenderDrawColor(ren, entity.colorVal, entity.colorVal, 65, 255); + + SDL_Rect rect { + static_cast(entity.pos.x()), + static_cast(entity.pos.y()), + static_cast(entity.size.w()), + static_cast(entity.size.h()) + }; + + SDL_RenderFillRect(ren, &rect); + }); +} + id_type Simulation::emplaceEntity() { id_type nextId; -- cgit 1.4.1