Project Submission (late)

Dependencies:   mbed

Revision:
0:72f372170a73
Child:
3:83e79d31930c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Player/Player.cpp	Fri May 10 08:07:10 2019 +0000
@@ -0,0 +1,42 @@
+#include "Player.h"
+#include "mbed.h"
+
+const Vector2Di UP = {0,1};
+const Vector2Di DOWN = {0,-1};
+
+Player::Player(Maze* mazePtr) {
+    maze = mazePtr;
+    pos = UP;
+    direction = DOWN;
+}
+
+bool Player::checkLocation(Vector2Di origin, double angle, int checkVal) {
+    Vector2Di peekDirection = direction;
+    peekDirection.rotateVector(angle);
+    origin.addVector(peekDirection);
+    if (maze->mazeMatrix[origin.y][origin.x] == checkVal) {
+        // eg if index == 1 that indicates a solid cell
+        // or if index == 2 that is the maze exit 
+        return true;
+    } else {
+        return false;
+    }
+}
+
+void Player::walk() { 
+    if (checkLocation(pos,0,0)) {
+        printf("v = (%i, %i)\nwalking\n", pos.x, pos.y);
+        pos.addVector(direction); 
+        printf("v = (%i, %i)\n", pos.x, pos.y);
+    }
+};
+
+void Player::turnLeft() { direction.rotateVector(-PI/2); };
+
+void Player::turnRight() { direction.rotateVector(PI/2); };
+
+void Player::stepBack() {
+    if (checkLocation(pos,PI,0)) {
+        pos.addVector(-direction);
+    }
+};
\ No newline at end of file