200943373MAZE
Dependencies: Gamepad N5110 mbed
Player/Player.cpp@0:df4347043adf, 2017-05-04 (annotated)
- Committer:
- hongyunAHN
- Date:
- Thu May 04 11:25:43 2017 +0000
- Revision:
- 0:df4347043adf
200943373 hongyun AHN
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hongyunAHN | 0:df4347043adf | 1 | #include "Player.h" |
hongyunAHN | 0:df4347043adf | 2 | //#include "Background.h" |
hongyunAHN | 0:df4347043adf | 3 | Player::Player() |
hongyunAHN | 0:df4347043adf | 4 | { |
hongyunAHN | 0:df4347043adf | 5 | |
hongyunAHN | 0:df4347043adf | 6 | } |
hongyunAHN | 0:df4347043adf | 7 | Player::~Player() |
hongyunAHN | 0:df4347043adf | 8 | { |
hongyunAHN | 0:df4347043adf | 9 | |
hongyunAHN | 0:df4347043adf | 10 | } |
hongyunAHN | 0:df4347043adf | 11 | |
hongyunAHN | 0:df4347043adf | 12 | void Player::init(){ |
hongyunAHN | 0:df4347043adf | 13 | |
hongyunAHN | 0:df4347043adf | 14 | |
hongyunAHN | 0:df4347043adf | 15 | const char array[3][3]={ |
hongyunAHN | 0:df4347043adf | 16 | {1,1,1}, |
hongyunAHN | 0:df4347043adf | 17 | {1,1,1}, |
hongyunAHN | 0:df4347043adf | 18 | {1,1,1}, |
hongyunAHN | 0:df4347043adf | 19 | }; |
hongyunAHN | 0:df4347043adf | 20 | |
hongyunAHN | 0:df4347043adf | 21 | _x==2; |
hongyunAHN | 0:df4347043adf | 22 | _y==2; |
hongyunAHN | 0:df4347043adf | 23 | |
hongyunAHN | 0:df4347043adf | 24 | |
hongyunAHN | 0:df4347043adf | 25 | } |
hongyunAHN | 0:df4347043adf | 26 | |
hongyunAHN | 0:df4347043adf | 27 | void Player::update(Direction d,N5110 &lcd,Gamepad &pad) |
hongyunAHN | 0:df4347043adf | 28 | { |
hongyunAHN | 0:df4347043adf | 29 | |
hongyunAHN | 0:df4347043adf | 30 | const char map[48][85] = _background.draw(N5110 &lcd); |
hongyunAHN | 0:df4347043adf | 31 | Vector2D monsterPos = get_pos(); |
hongyunAHN | 0:df4347043adf | 32 | if(A_PRESSED==1){ |
hongyunAHN | 0:df4347043adf | 33 | if(map[_y][_x+5]==1){ |
hongyunAHN | 0:df4347043adf | 34 | _x==_x; |
hongyunAHN | 0:df4347043adf | 35 | _y==_y; |
hongyunAHN | 0:df4347043adf | 36 | } |
hongyunAHN | 0:df4347043adf | 37 | else{ |
hongyunAHN | 0:df4347043adf | 38 | _x+5==_x; |
hongyunAHN | 0:df4347043adf | 39 | _y==_y; |
hongyunAHN | 0:df4347043adf | 40 | } |
hongyunAHN | 0:df4347043adf | 41 | } |
hongyunAHN | 0:df4347043adf | 42 | else if (B_PRESSED==1){ |
hongyunAHN | 0:df4347043adf | 43 | if(map[_y+5][_x]==1){ |
hongyunAHN | 0:df4347043adf | 44 | _x==_x; |
hongyunAHN | 0:df4347043adf | 45 | _y==_y; |
hongyunAHN | 0:df4347043adf | 46 | } |
hongyunAHN | 0:df4347043adf | 47 | else{ _x==_x; |
hongyunAHN | 0:df4347043adf | 48 | _y+5==_y; |
hongyunAHN | 0:df4347043adf | 49 | } |
hongyunAHN | 0:df4347043adf | 50 | } |
hongyunAHN | 0:df4347043adf | 51 | else if (d == N) { |
hongyunAHN | 0:df4347043adf | 52 | if(map[_y+3][_x]==1){ |
hongyunAHN | 0:df4347043adf | 53 | _x==_x; |
hongyunAHN | 0:df4347043adf | 54 | _y==_y; |
hongyunAHN | 0:df4347043adf | 55 | } |
hongyunAHN | 0:df4347043adf | 56 | else if (map[_y+3][_x+2]==1){ |
hongyunAHN | 0:df4347043adf | 57 | _x==_x; |
hongyunAHN | 0:df4347043adf | 58 | _y==_y; |
hongyunAHN | 0:df4347043adf | 59 | } |
hongyunAHN | 0:df4347043adf | 60 | else{ |
hongyunAHN | 0:df4347043adf | 61 | _x==_x; |
hongyunAHN | 0:df4347043adf | 62 | _y+1==_y; |
hongyunAHN | 0:df4347043adf | 63 | |
hongyunAHN | 0:df4347043adf | 64 | } |
hongyunAHN | 0:df4347043adf | 65 | } |
hongyunAHN | 0:df4347043adf | 66 | else if (d == S) { |
hongyunAHN | 0:df4347043adf | 67 | if(map[_y-1][_x]==1){ |
hongyunAHN | 0:df4347043adf | 68 | _x==_x; |
hongyunAHN | 0:df4347043adf | 69 | _y==_y; |
hongyunAHN | 0:df4347043adf | 70 | } |
hongyunAHN | 0:df4347043adf | 71 | else if(map[_y-1][_x+2]==1){ |
hongyunAHN | 0:df4347043adf | 72 | _x==_x; |
hongyunAHN | 0:df4347043adf | 73 | _y==_y; |
hongyunAHN | 0:df4347043adf | 74 | } |
hongyunAHN | 0:df4347043adf | 75 | else{ |
hongyunAHN | 0:df4347043adf | 76 | _x==_x; |
hongyunAHN | 0:df4347043adf | 77 | _y-1==_y; |
hongyunAHN | 0:df4347043adf | 78 | ; |
hongyunAHN | 0:df4347043adf | 79 | } |
hongyunAHN | 0:df4347043adf | 80 | }else if (d == W) { |
hongyunAHN | 0:df4347043adf | 81 | if(map[_y][_x-1]==1){ |
hongyunAHN | 0:df4347043adf | 82 | _x==_x; |
hongyunAHN | 0:df4347043adf | 83 | _y==_y;; |
hongyunAHN | 0:df4347043adf | 84 | } |
hongyunAHN | 0:df4347043adf | 85 | else if(map[_y+2][_x-1]==1){ |
hongyunAHN | 0:df4347043adf | 86 | _x==_x; |
hongyunAHN | 0:df4347043adf | 87 | _y==_y; |
hongyunAHN | 0:df4347043adf | 88 | } |
hongyunAHN | 0:df4347043adf | 89 | else{ |
hongyunAHN | 0:df4347043adf | 90 | _x-1==_x; |
hongyunAHN | 0:df4347043adf | 91 | _y==_y; |
hongyunAHN | 0:df4347043adf | 92 | |
hongyunAHN | 0:df4347043adf | 93 | } |
hongyunAHN | 0:df4347043adf | 94 | }else if (d == E) { |
hongyunAHN | 0:df4347043adf | 95 | if(map[_y][_x+3]==1){ |
hongyunAHN | 0:df4347043adf | 96 | _x==_x; |
hongyunAHN | 0:df4347043adf | 97 | _y==_y; |
hongyunAHN | 0:df4347043adf | 98 | } |
hongyunAHN | 0:df4347043adf | 99 | else if(map[_y+2][_x+3]==1){ |
hongyunAHN | 0:df4347043adf | 100 | _x==_x; |
hongyunAHN | 0:df4347043adf | 101 | _y==_y; |
hongyunAHN | 0:df4347043adf | 102 | } |
hongyunAHN | 0:df4347043adf | 103 | else{ |
hongyunAHN | 0:df4347043adf | 104 | _x+1==_x; |
hongyunAHN | 0:df4347043adf | 105 | _y==_y; |
hongyunAHN | 0:df4347043adf | 106 | |
hongyunAHN | 0:df4347043adf | 107 | } |
hongyunAHN | 0:df4347043adf | 108 | } |
hongyunAHN | 0:df4347043adf | 109 | } |
hongyunAHN | 0:df4347043adf | 110 | |
hongyunAHN | 0:df4347043adf | 111 | |
hongyunAHN | 0:df4347043adf | 112 | Vector2D Player::get_pos() { |
hongyunAHN | 0:df4347043adf | 113 | Vector2D p = {_x,_y}; |
hongyunAHN | 0:df4347043adf | 114 | return p; |
hongyunAHN | 0:df4347043adf | 115 | } |