summary refs log tree commit diff stats
path: root/src/simulation.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2019-02-24 12:30:40 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2019-02-24 12:30:40 -0500
commit90b9831d6fb89feedeec63cb392c4535c5df60fe (patch)
tree78faf1865bc0566454254d072b85f872bbc585ea /src/simulation.cpp
parentf264cfd7655a48f7e9a6e2fc5b1c62d6d2036025 (diff)
downloaddispatcher-90b9831d6fb89feedeec63cb392c4535c5df60fe.tar.gz
dispatcher-90b9831d6fb89feedeec63cb392c4535c5df60fe.tar.bz2
dispatcher-90b9831d6fb89feedeec63cb392c4535c5df60fe.zip
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.
Diffstat (limited to 'src/simulation.cpp')
-rw-r--r--src/simulation.cpp43
1 files changed, 43 insertions, 0 deletions
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(
233 } 233 }
234} 234}
235 235
236void Simulation::render(SDL_Renderer* ren)
237{
238 for (size_t y = 0; y < level_.getSize().h(); y++)
239 {
240 for (size_t x = 0; x < level_.getSize().w(); x++)
241 {
242 int val = 255 - level_.at(x, y) * 10;
243
244 SDL_SetRenderDrawColor(ren, val, val, val, 255);
245
246 SDL_Rect rect {
247 static_cast<int>(x * TILE_SIZE.w()),
248 static_cast<int>(y * TILE_SIZE.h()),
249 TILE_SIZE.w(),
250 TILE_SIZE.h()
251 };
252
253 SDL_RenderFillRect(ren, &rect);
254 }
255 }
256
257 constexpr Layer renderOrder[] = { Layer::track, Layer::object };
258
259 ranges::for_each(
260 ranges::view::for_each(
261 renderOrder,
262 [&] (Layer layer) {
263 return entityRange() | views::isOnLayer(layer);
264 }),
265 [&] (const Entity& entity) {
266 SDL_SetRenderDrawColor(ren, entity.colorVal, entity.colorVal, 65, 255);
267
268 SDL_Rect rect {
269 static_cast<int>(entity.pos.x()),
270 static_cast<int>(entity.pos.y()),
271 static_cast<int>(entity.size.w()),
272 static_cast<int>(entity.size.h())
273 };
274
275 SDL_RenderFillRect(ren, &rect);
276 });
277}
278
236id_type Simulation::emplaceEntity() 279id_type Simulation::emplaceEntity()
237{ 280{
238 id_type nextId; 281 id_type nextId;