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@11:61f28e3448d3, 2019-03-28 (annotated)
- Committer:
- el17arm
- Date:
- Thu Mar 28 01:07:49 2019 +0000
- Revision:
- 11:61f28e3448d3
- Parent:
- 10:65a6866d418b
- Child:
- 12:adf4ec04ced2
sprite collision resembles that of Manic Miner now, first level platforms laid out as per level 1 of Manic Miner game.
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 | 7:c6e6ec0e3396 | 16 | } |
| el17arm | 8:9bc80e40ac0d | 17 | |
| el17arm | 7:c6e6ec0e3396 | 18 | |
| el17arm | 1:813ba5341985 | 19 | void Minerengine::read_direction(Gamepad &pad) |
| el17arm | 1:813ba5341985 | 20 | { |
| el17arm | 1:813ba5341985 | 21 | _d = pad.get_direction(); |
| el17arm | 9:f16581e1eba9 | 22 | } |
| el17arm | 9:f16581e1eba9 | 23 | |
| el17arm | 9:f16581e1eba9 | 24 | void Minerengine::miner_collision(N5110 &lcd) |
| el17arm | 9:f16581e1eba9 | 25 | { |
| el17arm | 11:61f28e3448d3 | 26 | /*_right_collision = lcd.getPixel(_x+3,_y) + lcd.getPixel(_x+3,_y+3) + |
| el17arm | 10:65a6866d418b | 27 | lcd.getPixel(_x+3,_y+5) + lcd.getPixel(_x+3,_y+7); |
| el17arm | 10:65a6866d418b | 28 | |
| el17arm | 10:65a6866d418b | 29 | _left_collision = lcd.getPixel(_x-1,_y) + lcd.getPixel(_x-1,_y+3) + |
| el17arm | 11:61f28e3448d3 | 30 | lcd.getPixel(_x-1,_y+5) + lcd.getPixel(_x-1,_y+7);*/ |
| el17arm | 10:65a6866d418b | 31 | |
| el17arm | 10:65a6866d418b | 32 | _jump = (lcd.getPixel(_x+4,_y+8) || lcd.getPixel(_x-1,_y+8)); |
| el17arm | 10:65a6866d418b | 33 | |
| el17arm | 10:65a6866d418b | 34 | _stop_jump = lcd.getPixel(_x,_y-2) || lcd.getPixel(_x+3,_y-2); |
| el17arm | 11:61f28e3448d3 | 35 | |
| el17arm | 11:61f28e3448d3 | 36 | _gravity = !lcd.getPixel(_x, _y + 8) && !lcd.getPixel(_x + 2, _y + 8); |
| el17arm | 1:813ba5341985 | 37 | } |
| el17arm | 0:fe19852199d2 | 38 | |
| el17arm | 10:65a6866d418b | 39 | void Minerengine::miner_move() |
| el17arm | 1:813ba5341985 | 40 | { |
| el17arm | 11:61f28e3448d3 | 41 | if (_d==E && _x < WIDTH-3) { |
| el17arm | 9:f16581e1eba9 | 42 | _x++; |
| el17arm | 10:65a6866d418b | 43 | _direction = 1; //chooses right facing sprite |
| el17arm | 0:fe19852199d2 | 44 | } |
| el17arm | 11:61f28e3448d3 | 45 | if (_d==W && _x > 0) { |
| el17arm | 9:f16581e1eba9 | 46 | _x--; |
| el17arm | 10:65a6866d418b | 47 | _direction = 0; //chooses left facing sprite |
| el17arm | 1:813ba5341985 | 48 | } |
| el17arm | 1:813ba5341985 | 49 | } |
| el17arm | 6:866281ce2b44 | 50 | |
| el17arm | 1:813ba5341985 | 51 | void Minerengine::miner_jump(N5110 &lcd, Gamepad &pad) |
| el17arm | 1:813ba5341985 | 52 | { |
| el17arm | 11:61f28e3448d3 | 53 | if(pad.check_event(Gamepad::A_PRESSED) && _jump==1) { |
| el17arm | 11:61f28e3448d3 | 54 | int i=0; |
| el17arm | 11:61f28e3448d3 | 55 | while(i < 8){ |
| el17arm | 11:61f28e3448d3 | 56 | _y = _y--; |
| el17arm | 11:61f28e3448d3 | 57 | i++; |
| el17arm | 1:813ba5341985 | 58 | } |
| el17arm | 1:813ba5341985 | 59 | } |
| el17arm | 1:813ba5341985 | 60 | } |
| el17arm | 0:fe19852199d2 | 61 | |
| el17arm | 1:813ba5341985 | 62 | void Minerengine::miner_draw(N5110 &lcd) |
| el17arm | 1:813ba5341985 | 63 | { |
| el17arm | 2:725c213b2396 | 64 | if (_direction == 1) { |
| el17arm | 6:866281ce2b44 | 65 | lcd.drawSprite(_x,_y,8,3,(int *)miner_right); |
| el17arm | 1:813ba5341985 | 66 | } |
| el17arm | 2:725c213b2396 | 67 | if (_direction == 0) { |
| el17arm | 6:866281ce2b44 | 68 | lcd.drawSprite(_x,_y,8,3,(int *)miner_left); |
| el17arm | 0:fe19852199d2 | 69 | } |
| el17arm | 3:d27ee2440829 | 70 | } |
| el17arm | 3:d27ee2440829 | 71 | |
| el17arm | 3:d27ee2440829 | 72 | void Minerengine::miner_gravity(N5110 &lcd) |
| el17arm | 3:d27ee2440829 | 73 | { |
| el17arm | 11:61f28e3448d3 | 74 | if(_gravity == 1) { |
| el17arm | 3:d27ee2440829 | 75 | _y = _y + 1; |
| el17arm | 4:b92da6a09c8b | 76 | } |
| el17arm | 7:c6e6ec0e3396 | 77 | } |