Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Map/Map.cpp@9:3a0194c87afe, 2019-05-12 (annotated)
- Committer:
- el17ttds
- Date:
- Sun May 12 16:21:08 2019 +0000
- Revision:
- 9:3a0194c87afe
- Parent:
- 6:e8c03f264ffc
Final Submission. I have read and agreed with Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17ttds | 2:ee9b361ba6df | 1 | #include "Map.h" |
el17ttds | 2:ee9b361ba6df | 2 | |
el17ttds | 2:ee9b361ba6df | 3 | Map::Map() { |
el17ttds | 2:ee9b361ba6df | 4 | |
el17ttds | 2:ee9b361ba6df | 5 | } |
el17ttds | 2:ee9b361ba6df | 6 | |
el17ttds | 3:3d35ab70b565 | 7 | void Map::init(int width, int height, int swidth, int sheight) { // initialises map dimensions |
el17ttds | 3:3d35ab70b565 | 8 | _swidth = swidth; |
el17ttds | 3:3d35ab70b565 | 9 | _sheight = sheight; |
el17ttds | 4:3446009e2f38 | 10 | _width = width; |
el17ttds | 4:3446009e2f38 | 11 | _height = height; |
el17ttds | 3:3d35ab70b565 | 12 | _w = 0; |
el17ttds | 3:3d35ab70b565 | 13 | _h = 0; |
el17ttds | 4:3446009e2f38 | 14 | } |
el17ttds | 4:3446009e2f38 | 15 | |
el17ttds | 9:3a0194c87afe | 16 | void Map::write(int x1, int y1) { // uses top left corner as origin to create the map |
el17ttds | 9:3a0194c87afe | 17 | _x1 = x1 - 5; |
el17ttds | 4:3446009e2f38 | 18 | _x2 = _x1 + _width + (_swidth / 2); |
el17ttds | 9:3a0194c87afe | 19 | _y1 = y1 - 5; |
el17ttds | 4:3446009e2f38 | 20 | _y2 = _y1 + _height + (_sheight / 2); |
el17ttds | 4:3446009e2f38 | 21 | map_parameters(); |
el17ttds | 4:3446009e2f38 | 22 | } |
el17ttds | 4:3446009e2f38 | 23 | |
el17ttds | 4:3446009e2f38 | 24 | void Map::map_parameters() { |
el17ttds | 4:3446009e2f38 | 25 | horizontal(); |
el17ttds | 4:3446009e2f38 | 26 | veritical(); |
el17ttds | 2:ee9b361ba6df | 27 | } |
el17ttds | 2:ee9b361ba6df | 28 | |
el17ttds | 4:3446009e2f38 | 29 | void Map::horizontal() { |
el17ttds | 9:3a0194c87afe | 30 | if (_x1 < -(_swidth / 2) ) { |
el17ttds | 4:3446009e2f38 | 31 | _x1_pos = -1; |
el17ttds | 4:3446009e2f38 | 32 | } else if (_x1 < 0) { |
el17ttds | 4:3446009e2f38 | 33 | _x1_pos = 0; |
el17ttds | 4:3446009e2f38 | 34 | _w = (_swidth / 2) + _x1; |
el17ttds | 4:3446009e2f38 | 35 | } else { |
el17ttds | 4:3446009e2f38 | 36 | _x1_pos = 0; |
el17ttds | 9:3a0194c87afe | 37 | _w = _swidth / 2 - 5; |
el17ttds | 4:3446009e2f38 | 38 | } |
el17ttds | 4:3446009e2f38 | 39 | } |
el17ttds | 3:3d35ab70b565 | 40 | |
el17ttds | 4:3446009e2f38 | 41 | void Map::veritical() { |
el17ttds | 9:3a0194c87afe | 42 | if (_y1 < -(_sheight / 2) ) { |
el17ttds | 4:3446009e2f38 | 43 | _y1_pos = -1; |
el17ttds | 4:3446009e2f38 | 44 | } else if (_y1 < 0) { |
el17ttds | 4:3446009e2f38 | 45 | _y1_pos = 0; |
el17ttds | 4:3446009e2f38 | 46 | _h = (_sheight / 2) + _y1; |
el17ttds | 4:3446009e2f38 | 47 | } else { |
el17ttds | 4:3446009e2f38 | 48 | _y1_pos = 0; |
el17ttds | 9:3a0194c87afe | 49 | _h = _sheight / 2 - 5; |
el17ttds | 4:3446009e2f38 | 50 | } |
el17ttds | 2:ee9b361ba6df | 51 | } |
el17ttds | 2:ee9b361ba6df | 52 | |
el17ttds | 2:ee9b361ba6df | 53 | void Map::draw(N5110 &lcd) { |
el17ttds | 3:3d35ab70b565 | 54 | |
el17ttds | 3:3d35ab70b565 | 55 | lcd.drawRect(_x1_pos,0,_w,_sheight,FILL_BLACK); |
el17ttds | 3:3d35ab70b565 | 56 | lcd.drawRect(0,_y1_pos,_swidth,_h,FILL_BLACK); |
el17ttds | 9:3a0194c87afe | 57 | lcd.drawRect(0,_y2 + 11,_swidth,(_sheight / 2),FILL_BLACK); |
el17ttds | 9:3a0194c87afe | 58 | lcd.drawRect(_x2 + 11,0,(_swidth / 2),_sheight,FILL_BLACK); |
el17ttds | 4:3446009e2f38 | 59 | } |