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
Diff: Minerengine.cpp
- Revision:
- 10:65a6866d418b
- Parent:
- 9:f16581e1eba9
- Child:
- 11:61f28e3448d3
diff -r f16581e1eba9 -r 65a6866d418b Minerengine.cpp
--- a/Minerengine.cpp Mon Mar 25 18:57:48 2019 +0000
+++ b/Minerengine.cpp Wed Mar 27 21:51:11 2019 +0000
@@ -13,7 +13,6 @@
{
_x = 3;
_y = 33;
- _collision = 10;
}
@@ -24,64 +23,54 @@
void Minerengine::miner_collision(N5110 &lcd)
{
- int x = _x+3;
- int y = _y;
- int sum;
-
- for (int i = 0; i < 11; i++) {
- sum += (lcd.getPixel(_x,_y+i));
- }
- if (sum > 0){
- _collision = 1;
- }
- else{
- _collision = 0;
- }
- printf("collision = %i \n", _collision);
+ _right_collision = lcd.getPixel(_x+3,_y) + lcd.getPixel(_x+3,_y+3) +
+ lcd.getPixel(_x+3,_y+5) + lcd.getPixel(_x+3,_y+7);
+
+ _left_collision = lcd.getPixel(_x-1,_y) + lcd.getPixel(_x-1,_y+3) +
+ lcd.getPixel(_x-1,_y+5) + lcd.getPixel(_x-1,_y+7);
+
+ _jump = (lcd.getPixel(_x+4,_y+8) || lcd.getPixel(_x-1,_y+8));
+
+ _stop_jump = lcd.getPixel(_x,_y-2) || lcd.getPixel(_x+3,_y-2);
}
-void Minerengine::miner_move(N5110 &lcd, Gamepad &pad)
+void Minerengine::miner_move()
{
-
- if (_d==3 && _collision == 0) {
-
+ if (_d==E && _right_collision == 0) {
_x++;
- _direction = 1;
+ _direction = 1; //chooses right facing sprite
}
- if (_d==7) {
-
+ if (_d==W && _left_collision == 0) {
_x--;
- _direction = 0;
+ _direction = 0; //chooses left facing sprite
}
}
void Minerengine::miner_jump(N5110 &lcd, Gamepad &pad)
{
- if(_d==3 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x + 3, _y + 8)) {
+ if(_d==3 && pad.check_event(Gamepad::A_PRESSED) && _jump==1) {
for (int i = 0; i < 6; i++) {
_y = _y -1;
- if(lcd.getPixel(_x, _y) || lcd.getPixel(_x, _y + 7) ||
- lcd.getPixel(_x + 3, _y + 7)) {
+ if(_stop_jump == 1) {
i = 6;
}
}
}
- if(_d==7 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) {
+ if(_d==7 && pad.check_event(Gamepad::A_PRESSED) && _jump == 1) {
for (int i = 0; i < 6; i++) {
_y = _y -1;
-
- if(lcd.getPixel(_x, _y) || lcd.getPixel(_x+2, _y + 7) ||
- lcd.getPixel(_x, _y + 7)) {
+
+ if(_stop_jump == 1) {
i = 6;
}
}
}
- if(_d==0 && pad.check_event(Gamepad::A_PRESSED) && lcd.getPixel(_x, _y + 8)) {
+ if(_d==0 && pad.check_event(Gamepad::A_PRESSED) && _jump == 1) {
for (int i = 0; i < 6; i++) {
_y = _y -1;
- if(lcd.getPixel(_x, _y) || lcd.getPixel(_x + 2, _y + 7)
- || lcd.getPixel(_x, _y + 7)) {
+
+ if(_stop_jump == 1) {
i = 6;
}
}