Faizan and Pages fun little game
Dependencies: 4DGL-uLCD-SE mbed SDFileSystem wave_player
Diff: food.cpp
- Revision:
- 1:9eeeb0d8f036
- Parent:
- 0:de9ffb858be9
- Child:
- 2:4c5f409d6bb8
diff -r de9ffb858be9 -r 9eeeb0d8f036 food.cpp --- a/food.cpp Fri Oct 28 17:33:29 2016 +0000 +++ b/food.cpp Sat Oct 29 19:35:46 2016 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" #include "uLCD_4DGL.h" #include "food.h" +#include <algorithm> + #define BREAD 1 #define LETTUCE 2 #define CHEESE 3 @@ -9,25 +11,71 @@ #define BADCHEESE 6 #define BADTOMATO 7 -uLCD_4DGL lcd(p9,p10,p11); +#define MAX(i) std::max(i,0) +#define MIN(i) std::min(i,128) -Food::Food(int type) { +#define MAROON 0x8b0000; +#define DARKBROWN 0x654321; + +Food::Food(int type, int location, uLCD_4DGL * uLCD) { + lcd = uLCD; typeOfFood = type; isBad = (type == BADLETTUCE || type == BADTOMATO || type == BADCHEESE) ? true : false; + x = location; + y = -3; } void Food::draw() { switch (typeOfFood) { - case LETTUCE: drawLettuce(); + case LETTUCE: drawLettuce(GREEN); + break; + case TOMATO: drawTomato(RED): + break; + case CHEESE: drawCheese(YELLOW); + break; + case BREAD: drawBread(); break; - case TOMATO: - case CHEESE: - case BREAD: - case BADLETTUCE: - case BADTOMATO: - case BADCHEESE: + case BADLETTUCE: drawLettuce(PURPLE); + break; + case BADTOMATO: drawTomato(PURPLE); + break; + case BADCHEESE: drawCheese(PURPLE); + break; + case + default: } } -void F \ No newline at end of file +void Food::drawLettuce(int color) { + lcd.filled_rectangle(MAX(x), MAX(y), MIN(x + 7), MIN(y + 3), color); + lcd.pixel(x + 1, y, BLACK); + lcd.pixel(x + 3, y, BLACK); + lcd.pixel(x + 5, y, BLACK); + lcd.pixel(x, y + 3, BLACK); + lcd.pixel(x + 6, y + 3, BLACK); + lcd.pixel(x + 7, y + 3, BLACK); +} + +void Food::drawTomato(int color) { + lcd.filled_rectangle(MAX(x + 1), MAX(y), MIN(x + 2), MIN(y + 7), color); + lcd.line(x + 2, y, x + 5, y, MAROON); + lcd.line(x + 2, y + 3, x + 5, y + 3, color); + lcd.line(x, y + 1, x + 1, y + 1, MAROON); + lcd.line(x, y + 6, x + 1, y + 7, MAROON); +} + +void Food::drawCheese(int color) { + lcd.filled_rectangle(MAX(x), MAX(y), MIN(x + 7), MIN(y + 3), color); + lcd.pixel(x, y + 7, WHITE); + lcd.pixel(x + 1, y + 5, WHITE); + lcd.filled_rectangle(x + 2, y + 2, x + 3, y + 3, WHITE); +} + +void Food::drawBread() { + lcd.filled_rectangle(MAX(x), MAX(y), MIN(x + 7), MIN(y + 3), BROWN); + lcd.pixel(x, y, BLACK); + lcd.pixel(x, y + 3, BLACK); + lcd.pixel(x, y + 1, DARKBROWN); + lcd.pixel(x, y + 2, DARKBROWN); +} \ No newline at end of file