diff options
Diffstat (limited to 'src/components/map_render.cpp')
| -rw-r--r-- | src/components/map_render.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
| diff --git a/src/components/map_render.cpp b/src/components/map_render.cpp new file mode 100644 index 0000000..d93afe6 --- /dev/null +++ b/src/components/map_render.cpp | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #include "map_render.h" | ||
| 2 | #include "map.h" | ||
| 3 | #include "game.h" | ||
| 4 | |||
| 5 | MapRenderComponent::MapRenderComponent(const Map& map) : screen(GAME_WIDTH, GAME_HEIGHT) | ||
| 6 | { | ||
| 7 | screen.fill(screen.entirety(), 0, 0, 0); | ||
| 8 | |||
| 9 | Texture tiles("../res/tiles.png"); | ||
| 10 | |||
| 11 | for (int i=0; i<MAP_WIDTH*(MAP_HEIGHT-1); i++) | ||
| 12 | { | ||
| 13 | int tile = map.getMapdata()[i]; | ||
| 14 | int x = i % MAP_WIDTH; | ||
| 15 | int y = i / MAP_WIDTH; | ||
| 16 | Rectangle dst {x*TILE_WIDTH, y*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT}; | ||
| 17 | Rectangle src {tile%8*TILE_WIDTH, tile/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT}; | ||
| 18 | |||
| 19 | if (tile > 0) | ||
| 20 | { | ||
| 21 | screen.blit(tiles, src, dst); | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | Texture font("../res/font.bmp"); | ||
| 26 | const char* map_name = map.getTitle(); | ||
| 27 | int start_x = (40/2) - (strlen(map_name)/2); | ||
| 28 | for (size_t i=0; i<strlen(map_name); i++) | ||
| 29 | { | ||
| 30 | Rectangle srcRect {map_name[i] % 16 * 8, map_name[i] / 16 * 8, 8, 8}; | ||
| 31 | Rectangle dstRect {(start_x + (int)i)*8, 24*8, 8, 8}; | ||
| 32 | screen.blit(font, srcRect, dstRect); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | void MapRenderComponent::render(Game&, Entity&, Texture& buffer) | ||
| 37 | { | ||
| 38 | buffer.blit(screen, screen.entirety(), buffer.entirety()); | ||
| 39 | } | ||
