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@3:3d35ab70b565, 2019-05-06 (annotated)
- Committer:
- el17ttds
- Date:
- Mon May 06 19:50:27 2019 +0000
- Revision:
- 3:3d35ab70b565
- Parent:
- 2:ee9b361ba6df
- Child:
- 4:3446009e2f38
Full movement on 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 | 3:3d35ab70b565 | 10 | _w = 0; |
el17ttds | 3:3d35ab70b565 | 11 | _h = 0; |
el17ttds | 3:3d35ab70b565 | 12 | _x1 = -(_swidth / 2) - (width - 84) / 2; |
el17ttds | 3:3d35ab70b565 | 13 | _x2 = _swidth + (width - 84) / 2; //84 + (_w - 84) / 2; |
el17ttds | 3:3d35ab70b565 | 14 | _y1 = -(_sheight) - (height - _sheight) / 2; //-24 - (_h - 48) / 2; |
el17ttds | 3:3d35ab70b565 | 15 | _y2 = _sheight + (height - _sheight) / 2; //48 + (_h - 48) / 2; |
el17ttds | 2:ee9b361ba6df | 16 | } |
el17ttds | 2:ee9b361ba6df | 17 | |
el17ttds | 3:3d35ab70b565 | 18 | void Map::write(int pix_x, int pix_y) { // Builds new parameters of map |
el17ttds | 3:3d35ab70b565 | 19 | |
el17ttds | 3:3d35ab70b565 | 20 | _x1 += pix_x; |
el17ttds | 3:3d35ab70b565 | 21 | _x2 += pix_x; |
el17ttds | 3:3d35ab70b565 | 22 | _y1 += pix_y; |
el17ttds | 3:3d35ab70b565 | 23 | _y2 += pix_y; |
el17ttds | 3:3d35ab70b565 | 24 | |
el17ttds | 3:3d35ab70b565 | 25 | if (_x1 < -(_swidth / 2)) { |
el17ttds | 3:3d35ab70b565 | 26 | _x1_pos = -1; |
el17ttds | 3:3d35ab70b565 | 27 | } else if (_x1 < 0) { |
el17ttds | 3:3d35ab70b565 | 28 | _x1_pos = 0; |
el17ttds | 3:3d35ab70b565 | 29 | _w = (_swidth / 2) + _x1; |
el17ttds | 3:3d35ab70b565 | 30 | } else { |
el17ttds | 2:ee9b361ba6df | 31 | _x1 = 0; |
el17ttds | 3:3d35ab70b565 | 32 | _x1_pos = 0; |
el17ttds | 3:3d35ab70b565 | 33 | _w = _swidth / 2; |
el17ttds | 2:ee9b361ba6df | 34 | } |
el17ttds | 3:3d35ab70b565 | 35 | if (_y1 < -(_sheight / 2)) { |
el17ttds | 3:3d35ab70b565 | 36 | _y1_pos = -1; |
el17ttds | 3:3d35ab70b565 | 37 | } else if (_y1 < 0) { |
el17ttds | 3:3d35ab70b565 | 38 | _y1_pos = 0; |
el17ttds | 3:3d35ab70b565 | 39 | _h = (_sheight / 2) + _y1; |
el17ttds | 3:3d35ab70b565 | 40 | } else { |
el17ttds | 2:ee9b361ba6df | 41 | _y1 = 0; |
el17ttds | 3:3d35ab70b565 | 42 | _y1_pos = 0; |
el17ttds | 3:3d35ab70b565 | 43 | _h = _sheight / 2; |
el17ttds | 2:ee9b361ba6df | 44 | } |
el17ttds | 3:3d35ab70b565 | 45 | if (_y2 < (_sheight / 2)) { |
el17ttds | 3:3d35ab70b565 | 46 | _y2 = (_sheight / 2); |
el17ttds | 3:3d35ab70b565 | 47 | } |
el17ttds | 3:3d35ab70b565 | 48 | if (_x2 < (_swidth / 2)) { |
el17ttds | 3:3d35ab70b565 | 49 | _x2 = (_swidth / 2); |
el17ttds | 2:ee9b361ba6df | 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 | 3:3d35ab70b565 | 57 | lcd.drawRect(0,_y2,_swidth,_sheight / 2,FILL_BLACK); |
el17ttds | 3:3d35ab70b565 | 58 | lcd.drawRect(_x2,0,_swidth / 2,_sheight,FILL_BLACK); |
el17ttds | 2:ee9b361ba6df | 59 | } |