diff options
Diffstat (limited to 'src/simulation.cpp')
| -rw-r--r-- | src/simulation.cpp | 43 |
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 | ||
| 236 | void 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 | |||
| 236 | id_type Simulation::emplaceEntity() | 279 | id_type Simulation::emplaceEntity() |
| 237 | { | 280 | { |
| 238 | id_type nextId; | 281 | id_type nextId; |
