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:
- 3:d27ee2440829
- Parent:
- 2:725c213b2396
- Child:
- 4:b92da6a09c8b
--- a/Minerengine.cpp Wed Mar 20 01:32:31 2019 +0000
+++ b/Minerengine.cpp Wed Mar 20 18:32:25 2019 +0000
@@ -3,7 +3,7 @@
Minerengine::Minerengine()
{
- _x = 0;
+ _x = 3;
_y = 33;
}
@@ -17,38 +17,44 @@
printf("direction %i \n", _d);
}
-void Minerengine::miner_move()
+void Minerengine::miner_move(N5110 &lcd, Gamepad &pad)
{
- if (_d==3) {
+ if (_d==3 && !lcd.getPixel(_x + 5, _y)) {
_x = _x + 1;
_direction = 1;
}
- if (_d==7) {
+ if (_d==7 && !lcd.getPixel(_x -1, _y)) {
_x = _x - 1;
_direction = 0;
}
- printf(" x = %i \n", _x);
}
-
void Minerengine::miner_jump(N5110 &lcd, Gamepad &pad)
{
if(_d==3 && pad.check_event(Gamepad::A_PRESSED)) {
for (int i = 0; i < 6; i++) {
_y = _y -1;
lcd.drawSprite(_x,_y,12,5,(int *)miner_right);
-
+
+ if(lcd.getPixel(_x + 5, _y)){
+ i = 6;
+ }
}
}
if(_d==7 && pad.check_event(Gamepad::A_PRESSED)) {
for (int i = 0; i < 6; i++) {
_y = _y -1;
+ if(lcd.getPixel(_x + 5, _y)){
+ i = 6;
+ }
lcd.drawSprite(_x,_y,12,5,(int *)miner_left);
-
+ }
}
- }
if(_d==0 && pad.check_event(Gamepad::A_PRESSED)) {
for (int i = 0; i < 6; i++) {
_y = _y -1;
+ if(lcd.getPixel(_x + 5, _y)){
+ i = 6;
+ }
lcd.drawSprite(_x,_y,12,5,(int *)miner_left);
}
}
@@ -62,4 +68,11 @@
if (_direction == 0) {
lcd.drawSprite(_x,_y,12,5,(int *)miner_left);
}
+}
+
+void Minerengine::miner_gravity(N5110 &lcd)
+{
+ if(!lcd.getPixel(_x, _y + 12)) {
+ _y = _y + 1;
+ }
}
\ No newline at end of file