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@6:866281ce2b44, 2019-03-22 (annotated)
- Committer:
- el17arm
- Date:
- Fri Mar 22 02:00:48 2019 +0000
- Revision:
- 6:866281ce2b44
- Parent:
- 4:b92da6a09c8b
- Child:
- 7:c6e6ec0e3396
Sprite made smaller, problem with multiple jumping solved, collision much better but still some slight issues.
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 | 0:fe19852199d2 | 3 | Minerengine::Minerengine() |
| el17arm | 2:725c213b2396 | 4 | |
| el17arm | 0:fe19852199d2 | 5 | { |
| el17arm | 3:d27ee2440829 | 6 | _x = 3; |
| el17arm | 2:725c213b2396 | 7 | _y = 33; |
| el17arm | 0:fe19852199d2 | 8 | } |
| el17arm | 0:fe19852199d2 | 9 | |
| el17arm | 1:813ba5341985 | 10 | Minerengine::~Minerengine() |
| el17arm | 0:fe19852199d2 | 11 | { |
| el17arm | 1:813ba5341985 | 12 | } |
| el17arm | 0:fe19852199d2 | 13 | |
| el17arm | 1:813ba5341985 | 14 | void Minerengine::read_direction(Gamepad &pad) |
| el17arm | 1:813ba5341985 | 15 | { |
| el17arm | 1:813ba5341985 | 16 | _d = pad.get_direction(); |
| el17arm | 1:813ba5341985 | 17 | printf("direction %i \n", _d); |
| el17arm | 1:813ba5341985 | 18 | } |
| el17arm | 0:fe19852199d2 | 19 | |
| el17arm | 3:d27ee2440829 | 20 | void Minerengine::miner_move(N5110 &lcd, Gamepad &pad) |
| el17arm | 1:813ba5341985 | 21 | { |
| el17arm | 6:866281ce2b44 | 22 | |
| el17arm | 6:866281ce2b44 | 23 | if (_d==3 && !lcd.getPixel(_x + 3, _y+1) && !lcd.getPixel(_x + 3, _y + 3) && |
| el17arm | 6:866281ce2b44 | 24 | !lcd.getPixel(_x + 3, _y + 5) && !lcd.getPixel(_x + 3, _y + 7)) { |
| el17arm | 6:866281ce2b44 | 25 | |
| el17arm | 4:b92da6a09c8b | 26 | _x += 1; |
| el17arm | 1:813ba5341985 | 27 | _direction = 1; |
| el17arm | 0:fe19852199d2 | 28 | } |
| el17arm | 6:866281ce2b44 | 29 | if (_d==7 && !lcd.getPixel(_x - 1, _y+1) && !lcd.getPixel(_x - 1, _y + 3) && |
| el17arm | 6:866281ce2b44 | 30 | !lcd.getPixel(_x - 1, _y + 5)&& !lcd.getPixel(_x + 3, _y + 7)) { |
| el17arm | 6:866281ce2b44 | 31 | |
| el17arm | 1:813ba5341985 | 32 | _x = _x - 1; |
| el17arm | 1:813ba5341985 | 33 | _direction = 0; |
| el17arm | 1:813ba5341985 | 34 | } |
| el17arm | 1:813ba5341985 | 35 | } |
| el17arm | 6:866281ce2b44 | 36 | |
| el17arm | 1:813ba5341985 | 37 | void Minerengine::miner_jump(N5110 &lcd, Gamepad &pad) |
| el17arm | 1:813ba5341985 | 38 | { |
| el17arm | 6:866281ce2b44 | 39 | if(_d==3 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) { |
| el17arm | 2:725c213b2396 | 40 | for (int i = 0; i < 6; i++) { |
| el17arm | 1:813ba5341985 | 41 | _y = _y -1; |
| el17arm | 4:b92da6a09c8b | 42 | |
| el17arm | 6:866281ce2b44 | 43 | if(lcd.getPixel(_x, _y) || lcd.getPixel(_x, _y + 7) || |
| el17arm | 6:866281ce2b44 | 44 | lcd.getPixel(_x + 3, _y + 7)) { |
| el17arm | 3:d27ee2440829 | 45 | i = 6; |
| el17arm | 3:d27ee2440829 | 46 | } |
| el17arm | 1:813ba5341985 | 47 | } |
| el17arm | 0:fe19852199d2 | 48 | } |
| el17arm | 6:866281ce2b44 | 49 | if(_d==7 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) { |
| el17arm | 2:725c213b2396 | 50 | for (int i = 0; i < 6; i++) { |
| el17arm | 1:813ba5341985 | 51 | _y = _y -1; |
| el17arm | 6:866281ce2b44 | 52 | |
| el17arm | 6:866281ce2b44 | 53 | if(lcd.getPixel(_x, _y) || lcd.getPixel(_x+2, _y + 7) || |
| el17arm | 6:866281ce2b44 | 54 | lcd.getPixel(_x, _y + 7)) { |
| el17arm | 3:d27ee2440829 | 55 | i = 6; |
| el17arm | 3:d27ee2440829 | 56 | } |
| el17arm | 2:725c213b2396 | 57 | } |
| el17arm | 4:b92da6a09c8b | 58 | } |
| el17arm | 6:866281ce2b44 | 59 | if(_d==0 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) { |
| el17arm | 2:725c213b2396 | 60 | for (int i = 0; i < 6; i++) { |
| el17arm | 2:725c213b2396 | 61 | _y = _y -1; |
| 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 | 1:813ba5341985 | 66 | } |
| el17arm | 1:813ba5341985 | 67 | } |
| el17arm | 1:813ba5341985 | 68 | } |
| el17arm | 0:fe19852199d2 | 69 | |
| el17arm | 1:813ba5341985 | 70 | void Minerengine::miner_draw(N5110 &lcd) |
| el17arm | 1:813ba5341985 | 71 | { |
| el17arm | 2:725c213b2396 | 72 | if (_direction == 1) { |
| el17arm | 6:866281ce2b44 | 73 | lcd.drawSprite(_x,_y,8,3,(int *)miner_right); |
| el17arm | 1:813ba5341985 | 74 | } |
| el17arm | 2:725c213b2396 | 75 | if (_direction == 0) { |
| el17arm | 6:866281ce2b44 | 76 | lcd.drawSprite(_x,_y,8,3,(int *)miner_left); |
| el17arm | 0:fe19852199d2 | 77 | } |
| el17arm | 3:d27ee2440829 | 78 | } |
| el17arm | 3:d27ee2440829 | 79 | |
| el17arm | 3:d27ee2440829 | 80 | void Minerengine::miner_gravity(N5110 &lcd) |
| el17arm | 3:d27ee2440829 | 81 | { |
| el17arm | 6:866281ce2b44 | 82 | if(!lcd.getPixel(_x, _y + 8)) { |
| el17arm | 3:d27ee2440829 | 83 | _y = _y + 1; |
| el17arm | 4:b92da6a09c8b | 84 | } |
| el17arm | 6:866281ce2b44 | 85 | } |