Joe Shotton / Mbed 2 deprecated ELEC2645_Project_ll16j23s

Dependencies:   mbed ll16j23s_test_docs

Committer:
JoeShotton
Date:
Mon May 25 20:31:52 2020 +0000
Revision:
9:0571880085cc
Parent:
8:bcc3403d7e79
Child:
10:a2d643b3c782
Post death menus partially implemented, mostly fixed food location issues and issues with tail display

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JoeShotton 3:fcd6d70e9694 1 #include "SnakeEngine.h"
JoeShotton 3:fcd6d70e9694 2
JoeShotton 7:dd84e0fab346 3 SnakeEngine::SnakeEngine() {
JoeShotton 7:dd84e0fab346 4 //constructor
JoeShotton 4:ea3fa51c4386 5 score = 0;
JoeShotton 9:0571880085cc 6 _menu_select = 0;
JoeShotton 9:0571880085cc 7 _map_select = 0;
JoeShotton 7:dd84e0fab346 8 _game_state = 1;
JoeShotton 8:bcc3403d7e79 9 _pot2 = 0.5;
JoeShotton 9:0571880085cc 10 _death = false;
JoeShotton 9:0571880085cc 11
JoeShotton 3:fcd6d70e9694 12 }
JoeShotton 3:fcd6d70e9694 13
JoeShotton 3:fcd6d70e9694 14 SnakeEngine::~SnakeEngine()
JoeShotton 3:fcd6d70e9694 15 {
JoeShotton 3:fcd6d70e9694 16 //destructor
JoeShotton 3:fcd6d70e9694 17 }
JoeShotton 3:fcd6d70e9694 18
JoeShotton 7:dd84e0fab346 19 void SnakeEngine::game_init(Gamepad &pad, N5110 &lcd, FXOS8700CQ &mag){
JoeShotton 9:0571880085cc 20 transition_black(lcd);
JoeShotton 9:0571880085cc 21 transition_white(lcd);
JoeShotton 9:0571880085cc 22 map_run(lcd);
JoeShotton 5:06fa7674622a 23 _food.init(mag);
JoeShotton 6:6c9453397f4a 24 _body.init();
JoeShotton 8:bcc3403d7e79 25 _food.rand_pos(pad, lcd);
JoeShotton 9:0571880085cc 26 menu_flash(pad, 3);
JoeShotton 7:dd84e0fab346 27 }
JoeShotton 7:dd84e0fab346 28
JoeShotton 4:ea3fa51c4386 29
JoeShotton 7:dd84e0fab346 30 void SnakeEngine::game_run(Gamepad &pad, N5110 &lcd){
JoeShotton 7:dd84e0fab346 31 //input???
JoeShotton 8:bcc3403d7e79 32 map_run(lcd);
JoeShotton 9:0571880085cc 33 _body.run(pad, lcd, _death);
JoeShotton 9:0571880085cc 34 _food.run(lcd);
JoeShotton 8:bcc3403d7e79 35 snake_food_collision(pad, lcd, _body._length);
JoeShotton 9:0571880085cc 36 if (_death == true) {
JoeShotton 9:0571880085cc 37 printf("Dead!");
JoeShotton 9:0571880085cc 38 _game_state = 4;
JoeShotton 9:0571880085cc 39 death_init(pad, lcd);
JoeShotton 8:bcc3403d7e79 40 }
JoeShotton 7:dd84e0fab346 41 //snake-wall collision
JoeShotton 7:dd84e0fab346 42 }
JoeShotton 7:dd84e0fab346 43
JoeShotton 8:bcc3403d7e79 44 void SnakeEngine::snake_food_collision(Gamepad &pad, N5110 &lcd, int &_length) {
JoeShotton 4:ea3fa51c4386 45 if (_food._x == _body._x_head && _food._y == _body._y_head){
JoeShotton 4:ea3fa51c4386 46 //printf("FOOD!");
JoeShotton 9:0571880085cc 47 pad.led(3,0.9);
JoeShotton 9:0571880085cc 48 pad.led(6,0.9);
JoeShotton 9:0571880085cc 49 while (_food.rand_pos(pad, lcd) == false){
JoeShotton 9:0571880085cc 50 _food.rand_pos(pad, lcd);
JoeShotton 9:0571880085cc 51 printf("Reselected food position\n");
JoeShotton 9:0571880085cc 52 }
JoeShotton 9:0571880085cc 53 _body.add_length(5);
JoeShotton 9:0571880085cc 54 score++;
JoeShotton 9:0571880085cc 55 pad.led(3,0.0);
JoeShotton 9:0571880085cc 56 pad.led(6,0.0);
JoeShotton 4:ea3fa51c4386 57 }
JoeShotton 4:ea3fa51c4386 58 }
JoeShotton 4:ea3fa51c4386 59
JoeShotton 8:bcc3403d7e79 60 void SnakeEngine::map_run(N5110 &lcd) {
JoeShotton 9:0571880085cc 61 switch(_map_select+1) {
JoeShotton 8:bcc3403d7e79 62 case 2:
JoeShotton 8:bcc3403d7e79 63 map2_draw(lcd);
JoeShotton 8:bcc3403d7e79 64 snake_map2_collision();
JoeShotton 8:bcc3403d7e79 65 break;
JoeShotton 8:bcc3403d7e79 66 case 3:
JoeShotton 8:bcc3403d7e79 67 map3_draw(lcd);
JoeShotton 8:bcc3403d7e79 68 snake_map3_collision();
JoeShotton 8:bcc3403d7e79 69 break;
JoeShotton 8:bcc3403d7e79 70 case 4:
JoeShotton 8:bcc3403d7e79 71 map4_draw(lcd);
JoeShotton 8:bcc3403d7e79 72 snake_map4_collision();
JoeShotton 8:bcc3403d7e79 73 break;
JoeShotton 7:dd84e0fab346 74 }
JoeShotton 7:dd84e0fab346 75 }
JoeShotton 7:dd84e0fab346 76
JoeShotton 9:0571880085cc 77 void SnakeEngine::snake_map2_collision() {
JoeShotton 9:0571880085cc 78 if (_body._x_head < 2 || _body._x_head > 81 || _body._y_head < 2 || _body._y_head > 45){ //if snakehead coords exceed the ring coords
JoeShotton 9:0571880085cc 79 _death = true;
JoeShotton 8:bcc3403d7e79 80 }
JoeShotton 8:bcc3403d7e79 81 }
JoeShotton 8:bcc3403d7e79 82
JoeShotton 9:0571880085cc 83 void SnakeEngine::snake_map3_collision() {
JoeShotton 9:0571880085cc 84 if ((_body._x_head == 40 || _body._x_head == 42) && (_body._y_head < 16 || _body._y_head > 30)){
JoeShotton 9:0571880085cc 85 //if head is at the either of the N/S walls' x coords, and above (y=18) or below (y=30), trigger death
JoeShotton 9:0571880085cc 86 _death = true;
JoeShotton 9:0571880085cc 87 } else if ((_body._x_head < 16 || _body._x_head > 66) && (_body._y_head == 22 || _body._y_head == 24)){
JoeShotton 9:0571880085cc 88 //if head is at west of x=18 or east of x=66, and at either of the W/E wall's y coords, trigger death
JoeShotton 9:0571880085cc 89 _death = true;
JoeShotton 8:bcc3403d7e79 90 }
JoeShotton 8:bcc3403d7e79 91 }
JoeShotton 8:bcc3403d7e79 92
JoeShotton 9:0571880085cc 93 void SnakeEngine::snake_map4_collision() {
JoeShotton 8:bcc3403d7e79 94 /*
JoeShotton 8:bcc3403d7e79 95 for(int i = 0; i < 48; i++){
JoeShotton 8:bcc3403d7e79 96 if(_body._x_head == MAP 4 COORDS && _body._y_head == MAP 4 COORDS) {
JoeShotton 8:bcc3403d7e79 97 return true;
JoeShotton 8:bcc3403d7e79 98 }
JoeShotton 8:bcc3403d7e79 99 */
JoeShotton 8:bcc3403d7e79 100 }
JoeShotton 8:bcc3403d7e79 101
JoeShotton 8:bcc3403d7e79 102 void SnakeEngine::map2_draw(N5110 &lcd){
JoeShotton 7:dd84e0fab346 103 lcd.drawRect(0, 0, 84, 48,FILL_TRANSPARENT);
JoeShotton 7:dd84e0fab346 104 lcd.drawRect(1, 1, 82, 46,FILL_TRANSPARENT);
JoeShotton 7:dd84e0fab346 105 }
JoeShotton 7:dd84e0fab346 106
JoeShotton 8:bcc3403d7e79 107 void SnakeEngine::map3_draw(N5110 &lcd){
JoeShotton 8:bcc3403d7e79 108 lcd.drawRect(40, 0, 4, 16,FILL_BLACK); //N wall
JoeShotton 8:bcc3403d7e79 109 lcd.drawRect(68, 22, 16, 4,FILL_BLACK);//E wall
JoeShotton 8:bcc3403d7e79 110 lcd.drawRect(40, 32, 4, 16,FILL_BLACK);//S wall
JoeShotton 8:bcc3403d7e79 111 lcd.drawRect(0, 22, 16, 4,FILL_BLACK); //W wall
JoeShotton 7:dd84e0fab346 112 }
JoeShotton 7:dd84e0fab346 113
JoeShotton 8:bcc3403d7e79 114 void SnakeEngine::map4_draw(N5110 &lcd){
JoeShotton 7:dd84e0fab346 115 lcd.drawRect(12, 8, 4, 4,FILL_BLACK); //NW square
JoeShotton 7:dd84e0fab346 116 lcd.drawRect(12, 36, 4, 4,FILL_BLACK);//SW square
JoeShotton 7:dd84e0fab346 117 lcd.drawRect(68, 8, 4, 4,FILL_BLACK); //NE square
JoeShotton 7:dd84e0fab346 118 lcd.drawRect(68, 36, 4, 4,FILL_BLACK);//SE square
JoeShotton 7:dd84e0fab346 119
JoeShotton 9:0571880085cc 120 lcd.drawRect(38, 6, 8, 8,FILL_BLACK); //N large square
JoeShotton 9:0571880085cc 121 lcd.drawRect(24, 20, 8, 8,FILL_BLACK);//E large square
JoeShotton 9:0571880085cc 122 lcd.drawRect(38, 34, 8, 8,FILL_BLACK);//S large square
JoeShotton 9:0571880085cc 123 lcd.drawRect(52, 20, 8, 8,FILL_BLACK);//W large square
JoeShotton 7:dd84e0fab346 124 }
JoeShotton 7:dd84e0fab346 125
JoeShotton 7:dd84e0fab346 126
JoeShotton 6:6c9453397f4a 127 void SnakeEngine::transition_black(N5110 &lcd) {
JoeShotton 6:6c9453397f4a 128 //lcd.clear();
JoeShotton 7:dd84e0fab346 129 for (int j = 0; j < 21; j += 4) { //j iterator controls the size and location of current loop
JoeShotton 7:dd84e0fab346 130 //printf("j: %d\n", j);
JoeShotton 7:dd84e0fab346 131 for (int i = 1; i < 84 - (2*j); i += 2) { //i iterator controls length of rectangles
JoeShotton 7:dd84e0fab346 132 lcd.drawRect(j, j, i + 1, 4, FILL_BLACK); //top horizontal rectangle
JoeShotton 7:dd84e0fab346 133 lcd.drawRect(83 - j - i, 44 - j, i + 1, 4, FILL_BLACK); //bottom horizontal rectangle
JoeShotton 6:6c9453397f4a 134 wait_ms(5);
JoeShotton 7:dd84e0fab346 135 lcd.refresh(); //refreshes screen without clearing it to maintain previous loops
JoeShotton 6:6c9453397f4a 136 }
JoeShotton 7:dd84e0fab346 137 for (int i = 1; i < 43 - (2*j); i += 2) { //i iterator controls length of rectangles
JoeShotton 7:dd84e0fab346 138 lcd.drawRect(80 - j, 4 + j, 4, i,FILL_BLACK); //right vertical rectangle
JoeShotton 7:dd84e0fab346 139 lcd.drawRect(j, 44 - i - j, 4, i,FILL_BLACK); //left vertical rectangle
JoeShotton 6:6c9453397f4a 140 wait_ms(5);
JoeShotton 7:dd84e0fab346 141 lcd.refresh(); //refreshes screen without clearing it to maintain previous loops
JoeShotton 6:6c9453397f4a 142 }
JoeShotton 6:6c9453397f4a 143 }
JoeShotton 7:dd84e0fab346 144 //wait_ms(500);
JoeShotton 6:6c9453397f4a 145 }
JoeShotton 6:6c9453397f4a 146
JoeShotton 6:6c9453397f4a 147 void SnakeEngine::transition_white(N5110 &lcd) {
JoeShotton 6:6c9453397f4a 148 //lcd.clear();
JoeShotton 6:6c9453397f4a 149 for (int j = 0; j < 21; j += 4) {
JoeShotton 7:dd84e0fab346 150 //printf("j: %d\n", j);
JoeShotton 6:6c9453397f4a 151 for (int i = 1; i < 84 - (2*j); i += 2) {
JoeShotton 6:6c9453397f4a 152 lcd.drawRect(j, j, i + 1, 4, FILL_WHITE);
JoeShotton 6:6c9453397f4a 153 lcd.drawRect(83 - j - i, 44 - j, i + 1, 4, FILL_WHITE);
JoeShotton 6:6c9453397f4a 154 wait_ms(5);
JoeShotton 6:6c9453397f4a 155 lcd.refresh();
JoeShotton 6:6c9453397f4a 156 }
JoeShotton 6:6c9453397f4a 157 for (int i = 1; i < 43 - (2*j); i += 2) {
JoeShotton 6:6c9453397f4a 158 lcd.drawRect(80 - j, 4 + j, 4, i,FILL_WHITE);
JoeShotton 6:6c9453397f4a 159 lcd.drawRect(j, 44 - i - j, 4, i,FILL_WHITE);
JoeShotton 6:6c9453397f4a 160 wait_ms(5);
JoeShotton 6:6c9453397f4a 161 lcd.refresh();
JoeShotton 6:6c9453397f4a 162 }
JoeShotton 6:6c9453397f4a 163 }
JoeShotton 6:6c9453397f4a 164 //wait_ms(500);
JoeShotton 6:6c9453397f4a 165 }
JoeShotton 7:dd84e0fab346 166
JoeShotton 9:0571880085cc 167 void SnakeEngine::menu1_init(Gamepad &pad, N5110 &lcd){
JoeShotton 9:0571880085cc 168 contrast(pad, lcd);
JoeShotton 7:dd84e0fab346 169 transition_black(lcd);
JoeShotton 7:dd84e0fab346 170 transition_white(lcd);
JoeShotton 7:dd84e0fab346 171 lcd.clear();
JoeShotton 7:dd84e0fab346 172 lcd.refresh();
JoeShotton 7:dd84e0fab346 173 //printf("Menu 2\n");
JoeShotton 7:dd84e0fab346 174 lcd.printString(" SNAKE",3,0);
JoeShotton 7:dd84e0fab346 175 lcd.printString("Play",30,2);
JoeShotton 7:dd84e0fab346 176 lcd.drawCircle(24,19,3,FILL_TRANSPARENT);
JoeShotton 7:dd84e0fab346 177 lcd.printString("Maps",30,3);
JoeShotton 7:dd84e0fab346 178 lcd.drawCircle(24,27,3,FILL_TRANSPARENT);
JoeShotton 7:dd84e0fab346 179 lcd.refresh();
JoeShotton 9:0571880085cc 180 menu_flash(pad, 2);
JoeShotton 7:dd84e0fab346 181 }
JoeShotton 7:dd84e0fab346 182
JoeShotton 9:0571880085cc 183 void SnakeEngine::menu1_select(N5110 &lcd, Gamepad &pad, FXOS8700CQ &mag){
JoeShotton 7:dd84e0fab346 184 //printf("Menu 1\n");
JoeShotton 7:dd84e0fab346 185 if (pad.X_pressed() == true){ //detect if 'up' selection
JoeShotton 7:dd84e0fab346 186 _menu_select--;
JoeShotton 7:dd84e0fab346 187 } else if (pad.B_pressed() == true){ //detect if 'down' selection
JoeShotton 7:dd84e0fab346 188 _menu_select++;
JoeShotton 7:dd84e0fab346 189 }
JoeShotton 9:0571880085cc 190 _menu_select = ((_menu_select % 2) + 2) % 2; //wrap around numbers, ie down on 2 goes to 1 and up on 1 goes to 2
JoeShotton 9:0571880085cc 191 select_circles(lcd, _menu_select + 1); //draw black circle in selected option
JoeShotton 9:0571880085cc 192 //printf("Option: %d\n", _menu_select + 1);
JoeShotton 9:0571880085cc 193
JoeShotton 9:0571880085cc 194 if (pad.A_pressed() == true){ //if option 1 selected and 'A' pressed
JoeShotton 9:0571880085cc 195 if (_menu_select == 0){
JoeShotton 9:0571880085cc 196 game_init(pad, lcd, mag); //Initialise game
JoeShotton 9:0571880085cc 197 _game_state = 3; //switch state
JoeShotton 9:0571880085cc 198 } else {
JoeShotton 9:0571880085cc 199 menu2_init(pad, lcd); //Initialise menu 2
JoeShotton 9:0571880085cc 200 _game_state = 2; //switch state
JoeShotton 9:0571880085cc 201 }
JoeShotton 7:dd84e0fab346 202 }
JoeShotton 7:dd84e0fab346 203 }
JoeShotton 7:dd84e0fab346 204
JoeShotton 9:0571880085cc 205 void SnakeEngine::menu2_init(Gamepad &pad, N5110 &lcd){
JoeShotton 7:dd84e0fab346 206 //transition_black(lcd);
JoeShotton 7:dd84e0fab346 207 //transition_white(lcd);
JoeShotton 7:dd84e0fab346 208 //printf("Menu 1\n");
JoeShotton 7:dd84e0fab346 209 lcd.clear();
JoeShotton 7:dd84e0fab346 210 lcd.printString(" MAPS",0,0);
JoeShotton 7:dd84e0fab346 211 lcd.printString("Empty",30,2);
JoeShotton 7:dd84e0fab346 212 lcd.drawCircle(24,19,3,FILL_TRANSPARENT);
JoeShotton 7:dd84e0fab346 213 lcd.printString("Ring",30,3);
JoeShotton 7:dd84e0fab346 214 lcd.drawCircle(24,27,3,FILL_TRANSPARENT);
JoeShotton 7:dd84e0fab346 215 lcd.printString("Cross",30,4);
JoeShotton 7:dd84e0fab346 216 lcd.drawCircle(24,35,3,FILL_TRANSPARENT);
JoeShotton 7:dd84e0fab346 217 lcd.printString("Spots",30,5);
JoeShotton 7:dd84e0fab346 218 lcd.drawCircle(24,43,3,FILL_TRANSPARENT);
JoeShotton 7:dd84e0fab346 219 lcd.refresh();
JoeShotton 9:0571880085cc 220 menu_flash(pad, 2);
JoeShotton 7:dd84e0fab346 221 }
JoeShotton 7:dd84e0fab346 222
JoeShotton 7:dd84e0fab346 223 void SnakeEngine::menu2_select(N5110 &lcd, Gamepad &pad){
JoeShotton 7:dd84e0fab346 224
JoeShotton 7:dd84e0fab346 225 //printf("Menu 2\n");
JoeShotton 7:dd84e0fab346 226 if (pad.X_pressed() == true){
JoeShotton 9:0571880085cc 227 _map_select--;
JoeShotton 7:dd84e0fab346 228 } else if (pad.B_pressed() == true){
JoeShotton 9:0571880085cc 229 _map_select++;
JoeShotton 7:dd84e0fab346 230 } else if (pad.Y_pressed() == true){
JoeShotton 9:0571880085cc 231 preview(pad, lcd, _map_select+1);
JoeShotton 7:dd84e0fab346 232 } else if (pad.A_pressed() == true){
JoeShotton 7:dd84e0fab346 233 //game_init();
JoeShotton 7:dd84e0fab346 234 _game_state = 3;
JoeShotton 7:dd84e0fab346 235 }
JoeShotton 7:dd84e0fab346 236
JoeShotton 9:0571880085cc 237 //printf("Map: %d\n", _map_select);
JoeShotton 9:0571880085cc 238 _map_select = ((_map_select % 4) + 4) % 4;
JoeShotton 9:0571880085cc 239 select_circles(lcd, _map_select+1);
JoeShotton 7:dd84e0fab346 240 }
JoeShotton 7:dd84e0fab346 241
JoeShotton 7:dd84e0fab346 242
JoeShotton 9:0571880085cc 243 void SnakeEngine::death_init(Gamepad &pad, N5110 &lcd){
JoeShotton 9:0571880085cc 244 _death = 0;
JoeShotton 9:0571880085cc 245 _menu_select = 0;
JoeShotton 7:dd84e0fab346 246 transition_black(lcd);
JoeShotton 7:dd84e0fab346 247 transition_white(lcd);
JoeShotton 7:dd84e0fab346 248 //printf("Game over\n");
JoeShotton 9:0571880085cc 249 lcd.printString(" GAME OVER",3,0);
JoeShotton 9:0571880085cc 250 lcd.printString(" Score:",0,1);
JoeShotton 7:dd84e0fab346 251 char buffer[14];
JoeShotton 9:0571880085cc 252 sprintf(buffer," %2d",score);
JoeShotton 7:dd84e0fab346 253 lcd.printString(buffer,0,2);
JoeShotton 9:0571880085cc 254 lcd.printString("Again!",30,4);
JoeShotton 7:dd84e0fab346 255 lcd.drawCircle(24,35,3,FILL_TRANSPARENT);
JoeShotton 9:0571880085cc 256 lcd.printString("Maps",30,5);
JoeShotton 9:0571880085cc 257 lcd.drawCircle(24,43,3,FILL_TRANSPARENT);
JoeShotton 9:0571880085cc 258 lcd.refresh();
JoeShotton 9:0571880085cc 259 menu_flash(pad, 1);
JoeShotton 7:dd84e0fab346 260 }
JoeShotton 7:dd84e0fab346 261
JoeShotton 9:0571880085cc 262 void SnakeEngine::death_select(N5110 &lcd, Gamepad &pad, FXOS8700CQ &mag){
JoeShotton 9:0571880085cc 263 //printf("Menu 1\n");
JoeShotton 9:0571880085cc 264 if (pad.X_pressed() == true){ //detect if 'up' selection
JoeShotton 9:0571880085cc 265 _menu_select--;
JoeShotton 9:0571880085cc 266 } else if (pad.B_pressed() == true){ //detect if 'down' selection
JoeShotton 9:0571880085cc 267 _menu_select++;
JoeShotton 9:0571880085cc 268 }
JoeShotton 9:0571880085cc 269 _menu_select = ((_menu_select % 2) + 2) % 2; //wrap around numbers, ie down on 2 goes to 1 and up on 1 goes to 2
JoeShotton 9:0571880085cc 270 select_circles(lcd, _menu_select + 3); //draw black circle in selected option
JoeShotton 9:0571880085cc 271 //printf("Option: %d\n", _menu_select + 1);
JoeShotton 7:dd84e0fab346 272
JoeShotton 9:0571880085cc 273 if (pad.A_pressed() == true){ //if option 1 selected and 'A' pressed
JoeShotton 9:0571880085cc 274 if (_menu_select == 0){
JoeShotton 9:0571880085cc 275 game_init(pad, lcd, mag); //Initialise game
JoeShotton 9:0571880085cc 276 _game_state = 3; //switch state
JoeShotton 9:0571880085cc 277 } else {
JoeShotton 9:0571880085cc 278 menu2_init(pad, lcd); //Initialise menu 2
JoeShotton 9:0571880085cc 279 _game_state = 2; //switch state
JoeShotton 9:0571880085cc 280 }
JoeShotton 9:0571880085cc 281 }
JoeShotton 9:0571880085cc 282 }
JoeShotton 7:dd84e0fab346 283
JoeShotton 7:dd84e0fab346 284 void SnakeEngine::select_circles(N5110 &lcd, int line) {
JoeShotton 7:dd84e0fab346 285 for(int i = 19; i < 52; i +=8) {
JoeShotton 7:dd84e0fab346 286 lcd.drawCircle(24,i,2,FILL_WHITE);
JoeShotton 7:dd84e0fab346 287 }
JoeShotton 7:dd84e0fab346 288 lcd.drawCircle(24,11+line*8,2,FILL_BLACK);
JoeShotton 7:dd84e0fab346 289 lcd.refresh();
JoeShotton 7:dd84e0fab346 290 wait_ms(200);
JoeShotton 7:dd84e0fab346 291 //snake_select1.render(lcd, 0, 8);
JoeShotton 7:dd84e0fab346 292 //wait_ms(200);
JoeShotton 7:dd84e0fab346 293 //snake_select2.render(lcd, 0, 8);
JoeShotton 7:dd84e0fab346 294 //wait_ms(200);
JoeShotton 7:dd84e0fab346 295 //snake_select3.render(lcd, 0, 8);
JoeShotton 7:dd84e0fab346 296 //wait_ms(200);
JoeShotton 7:dd84e0fab346 297 }
JoeShotton 7:dd84e0fab346 298
JoeShotton 9:0571880085cc 299 void SnakeEngine::preview(Gamepad &pad, N5110 &lcd, int _map_select){
JoeShotton 7:dd84e0fab346 300 lcd.clear();
JoeShotton 9:0571880085cc 301 switch(_map_select) {
JoeShotton 7:dd84e0fab346 302 case 1:
JoeShotton 7:dd84e0fab346 303 lcd.clear();
JoeShotton 8:bcc3403d7e79 304 lcd.printString("(Empty)",21,2);
JoeShotton 7:dd84e0fab346 305 break;
JoeShotton 7:dd84e0fab346 306 case 2:
JoeShotton 8:bcc3403d7e79 307 map2_draw(lcd);
JoeShotton 8:bcc3403d7e79 308 //lcd.printString("Ring",30,2);
JoeShotton 7:dd84e0fab346 309 break;
JoeShotton 7:dd84e0fab346 310 case 3:
JoeShotton 8:bcc3403d7e79 311 map3_draw(lcd);
JoeShotton 8:bcc3403d7e79 312 //lcd.printString("Cross",27,2);
JoeShotton 7:dd84e0fab346 313 break;
JoeShotton 7:dd84e0fab346 314 case 4:
JoeShotton 8:bcc3403d7e79 315 map4_draw(lcd);
JoeShotton 8:bcc3403d7e79 316 //lcd.printString("Spots",27,2);
JoeShotton 7:dd84e0fab346 317 break;
JoeShotton 7:dd84e0fab346 318 }
JoeShotton 7:dd84e0fab346 319 lcd.refresh();
JoeShotton 7:dd84e0fab346 320 wait_ms(1000);
JoeShotton 7:dd84e0fab346 321 lcd.clear();
JoeShotton 9:0571880085cc 322 menu2_init(pad, lcd);
JoeShotton 8:bcc3403d7e79 323 }
JoeShotton 8:bcc3403d7e79 324
JoeShotton 8:bcc3403d7e79 325 void SnakeEngine::contrast(Gamepad &pad, N5110 &lcd){
JoeShotton 8:bcc3403d7e79 326 _pot2 = pad.read_pot2();
JoeShotton 8:bcc3403d7e79 327 lcd.setContrast(0.25 + _pot2 * 0.5);
JoeShotton 8:bcc3403d7e79 328 //printf("Contrast: %f\n", 0.25 + _pot2 * 0.5);
JoeShotton 9:0571880085cc 329 }
JoeShotton 9:0571880085cc 330
JoeShotton 9:0571880085cc 331 void SnakeEngine::menu_flash(Gamepad &pad, int led){
JoeShotton 9:0571880085cc 332 for(int i = 1; i < 7; i++){
JoeShotton 9:0571880085cc 333 pad.led(led, i % 2);
JoeShotton 9:0571880085cc 334 pad.led(led + 3, i % 2);
JoeShotton 9:0571880085cc 335 wait_ms(100);
JoeShotton 9:0571880085cc 336 }
JoeShotton 7:dd84e0fab346 337 }