class for obstacles in Car_race game
Obstacles.cpp@1:a735e7396af4, 2017-03-14 (annotated)
- Committer:
- fy14aaz
- Date:
- Tue Mar 14 10:13:40 2017 +0000
- Revision:
- 1:a735e7396af4
- Parent:
- 0:f8968ec0ec1b
- Child:
- 2:4430d4fd91c2
successfully managed to shift the screen. Need now to make the interaction conditions of objects and extras
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:f8968ec0ec1b | 27 | lcd.drawRect(2,2,24,2,1); |
fy14aaz | 0:f8968ec0ec1b | 28 | break; |
fy14aaz | 0:f8968ec0ec1b | 29 | |
fy14aaz | 0:f8968ec0ec1b | 30 | case 1: |
fy14aaz | 0:f8968ec0ec1b | 31 | lcd.drawRect(30,2,24,2,1); |
fy14aaz | 0:f8968ec0ec1b | 32 | break; |
fy14aaz | 0:f8968ec0ec1b | 33 | |
fy14aaz | 0:f8968ec0ec1b | 34 | case 2: |
fy14aaz | 0:f8968ec0ec1b | 35 | lcd.drawRect(58,2,24,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 | 1:a735e7396af4 | 43 | char pixelstate[82][46]; |
fy14aaz | 1:a735e7396af4 | 44 | for (int i=0; i<82; i+=1) { |
fy14aaz | 1:a735e7396af4 | 45 | for (int j=0; j<46; j+=1) { |
fy14aaz | 1:a735e7396af4 | 46 | if (lcd.getPixel(i,j)) { |
fy14aaz | 1:a735e7396af4 | 47 | pixelstate[i][j]=1; |
fy14aaz | 1:a735e7396af4 | 48 | } |
fy14aaz | 1:a735e7396af4 | 49 | else { |
fy14aaz | 1:a735e7396af4 | 50 | pixelstate[i][j]=0; |
fy14aaz | 1:a735e7396af4 | 51 | } |
fy14aaz | 1:a735e7396af4 | 52 | } |
fy14aaz | 1:a735e7396af4 | 53 | } |
fy14aaz | 1:a735e7396af4 | 54 | for (int i=0; i<82; i+=1) { |
fy14aaz | 1:a735e7396af4 | 55 | for (int j=0; j<46; j+=1) { |
fy14aaz | 1:a735e7396af4 | 56 | if (pixelstate[i][j]) { |
fy14aaz | 1:a735e7396af4 | 57 | lcd.clearPixel(i,j); |
fy14aaz | 1:a735e7396af4 | 58 | lcd.setPixel(i,j+1); |
fy14aaz | 1:a735e7396af4 | 59 | } |
fy14aaz | 1:a735e7396af4 | 60 | } |
fy14aaz | 1:a735e7396af4 | 61 | } |
fy14aaz | 0:f8968ec0ec1b | 62 | } |