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:
- 9:f16581e1eba9
- Parent:
- 8:9bc80e40ac0d
- Child:
- 10:65a6866d418b
diff -r 9bc80e40ac0d -r f16581e1eba9 Minerengine.cpp
--- a/Minerengine.cpp Mon Mar 25 15:29:19 2019 +0000
+++ b/Minerengine.cpp Mon Mar 25 18:57:48 2019 +0000
@@ -2,7 +2,6 @@
Minerengine::Minerengine()
-
{
}
@@ -14,31 +13,46 @@
{
_x = 3;
_y = 33;
+ _collision = 10;
}
void Minerengine::read_direction(Gamepad &pad)
{
_d = pad.get_direction();
- printf("direction %i \n", _d);
+}
+
+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);
}
void Minerengine::miner_move(N5110 &lcd, Gamepad &pad)
{
- if (_d==3 && !lcd.getPixel(_x + 3, _y+1) && !lcd.getPixel(_x + 3, _y + 3) &&
- !lcd.getPixel(_x + 3, _y + 5) && !lcd.getPixel(_x + 3, _y + 7)) {
+ if (_d==3 && _collision == 0) {
- _x += 1;
+ _x++;
_direction = 1;
}
- if (_d==7 && !lcd.getPixel(_x - 1, _y + 1) && !lcd.getPixel(_x - 1, _y + 3) &&
- !lcd.getPixel(_x - 1, _y + 5)&& !lcd.getPixel(_x + 3, _y + 7)) {
+ if (_d==7) {
- _x = _x - 1;
+ _x--;
_direction = 0;
}
- x = _x;
}
void Minerengine::miner_jump(N5110 &lcd, Gamepad &pad)
@@ -47,8 +61,8 @@
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(lcd.getPixel(_x, _y) || lcd.getPixel(_x, _y + 7) ||
+ lcd.getPixel(_x + 3, _y + 7)) {
i = 6;
}
}
@@ -57,8 +71,8 @@
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(lcd.getPixel(_x, _y) || lcd.getPixel(_x+2, _y + 7) ||
+ lcd.getPixel(_x, _y + 7)) {
i = 6;
}
}
@@ -67,7 +81,7 @@
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)) {
+ || lcd.getPixel(_x, _y + 7)) {
i = 6;
}
}
@@ -88,6 +102,5 @@
{
if(!lcd.getPixel(_x, _y + 8) && !lcd.getPixel(_x + 3, _y + 8)) {
_y = _y + 1;
- wait(0.1);
}
}
\ No newline at end of file