ELEC2645 (2018/19) / Mbed 2 deprecated el17arm

Dependencies:   mbed

Revision:
29:d85886364643
Parent:
27:e73dd64ef334
Child:
30:6d6b48fe3679
diff -r e73dd64ef334 -r d85886364643 Miner/Miner.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Miner/Miner.cpp	Wed Apr 10 00:50:14 2019 +0000
@@ -0,0 +1,112 @@
+#include "Miner.h"
+
+Miner::Miner()
+{
+    _enem.eflag[0] = false;
+}
+
+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)
+{
+    while(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 i, int x, int y, int d)
+{
+    _enem.ex[i] = x;
+    _enem.ey[i] = y;
+    _enem.distance[i] = d;
+}
+
+void Miner::enemy_move(int i, double v, N5110 &lcd)
+{
+    lcd.drawSprite(_enem.ex[i],_enem.ey[i],5,3, (int *) enemy);
+
+    if (_enem.eflag[i] == false) {
+        _enem.ex[i] = _enem.ex[i] + v;
+        _enem.counter[i]++;
+    }
+    if(_enem.counter[i] == _enem.distance[i]) {
+        _enem.eflag[i] = true;
+    }
+    if (_enem.eflag[i] == true) {
+        _enem.ex[i] = _enem.ex[i] - v;
+        _enem.counter[i]--;
+    }
+    if (_enem.counter[i] == 0) {
+        _enem.eflag[i] = false;
+    }
+}
+
+bool Miner::enemy_collision(int i)
+{
+    Vector2D p = get_pos();
+    
+    if (p.x < _enem.ex[i] + 2 && p.x + 2 > _enem.ex[i] && p.y < _enem.ey[i] + 4
+     && p.y + 9 > _enem.ey[i]) {
+        return true;
+    } else {
+        return false;
+    }
+}
\ No newline at end of file