ECE2035 Project 2
Dependencies: mbed mbed-rtos SDFileSystem
Revision 10:1994adcfc86f, committed 2021-04-20
- Comitter:
- kwengryn3
- Date:
- Tue Apr 20 18:15:22 2021 +0000
- Parent:
- 9:f1d34ef049c5
- Commit message:
- adv features
Changed in this revision
diff -r f1d34ef049c5 -r 1994adcfc86f fruit.cpp --- a/fruit.cpp Tue Apr 20 13:46:45 2021 +0000 +++ b/fruit.cpp Tue Apr 20 18:15:22 2021 +0000 @@ -42,7 +42,7 @@ // M->y = 0; //each fruit has its own tick //pc.printf("rand\n"); - M->type = rand() % 3; + M->type = rand() % 4; switch (M->type) { case 0: @@ -54,6 +54,8 @@ case 2: M->draw = draw_banana; break; + case 3: + M->draw = draw_apple; default: break; } @@ -138,9 +140,8 @@ //pc.printf("Fruit %d: - (%d, %d),(%d, %d)\n", count, newFruit->box.topLeft.x, newFruit->box.topLeft.y, newFruit->box.bottomRight.x, newFruit->box.bottomRight.y); if(newFruit->status == FRUIT_SLICED || newFruit->box.topLeft.x > 127 || - newFruit->box.topLeft.y > 127 || - newFruit->box.bottomRight.x <= 0 || - newFruit->box.bottomRight.y <= 0) + newFruit->box.topLeft.y > 120 || + newFruit->box.topLeft.x <= 0) { //cover the last fruit location draw_nothing(newFruit->box);
diff -r f1d34ef049c5 -r 1994adcfc86f graphics.cpp --- a/graphics.cpp Tue Apr 20 13:46:45 2021 +0000 +++ b/graphics.cpp Tue Apr 20 18:15:22 2021 +0000 @@ -9,6 +9,81 @@ #define DIRT BROWN #define RED 0xFF0000 #define ORANGE 0xFFA500 +#define X 0xFF0000 +#define _ 0x000000 +#define W 0xFFFFFF +#define O 0xFD6A02 +#define G 0x00FF00 +#define B 0x664229 +#define Y 0xFFFF00 + + +int bomb_sprite[10 * 10] = { +_,_,_,_,_,X,X,X,X,X, +_,_,_,X,X,X,X,_,_,X, +_,_,_,X,X,X,X,_,_,_, +_,X,X,X,X,X,X,X,X,_, +X,X,X,X,X,X,X,X,X,X, +X,X,X,X,X,X,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,_,_,_,_, + +}; + + void draw_img(int u, int v, const char* img) { int colors[11*11]; @@ -34,23 +109,33 @@ void draw_nothing(boundingBox b) { // Erase a bounding box - uLCD.filled_rectangle(b.topLeft.x, b.topLeft.y, b.bottomRight.x, b.bottomRight.y, BLACK); + //uLCD.filled_rectangle(b.topLeft.x, b.topLeft.y, b.bottomRight.x, b.bottomRight.y, BLACK); + uLCD.BLIT(b.topLeft.x, b.topLeft.y, 10, 10, fruit_mask); } void draw_bomb(boundingBox b) { // Draw an apple using a filled_rectangle or get creative and use a sprite! - uLCD.filled_rectangle(b.topLeft.x, b.topLeft.y, b.bottomRight.x, b.bottomRight.y, RED); + //uLCD.filled_rectangle(b.topLeft.x, b.topLeft.y, b.bottomRight.x, b.bottomRight.y, RED); + uLCD.BLIT(b.topLeft.x, b.topLeft.y, 10, 10, bomb_sprite); } void draw_banana(boundingBox b) { // Draw a banana using a filled_rectangle or get creative and use a sprite! - uLCD.filled_rectangle(b.topLeft.x, b.topLeft.y, b.bottomRight.x, b.bottomRight.y, YELLOW); + //uLCD.filled_rectangle(b.topLeft.x, b.topLeft.y, b.bottomRight.x, b.bottomRight.y, YELLOW); + uLCD.BLIT(b.topLeft.x, b.topLeft.y, 10, 10, banana_sprite); } void draw_orange(boundingBox b) { // Draw an orange using a filled_rectangle or get creative and use a sprite! - uLCD.filled_rectangle(b.topLeft.x, b.topLeft.y, b.bottomRight.x, b.bottomRight.y, ORANGE); + //uLCD.filled_rectangle(b.topLeft.x, b.topLeft.y, b.bottomRight.x, b.bottomRight.y, ORANGE); + uLCD.BLIT(b.topLeft.x, b.topLeft.y, 10, 10, orange_sprite); } + +void draw_apple(boundingBox b) { + uLCD.BLIT(b.topLeft.x, b.topLeft.y, 10, 10, apple_sprite); +} + +
diff -r f1d34ef049c5 -r 1994adcfc86f graphics.h --- a/graphics.h Tue Apr 20 13:46:45 2021 +0000 +++ b/graphics.h Tue Apr 20 18:15:22 2021 +0000 @@ -39,6 +39,7 @@ void draw_bomb(boundingBox b); void draw_banana(boundingBox b); void draw_orange(boundingBox b); +void draw_apple(boundingBox b); #endif // GRAPHICS_H