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@4:3446009e2f38, 2019-05-07 (annotated)
- Committer:
- el17ttds
- Date:
- Tue May 07 19:25:20 2019 +0000
- Revision:
- 4:3446009e2f38
- Parent:
- 3:3d35ab70b565
- Child:
- 6:e8c03f264ffc
Free movement from engine not map
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 | 4:3446009e2f38 | 16 | void Map::write(int x1, int y1) { // uses origin of top left corner to create the map |
el17ttds | 4:3446009e2f38 | 17 | |
el17ttds | 4:3446009e2f38 | 18 | _x1 = x1; |
el17ttds | 4:3446009e2f38 | 19 | _x2 = _x1 + _width + (_swidth / 2); |
el17ttds | 4:3446009e2f38 | 20 | _y1 = y1; |
el17ttds | 4:3446009e2f38 | 21 | _y2 = _y1 + _height + (_sheight / 2); |
el17ttds | 4:3446009e2f38 | 22 | map_parameters(); |
el17ttds | 4:3446009e2f38 | 23 | } |
el17ttds | 4:3446009e2f38 | 24 | |
el17ttds | 4:3446009e2f38 | 25 | void Map::map_parameters() { |
el17ttds | 4:3446009e2f38 | 26 | horizontal(); |
el17ttds | 4:3446009e2f38 | 27 | veritical(); |
el17ttds | 2:ee9b361ba6df | 28 | } |
el17ttds | 2:ee9b361ba6df | 29 | |
el17ttds | 4:3446009e2f38 | 30 | void Map::horizontal() { |
el17ttds | 4:3446009e2f38 | 31 | if (_x1 < -(_swidth / 2)) { |
el17ttds | 4:3446009e2f38 | 32 | _x1_pos = -1; |
el17ttds | 4:3446009e2f38 | 33 | } else if (_x1 < 0) { |
el17ttds | 4:3446009e2f38 | 34 | _x1_pos = 0; |
el17ttds | 4:3446009e2f38 | 35 | _w = (_swidth / 2) + _x1; |
el17ttds | 4:3446009e2f38 | 36 | } else { |
el17ttds | 4:3446009e2f38 | 37 | _x1_pos = 0; |
el17ttds | 4:3446009e2f38 | 38 | _w = _swidth / 2; |
el17ttds | 4:3446009e2f38 | 39 | } |
el17ttds | 4:3446009e2f38 | 40 | if (_x2 < (_swidth / 2)) { |
el17ttds | 4:3446009e2f38 | 41 | _x2 = (_swidth / 2); |
el17ttds | 4:3446009e2f38 | 42 | // _x1 = -100; do this in Engine |
el17ttds | 4:3446009e2f38 | 43 | } |
el17ttds | 4:3446009e2f38 | 44 | } |
el17ttds | 3:3d35ab70b565 | 45 | |
el17ttds | 4:3446009e2f38 | 46 | void Map::veritical() { |
el17ttds | 4:3446009e2f38 | 47 | if (_y1 < -(_sheight / 2)) { |
el17ttds | 4:3446009e2f38 | 48 | _y1_pos = -1; |
el17ttds | 4:3446009e2f38 | 49 | } else if (_y1 < 0) { |
el17ttds | 4:3446009e2f38 | 50 | _y1_pos = 0; |
el17ttds | 4:3446009e2f38 | 51 | _h = (_sheight / 2) + _y1; |
el17ttds | 4:3446009e2f38 | 52 | } else { |
el17ttds | 4:3446009e2f38 | 53 | _y1_pos = 0; |
el17ttds | 4:3446009e2f38 | 54 | _h = _sheight / 2; |
el17ttds | 4:3446009e2f38 | 55 | } |
el17ttds | 4:3446009e2f38 | 56 | if (_y2 < (_sheight / 2)) { |
el17ttds | 4:3446009e2f38 | 57 | _y2 = (_sheight / 2); |
el17ttds | 4:3446009e2f38 | 58 | // _y1 = -100; do this in Engine |
el17ttds | 4:3446009e2f38 | 59 | } |
el17ttds | 2:ee9b361ba6df | 60 | } |
el17ttds | 2:ee9b361ba6df | 61 | |
el17ttds | 2:ee9b361ba6df | 62 | void Map::draw(N5110 &lcd) { |
el17ttds | 3:3d35ab70b565 | 63 | |
el17ttds | 3:3d35ab70b565 | 64 | lcd.drawRect(_x1_pos,0,_w,_sheight,FILL_BLACK); |
el17ttds | 3:3d35ab70b565 | 65 | lcd.drawRect(0,_y1_pos,_swidth,_h,FILL_BLACK); |
el17ttds | 3:3d35ab70b565 | 66 | lcd.drawRect(0,_y2,_swidth,_sheight / 2,FILL_BLACK); |
el17ttds | 3:3d35ab70b565 | 67 | lcd.drawRect(_x2,0,_swidth / 2,_sheight,FILL_BLACK); |
el17ttds | 4:3446009e2f38 | 68 | } |