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@15:2bda80896a84, 2019-03-29 (annotated)
- Committer:
- el17arm
- Date:
- Fri Mar 29 19:03:10 2019 +0000
- Revision:
- 15:2bda80896a84
- Parent:
- 14:dc3524d11921
- Child:
- 16:8384e9a480ef
major restructuring of classes and functions so no need for global variables anymore.; ; added collision with specific blocks on level.
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 | 0:fe19852199d2 | 4 | { |
| el17arm | 0:fe19852199d2 | 5 | } |
| el17arm | 0:fe19852199d2 | 6 | |
| el17arm | 1:813ba5341985 | 7 | Minerengine::~Minerengine() |
| el17arm | 0:fe19852199d2 | 8 | { |
| el17arm | 1:813ba5341985 | 9 | } |
| el17arm | 0:fe19852199d2 | 10 | |
| el17arm | 15:2bda80896a84 | 11 | void Minerengine::miner_init(int x, int y) |
| el17arm | 15:2bda80896a84 | 12 | { |
| el17arm | 15:2bda80896a84 | 13 | _x = x; |
| el17arm | 15:2bda80896a84 | 14 | _y = y; |
| el17arm | 7:c6e6ec0e3396 | 15 | } |
| el17arm | 8:9bc80e40ac0d | 16 | |
| el17arm | 12:adf4ec04ced2 | 17 | Vector2D Minerengine::get_pos() |
| el17arm | 12:adf4ec04ced2 | 18 | { |
| el17arm | 12:adf4ec04ced2 | 19 | Vector2D p = {_x,_y}; |
| el17arm | 15:2bda80896a84 | 20 | printf("x = %f \n", p.x); |
| el17arm | 12:adf4ec04ced2 | 21 | return p; |
| el17arm | 14:dc3524d11921 | 22 | |
| el17arm | 12:adf4ec04ced2 | 23 | } |
| el17arm | 7:c6e6ec0e3396 | 24 | |
| el17arm | 15:2bda80896a84 | 25 | void Minerengine::miner_draw(N5110 &lcd) |
| el17arm | 9:f16581e1eba9 | 26 | { |
| el17arm | 15:2bda80896a84 | 27 | if (_direction == 1) { |
| el17arm | 15:2bda80896a84 | 28 | lcd.drawSprite(_x,_y,8,3,(int *)miner_right); |
| el17arm | 15:2bda80896a84 | 29 | } |
| el17arm | 15:2bda80896a84 | 30 | if (_direction == 0) { |
| el17arm | 15:2bda80896a84 | 31 | lcd.drawSprite(_x,_y,8,3,(int *)miner_left); |
| el17arm | 15:2bda80896a84 | 32 | } |
| el17arm | 15:2bda80896a84 | 33 | |
| el17arm | 15:2bda80896a84 | 34 | } |
| el17arm | 15:2bda80896a84 | 35 | void Minerengine::miner_land(N5110 &lcd) |
| el17arm | 15:2bda80896a84 | 36 | { |
| el17arm | 10:65a6866d418b | 37 | _jump = (lcd.getPixel(_x+4,_y+8) || lcd.getPixel(_x-1,_y+8)); |
| el17arm | 10:65a6866d418b | 38 | |
| el17arm | 10:65a6866d418b | 39 | _stop_jump = lcd.getPixel(_x,_y-2) || lcd.getPixel(_x+3,_y-2); |
| el17arm | 11:61f28e3448d3 | 40 | |
| el17arm | 12:adf4ec04ced2 | 41 | _gravity = !lcd.getPixel(_x,_y+8) && !lcd.getPixel(_x+2, _y+8); |
| el17arm | 1:813ba5341985 | 42 | } |
| el17arm | 0:fe19852199d2 | 43 | |
| el17arm | 15:2bda80896a84 | 44 | void Minerengine::miner_move(Direction d) |
| el17arm | 15:2bda80896a84 | 45 | { |
| el17arm | 15:2bda80896a84 | 46 | if (d==E && _right_collision == 0) { |
| el17arm | 15:2bda80896a84 | 47 | _x ++; |
| el17arm | 10:65a6866d418b | 48 | _direction = 1; //chooses right facing sprite |
| el17arm | 0:fe19852199d2 | 49 | } |
| el17arm | 15:2bda80896a84 | 50 | if (d==W && _left_collision == 0) { |
| el17arm | 15:2bda80896a84 | 51 | _x --; |
| el17arm | 10:65a6866d418b | 52 | _direction = 0; //chooses left facing sprite |
| el17arm | 1:813ba5341985 | 53 | } |
| el17arm | 1:813ba5341985 | 54 | } |
| el17arm | 6:866281ce2b44 | 55 | |
| el17arm | 1:813ba5341985 | 56 | void Minerengine::miner_jump(N5110 &lcd, Gamepad &pad) |
| el17arm | 1:813ba5341985 | 57 | { |
| el17arm | 11:61f28e3448d3 | 58 | if(pad.check_event(Gamepad::A_PRESSED) && _jump==1) { |
| el17arm | 11:61f28e3448d3 | 59 | int i=0; |
| el17arm | 11:61f28e3448d3 | 60 | while(i < 8){ |
| el17arm | 11:61f28e3448d3 | 61 | _y = _y--; |
| el17arm | 11:61f28e3448d3 | 62 | i++; |
| el17arm | 1:813ba5341985 | 63 | } |
| el17arm | 1:813ba5341985 | 64 | } |
| el17arm | 1:813ba5341985 | 65 | } |
| el17arm | 0:fe19852199d2 | 66 | |
| el17arm | 3:d27ee2440829 | 67 | void Minerengine::miner_gravity(N5110 &lcd) |
| el17arm | 3:d27ee2440829 | 68 | { |
| el17arm | 11:61f28e3448d3 | 69 | if(_gravity == 1) { |
| el17arm | 3:d27ee2440829 | 70 | _y = _y + 1; |
| el17arm | 4:b92da6a09c8b | 71 | } |
| el17arm | 15:2bda80896a84 | 72 | } |
| el17arm | 15:2bda80896a84 | 73 | |
| el17arm | 15:2bda80896a84 | 74 | //collision points in levels |
| el17arm | 15:2bda80896a84 | 75 | |
| el17arm | 15:2bda80896a84 | 76 | void Minerengine::level_one_collision(N5110 &lcd) |
| el17arm | 15:2bda80896a84 | 77 | { |
| el17arm | 15:2bda80896a84 | 78 | if (lcd.getPixel(48,38)){ |
| el17arm | 15:2bda80896a84 | 79 | _right_collision = 1; |
| el17arm | 15:2bda80896a84 | 80 | } |
| el17arm | 15:2bda80896a84 | 81 | else{ |
| el17arm | 15:2bda80896a84 | 82 | _right_collision = 0; |
| el17arm | 15:2bda80896a84 | 83 | } |
| el17arm | 15:2bda80896a84 | 84 | _left_collision = 0; |
| el17arm | 7:c6e6ec0e3396 | 85 | } |