diff options
Diffstat (limited to 'src/level.cpp')
| -rw-r--r-- | src/level.cpp | 41 | 
1 files changed, 24 insertions, 17 deletions
| diff --git a/src/level.cpp b/src/level.cpp index b97eb70..e22a43f 100644 --- a/src/level.cpp +++ b/src/level.cpp | |||
| @@ -7,30 +7,37 @@ texture_ptr Level::render(SDL_Renderer* ren, Layer layer) const | |||
| 7 | ren, | 7 | ren, | 
| 8 | SDL_PIXELFORMAT_RGBA8888, | 8 | SDL_PIXELFORMAT_RGBA8888, | 
| 9 | SDL_TEXTUREACCESS_TARGET, | 9 | SDL_TEXTUREACCESS_TARGET, | 
| 10 | WINDOW_SIZE.w(), | 10 | LEVEL_SIZE.w(), | 
| 11 | WINDOW_SIZE.h())); | 11 | LEVEL_SIZE.h())); | 
| 12 | 12 | ||
| 13 | SDL_SetRenderTarget(ren, canvas.get()); | 13 | SDL_SetRenderTarget(ren, canvas.get()); | 
| 14 | SDL_SetTextureBlendMode(canvas.get(), SDL_BLENDMODE_BLEND); | ||
| 15 | SDL_SetRenderDrawColor(ren, 0, 0, 0, 0); | ||
| 16 | SDL_RenderFillRect(ren, nullptr); | ||
| 14 | 17 | ||
| 15 | for (size_t y = 0; y < size_.h(); y++) | 18 | for (size_t y = 0; y < size_.h(); y++) | 
| 16 | { | 19 | { | 
| 17 | for (size_t x = 0; x < size_.w(); x++) | 20 | for (size_t x = 0; x < size_.w(); x++) | 
| 18 | { | 21 | { | 
| 19 | if (layer == Layer::map) | 22 | SDL_Rect src { | 
| 20 | { | 23 | 0, | 
| 21 | int val = 255 - at(x, y) * 10; | 24 | static_cast<int>(at(x, y, layer) * TILE_SIZE.h()), | 
| 22 | 25 | TILE_SIZE.w(), | |
| 23 | SDL_SetRenderDrawColor(ren, val, val, val, 255); | 26 | TILE_SIZE.h() | 
| 24 | 27 | }; | |
| 25 | SDL_Rect rect { | 28 | |
| 26 | static_cast<int>(x * TILE_SIZE.w()), | 29 | SDL_Rect dest { | 
| 27 | static_cast<int>(y * TILE_SIZE.h()), | 30 | static_cast<int>(x * TILE_SIZE.w()), | 
| 28 | TILE_SIZE.w(), | 31 | static_cast<int>(y * TILE_SIZE.h()), | 
| 29 | TILE_SIZE.h() | 32 | TILE_SIZE.w(), | 
| 30 | }; | 33 | TILE_SIZE.h() | 
| 31 | 34 | }; | |
| 32 | SDL_RenderFillRect(ren, &rect); | 35 | |
| 33 | } | 36 | SDL_RenderCopy( | 
| 37 | ren, | ||
| 38 | getTileset(layer).getImage().get(), | ||
| 39 | &src, | ||
| 40 | &dest); | ||
| 34 | } | 41 | } | 
| 35 | } | 42 | } | 
| 36 | 43 | ||
