class for obstacles in Car_race game

Obstacles.cpp

Committer:
fy14aaz
Date:
2017-03-23
Revision:
4:b1648ba28d3f
Parent:
3:124cf90ee993
Child:
5:b000cefeb3c5

File content as of revision 4:b1648ba28d3f:

#include "Obstacles.h"

Obstacles::Obstacles()
{
    
}

Obstacles::~Obstacles()
{
    
}

void Obstacles::init(int seed)
{
    _Obstacle_x = seed;
    // 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
}

void Obstacles::draw(N5110 &lcd,int seed)
{
    _Obstacle_x = seed;
    switch(_Obstacle_x){
      
      case 0:
      lcd.drawRect(2,2,25,2,1);
      break;
      
      case 1:
      lcd.drawRect(28,2,27,2,1);
      break;
      
      case 2:
      lcd.drawRect(56,2,25,2,1);
      break;
   }
}

void Obstacles::update(N5110 &lcd) // adjust this function to be able to store all pixels values
{                                 // then they are used to shift th screen
  //  _Obstacle_x = seed; 
 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;
                }
             else  {
             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+1);
                }      // CAN INCREASE THE SPEED BY ADDING 1 FOR Y VALUES
                if ((pixelstate[i-1][j-2]==0) ) {
                    lcd.clearPixel(i,j);
                }  
           }
     } 
}