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@3:d27ee2440829, 2019-03-20 (annotated)
- Committer:
- el17arm
- Date:
- Wed Mar 20 18:32:25 2019 +0000
- Revision:
- 3:d27ee2440829
- Parent:
- 2:725c213b2396
- Child:
- 4:b92da6a09c8b
Collision added, border levels added, tested and both are working as they should.
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 | 3:d27ee2440829 | 22 | if (_d==3 && !lcd.getPixel(_x + 5, _y)) { |
| el17arm | 1:813ba5341985 | 23 | _x = _x + 1; |
| el17arm | 1:813ba5341985 | 24 | _direction = 1; |
| el17arm | 0:fe19852199d2 | 25 | } |
| el17arm | 3:d27ee2440829 | 26 | if (_d==7 && !lcd.getPixel(_x -1, _y)) { |
| el17arm | 1:813ba5341985 | 27 | _x = _x - 1; |
| el17arm | 1:813ba5341985 | 28 | _direction = 0; |
| el17arm | 1:813ba5341985 | 29 | } |
| el17arm | 1:813ba5341985 | 30 | } |
| el17arm | 1:813ba5341985 | 31 | void Minerengine::miner_jump(N5110 &lcd, Gamepad &pad) |
| el17arm | 1:813ba5341985 | 32 | { |
| el17arm | 1:813ba5341985 | 33 | if(_d==3 && pad.check_event(Gamepad::A_PRESSED)) { |
| el17arm | 2:725c213b2396 | 34 | for (int i = 0; i < 6; i++) { |
| el17arm | 1:813ba5341985 | 35 | _y = _y -1; |
| el17arm | 2:725c213b2396 | 36 | lcd.drawSprite(_x,_y,12,5,(int *)miner_right); |
| el17arm | 3:d27ee2440829 | 37 | |
| el17arm | 3:d27ee2440829 | 38 | if(lcd.getPixel(_x + 5, _y)){ |
| el17arm | 3:d27ee2440829 | 39 | i = 6; |
| el17arm | 3:d27ee2440829 | 40 | } |
| el17arm | 1:813ba5341985 | 41 | } |
| el17arm | 0:fe19852199d2 | 42 | } |
| el17arm | 2:725c213b2396 | 43 | if(_d==7 && pad.check_event(Gamepad::A_PRESSED)) { |
| el17arm | 2:725c213b2396 | 44 | for (int i = 0; i < 6; i++) { |
| el17arm | 1:813ba5341985 | 45 | _y = _y -1; |
| el17arm | 3:d27ee2440829 | 46 | if(lcd.getPixel(_x + 5, _y)){ |
| el17arm | 3:d27ee2440829 | 47 | i = 6; |
| el17arm | 3:d27ee2440829 | 48 | } |
| el17arm | 2:725c213b2396 | 49 | lcd.drawSprite(_x,_y,12,5,(int *)miner_left); |
| el17arm | 3:d27ee2440829 | 50 | } |
| el17arm | 2:725c213b2396 | 51 | } |
| el17arm | 2:725c213b2396 | 52 | if(_d==0 && pad.check_event(Gamepad::A_PRESSED)) { |
| el17arm | 2:725c213b2396 | 53 | for (int i = 0; i < 6; i++) { |
| el17arm | 2:725c213b2396 | 54 | _y = _y -1; |
| el17arm | 3:d27ee2440829 | 55 | if(lcd.getPixel(_x + 5, _y)){ |
| el17arm | 3:d27ee2440829 | 56 | i = 6; |
| el17arm | 3:d27ee2440829 | 57 | } |
| el17arm | 2:725c213b2396 | 58 | lcd.drawSprite(_x,_y,12,5,(int *)miner_left); |
| el17arm | 1:813ba5341985 | 59 | } |
| el17arm | 1:813ba5341985 | 60 | } |
| el17arm | 1:813ba5341985 | 61 | } |
| el17arm | 0:fe19852199d2 | 62 | |
| el17arm | 1:813ba5341985 | 63 | void Minerengine::miner_draw(N5110 &lcd) |
| el17arm | 1:813ba5341985 | 64 | { |
| el17arm | 2:725c213b2396 | 65 | if (_direction == 1) { |
| el17arm | 2:725c213b2396 | 66 | lcd.drawSprite(_x,_y,12,5,(int *)miner_right); |
| el17arm | 1:813ba5341985 | 67 | } |
| el17arm | 2:725c213b2396 | 68 | if (_direction == 0) { |
| el17arm | 2:725c213b2396 | 69 | lcd.drawSprite(_x,_y,12,5,(int *)miner_left); |
| el17arm | 0:fe19852199d2 | 70 | } |
| el17arm | 3:d27ee2440829 | 71 | } |
| el17arm | 3:d27ee2440829 | 72 | |
| el17arm | 3:d27ee2440829 | 73 | void Minerengine::miner_gravity(N5110 &lcd) |
| el17arm | 3:d27ee2440829 | 74 | { |
| el17arm | 3:d27ee2440829 | 75 | if(!lcd.getPixel(_x, _y + 12)) { |
| el17arm | 3:d27ee2440829 | 76 | _y = _y + 1; |
| el17arm | 3:d27ee2440829 | 77 | } |
| el17arm | 0:fe19852199d2 | 78 | } |