Frogger for mbed

Dependencies:   4DGL-uLCD-SE Motor PinDetect SDFileSystem mbed-rtos mbed wave_player

Fork of 4180_Lab4_v6 by Erick Cardenas

Revision:
1:abd7e0631db8
Parent:
0:9f1095365b9a
Child:
3:427c365950d7
--- a/Robot.h	Sat Oct 29 22:15:03 2016 +0000
+++ b/Robot.h	Mon Oct 31 19:52:09 2016 +0000
@@ -2,11 +2,17 @@
 class Robot
 {
     Mutex stdio_mutex;
+    int FrogX;
+    int FrogY;
 public:
     void drawFrog() {
     uLCD.filled_rectangle(XPosition-5,YPosition-5,XPosition+5,YPosition+5,RED);
     }
     
+    void drawDeadFrog() {
+    uLCD.filled_rectangle(XPosition-5,YPosition-5,XPosition+5,YPosition+5,WHITE);
+    }
+    
     void drawOutline() {
     uLCD.line(0, 0 , 0, 127, BLACK);
     uLCD.line(0, 0 , 127, 0, BLACK);
@@ -27,10 +33,16 @@
     uLCD.filled_rectangle(Xp-2,Yp-1,Xp+2,Yp+1,WHITE);
     }
     
-    void drawCar1(int Position1) {
-    stdio_mutex.lock();
-    uLCD.filled_rectangle(Position1-10,95-4,Position1+10,95+4,BLUE);
-    stdio_mutex.unlock();
+    void drawCar1(int Position1, int CarWidth) {
+    //stdio_mutex.lock();
+    uLCD.filled_rectangle(Position1-CarWidth,95-4,Position1+CarWidth,95+4,BLUE);
+    //stdio_mutex.unlock();
+    }
+    
+    void drawCar2(int Position2, int CarWidth) {
+    //stdio_mutex.lock();
+    uLCD.filled_rectangle(Position2-CarWidth,52-4,Position2+CarWidth,52+4,RED);
+    //stdio_mutex.unlock();
     }
     
     void drawWater(int Xp,int Yp) {
@@ -90,16 +102,33 @@
     }
     
     void moveForward() {
-    setYPosition(getYPosition() - 21);
+        drawHelper(XPosition,YPosition);
+        setYPosition(getYPosition() - 21);
+        drawFrog();
     }
     void moveBackward() {
-    setYPosition(getYPosition() + 21);
+    FrogY = getYPosition();
+        if(FrogY > 11){
+        drawHelper(XPosition,YPosition);
+        setYPosition(FrogY + 21);
+        drawFrog();
+        }
     }
     void moveLeft() {
-    setXPosition(getXPosition() - 21);
+    FrogX = getXPosition();
+        if(FrogX > 11){
+        drawHelper(XPosition,YPosition);
+        setXPosition(FrogX - 21);
+        drawFrog();
+        }
     }
     void moveRight() {
-    setXPosition(getXPosition() + 21);
+    FrogX = getXPosition();
+        if(FrogX < 116){
+        drawHelper(XPosition,YPosition);
+        setXPosition(FrogX + 21);
+        drawFrog();
+        }
     }
     
     int getXPosition() {
@@ -118,7 +147,7 @@
     
     Robot() 
     {
-    XPosition = 74;
+    XPosition = 53;
     YPosition = 116;
     }
 private: