class for obstacles in Car_race game
Diff: Obstacles.cpp
- Revision:
- 8:c8007ccac5c0
- Parent:
- 7:55d1306f5df5
- Child:
- 9:d5f90988545e
diff -r 55d1306f5df5 -r c8007ccac5c0 Obstacles.cpp --- a/Obstacles.cpp Mon Apr 17 20:45:19 2017 +0000 +++ b/Obstacles.cpp Wed Apr 19 20:55:18 2017 +0000 @@ -13,6 +13,7 @@ void Obstacles::init(int seed) { _Obstacle_x = seed; + _score = 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 @@ -40,6 +41,7 @@ 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; + addScore(lcd); char pixelstate[82][46]; for (int i=1; i<83; i+=1) { for (int j=1; j<47; j+=1) { @@ -61,4 +63,24 @@ } } } +} + +void Obstacles::addScore(N5110 &lcd) +{ + for (int i=2; i<83; i+=1) { + if (lcd.getPixel(i,46)) { + _score++; + break; + } + } +} + +int Obstacles::getScore() +{ + return _score; +} + +void Obstacles::resetScore() +{ + _score = 0; } \ No newline at end of file