ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19tb

Dependencies:   mbed

Committer:
el19tb
Date:
Mon May 25 17:53:05 2020 +0000
Revision:
52:1145e99264ea
Parent:
51:4c1f49729d88
Child:
53:b6bb4dab7823
added turtle states, if the frog jumps on turtles under water he is dead...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el19tb 35:db257b7bdefc 1 #include "GraphicEngine.h"
el19tb 35:db257b7bdefc 2
el19tb 50:9ffeb4a10c0a 3 GraphicEngine::GraphicEngine(){}
el19tb 50:9ffeb4a10c0a 4
el19tb 50:9ffeb4a10c0a 5 void GraphicEngine::getPointerPos(int sel)
el19tb 50:9ffeb4a10c0a 6 {
el19tb 50:9ffeb4a10c0a 7 switch(sel)
el19tb 50:9ffeb4a10c0a 8 {
el19tb 50:9ffeb4a10c0a 9 case 0:
el19tb 50:9ffeb4a10c0a 10 lcd.drawSprite(30, 48 - 4*12, 8, 12, (int *)frog);
el19tb 50:9ffeb4a10c0a 11 break;
el19tb 50:9ffeb4a10c0a 12 case 1:
el19tb 50:9ffeb4a10c0a 13 lcd.drawSprite(55, 44 - 4*7, 8, 12, (int *)frog);
el19tb 50:9ffeb4a10c0a 14 break;
el19tb 50:9ffeb4a10c0a 15 case 2:
el19tb 50:9ffeb4a10c0a 16 lcd.drawSprite(50, 48 - 4*4, 8, 12, (int *)frog);
el19tb 50:9ffeb4a10c0a 17 break;
el19tb 50:9ffeb4a10c0a 18 }
el19tb 50:9ffeb4a10c0a 19
el19tb 50:9ffeb4a10c0a 20 wait_ms(10);
el19tb 50:9ffeb4a10c0a 21 }
el19tb 43:2cd1cfe07770 22
el19tb 50:9ffeb4a10c0a 23 void GraphicEngine::drawMenu()
el19tb 50:9ffeb4a10c0a 24 {
el19tb 50:9ffeb4a10c0a 25 lcd.printString("Play",3, 0);
el19tb 50:9ffeb4a10c0a 26 lcd.drawRect(-1, 48 - 4*12, 30, 11, FILL_TRANSPARENT);
el19tb 50:9ffeb4a10c0a 27
el19tb 50:9ffeb4a10c0a 28 lcd.printString("Tutorial",3,2);
el19tb 50:9ffeb4a10c0a 29 lcd.drawRect(-1, 50 - 4*9, 55, 10, FILL_TRANSPARENT);
el19tb 50:9ffeb4a10c0a 30
el19tb 50:9ffeb4a10c0a 31 lcd.printString("Setting",3,4);
el19tb 50:9ffeb4a10c0a 32 lcd.drawRect(-1, 50 - 4*5, 50, 10, FILL_TRANSPARENT);
el19tb 50:9ffeb4a10c0a 33 }
el19tb 50:9ffeb4a10c0a 34
el19tb 50:9ffeb4a10c0a 35 void GraphicEngine::drawTutor1()
el19tb 50:9ffeb4a10c0a 36 {
el19tb 50:9ffeb4a10c0a 37 lcd.printString("Tutorial: (A) ", 0,0);
el19tb 50:9ffeb4a10c0a 38 lcd.printString("To move frog ", 0,1);
el19tb 50:9ffeb4a10c0a 39 lcd.printString("press X(UP), ", 0,2);
el19tb 50:9ffeb4a10c0a 40 lcd.printString("B(DOWN) ", 0,3);
el19tb 50:9ffeb4a10c0a 41 lcd.printString("A(LEFT), ", 0,4);
el19tb 50:9ffeb4a10c0a 42 lcd.printString("Y(right) ", 0,5);
el19tb 50:9ffeb4a10c0a 43 wait_ms(20);
el19tb 50:9ffeb4a10c0a 44 }
el19tb 50:9ffeb4a10c0a 45
el19tb 50:9ffeb4a10c0a 46 void GraphicEngine::drawTutor2()
el19tb 50:9ffeb4a10c0a 47 {
el19tb 50:9ffeb4a10c0a 48 lcd.printString("Tutorial: (A) ", 0,0);
el19tb 50:9ffeb4a10c0a 49 lcd.printString("Avoid, water, ", 0,1);
el19tb 50:9ffeb4a10c0a 50 lcd.printString("vehicles, ", 0,2);
el19tb 50:9ffeb4a10c0a 51 lcd.printString("snakes ", 0,3);
el19tb 50:9ffeb4a10c0a 52 lcd.printString("jump on logs, ", 0,4);
el19tb 50:9ffeb4a10c0a 53 lcd.printString("reach the goal", 0,5);
el19tb 50:9ffeb4a10c0a 54 wait_ms(20);
el19tb 43:2cd1cfe07770 55 }
el19tb 35:db257b7bdefc 56
el19tb 50:9ffeb4a10c0a 57 void GraphicEngine::drawTutor3()
el19tb 50:9ffeb4a10c0a 58 {
el19tb 50:9ffeb4a10c0a 59 lcd.printString("Tutorial: (A) ", 0,0);
el19tb 50:9ffeb4a10c0a 60 lcd.printString("Most ", 0,1);
el19tb 50:9ffeb4a10c0a 61 lcd.printString("importantly ", 0,2);
el19tb 50:9ffeb4a10c0a 62 lcd.printString("Have fun :) ", 0,3);
el19tb 50:9ffeb4a10c0a 63 lcd.printString("Press A ", 0,4);
el19tb 50:9ffeb4a10c0a 64 lcd.printString("to play! ", 0,5);
el19tb 50:9ffeb4a10c0a 65 wait_ms(20);
el19tb 50:9ffeb4a10c0a 66 }
el19tb 50:9ffeb4a10c0a 67
el19tb 50:9ffeb4a10c0a 68 void GraphicEngine::newLevel1()
el19tb 50:9ffeb4a10c0a 69 {
el19tb 50:9ffeb4a10c0a 70 lcd.printString("|------------|", 0,0);
el19tb 51:4c1f49729d88 71 lcd.printString("|Congrats! |", 0,1);
el19tb 50:9ffeb4a10c0a 72 lcd.printString("| |", 0,2);
el19tb 50:9ffeb4a10c0a 73 lcd.printString("| |", 0,3);
el19tb 50:9ffeb4a10c0a 74 lcd.printString("| |", 0,4);
el19tb 50:9ffeb4a10c0a 75 lcd.printString("|------------|", 0,5);
el19tb 50:9ffeb4a10c0a 76 }
el19tb 50:9ffeb4a10c0a 77
el19tb 50:9ffeb4a10c0a 78
el19tb 50:9ffeb4a10c0a 79 void GraphicEngine::newLevel2()
el19tb 50:9ffeb4a10c0a 80 {
el19tb 50:9ffeb4a10c0a 81 lcd.printString("|------------|", 0,0);
el19tb 51:4c1f49729d88 82 lcd.printString("| Loading |", 0,1);
el19tb 51:4c1f49729d88 83 lcd.printString("| |", 0,2);
el19tb 51:4c1f49729d88 84 lcd.printString("| Level 2 |", 0,3);
el19tb 50:9ffeb4a10c0a 85 lcd.printString("| |", 0,4);
el19tb 50:9ffeb4a10c0a 86 lcd.printString("|------------|", 0,5);
el19tb 50:9ffeb4a10c0a 87 }
el19tb 50:9ffeb4a10c0a 88
el19tb 42:04e326dcf09b 89 void GraphicEngine::init()
el19tb 42:04e326dcf09b 90 {
el19tb 35:db257b7bdefc 91 lcd.init();
el19tb 35:db257b7bdefc 92 }
el19tb 35:db257b7bdefc 93
el19tb 42:04e326dcf09b 94 /* TO-DO: ADD CONTROLS FOR BACKLIGHT */
el19tb 42:04e326dcf09b 95 void GraphicEngine::contrast()
el19tb 42:04e326dcf09b 96 {
el19tb 48:8ccfc74b60a5 97 lcd.setContrast(0.45);
el19tb 42:04e326dcf09b 98 }
el19tb 42:04e326dcf09b 99
el19tb 42:04e326dcf09b 100 void GraphicEngine::clear()
el19tb 42:04e326dcf09b 101 {
el19tb 42:04e326dcf09b 102 lcd.clear();
el19tb 35:db257b7bdefc 103 }
el19tb 35:db257b7bdefc 104
el19tb 42:04e326dcf09b 105 void GraphicEngine::refresh()
el19tb 42:04e326dcf09b 106 {
el19tb 42:04e326dcf09b 107 lcd.refresh();
el19tb 42:04e326dcf09b 108 }
el19tb 42:04e326dcf09b 109
el19tb 42:04e326dcf09b 110 void GraphicEngine::backLightOn()
el19tb 35:db257b7bdefc 111 {
el19tb 42:04e326dcf09b 112 lcd.backLightOn();
el19tb 42:04e326dcf09b 113 }
el19tb 42:04e326dcf09b 114
el19tb 52:1145e99264ea 115 void GraphicEngine::showObj(Object *obj, int turtles_state)
el19tb 42:04e326dcf09b 116 {
el19tb 52:1145e99264ea 117 if(obj->object.c == 'G' || obj->object.c == 'M') {
el19tb 44:f02510eeb165 118 displayLog(obj->object.x, obj->object.y, obj->object.c);
el19tb 52:1145e99264ea 119 } else if(obj->object.c == 'T') {
el19tb 52:1145e99264ea 120 displayTurtles(obj->object.x, obj->object.y, obj->object.c, turtles_state);
el19tb 42:04e326dcf09b 121 } else {
el19tb 44:f02510eeb165 122 displayVehicle(obj->object.x, obj->object.y, obj->object.c);
el19tb 52:1145e99264ea 123 }
el19tb 35:db257b7bdefc 124 }
el19tb 52:1145e99264ea 125
el19tb 49:6cad8b6ec5f2 126 void GraphicEngine::drawDangerZone()
el19tb 49:6cad8b6ec5f2 127 {
el19tb 49:6cad8b6ec5f2 128 lcd.drawSprite(0, 48 - 4*11, 7, 83, (int *)danger_zone);
el19tb 49:6cad8b6ec5f2 129 }
el19tb 35:db257b7bdefc 130
el19tb 52:1145e99264ea 131 void GraphicEngine::displayTurtles(int x, int y, char c, int turtle_sate){
el19tb 52:1145e99264ea 132 switch(turtle_sate)
el19tb 52:1145e99264ea 133 {
el19tb 52:1145e99264ea 134 case 0 ... 1000:
el19tb 52:1145e99264ea 135 lcd.drawSprite(x, y, 4, 20, (int *)turtles_state_one);
el19tb 52:1145e99264ea 136 break;
el19tb 52:1145e99264ea 137 case 1001 ... 2000:
el19tb 52:1145e99264ea 138 lcd.drawSprite(x, y, 4, 20, (int *)turtles_state_one);
el19tb 52:1145e99264ea 139 break;
el19tb 52:1145e99264ea 140 case 2001 ... 3000:
el19tb 52:1145e99264ea 141 lcd.drawSprite(x, y, 4, 20, (int *)turtles_state_two);
el19tb 52:1145e99264ea 142 break;
el19tb 52:1145e99264ea 143 case 3001 ... 4000:
el19tb 52:1145e99264ea 144 lcd.drawSprite(x, y, 4, 20, (int *)turtles_state_two);
el19tb 52:1145e99264ea 145 break;
el19tb 52:1145e99264ea 146 case 4001 ... 5000:
el19tb 52:1145e99264ea 147 lcd.drawSprite(x, y, 4, 20, (int *)turtles_state_three);
el19tb 52:1145e99264ea 148 break;
el19tb 52:1145e99264ea 149 }
el19tb 52:1145e99264ea 150 }
el19tb 52:1145e99264ea 151
el19tb 42:04e326dcf09b 152 void GraphicEngine::displayVehicle(int x, int y, char c)
el19tb 35:db257b7bdefc 153 {
el19tb 42:04e326dcf09b 154 switch(c)
el19tb 35:db257b7bdefc 155 {
el19tb 44:f02510eeb165 156 case 'L':
el19tb 46:e39abe665271 157 lcd.drawSprite(x, y, 4, 12, (int *)left_racer);
el19tb 42:04e326dcf09b 158 break;
el19tb 44:f02510eeb165 159 case 'R' :
el19tb 46:e39abe665271 160 lcd.drawSprite(x, y, 4, 12, (int *)right_racer);
el19tb 42:04e326dcf09b 161 break;
el19tb 44:f02510eeb165 162 case 'B':
el19tb 46:e39abe665271 163 lcd.drawSprite(x, y, 4, 16, (int *)bus);
el19tb 35:db257b7bdefc 164 break;
el19tb 44:f02510eeb165 165 case 'N':
el19tb 46:e39abe665271 166 lcd.drawSprite(x, y, 4, 10, (int *)right_normal);
el19tb 42:04e326dcf09b 167 break;
el19tb 44:f02510eeb165 168 case 'X':
el19tb 46:e39abe665271 169 lcd.drawSprite(x, y, 4, 10, (int *)left_normal);
el19tb 42:04e326dcf09b 170 break;
el19tb 42:04e326dcf09b 171 }
el19tb 35:db257b7bdefc 172 }
el19tb 35:db257b7bdefc 173
el19tb 42:04e326dcf09b 174 void GraphicEngine::displayLog(int x, int y, char c)
el19tb 35:db257b7bdefc 175 {
el19tb 42:04e326dcf09b 176 switch(c)
el19tb 42:04e326dcf09b 177 {
el19tb 42:04e326dcf09b 178 case 'G':
el19tb 46:e39abe665271 179 lcd.drawSprite(x, y, 4, 20, (int *)log_big);
el19tb 42:04e326dcf09b 180 break;
el19tb 42:04e326dcf09b 181
el19tb 42:04e326dcf09b 182 case 'M':
el19tb 46:e39abe665271 183 lcd.drawSprite(x, y, 4, 16, (int *)medium_log);
el19tb 42:04e326dcf09b 184 break;
el19tb 42:04e326dcf09b 185 }
el19tb 35:db257b7bdefc 186 }
el19tb 35:db257b7bdefc 187
el19tb 42:04e326dcf09b 188 /* TO-DO: ADD SPRITES AND SPRITE STATE */
el19tb 47:29c4796a49e5 189 void GraphicEngine::showFrog(float x, int y, int width, int height, int state)
el19tb 35:db257b7bdefc 190 {
el19tb 47:29c4796a49e5 191 switch(state)
el19tb 47:29c4796a49e5 192 {
el19tb 47:29c4796a49e5 193 case 0:
el19tb 47:29c4796a49e5 194 lcd.drawSprite(x, y, 4, 6, (int *)frog_state_up);
el19tb 47:29c4796a49e5 195 break;
el19tb 52:1145e99264ea 196 case 1:
el19tb 47:29c4796a49e5 197 lcd.drawSprite(x, y, 4, 6, (int *)frog_state_left);
el19tb 47:29c4796a49e5 198 break;
el19tb 47:29c4796a49e5 199 case 2:
el19tb 47:29c4796a49e5 200 lcd.drawSprite(x, y, 4, 6, (int *)frog_state_right);
el19tb 47:29c4796a49e5 201 break;
el19tb 47:29c4796a49e5 202 case 3:
el19tb 47:29c4796a49e5 203 lcd.drawSprite(x, y, 4, 6, (int *)frog_state_down);
el19tb 47:29c4796a49e5 204 break;
el19tb 47:29c4796a49e5 205 }
el19tb 42:04e326dcf09b 206 }
el19tb 35:db257b7bdefc 207
el19tb 42:04e326dcf09b 208 void GraphicEngine::drawSafetyLanes()
el19tb 42:04e326dcf09b 209 {
el19tb 49:6cad8b6ec5f2 210 lcd.drawSprite(0, 48 - 4, 4, 83, (int *)safety_zone); // row 0 -> bottom
el19tb 49:6cad8b6ec5f2 211
el19tb 49:6cad8b6ec5f2 212 lcd.drawSprite(0, 48 - 4*6, 4, 83, (int *)safety_zone); // row 6 -> middle(ish)
el19tb 49:6cad8b6ec5f2 213 }
el19tb 49:6cad8b6ec5f2 214
el19tb 50:9ffeb4a10c0a 215 void GraphicEngine::drawEndPost(int x_pos)
el19tb 49:6cad8b6ec5f2 216 {
el19tb 50:9ffeb4a10c0a 217 lcd.drawSprite(x_pos, 48 - 4*11, 8, 12, (int *)goal_post);
el19tb 35:db257b7bdefc 218 }
el19tb 35:db257b7bdefc 219
el19tb 44:f02510eeb165 220 void GraphicEngine::printTest()
el19tb 44:f02510eeb165 221 {
el19tb 35:db257b7bdefc 222 lcd.printString("SQUISHED", 1, 1);
el19tb 35:db257b7bdefc 223 }
el19tb 35:db257b7bdefc 224
el19tb 44:f02510eeb165 225 void GraphicEngine::print()
el19tb 44:f02510eeb165 226 {
el19tb 35:db257b7bdefc 227 lcd.printString("DROWNED",1,1);
el19tb 35:db257b7bdefc 228 }
el19tb 43:2cd1cfe07770 229
el19tb 44:f02510eeb165 230 void GraphicEngine::printLoser()
el19tb 44:f02510eeb165 231 {
el19tb 44:f02510eeb165 232 lcd.printString("LOSER!!!!",1,1);
el19tb 44:f02510eeb165 233 }
el19tb 44:f02510eeb165 234
el19tb 50:9ffeb4a10c0a 235 void GraphicEngine::printCongrats()
el19tb 50:9ffeb4a10c0a 236 {
el19tb 50:9ffeb4a10c0a 237 lcd.printString("CONGTATS NEXT LEVEL!!!!",1,1);
el19tb 52:1145e99264ea 238 }