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/Miner.cpp
- Revision:
- 27:e73dd64ef334
diff -r bce40bf4c9fc -r e73dd64ef334 Minerengine/Miner.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Minerengine/Miner.cpp Tue Apr 09 18:46:14 2019 +0000
@@ -0,0 +1,71 @@
+#include "Miner.h"
+
+Miner::Miner()
+{
+}
+
+Miner::~Miner()
+{
+}
+
+void Miner::miner_init(int x, int y)
+{
+ _x = x;
+ _y = y;
+}
+
+Vector2D Miner::get_pos()
+{
+ Vector2D p = {_x,_y};
+ return p;
+}
+
+void Miner::miner_draw(N5110 &lcd)
+{
+ if (_direction == 1) {
+ lcd.drawSprite(_x,_y,8,3,(int *)miner_right);
+ }
+ if (_direction == 0) {
+ lcd.drawSprite(_x,_y,8,3,(int *)miner_left);
+ }
+
+}
+void Miner::miner_land(N5110 &lcd)
+{
+ _jump = (lcd.getPixel(_x+4,_y+8) || lcd.getPixel(_x-1,_y+8));
+
+ _gravity = !lcd.getPixel(_x,_y+8) && !lcd.getPixel(_x+2, _y+8);
+}
+
+void Miner::miner_move(Direction d, N5110 &lcd)
+{
+ if (d==E || d==NE) {
+ _x++;
+ _direction = 1; //chooses right facing sprite
+ }
+ if (d==W || d==NW) {
+ _x --;
+ _direction = 0; //chooses left facing sprite
+ }
+ if(_x > 81){
+ _x=WIDTH-3;
+ }
+ if(_x < 0){
+ _x=0;
+ }
+}
+
+void Miner::miner_jump(N5110 &lcd, Gamepad &pad)
+{
+ if(pad.check_event(Gamepad::A_PRESSED) && _jump==1) {
+ _y-=8;
+ pad.tone(750,0.1);
+ }
+}
+
+void Miner::miner_gravity(N5110 &lcd)
+{
+ if(_gravity == 1) {
+ _y = _y + 1;
+ }
+}
\ No newline at end of file