class for obstacles in Car_race game

Committer:
fy14aaz
Date:
Tue Apr 11 22:37:40 2017 +0000
Revision:
6:44243b2bc27c
Parent:
5:b000cefeb3c5
Child:
7:55d1306f5df5
working on bullet class

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 5:b000cefeb3c5 27 lcd.drawRect(2,2,25,2,FILL_BLACK);
fy14aaz 0:f8968ec0ec1b 28 break;
fy14aaz 0:f8968ec0ec1b 29
fy14aaz 0:f8968ec0ec1b 30 case 1:
fy14aaz 5:b000cefeb3c5 31 lcd.drawRect(28,2,27,2,FILL_BLACK);
fy14aaz 0:f8968ec0ec1b 32 break;
fy14aaz 0:f8968ec0ec1b 33
fy14aaz 0:f8968ec0ec1b 34 case 2:
fy14aaz 5:b000cefeb3c5 35 lcd.drawRect(56,2,25,2,FILL_BLACK);
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 4:b1648ba28d3f 58 } // CAN INCREASE THE SPEED BY ADDING 1 FOR Y VALUES
fy14aaz 2:4430d4fd91c2 59 if ((pixelstate[i-1][j-2]==0) ) {
fy14aaz 6:44243b2bc27c 60 lcd.setPixel(i,j,false);
fy14aaz 2:4430d4fd91c2 61 }
fy14aaz 1:a735e7396af4 62 }
fy14aaz 2:4430d4fd91c2 63 }
fy14aaz 0:f8968ec0ec1b 64 }