diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-14 19:25:23 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-14 19:25:23 -0400 |
commit | 6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b (patch) | |
tree | 0a884ddd12b4e5b0afcc9c4ecaea5ecc73605b57 /src/components/map_render.cpp | |
parent | d9349f10d6d1972e87aea76d502703fae128a0e5 (diff) | |
download | therapy-6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b.tar.gz therapy-6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b.tar.bz2 therapy-6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b.zip |
Added sound when you hit the ground
Also split up components.cpp into files for each class, fixed a bug concerning falling off the screen when you change maps, and converted collision data into doubles.
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 | } | ||