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.
Dependencies: mbed
Minerengine.cpp@7:c6e6ec0e3396, 2019-03-25 (annotated)
- Committer:
- el17arm
- Date:
- Mon Mar 25 11:19:20 2019 +0000
- Revision:
- 7:c6e6ec0e3396
- Parent:
- 6:866281ce2b44
- Child:
- 8:9bc80e40ac0d
back up
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17arm | 0:fe19852199d2 | 1 | #include "Minerengine.h" |
| el17arm | 0:fe19852199d2 | 2 | |
| el17arm | 7:c6e6ec0e3396 | 3 | int _x; |
| el17arm | 7:c6e6ec0e3396 | 4 | int _y; |
| el17arm | 7:c6e6ec0e3396 | 5 | |
| el17arm | 0:fe19852199d2 | 6 | Minerengine::Minerengine() |
| el17arm | 2:725c213b2396 | 7 | |
| el17arm | 0:fe19852199d2 | 8 | { |
| el17arm | 0:fe19852199d2 | 9 | } |
| el17arm | 0:fe19852199d2 | 10 | |
| el17arm | 1:813ba5341985 | 11 | Minerengine::~Minerengine() |
| el17arm | 0:fe19852199d2 | 12 | { |
| el17arm | 1:813ba5341985 | 13 | } |
| el17arm | 0:fe19852199d2 | 14 | |
| el17arm | 7:c6e6ec0e3396 | 15 | /*void Minerengine::miner_init() |
| el17arm | 7:c6e6ec0e3396 | 16 | { |
| el17arm | 7:c6e6ec0e3396 | 17 | _x = 3; |
| el17arm | 7:c6e6ec0e3396 | 18 | _y = 33; |
| el17arm | 7:c6e6ec0e3396 | 19 | } |
| el17arm | 7:c6e6ec0e3396 | 20 | */ |
| el17arm | 7:c6e6ec0e3396 | 21 | |
| el17arm | 1:813ba5341985 | 22 | void Minerengine::read_direction(Gamepad &pad) |
| el17arm | 1:813ba5341985 | 23 | { |
| el17arm | 1:813ba5341985 | 24 | _d = pad.get_direction(); |
| el17arm | 1:813ba5341985 | 25 | printf("direction %i \n", _d); |
| el17arm | 1:813ba5341985 | 26 | } |
| el17arm | 0:fe19852199d2 | 27 | |
| el17arm | 3:d27ee2440829 | 28 | void Minerengine::miner_move(N5110 &lcd, Gamepad &pad) |
| el17arm | 1:813ba5341985 | 29 | { |
| el17arm | 6:866281ce2b44 | 30 | |
| el17arm | 6:866281ce2b44 | 31 | if (_d==3 && !lcd.getPixel(_x + 3, _y+1) && !lcd.getPixel(_x + 3, _y + 3) && |
| el17arm | 6:866281ce2b44 | 32 | !lcd.getPixel(_x + 3, _y + 5) && !lcd.getPixel(_x + 3, _y + 7)) { |
| el17arm | 6:866281ce2b44 | 33 | |
| el17arm | 4:b92da6a09c8b | 34 | _x += 1; |
| el17arm | 1:813ba5341985 | 35 | _direction = 1; |
| el17arm | 0:fe19852199d2 | 36 | } |
| el17arm | 6:866281ce2b44 | 37 | if (_d==7 && !lcd.getPixel(_x - 1, _y+1) && !lcd.getPixel(_x - 1, _y + 3) && |
| el17arm | 6:866281ce2b44 | 38 | !lcd.getPixel(_x - 1, _y + 5)&& !lcd.getPixel(_x + 3, _y + 7)) { |
| el17arm | 6:866281ce2b44 | 39 | |
| el17arm | 1:813ba5341985 | 40 | _x = _x - 1; |
| el17arm | 1:813ba5341985 | 41 | _direction = 0; |
| el17arm | 1:813ba5341985 | 42 | } |
| el17arm | 7:c6e6ec0e3396 | 43 | x = _x; |
| el17arm | 1:813ba5341985 | 44 | } |
| el17arm | 6:866281ce2b44 | 45 | |
| el17arm | 1:813ba5341985 | 46 | void Minerengine::miner_jump(N5110 &lcd, Gamepad &pad) |
| el17arm | 1:813ba5341985 | 47 | { |
| el17arm | 6:866281ce2b44 | 48 | if(_d==3 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) { |
| el17arm | 2:725c213b2396 | 49 | for (int i = 0; i < 6; i++) { |
| el17arm | 1:813ba5341985 | 50 | _y = _y -1; |
| el17arm | 4:b92da6a09c8b | 51 | |
| el17arm | 6:866281ce2b44 | 52 | if(lcd.getPixel(_x, _y) || lcd.getPixel(_x, _y + 7) || |
| el17arm | 6:866281ce2b44 | 53 | lcd.getPixel(_x + 3, _y + 7)) { |
| el17arm | 3:d27ee2440829 | 54 | i = 6; |
| el17arm | 3:d27ee2440829 | 55 | } |
| el17arm | 1:813ba5341985 | 56 | } |
| el17arm | 0:fe19852199d2 | 57 | } |
| el17arm | 6:866281ce2b44 | 58 | if(_d==7 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) { |
| el17arm | 2:725c213b2396 | 59 | for (int i = 0; i < 6; i++) { |
| el17arm | 1:813ba5341985 | 60 | _y = _y -1; |
| el17arm | 6:866281ce2b44 | 61 | |
| el17arm | 6:866281ce2b44 | 62 | if(lcd.getPixel(_x, _y) || lcd.getPixel(_x+2, _y + 7) || |
| el17arm | 6:866281ce2b44 | 63 | lcd.getPixel(_x, _y + 7)) { |
| el17arm | 3:d27ee2440829 | 64 | i = 6; |
| el17arm | 3:d27ee2440829 | 65 | } |
| el17arm | 2:725c213b2396 | 66 | } |
| el17arm | 4:b92da6a09c8b | 67 | } |
| el17arm | 6:866281ce2b44 | 68 | if(_d==0 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) { |
| el17arm | 2:725c213b2396 | 69 | for (int i = 0; i < 6; i++) { |
| el17arm | 2:725c213b2396 | 70 | _y = _y -1; |
| el17arm | 6:866281ce2b44 | 71 | if(lcd.getPixel(_x, _y) || lcd.getPixel(_x + 2, _y + 7) |
| el17arm | 6:866281ce2b44 | 72 | || lcd.getPixel(_x, _y + 7)) { |
| el17arm | 3:d27ee2440829 | 73 | i = 6; |
| el17arm | 3:d27ee2440829 | 74 | } |
| el17arm | 1:813ba5341985 | 75 | } |
| el17arm | 1:813ba5341985 | 76 | } |
| el17arm | 1:813ba5341985 | 77 | } |
| el17arm | 0:fe19852199d2 | 78 | |
| el17arm | 1:813ba5341985 | 79 | void Minerengine::miner_draw(N5110 &lcd) |
| el17arm | 1:813ba5341985 | 80 | { |
| el17arm | 2:725c213b2396 | 81 | if (_direction == 1) { |
| el17arm | 6:866281ce2b44 | 82 | lcd.drawSprite(_x,_y,8,3,(int *)miner_right); |
| el17arm | 1:813ba5341985 | 83 | } |
| el17arm | 2:725c213b2396 | 84 | if (_direction == 0) { |
| el17arm | 6:866281ce2b44 | 85 | lcd.drawSprite(_x,_y,8,3,(int *)miner_left); |
| el17arm | 0:fe19852199d2 | 86 | } |
| el17arm | 3:d27ee2440829 | 87 | } |
| el17arm | 3:d27ee2440829 | 88 | |
| el17arm | 3:d27ee2440829 | 89 | void Minerengine::miner_gravity(N5110 &lcd) |
| el17arm | 3:d27ee2440829 | 90 | { |
| el17arm | 6:866281ce2b44 | 91 | if(!lcd.getPixel(_x, _y + 8)) { |
| el17arm | 3:d27ee2440829 | 92 | _y = _y + 1; |
| el17arm | 7:c6e6ec0e3396 | 93 | wait(0.1); |
| el17arm | 4:b92da6a09c8b | 94 | } |
| el17arm | 7:c6e6ec0e3396 | 95 | } |