class for obstacles in Car_race game

Revision:
9:d5f90988545e
Parent:
8:c8007ccac5c0
Child:
10:515df7535b2f
--- a/Obstacles.cpp	Wed Apr 19 20:55:18 2017 +0000
+++ b/Obstacles.cpp	Fri Apr 21 21:45:49 2017 +0000
@@ -14,6 +14,7 @@
 {
     _Obstacle_x = seed;
     _score = 0;
+    _totalscore = 0;
     // try to draw them here in this function as we need the draw function for another purpose 
     // are we done though? we might need to split the draw function into two, one for drawing the car
     // and the other for drawing the obstacles as they are drawn in a time basis
@@ -25,15 +26,15 @@
     switch(_Obstacle_x){
       
       case 0:
-      lcd.drawRect(2,2,25,2,FILL_BLACK);
+      lcd.drawRect(2,11,25,2,FILL_BLACK);  // it was lcd.drawRect(2,2,25,2,FILL_BLACK); 
       break;
       
       case 1:
-      lcd.drawRect(28,2,27,2,FILL_BLACK);
+      lcd.drawRect(28,11,27,2,FILL_BLACK);  // it was lcd.drawRect(28,2,27,2,FILL_BLACK);
       break;
       
       case 2:
-      lcd.drawRect(56,2,25,2,FILL_BLACK);
+      lcd.drawRect(56,11,25,2,FILL_BLACK);  // it was  lcd.drawRect(56,2,25,2,FILL_BLACK);
       break;
    }
 }
@@ -42,24 +43,24 @@
 {                                 // then they are used to shift th screen
   //  _Obstacle_x = seed; 
   addScore(lcd);
- char pixelstate[82][46];
-  for (int i=1; i<83; i+=1) {
-            for (int j=1; j<47; j+=1) {
-             if (lcd.getPixel(i,j)) {
-                 pixelstate[i-1][j-1]=1;
+ char pixelstate[82][37];              // it was char pixelstate[82][46]; 
+  for (int i=1; i<83; i+=1) {          // it was    for (int i=1; i<83; i+=1) {
+            for (int j=10; j<47; j+=1) {   // it was for (int j=1; j<47; j+=1) {
+             if (lcd.getPixel(i,j)) {      // if (lcd.getPixel(i,j)) {
+                 pixelstate[i-1][j-10]=1;   //  pixelstate[i-1][j-1]=1;
                 }
              else  {
-             pixelstate[i-1][j-1]=0;
+             pixelstate[i-1][j-10]=0;        //  pixelstate[i-1][j-1]=0;
          }
       }
    }
-   for (int i=1; i<83; i+=1) {
-            for (int j=1; j<47; j+=1) {
-                if ((pixelstate[i-1][j-1]) ) {
-                    lcd.setPixel(i,j+2);
+   for (int i=1; i<83; i+=1) {           // it was  for (int i=1; i<83; i+=1) { 
+            for (int j=10; j<47; j+=1) {    // it was  for (int j=1; j<47; j+=1) { 
+                if ((pixelstate[i-1][j-10]) ) {   // it was  if ((pixelstate[i-1][j-1]) ) { 
+                    lcd.setPixel(i,j+2);         //       lcd.setPixel(i,j+2);
                 }      // CAN INCREASE THE SPEED BY ADDING 1 FOR Y VALUES
-                if ((pixelstate[i-1][j-2]==0) ) {
-                    lcd.setPixel(i,j+1,false);
+                if ((pixelstate[i-1][j-11]==0) ) {    // if ((pixelstate[i-1][j-2]==0) ) {
+                    lcd.setPixel(i,j+1,false);     //  lcd.setPixel(i,j+1,false);
                 }  
            }
      } 
@@ -70,6 +71,7 @@
     for (int i=2; i<83; i+=1) {
      if (lcd.getPixel(i,46)) {
                 _score++;
+                _totalscore++;
                 break;
                 }
                 }
@@ -79,8 +81,17 @@
 {
     return _score;
 }
-
-void Obstacles::resetScore() 
+int Obstacles::getTotalScore()
 {
-    _score = 0;    
+    return _totalscore;
+}
+
+void Obstacles::updateScore(int Event) 
+{    
+    if (Event == 0) {
+    _score -= 10;
+    }
+    else if (Event == 1) {
+    _score -= 10;    
+    }  
 }
\ No newline at end of file