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@9:f16581e1eba9, 2019-03-25 (annotated)
- Committer:
- el17arm
- Date:
- Mon Mar 25 18:57:48 2019 +0000
- Revision:
- 9:f16581e1eba9
- Parent:
- 8:9bc80e40ac0d
- Child:
- 10:65a6866d418b
tried declaring collision pixels as an array but for some reason not registering
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 | 0:fe19852199d2 | 5 | { |
| el17arm | 0:fe19852199d2 | 6 | } |
| el17arm | 0:fe19852199d2 | 7 | |
| el17arm | 1:813ba5341985 | 8 | Minerengine::~Minerengine() |
| el17arm | 0:fe19852199d2 | 9 | { |
| el17arm | 1:813ba5341985 | 10 | } |
| el17arm | 0:fe19852199d2 | 11 | |
| el17arm | 8:9bc80e40ac0d | 12 | void Minerengine::miner_init() |
| el17arm | 7:c6e6ec0e3396 | 13 | { |
| el17arm | 7:c6e6ec0e3396 | 14 | _x = 3; |
| el17arm | 7:c6e6ec0e3396 | 15 | _y = 33; |
| el17arm | 9:f16581e1eba9 | 16 | _collision = 10; |
| 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 | 9:f16581e1eba9 | 23 | } |
| el17arm | 9:f16581e1eba9 | 24 | |
| el17arm | 9:f16581e1eba9 | 25 | void Minerengine::miner_collision(N5110 &lcd) |
| el17arm | 9:f16581e1eba9 | 26 | { |
| el17arm | 9:f16581e1eba9 | 27 | int x = _x+3; |
| el17arm | 9:f16581e1eba9 | 28 | int y = _y; |
| el17arm | 9:f16581e1eba9 | 29 | int sum; |
| el17arm | 9:f16581e1eba9 | 30 | |
| el17arm | 9:f16581e1eba9 | 31 | for (int i = 0; i < 11; i++) { |
| el17arm | 9:f16581e1eba9 | 32 | sum += (lcd.getPixel(_x,_y+i)); |
| el17arm | 9:f16581e1eba9 | 33 | } |
| el17arm | 9:f16581e1eba9 | 34 | if (sum > 0){ |
| el17arm | 9:f16581e1eba9 | 35 | _collision = 1; |
| el17arm | 9:f16581e1eba9 | 36 | } |
| el17arm | 9:f16581e1eba9 | 37 | else{ |
| el17arm | 9:f16581e1eba9 | 38 | _collision = 0; |
| el17arm | 9:f16581e1eba9 | 39 | } |
| el17arm | 9:f16581e1eba9 | 40 | printf("collision = %i \n", _collision); |
| el17arm | 1:813ba5341985 | 41 | } |
| el17arm | 0:fe19852199d2 | 42 | |
| el17arm | 3:d27ee2440829 | 43 | void Minerengine::miner_move(N5110 &lcd, Gamepad &pad) |
| el17arm | 1:813ba5341985 | 44 | { |
| el17arm | 6:866281ce2b44 | 45 | |
| el17arm | 9:f16581e1eba9 | 46 | if (_d==3 && _collision == 0) { |
| el17arm | 6:866281ce2b44 | 47 | |
| el17arm | 9:f16581e1eba9 | 48 | _x++; |
| el17arm | 1:813ba5341985 | 49 | _direction = 1; |
| el17arm | 0:fe19852199d2 | 50 | } |
| el17arm | 9:f16581e1eba9 | 51 | if (_d==7) { |
| el17arm | 6:866281ce2b44 | 52 | |
| el17arm | 9:f16581e1eba9 | 53 | _x--; |
| el17arm | 1:813ba5341985 | 54 | _direction = 0; |
| el17arm | 1:813ba5341985 | 55 | } |
| el17arm | 1:813ba5341985 | 56 | } |
| el17arm | 6:866281ce2b44 | 57 | |
| el17arm | 1:813ba5341985 | 58 | void Minerengine::miner_jump(N5110 &lcd, Gamepad &pad) |
| el17arm | 1:813ba5341985 | 59 | { |
| el17arm | 8:9bc80e40ac0d | 60 | if(_d==3 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x + 3, _y + 8)) { |
| el17arm | 2:725c213b2396 | 61 | for (int i = 0; i < 6; i++) { |
| el17arm | 1:813ba5341985 | 62 | _y = _y -1; |
| el17arm | 4:b92da6a09c8b | 63 | |
| el17arm | 9:f16581e1eba9 | 64 | if(lcd.getPixel(_x, _y) || lcd.getPixel(_x, _y + 7) || |
| el17arm | 9:f16581e1eba9 | 65 | lcd.getPixel(_x + 3, _y + 7)) { |
| el17arm | 3:d27ee2440829 | 66 | i = 6; |
| el17arm | 3:d27ee2440829 | 67 | } |
| el17arm | 1:813ba5341985 | 68 | } |
| el17arm | 0:fe19852199d2 | 69 | } |
| el17arm | 6:866281ce2b44 | 70 | if(_d==7 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) { |
| el17arm | 2:725c213b2396 | 71 | for (int i = 0; i < 6; i++) { |
| el17arm | 1:813ba5341985 | 72 | _y = _y -1; |
| el17arm | 6:866281ce2b44 | 73 | |
| el17arm | 9:f16581e1eba9 | 74 | if(lcd.getPixel(_x, _y) || lcd.getPixel(_x+2, _y + 7) || |
| el17arm | 9:f16581e1eba9 | 75 | lcd.getPixel(_x, _y + 7)) { |
| el17arm | 3:d27ee2440829 | 76 | i = 6; |
| el17arm | 3:d27ee2440829 | 77 | } |
| el17arm | 2:725c213b2396 | 78 | } |
| el17arm | 4:b92da6a09c8b | 79 | } |
| el17arm | 6:866281ce2b44 | 80 | if(_d==0 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) { |
| el17arm | 2:725c213b2396 | 81 | for (int i = 0; i < 6; i++) { |
| el17arm | 2:725c213b2396 | 82 | _y = _y -1; |
| el17arm | 6:866281ce2b44 | 83 | if(lcd.getPixel(_x, _y) || lcd.getPixel(_x + 2, _y + 7) |
| el17arm | 9:f16581e1eba9 | 84 | || lcd.getPixel(_x, _y + 7)) { |
| el17arm | 3:d27ee2440829 | 85 | i = 6; |
| el17arm | 3:d27ee2440829 | 86 | } |
| el17arm | 1:813ba5341985 | 87 | } |
| el17arm | 1:813ba5341985 | 88 | } |
| el17arm | 1:813ba5341985 | 89 | } |
| el17arm | 0:fe19852199d2 | 90 | |
| el17arm | 1:813ba5341985 | 91 | void Minerengine::miner_draw(N5110 &lcd) |
| el17arm | 1:813ba5341985 | 92 | { |
| el17arm | 2:725c213b2396 | 93 | if (_direction == 1) { |
| el17arm | 6:866281ce2b44 | 94 | lcd.drawSprite(_x,_y,8,3,(int *)miner_right); |
| el17arm | 1:813ba5341985 | 95 | } |
| el17arm | 2:725c213b2396 | 96 | if (_direction == 0) { |
| el17arm | 6:866281ce2b44 | 97 | lcd.drawSprite(_x,_y,8,3,(int *)miner_left); |
| el17arm | 0:fe19852199d2 | 98 | } |
| el17arm | 3:d27ee2440829 | 99 | } |
| el17arm | 3:d27ee2440829 | 100 | |
| el17arm | 3:d27ee2440829 | 101 | void Minerengine::miner_gravity(N5110 &lcd) |
| el17arm | 3:d27ee2440829 | 102 | { |
| el17arm | 8:9bc80e40ac0d | 103 | if(!lcd.getPixel(_x, _y + 8) && !lcd.getPixel(_x + 3, _y + 8)) { |
| el17arm | 3:d27ee2440829 | 104 | _y = _y + 1; |
| el17arm | 4:b92da6a09c8b | 105 | } |
| el17arm | 7:c6e6ec0e3396 | 106 | } |