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: Miner/Miner.cpp
- Revision:
- 28:a38070a1cdcf
- Parent:
- 27:e73dd64ef334
diff -r e73dd64ef334 -r a38070a1cdcf Miner/Miner.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Miner/Miner.cpp Tue Apr 09 21:03:49 2019 +0000
@@ -0,0 +1,103 @@
+#include "Miner.h"
+
+Miner::Miner()
+{
+}
+
+Miner::~Miner()
+{
+}
+
+Vector2D Miner::get_pos()
+{
+ Vector2D p = {_x,_y};
+ printf("miner x = %f \n", p.x);
+ 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;
+ }
+}
+
+void Miner::enemy_init(int x, int y, volatile int d)
+{
+ _xe = x;
+ _ye = y;
+ _distance = d;
+}
+
+void Miner::enemy_move(N5110 &lcd)
+{
+ lcd.drawSprite(_x,_y,5,3, (int *) enemy);
+ if (_turn_flag == 0) {
+ _x = _x + 0.5;
+ _counter++;
+ }
+ if(_counter == _distance) {
+ _turn_flag = 1;
+ }
+ if (_turn_flag == 1) {
+ _x = _x - 0.5;
+ _counter--;
+ }
+ if (_counter == 0) {
+ _turn_flag = 0;
+ }
+}
+
+bool Miner::enemy_collision()
+{
+ Vector2D p = get_pos();
+
+ if (p.x < _x+2 && p.x+2 > _x && p.y < _y+4 && p.y+8 > _y) {
+ return true;
+ } else {
+ return false;
+ }
+}
\ No newline at end of file