class for obstacles in Car_race game
Diff: Obstacles.cpp
- Revision:
- 2:4430d4fd91c2
- Parent:
- 1:a735e7396af4
- Child:
- 3:124cf90ee993
diff -r a735e7396af4 -r 4430d4fd91c2 Obstacles.cpp --- a/Obstacles.cpp Tue Mar 14 10:13:40 2017 +0000 +++ b/Obstacles.cpp Fri Mar 17 19:37:36 2017 +0000 @@ -40,23 +40,25 @@ 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=0; i<82; i+=1) { - for (int j=0; j<46; j+=1) { + 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][j]=1; + pixelstate[i-1][j-1]=1; } else { - pixelstate[i][j]=0; - } + pixelstate[i-1][j-1]=0; + } } } - for (int i=0; i<82; i+=1) { - for (int j=0; j<46; j+=1) { - if (pixelstate[i][j]) { - lcd.clearPixel(i,j); + 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); } + if ((pixelstate[i-1][j-2]==0) ) { + lcd.clearPixel(i,j); + } } - } + } } \ No newline at end of file