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