Hu Dongyu
/
HuDongyu
publish my project
Me/Me.cpp@7:4b92c1ee6231, 2020-04-29 (annotated)
- Committer:
- dongyuhu
- Date:
- Wed Apr 29 10:51:02 2020 +0000
- Revision:
- 7:4b92c1ee6231
- Parent:
- 0:9e95a5ef2659
publish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dongyuhu | 0:9e95a5ef2659 | 1 | #include "Me.h" |
dongyuhu | 0:9e95a5ef2659 | 2 | |
dongyuhu | 0:9e95a5ef2659 | 3 | Me::Me() |
dongyuhu | 0:9e95a5ef2659 | 4 | { |
dongyuhu | 0:9e95a5ef2659 | 5 | |
dongyuhu | 0:9e95a5ef2659 | 6 | } |
dongyuhu | 0:9e95a5ef2659 | 7 | |
dongyuhu | 0:9e95a5ef2659 | 8 | Me::~Me() |
dongyuhu | 0:9e95a5ef2659 | 9 | { |
dongyuhu | 0:9e95a5ef2659 | 10 | |
dongyuhu | 0:9e95a5ef2659 | 11 | } |
dongyuhu | 0:9e95a5ef2659 | 12 | |
dongyuhu | 0:9e95a5ef2659 | 13 | void Me::init(int x,int y,int height,int width) |
dongyuhu | 0:9e95a5ef2659 | 14 | { |
dongyuhu | 0:9e95a5ef2659 | 15 | _x = 41; //Initially set in the center of the screen |
dongyuhu | 0:9e95a5ef2659 | 16 | _y = 23; |
dongyuhu | 0:9e95a5ef2659 | 17 | _height = height; //3 The colltroller is 3 by 3 |
dongyuhu | 0:9e95a5ef2659 | 18 | _width = width; //3 |
dongyuhu | 0:9e95a5ef2659 | 19 | _speed = 2; |
dongyuhu | 0:9e95a5ef2659 | 20 | |
dongyuhu | 0:9e95a5ef2659 | 21 | } |
dongyuhu | 0:9e95a5ef2659 | 22 | |
dongyuhu | 0:9e95a5ef2659 | 23 | void Me::draw(N5110 &lcd) |
dongyuhu | 0:9e95a5ef2659 | 24 | { |
dongyuhu | 0:9e95a5ef2659 | 25 | |
dongyuhu | 0:9e95a5ef2659 | 26 | lcd.drawRect(_x,_y,_width,_height,FILL_BLACK); |
dongyuhu | 0:9e95a5ef2659 | 27 | } |
dongyuhu | 0:9e95a5ef2659 | 28 | |
dongyuhu | 0:9e95a5ef2659 | 29 | void Me::update(Direction d) |
dongyuhu | 0:9e95a5ef2659 | 30 | { |
dongyuhu | 0:9e95a5ef2659 | 31 | _speed =2; // scale is arbitrary, could be changed in future |
dongyuhu | 0:9e95a5ef2659 | 32 | |
dongyuhu | 0:9e95a5ef2659 | 33 | |
dongyuhu | 0:9e95a5ef2659 | 34 | if (d == N) { |
dongyuhu | 0:9e95a5ef2659 | 35 | _y-=_speed; //_y=_y-speed; |
dongyuhu | 0:9e95a5ef2659 | 36 | } if (d == S) { |
dongyuhu | 0:9e95a5ef2659 | 37 | _y+=_speed; |
dongyuhu | 0:9e95a5ef2659 | 38 | } if (d == E) { |
dongyuhu | 0:9e95a5ef2659 | 39 | _x+=_speed; //_x=_x+speed; |
dongyuhu | 0:9e95a5ef2659 | 40 | } if (d == W) { |
dongyuhu | 0:9e95a5ef2659 | 41 | _x-=_speed; |
dongyuhu | 0:9e95a5ef2659 | 42 | } |
dongyuhu | 0:9e95a5ef2659 | 43 | |
dongyuhu | 0:9e95a5ef2659 | 44 | if (_y < 11) { |
dongyuhu | 0:9e95a5ef2659 | 45 | _y = 11; //coboundary |
dongyuhu | 0:9e95a5ef2659 | 46 | } |
dongyuhu | 0:9e95a5ef2659 | 47 | if (_y > 34) { //lower boundary |
dongyuhu | 0:9e95a5ef2659 | 48 | _y = 34; |
dongyuhu | 0:9e95a5ef2659 | 49 | } |
dongyuhu | 0:9e95a5ef2659 | 50 | if (_x < 11) { //left border |
dongyuhu | 0:9e95a5ef2659 | 51 | _x = 11; |
dongyuhu | 0:9e95a5ef2659 | 52 | } |
dongyuhu | 0:9e95a5ef2659 | 53 | if (_x > 70) { //right border |
dongyuhu | 0:9e95a5ef2659 | 54 | _x = 70; |
dongyuhu | 0:9e95a5ef2659 | 55 | } |
dongyuhu | 0:9e95a5ef2659 | 56 | |
dongyuhu | 0:9e95a5ef2659 | 57 | } |
dongyuhu | 0:9e95a5ef2659 | 58 | |
dongyuhu | 0:9e95a5ef2659 | 59 | |
dongyuhu | 0:9e95a5ef2659 | 60 | Vector2D Me::get_pos() { |
dongyuhu | 0:9e95a5ef2659 | 61 | Vector2D p = {_x,_y}; |
dongyuhu | 0:9e95a5ef2659 | 62 | return p; |
dongyuhu | 0:9e95a5ef2659 | 63 | } |