class for obstacles in Car_race game

Committer:
fy14aaz
Date:
Sun Mar 19 22:52:41 2017 +0000
Revision:
3:124cf90ee993
Parent:
2:4430d4fd91c2
Child:
4:b1648ba28d3f
tried to resolve the randomness problem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fy14aaz 0:f8968ec0ec1b 1 #include "Obstacles.h"
fy14aaz 0:f8968ec0ec1b 2
fy14aaz 0:f8968ec0ec1b 3 Obstacles::Obstacles()
fy14aaz 0:f8968ec0ec1b 4 {
fy14aaz 0:f8968ec0ec1b 5
fy14aaz 0:f8968ec0ec1b 6 }
fy14aaz 0:f8968ec0ec1b 7
fy14aaz 0:f8968ec0ec1b 8 Obstacles::~Obstacles()
fy14aaz 0:f8968ec0ec1b 9 {
fy14aaz 0:f8968ec0ec1b 10
fy14aaz 0:f8968ec0ec1b 11 }
fy14aaz 0:f8968ec0ec1b 12
fy14aaz 0:f8968ec0ec1b 13 void Obstacles::init(int seed)
fy14aaz 0:f8968ec0ec1b 14 {
fy14aaz 0:f8968ec0ec1b 15 _Obstacle_x = seed;
fy14aaz 0:f8968ec0ec1b 16 // try to draw them here in this function as we need the draw function for another purpose
fy14aaz 0:f8968ec0ec1b 17 // are we done though? we might need to split the draw function into two, one for drawing the car
fy14aaz 0:f8968ec0ec1b 18 // and the other for drawing the obstacles as they are drawn in a time basis
fy14aaz 0:f8968ec0ec1b 19 }
fy14aaz 0:f8968ec0ec1b 20
fy14aaz 1:a735e7396af4 21 void Obstacles::draw(N5110 &lcd,int seed)
fy14aaz 0:f8968ec0ec1b 22 {
fy14aaz 1:a735e7396af4 23 _Obstacle_x = seed;
fy14aaz 0:f8968ec0ec1b 24 switch(_Obstacle_x){
fy14aaz 0:f8968ec0ec1b 25
fy14aaz 0:f8968ec0ec1b 26 case 0:
fy14aaz 3:124cf90ee993 27 lcd.drawRect(2,2,25,2,1);
fy14aaz 0:f8968ec0ec1b 28 break;
fy14aaz 0:f8968ec0ec1b 29
fy14aaz 0:f8968ec0ec1b 30 case 1:
fy14aaz 3:124cf90ee993 31 lcd.drawRect(28,2,27,2,1);
fy14aaz 0:f8968ec0ec1b 32 break;
fy14aaz 0:f8968ec0ec1b 33
fy14aaz 0:f8968ec0ec1b 34 case 2:
fy14aaz 3:124cf90ee993 35 lcd.drawRect(56,2,25,2,1);
fy14aaz 0:f8968ec0ec1b 36 break;
fy14aaz 0:f8968ec0ec1b 37 }
fy14aaz 0:f8968ec0ec1b 38 }
fy14aaz 0:f8968ec0ec1b 39
fy14aaz 1:a735e7396af4 40 void Obstacles::update(N5110 &lcd) // adjust this function to be able to store all pixels values
fy14aaz 0:f8968ec0ec1b 41 { // then they are used to shift th screen
fy14aaz 1:a735e7396af4 42 // _Obstacle_x = seed;
fy14aaz 2:4430d4fd91c2 43 char pixelstate[82][46];
fy14aaz 2:4430d4fd91c2 44 for (int i=1; i<83; i+=1) {
fy14aaz 2:4430d4fd91c2 45 for (int j=1; j<47; j+=1) {
fy14aaz 1:a735e7396af4 46 if (lcd.getPixel(i,j)) {
fy14aaz 2:4430d4fd91c2 47 pixelstate[i-1][j-1]=1;
fy14aaz 1:a735e7396af4 48 }
fy14aaz 1:a735e7396af4 49 else {
fy14aaz 2:4430d4fd91c2 50 pixelstate[i-1][j-1]=0;
fy14aaz 2:4430d4fd91c2 51 }
fy14aaz 1:a735e7396af4 52 }
fy14aaz 1:a735e7396af4 53 }
fy14aaz 2:4430d4fd91c2 54 for (int i=1; i<83; i+=1) {
fy14aaz 2:4430d4fd91c2 55 for (int j=1; j<47; j+=1) {
fy14aaz 2:4430d4fd91c2 56 if ((pixelstate[i-1][j-1]) ) {
fy14aaz 1:a735e7396af4 57 lcd.setPixel(i,j+1);
fy14aaz 1:a735e7396af4 58 }
fy14aaz 2:4430d4fd91c2 59 if ((pixelstate[i-1][j-2]==0) ) {
fy14aaz 2:4430d4fd91c2 60 lcd.clearPixel(i,j);
fy14aaz 2:4430d4fd91c2 61 }
fy14aaz 1:a735e7396af4 62 }
fy14aaz 2:4430d4fd91c2 63 }
fy14aaz 0:f8968ec0ec1b 64 }