class for obstacles in Car_race game

Committer:
fy14aaz
Date:
Fri Apr 21 21:45:49 2017 +0000
Revision:
9:d5f90988545e
Parent:
8:c8007ccac5c0
Child:
10:515df7535b2f
worked on the bullet with the jumping functions

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 8:c8007ccac5c0 16 _score = 0;
fy14aaz 9:d5f90988545e 17 _totalscore = 0;
fy14aaz 0:f8968ec0ec1b 18 // try to draw them here in this function as we need the draw function for another purpose
fy14aaz 0:f8968ec0ec1b 19 // are we done though? we might need to split the draw function into two, one for drawing the car
fy14aaz 0:f8968ec0ec1b 20 // and the other for drawing the obstacles as they are drawn in a time basis
fy14aaz 0:f8968ec0ec1b 21 }
fy14aaz 0:f8968ec0ec1b 22
fy14aaz 1:a735e7396af4 23 void Obstacles::draw(N5110 &lcd,int seed)
fy14aaz 0:f8968ec0ec1b 24 {
fy14aaz 1:a735e7396af4 25 _Obstacle_x = seed;
fy14aaz 0:f8968ec0ec1b 26 switch(_Obstacle_x){
fy14aaz 0:f8968ec0ec1b 27
fy14aaz 0:f8968ec0ec1b 28 case 0:
fy14aaz 9:d5f90988545e 29 lcd.drawRect(2,11,25,2,FILL_BLACK); // it was lcd.drawRect(2,2,25,2,FILL_BLACK);
fy14aaz 0:f8968ec0ec1b 30 break;
fy14aaz 0:f8968ec0ec1b 31
fy14aaz 0:f8968ec0ec1b 32 case 1:
fy14aaz 9:d5f90988545e 33 lcd.drawRect(28,11,27,2,FILL_BLACK); // it was lcd.drawRect(28,2,27,2,FILL_BLACK);
fy14aaz 0:f8968ec0ec1b 34 break;
fy14aaz 0:f8968ec0ec1b 35
fy14aaz 0:f8968ec0ec1b 36 case 2:
fy14aaz 9:d5f90988545e 37 lcd.drawRect(56,11,25,2,FILL_BLACK); // it was lcd.drawRect(56,2,25,2,FILL_BLACK);
fy14aaz 0:f8968ec0ec1b 38 break;
fy14aaz 0:f8968ec0ec1b 39 }
fy14aaz 0:f8968ec0ec1b 40 }
fy14aaz 0:f8968ec0ec1b 41
fy14aaz 1:a735e7396af4 42 void Obstacles::update(N5110 &lcd) // adjust this function to be able to store all pixels values
fy14aaz 0:f8968ec0ec1b 43 { // then they are used to shift th screen
fy14aaz 1:a735e7396af4 44 // _Obstacle_x = seed;
fy14aaz 8:c8007ccac5c0 45 addScore(lcd);
fy14aaz 9:d5f90988545e 46 char pixelstate[82][37]; // it was char pixelstate[82][46];
fy14aaz 9:d5f90988545e 47 for (int i=1; i<83; i+=1) { // it was for (int i=1; i<83; i+=1) {
fy14aaz 9:d5f90988545e 48 for (int j=10; j<47; j+=1) { // it was for (int j=1; j<47; j+=1) {
fy14aaz 9:d5f90988545e 49 if (lcd.getPixel(i,j)) { // if (lcd.getPixel(i,j)) {
fy14aaz 9:d5f90988545e 50 pixelstate[i-1][j-10]=1; // pixelstate[i-1][j-1]=1;
fy14aaz 1:a735e7396af4 51 }
fy14aaz 1:a735e7396af4 52 else {
fy14aaz 9:d5f90988545e 53 pixelstate[i-1][j-10]=0; // pixelstate[i-1][j-1]=0;
fy14aaz 2:4430d4fd91c2 54 }
fy14aaz 1:a735e7396af4 55 }
fy14aaz 1:a735e7396af4 56 }
fy14aaz 9:d5f90988545e 57 for (int i=1; i<83; i+=1) { // it was for (int i=1; i<83; i+=1) {
fy14aaz 9:d5f90988545e 58 for (int j=10; j<47; j+=1) { // it was for (int j=1; j<47; j+=1) {
fy14aaz 9:d5f90988545e 59 if ((pixelstate[i-1][j-10]) ) { // it was if ((pixelstate[i-1][j-1]) ) {
fy14aaz 9:d5f90988545e 60 lcd.setPixel(i,j+2); // lcd.setPixel(i,j+2);
fy14aaz 4:b1648ba28d3f 61 } // CAN INCREASE THE SPEED BY ADDING 1 FOR Y VALUES
fy14aaz 9:d5f90988545e 62 if ((pixelstate[i-1][j-11]==0) ) { // if ((pixelstate[i-1][j-2]==0) ) {
fy14aaz 9:d5f90988545e 63 lcd.setPixel(i,j+1,false); // lcd.setPixel(i,j+1,false);
fy14aaz 2:4430d4fd91c2 64 }
fy14aaz 1:a735e7396af4 65 }
fy14aaz 2:4430d4fd91c2 66 }
fy14aaz 8:c8007ccac5c0 67 }
fy14aaz 8:c8007ccac5c0 68
fy14aaz 8:c8007ccac5c0 69 void Obstacles::addScore(N5110 &lcd)
fy14aaz 8:c8007ccac5c0 70 {
fy14aaz 8:c8007ccac5c0 71 for (int i=2; i<83; i+=1) {
fy14aaz 8:c8007ccac5c0 72 if (lcd.getPixel(i,46)) {
fy14aaz 8:c8007ccac5c0 73 _score++;
fy14aaz 9:d5f90988545e 74 _totalscore++;
fy14aaz 8:c8007ccac5c0 75 break;
fy14aaz 8:c8007ccac5c0 76 }
fy14aaz 8:c8007ccac5c0 77 }
fy14aaz 8:c8007ccac5c0 78 }
fy14aaz 8:c8007ccac5c0 79
fy14aaz 8:c8007ccac5c0 80 int Obstacles::getScore()
fy14aaz 8:c8007ccac5c0 81 {
fy14aaz 8:c8007ccac5c0 82 return _score;
fy14aaz 8:c8007ccac5c0 83 }
fy14aaz 9:d5f90988545e 84 int Obstacles::getTotalScore()
fy14aaz 8:c8007ccac5c0 85 {
fy14aaz 9:d5f90988545e 86 return _totalscore;
fy14aaz 9:d5f90988545e 87 }
fy14aaz 9:d5f90988545e 88
fy14aaz 9:d5f90988545e 89 void Obstacles::updateScore(int Event)
fy14aaz 9:d5f90988545e 90 {
fy14aaz 9:d5f90988545e 91 if (Event == 0) {
fy14aaz 9:d5f90988545e 92 _score -= 10;
fy14aaz 9:d5f90988545e 93 }
fy14aaz 9:d5f90988545e 94 else if (Event == 1) {
fy14aaz 9:d5f90988545e 95 _score -= 10;
fy14aaz 9:d5f90988545e 96 }
fy14aaz 0:f8968ec0ec1b 97 }