Map
Map.cpp@4:96dca7f7f651, 2017-05-04 (annotated)
- Committer:
- JackCripps
- Date:
- Thu May 04 06:55:43 2017 +0000
- Revision:
- 4:96dca7f7f651
- Parent:
- 2:2729d17161f4
Final commit, everything working, Added some references
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 | 4:96dca7f7f651 | 41 | // Return value of cell at the specifed col and row using row-major indexing |
JackCripps | 4:96dca7f7f651 | 42 | // as from Alex Valavanis Bitmap library |
JackCripps | 0:1d3957b7699a | 43 | return tileMap[row * _cols + col]; |
JackCripps | 0:1d3957b7699a | 44 | } |
JackCripps | 0:1d3957b7699a | 45 | |
JackCripps | 1:afa730298a2b | 46 | /* |
JackCripps | 1:afa730298a2b | 47 | AABB Map::getAabbAtIndex(int col, int row) |
JackCripps | 1:afa730298a2b | 48 | { |
JackCripps | 1:afa730298a2b | 49 | // Create an AABB struct |
JackCripps | 1:afa730298a2b | 50 | AABB localAABB; |
JackCripps | 1:afa730298a2b | 51 | |
JackCripps | 1:afa730298a2b | 52 | // Store values of the AABB calculated from passed in col and row and the |
JackCripps | 1:afa730298a2b | 53 | // tiles size |
JackCripps | 1:afa730298a2b | 54 | localAABB.min.x = col * tileSize; |
JackCripps | 1:afa730298a2b | 55 | localAABB.max.x = (col * tileSize) + tileSize; |
JackCripps | 1:afa730298a2b | 56 | localAABB.min.y = row * tileSize; |
JackCripps | 1:afa730298a2b | 57 | localAABB.max.y = (row * tileSize) + tileSize; |
JackCripps | 1:afa730298a2b | 58 | |
JackCripps | 1:afa730298a2b | 59 | return localAABB; |
JackCripps | 1:afa730298a2b | 60 | } |
JackCripps | 1:afa730298a2b | 61 | */ |
JackCripps | 1:afa730298a2b | 62 | |
JackCripps | 1:afa730298a2b | 63 | int Map::getMaxCol() |
JackCripps | 1:afa730298a2b | 64 | { |
JackCripps | 1:afa730298a2b | 65 | return _cols; |
JackCripps | 1:afa730298a2b | 66 | } |
JackCripps | 1:afa730298a2b | 67 | |
JackCripps | 1:afa730298a2b | 68 | int Map::getMaxRow() |
JackCripps | 1:afa730298a2b | 69 | { |
JackCripps | 1:afa730298a2b | 70 | return _rows; |
JackCripps | 1:afa730298a2b | 71 | } |
JackCripps | 1:afa730298a2b | 72 | |
JackCripps | 2:2729d17161f4 | 73 | int Map::getTileSize() |
JackCripps | 2:2729d17161f4 | 74 | { |
JackCripps | 2:2729d17161f4 | 75 | return tileSize; |
JackCripps | 2:2729d17161f4 | 76 | } |
JackCripps | 0:1d3957b7699a | 77 | |
JackCripps | 0:1d3957b7699a | 78 | |
JackCripps | 0:1d3957b7699a | 79 | |
JackCripps | 2:2729d17161f4 | 80 |