Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE mbed SDFileSystem wave_player
food.cpp
00001 #include "mbed.h" 00002 #include "uLCD_4DGL.h" 00003 #include "food.h" 00004 #include <algorithm> 00005 00006 #define BREAD 1 00007 #define LETTUCE 2 00008 #define CHEESE 3 00009 #define TOMATO 4 00010 #define BADLETTUCE 5 00011 #define BADCHEESE 6 00012 #define BADTOMATO 7 00013 00014 #define MAX(i) std::max(i,0) 00015 #define MIN(i) std::min(i,128) 00016 00017 #define MAROON 0x8b0000 00018 #define DARKBROWN 0x654321 00019 #define YELLOW 0xffff00 00020 #define PURPLE 0x551a8b 00021 #define BROWN 0xf4a460 00022 00023 Food::Food(uLCD_4DGL * uLCD) { 00024 lcd = uLCD; 00025 typeOfFood = BREAD; 00026 isBad = false; 00027 // leave x and y uninitialized? 00028 } 00029 00030 Food::Food(int type, int location, uLCD_4DGL * uLCD) { 00031 lcd = uLCD; 00032 typeOfFood = type; 00033 isBad = (type == BADLETTUCE 00034 || type == BADTOMATO || type == BADCHEESE) ? true : false; 00035 x = location; 00036 y = 1; 00037 } 00038 00039 void Food::draw() { 00040 switch (typeOfFood) { 00041 case LETTUCE: drawLettuce(GREEN); 00042 break; 00043 case TOMATO: drawTomato(RED); 00044 break; 00045 case CHEESE: drawCheese(YELLOW); 00046 break; 00047 case BREAD: drawBread(); 00048 break; 00049 case BADLETTUCE: drawLettuce(PURPLE); 00050 break; 00051 case BADTOMATO: drawTomato(PURPLE); 00052 break; 00053 case BADCHEESE: drawCheese(PURPLE); 00054 break; 00055 } 00056 } 00057 00058 void Food::drawLettuce(int color) { 00059 lcd->filled_rectangle(x, y, x + 15, y + 3, color); 00060 /* 00061 lcd->pixel(x + 1, y, BLACK); 00062 lcd->pixel(x + 3, y, BLACK); 00063 lcd->pixel(x + 5, y, BLACK); 00064 lcd->pixel(x, y + 3, BLACK); 00065 lcd->pixel(x + 6, y + 3, BLACK); 00066 lcd->pixel(x + 7, y + 3, BLACK); 00067 */ 00068 } 00069 00070 void Food::drawTomato(int color) { 00071 lcd->filled_rectangle(x, y, x + 15, y + 3, color); 00072 /* 00073 lcd->line(x + 2, y, x + 5, y, 0x8b0000); 00074 lcd->line(x + 2, y + 3, x + 5, y + 3, color); 00075 lcd->line(x, y + 1, x + 1, y + 1, MAROON); 00076 lcd->line(x, y + 6, x + 1, y + 7, MAROON); 00077 */ 00078 } 00079 00080 void Food::drawCheese(int color) { 00081 lcd->filled_rectangle(x, y, x + 15, y + 3, color); 00082 /* 00083 lcd->pixel(x, y + 7, WHITE); 00084 lcd->pixel(x + 1, y + 5, WHITE); 00085 lcd->filled_rectangle(x + 2, y + 2, x + 3, y + 3, WHITE); 00086 */ 00087 } 00088 00089 void Food::drawBread() { 00090 lcd->filled_rectangle(x, y, x + 15, y + 3, BROWN); 00091 /* 00092 lcd->pixel(x, y, BLACK); 00093 lcd->pixel(x, y + 3, BLACK); 00094 lcd->pixel(x, y + 1, DARKBROWN); 00095 lcd->pixel(x, y + 2, DARKBROWN); 00096 */ 00097 } 00098 00099 void Food::erase() { 00100 lcd->filled_rectangle(x, y, x + 15, y + 3, BLACK); 00101 } 00102 00103 void Food::fall() { 00104 erase(); 00105 y = y + 1; 00106 draw(); 00107 }
Generated on Fri Jul 22 2022 03:38:06 by
1.7.2