Map
Map.cpp@1:afa730298a2b, 2017-04-30 (annotated)
- Committer:
- JackCripps
- Date:
- Sun Apr 30 09:49:55 2017 +0000
- Revision:
- 1:afa730298a2b
- Parent:
- 0:1d3957b7699a
- Child:
- 2:2729d17161f4
Moved level background and it's drawing code to map class to tidy up code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JackCripps | 0:1d3957b7699a | 1 | #include "Map.h" |
JackCripps | 0:1d3957b7699a | 2 | |
JackCripps | 0:1d3957b7699a | 3 | Map::Map() |
JackCripps | 0:1d3957b7699a | 4 | : |
JackCripps | 1:afa730298a2b | 5 | // Instantiate the bitmap tile |
JackCripps | 0:1d3957b7699a | 6 | _tileImageBitmap(tileImage, 4, 4), |
JackCripps | 1:afa730298a2b | 7 | // Instantiate the bitmap level |
JackCripps | 1:afa730298a2b | 8 | _levelBackground(levelBackground, 48, 84), |
JackCripps | 0:1d3957b7699a | 9 | _cols(21), |
JackCripps | 0:1d3957b7699a | 10 | _rows(12) |
JackCripps | 0:1d3957b7699a | 11 | |
JackCripps | 0:1d3957b7699a | 12 | {} |
JackCripps | 0:1d3957b7699a | 13 | |
JackCripps | 0:1d3957b7699a | 14 | Map::~Map() |
JackCripps | 0:1d3957b7699a | 15 | { |
JackCripps | 0:1d3957b7699a | 16 | |
JackCripps | 0:1d3957b7699a | 17 | } |
JackCripps | 0:1d3957b7699a | 18 | |
JackCripps | 0:1d3957b7699a | 19 | void Map::draw(N5110& lcd) |
JackCripps | 0:1d3957b7699a | 20 | { |
JackCripps | 1:afa730298a2b | 21 | // Draw the background first so the tilemap renders on top |
JackCripps | 1:afa730298a2b | 22 | _levelBackground.render(lcd, 0, 0); |
JackCripps | 1:afa730298a2b | 23 | |
JackCripps | 1:afa730298a2b | 24 | // Calculate the screen pixel coordinate to draw the correct tile at |
JackCripps | 0:1d3957b7699a | 25 | for (int c = 0; c < _cols; c++) |
JackCripps | 0:1d3957b7699a | 26 | { |
JackCripps | 0:1d3957b7699a | 27 | for (int r = 0; r < _rows; r++) |
JackCripps | 0:1d3957b7699a | 28 | { |
JackCripps | 0:1d3957b7699a | 29 | if (this->getTile(c, r) != 0) |
JackCripps | 0:1d3957b7699a | 30 | { |
JackCripps | 1:afa730298a2b | 31 | //printf("c %d\tr %d\n", c, r); |
JackCripps | 1:afa730298a2b | 32 | // If the tile value is not 0, render a tile at the location |
JackCripps | 0:1d3957b7699a | 33 | _tileImageBitmap.render(lcd, c * tileSize, r * tileSize); |
JackCripps | 0:1d3957b7699a | 34 | } |
JackCripps | 0:1d3957b7699a | 35 | } |
JackCripps | 0:1d3957b7699a | 36 | } |
JackCripps | 0:1d3957b7699a | 37 | } |
JackCripps | 0:1d3957b7699a | 38 | |
JackCripps | 0:1d3957b7699a | 39 | int Map::getTile(int col, int row) |
JackCripps | 0:1d3957b7699a | 40 | { |
JackCripps | 1:afa730298a2b | 41 | // Return value of cell at the specifed col and row |
JackCripps | 0:1d3957b7699a | 42 | return tileMap[row * _cols + col]; |
JackCripps | 0:1d3957b7699a | 43 | } |
JackCripps | 0:1d3957b7699a | 44 | |
JackCripps | 1:afa730298a2b | 45 | /* |
JackCripps | 1:afa730298a2b | 46 | AABB Map::getAabbAtIndex(int col, int row) |
JackCripps | 1:afa730298a2b | 47 | { |
JackCripps | 1:afa730298a2b | 48 | // Create an AABB struct |
JackCripps | 1:afa730298a2b | 49 | AABB localAABB; |
JackCripps | 1:afa730298a2b | 50 | |
JackCripps | 1:afa730298a2b | 51 | // Store values of the AABB calculated from passed in col and row and the |
JackCripps | 1:afa730298a2b | 52 | // tiles size |
JackCripps | 1:afa730298a2b | 53 | localAABB.min.x = col * tileSize; |
JackCripps | 1:afa730298a2b | 54 | localAABB.max.x = (col * tileSize) + tileSize; |
JackCripps | 1:afa730298a2b | 55 | localAABB.min.y = row * tileSize; |
JackCripps | 1:afa730298a2b | 56 | localAABB.max.y = (row * tileSize) + tileSize; |
JackCripps | 1:afa730298a2b | 57 | |
JackCripps | 1:afa730298a2b | 58 | return localAABB; |
JackCripps | 1:afa730298a2b | 59 | } |
JackCripps | 1:afa730298a2b | 60 | */ |
JackCripps | 1:afa730298a2b | 61 | |
JackCripps | 1:afa730298a2b | 62 | int Map::getMaxCol() |
JackCripps | 1:afa730298a2b | 63 | { |
JackCripps | 1:afa730298a2b | 64 | return _cols; |
JackCripps | 1:afa730298a2b | 65 | } |
JackCripps | 1:afa730298a2b | 66 | |
JackCripps | 1:afa730298a2b | 67 | int Map::getMaxRow() |
JackCripps | 1:afa730298a2b | 68 | { |
JackCripps | 1:afa730298a2b | 69 | return _rows; |
JackCripps | 1:afa730298a2b | 70 | } |
JackCripps | 1:afa730298a2b | 71 | |
JackCripps | 0:1d3957b7699a | 72 | |
JackCripps | 0:1d3957b7699a | 73 | |
JackCripps | 0:1d3957b7699a | 74 |