hgftf
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Revision 10:0b2f37cef9b9, committed 2021-04-17
- Comitter:
- ajorgih3
- Date:
- Sat Apr 17 14:09:46 2021 +0000
- Parent:
- 9:d09b96b6c39c
- Commit message:
- huhu
Changed in this revision
--- a/main.cpp Fri Nov 20 21:58:45 2020 +0000 +++ b/main.cpp Sat Apr 17 14:09:46 2021 +0000 @@ -22,6 +22,7 @@ #include <ctime> #include <cstdlib> #include <iostream> +using namespace std; #define CITY_HIT_MARGIN 1 #define CITY_UPPER_BOUND (SIZE_Y-(LANDSCAPE_HEIGHT+MAX_BUILDING_HEIGHT)) @@ -64,6 +65,19 @@ void additional_info(); int redCounter = 0; int blueCounter = 0; +int i = rand(); +void difficulty_modes(); +int main1(); +void map_1(); +void map_2(); +void game_over(); +bool map1 = false; +bool map2 = false; +void ingamemenu1part2(); +void ingamemenu2(); +void ingamemenu2part2(); +void ingamemenu2part3(); +void init_main_map(); // Function prototypes @@ -118,6 +132,10 @@ if (!inputs.b2) { return PAUSE; } + + if (!inputs.b3) { + return IN_GAME_MENU; + } // if we do not satisfy these conditions then // no action is done @@ -200,17 +218,14 @@ uLCD.color(0xFFFFFF); uLCD.text_width(1); uLCD.text_height(1); - uLCD.locate(4, 10); - uLCD.printf("Press 'B2'\n"); + uLCD.locate(3, 10); + uLCD.printf("Press 'RESET'\n"); uLCD.locate(2, 11); uLCD.printf("to play again!\n"); do { input = read_inputs(); - } while(input.b2); - - uLCD.filled_rectangle(0, 0, 255, 255, BLACK); - main2(); + } while(1); } @@ -232,17 +247,14 @@ uLCD.color(0xFFFFFF); uLCD.text_width(1); uLCD.text_height(1); - uLCD.locate(4, 10); - uLCD.printf("Press 'B2'\n"); + uLCD.locate(3, 10); + uLCD.printf("Press 'RESET'\n"); uLCD.locate(5, 11); uLCD.printf("to retry!\n"); - + do { input = read_inputs(); - } while(input.b2); - - uLCD.filled_rectangle(0, 0, 255, 255, BLACK); - main(); + } while(1); } @@ -377,7 +389,7 @@ uLCD.text_height(1); uLCD.locate(2, 4); uLCD.color(0xFFFFFF); - uLCD.printf("Eat 20 goodies!"); + uLCD.printf("Eat 15 goodies!"); uLCD.locate(7,5); draw_goodie(u, v); @@ -463,9 +475,9 @@ uLCD.text_width(1); uLCD.text_height(1); - uLCD.locate(5, 4); + uLCD.locate(4, 4); uLCD.color(0xFFFFFF); - uLCD.printf("Reverse"); + uLCD.printf("Stun snake"); uLCD.text_width(1); uLCD.text_height(1); @@ -614,9 +626,9 @@ uLCD.text_width(1); uLCD.text_height(1); - uLCD.locate(4, 7); + uLCD.locate(1, 7); uLCD.color(0xFFFFFF); - uLCD.printf("B3: START!"); + uLCD.printf("B3: DIFFICULTY!"); do { input = read_inputs(); @@ -629,18 +641,492 @@ uLCD.filled_rectangle(0, 0, 255, 255, BLACK); if (!input.b2) { - main2(); + map_1(); } if (!input.b3) { uLCD.filled_rectangle(0, 0, 255, 255, BLACK); - return; + difficulty_modes(); + } + +} + +void map_1() { + int u = 58; + int v = 56; + + uLCD.filled_rectangle(0, 9, 127, 14, 0xFFFF00); // Top + uLCD.filled_rectangle(0, 13, 2, 114, 0xFFFF00); // Left + uLCD.filled_rectangle(0, 114, 127, 117, 0xFFFF00); // Bottom + uLCD.filled_rectangle(124, 14, 127, 117, 0xFFFF00); // Right + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(7, 3); + uLCD.color(0xFFFF00); + uLCD.printf("CITY"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(5, 4); + uLCD.color(0xFFFFFF); + uLCD.printf("Easy Mode"); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 5); + uLCD.color(0xFFFFFF); + uLCD.printf("Buffs & Debuffs"); + + draw_wall(u, v); + draw_wall(u-11, v); + draw_wall(u+11, v); + + uLCD.textbackground_color(BLACK); + uLCD.color(0xFFFFFF); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 10); + uLCD.printf("Press 'B2'\n"); + uLCD.locate(2, 11); + uLCD.printf("to go continue!\n"); + + do { + input = read_inputs(); + } while(input.b2); + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + map_2(); +} + +void map_2() { + int u = 58; + int v = 56; + + uLCD.filled_rectangle(0, 9, 127, 14, 0x0000FF); // Top + uLCD.filled_rectangle(0, 13, 2, 114, 0x0000FF); // Left + uLCD.filled_rectangle(0, 114, 127, 117, 0x0000FF); // Bottom + uLCD.filled_rectangle(124, 14, 127, 117, 0x0000FF); // Right + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(6, 3); + uLCD.color(0xADD8E6); + uLCD.printf("ICEBOX"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(5, 4); + uLCD.color(0xFFFFFF); + uLCD.printf("Hard Mode"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 5); + uLCD.color(0xFFFFFF); + uLCD.printf("Only 15 Goodies"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 6); + uLCD.color(0xFFFFFF); + uLCD.printf("Trees & Debuffs"); + + draw_blue_wall(u, v+11); + draw_blue_wall(u-11, v+11); + draw_blue_wall(u+11, v+11); + + draw_plant(u+33, v+11); + draw_plant(u-33, v+11); + + uLCD.textbackground_color(BLACK); + uLCD.color(0xFFFFFF); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 11); + uLCD.printf("Press 'B2'\n"); + uLCD.locate(4, 12); + uLCD.printf("to go back!\n"); + + do { + input = read_inputs(); + } while(input.b2); + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + additional_info(); +} + +void difficulty_modes() { + + int u = 58; + int v = 56; + + draw_shield(u+22, v+22); + draw_blue_potion(u-22, v+22); + draw_red_potion(u-22, v+33); + draw_reverse(u+22, v+33); + + uLCD.filled_rectangle(0, 9, 127, 14, 0xFFFFFF); // Top + uLCD.filled_rectangle(0, 13, 2, 114, 0xFFFFFF); // Left + uLCD.filled_rectangle(0, 114, 127, 117, 0xFFFFFF); // Bottom + uLCD.filled_rectangle(124, 14, 127, 117, 0xFFFFFF); // Right + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 0); + uLCD.color(0xFFFF00); + uLCD.printf("DIFFICULTY"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(5, 4); + uLCD.color(0xFFFFFF); + uLCD.printf("B1: EASY"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(5, 6); + uLCD.color(0xFFFFFF); + uLCD.printf("B2: HARD"); + + do { + input = read_inputs(); + } while (input.b1 && input.b2); + + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + if (!input.b1) { + main1(); + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + } + + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + if (!input.b2) { + main2(); + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); } } -void bruh() { -return; +void ingamemenu1() { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + //int u = 58; + //int v = 56; + + draw_upper_status(snake.head_x, updateY(), score); + draw_lower_status(lives); + + uLCD.filled_rectangle(0, 9, 127, 14, 0xFFFF00); // Top + uLCD.filled_rectangle(0, 13, 2, 114, 0xFFFF00); // Left + uLCD.filled_rectangle(0, 114, 127, 117, 0xFFFF00); // Bottom + uLCD.filled_rectangle(124, 14, 127, 117, 0xFFFF00); // Right + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(7, 2); + uLCD.color(0xFFFF00); + uLCD.printf("CITY"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 4); + uLCD.color(0xFFFFFF); + uLCD.printf("Snake tired"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(3, 5); + uLCD.color(0xFFFFFF); + uLCD.printf("inside forest"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(1, 7); + uLCD.color(0xFFFFFF); + uLCD.printf("Snake want to go"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(5, 8); + uLCD.color(0xFFFFFF); + uLCD.printf("to city"); + + uLCD.textbackground_color(BLACK); + uLCD.color(0xFFFF00); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 11); + uLCD.printf("Press 'B3'\n"); + uLCD.locate(4, 12); + uLCD.printf("to go next!\n"); + + do { + input = read_inputs(); + } while (input.b3); + + if (!input.b3) { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + ingamemenu1part2(); + } +} + +void ingamemenu1part2() { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + int u = 58; + int v = 78; + + draw_upper_status(snake.head_x, updateY(), score); + draw_lower_status(lives); + + uLCD.filled_rectangle(0, 9, 127, 14, 0xFFFF00); // Top + uLCD.filled_rectangle(0, 13, 2, 114, 0xFFFF00); // Left + uLCD.filled_rectangle(0, 114, 127, 117, 0xFFFF00); // Bottom + uLCD.filled_rectangle(124, 14, 127, 117, 0xFFFF00); // Right + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 2); + uLCD.color(0xFFFFFF); + uLCD.printf("Help snake eat"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 3); + uLCD.color(0xFFFFFF); + uLCD.printf("15 goodies!"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 5); + uLCD.color(0xFFFFFF); + uLCD.printf("Move controller"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 6); + uLCD.color(0xFFFFFF); + uLCD.printf("in the desired"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 7); + uLCD.color(0xFFFFFF); + uLCD.printf("direction!"); + + draw_arrow_up(u+33, v); + draw_arrow_down(u+11, v); + draw_arrow_left(u-33, v); + draw_arrow_right(u-11, v); + + uLCD.textbackground_color(BLACK); + uLCD.color(0xFFFF00); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 12); + uLCD.printf("Press 'B3'\n"); + uLCD.locate(4, 13); + uLCD.printf("to go back!\n"); + + do { + input = read_inputs(); + } while (input.b3); + + if (!input.b3) { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + return; + } +} + +void ingamemenu2() { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + //int u = 58; + //int v = 56; + + draw_upper_status(snake.head_x, updateY(), score); + draw_lower_status(lives); + + uLCD.filled_rectangle(0, 9, 127, 14, 0x0000FF); // Top + uLCD.filled_rectangle(0, 13, 2, 114, 0x0000FF); // Left + uLCD.filled_rectangle(0, 114, 127, 117, 0x0000FF); // Bottom + uLCD.filled_rectangle(124, 14, 127, 117, 0x0000FF); // Right + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(5, 2); + uLCD.color(0xADD8E6); + uLCD.printf("ICEBOX"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 4); + uLCD.color(0xFFFFFF); + uLCD.printf("Snake: city ez"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 5); + uLCD.color(0xFFFFFF); + uLCD.printf("want hard map"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(3, 7); + uLCD.color(0xFFFFFF); + uLCD.printf("Snake hungry"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(3, 8); + uLCD.color(0xFFFFFF); + uLCD.printf("in cold brr.."); + + uLCD.textbackground_color(BLACK); + uLCD.color(0xFFFF00); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 11); + uLCD.printf("Press 'B3'\n"); + uLCD.locate(4, 12); + uLCD.printf("to go next!\n"); + + do { + input = read_inputs(); + } while (input.b3); + + if (!input.b3) { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + ingamemenu2part2(); + } +} + +void ingamemenu2part2() { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + int u = 58; + int v = 78; + + draw_upper_status(snake.head_x, updateY(), score); + draw_lower_status(lives); + + uLCD.filled_rectangle(0, 9, 127, 14, 0x0000FF); // Top + uLCD.filled_rectangle(0, 13, 2, 114, 0x0000FF); // Left + uLCD.filled_rectangle(0, 114, 127, 117, 0x0000FF); // Bottom + uLCD.filled_rectangle(124, 14, 127, 117, 0x0000FF); // Right + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 2); + uLCD.color(0xFFFFFF); + uLCD.printf("Snake see trees"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 3); + uLCD.color(0xFFFFFF); + uLCD.printf("but no food"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 5); + uLCD.color(0xFFFFFF); + uLCD.printf("Help snake find"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 6); + uLCD.color(0xFFFFFF); + uLCD.printf("the only 15"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 7); + uLCD.color(0xFFFFFF); + uLCD.printf("goodies in map!"); + + draw_plant(u+33, v); + draw_plant(u+11, v); + draw_plant(u-33, v); + draw_plant(u-11, v); + + uLCD.textbackground_color(BLACK); + uLCD.color(0xFFFF00); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 12); + uLCD.printf("Press 'B3'\n"); + uLCD.locate(4, 13); + uLCD.printf("to go next!\n"); + + do { + input = read_inputs(); + } while (input.b3); + + if (!input.b3) { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + ingamemenu2part3(); + } +} + +void ingamemenu2part3() { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + int u = 58; + int v = 78; + + draw_upper_status(snake.head_x, updateY(), score); + draw_lower_status(lives); + + uLCD.filled_rectangle(0, 9, 127, 14, 0x0000FF); // Top + uLCD.filled_rectangle(0, 13, 2, 114, 0x0000FF); // Left + uLCD.filled_rectangle(0, 114, 127, 117, 0x0000FF); // Bottom + uLCD.filled_rectangle(124, 14, 127, 117, 0x0000FF); // Right + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 2); + uLCD.color(0xFFFFFF); + uLCD.printf("Help snake eat"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 3); + uLCD.color(0xFFFFFF); + uLCD.printf("15 goodies!"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 5); + uLCD.color(0xFFFFFF); + uLCD.printf("Move controller"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2, 6); + uLCD.color(0xFFFFFF); + uLCD.printf("in the desired"); + + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 7); + uLCD.color(0xFFFFFF); + uLCD.printf("direction!"); + + draw_arrow_up(u+33, v); + draw_arrow_down(u+11, v); + draw_arrow_left(u-33, v); + draw_arrow_right(u-11, v); + + uLCD.textbackground_color(BLACK); + uLCD.color(0xFFFF00); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(4, 12); + uLCD.printf("Press 'B3'\n"); + uLCD.locate(4, 13); + uLCD.printf("to go back!\n"); + + do { + input = read_inputs(); + } while (input.b3); + + if (!input.b3) { + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + return; + } } @@ -654,55 +1140,59 @@ Map* map = set_active_map(0); pc.printf("plants\r\n"); - add_portal(7, 5); - - for (int i = 0; i < 20; i++) { - int goodieRandX = rand() % 50; - int goodieRandY = rand() % 50; - add_goodie(goodieRandX, goodieRandY); - } + add_life(40, 6); + add_life(25, 13); + add_blue_potion(30, 30); + add_blue_potion(47, 5); + add_blue_potion(40, 10); + add_blue_potion(29, 29); + add_blue_potion(26, 26); + add_goodie(11, 1); + add_goodie(13, 1); + add_goodie(19, 2); + add_snowflake(20, 5); + add_snowflake(25, 10); + add_snowflake(30, 11); + add_snowflake(31, 12); + add_snowflake(32, 13); for (int i = 0; i < 30; i++) { - int goodieRandX = rand() % 50; - int goodieRandY = rand() % 50; + int goodieRandX = rand() % 30; + int goodieRandY = rand() % 30; add_goodie(goodieRandX, goodieRandY); } for (int i = 0; i < 10; i++) { - int redRandX = rand() % 50; - int redRandY = rand() % 50; + int redRandX = rand() % 30; + int redRandY = rand() % 30; add_red_potion(redRandX, redRandY); } // for (int i = 0; i < 10; i++) { - int swordRandX = rand() % 50; - int swordRandY = rand() % 50; + int swordRandX = rand() % 30; + int swordRandY = rand() % 30; add_sword(swordRandX, swordRandY); } // - for (int i = 0; i < 5; i++) { - int lifeRandX = rand() % 50; - int lifeRandY = rand() % 50; - add_life(lifeRandX, lifeRandY); - } -// - for (int i = 0; i < 5; i++) { - int blueRandX = rand() % 50; - int blueRandY = rand() % 50; - add_blue_potion(blueRandX, blueRandY); - } -// for (int i = 0; i < 5; i++) { - int shieldRandX = rand() % 50; - int shieldRandY = rand() % 50; + int shieldRandX = rand() % 30; + int shieldRandY = rand() % 30; add_shield(shieldRandX, shieldRandY); } - for (int i = 0; i < 10; i++) { - int reverseRandX = rand() % 50; - int reverseRandY = rand() % 50; - add_reverse(reverseRandX, reverseRandY); + for (int i = 0; i < 5; i++) { + int lightspeedRandX = rand() % 30; + int lightspeedRandY = rand() % 30; + add_lightspeed(lightspeedRandX, lightspeedRandY); } + + add_goodie(20, 5); + add_goodie(25, 8); + add_goodie(30, 8); + add_goodie(35, 6); + add_goodie(40, 6); + add_blue_potion(10, 5); + add_shield(10, 10); pc.printf("Adding walls!\r\n"); add_wall(0, 0, HORIZONTAL, map_width()); @@ -742,6 +1232,38 @@ add_blue_wall(map_width()-1, 0, VERTICAL, map_height()); pc.printf("Walls done!\r\n"); print_map(); + + for (int i = 0; i < 20; i++) { + int plantRandX = rand() % 50; + int plantRandY = rand() % 50; + add_plant(plantRandX, plantRandY); + } + + for (int i = 0; i < 20; i++) { + int plantRandX = rand() % 50; + int plantRandY = rand() % 50; + add_plant(plantRandX, plantRandY); + } + + for (int i = 0; i < 10; i++) { + int reverseRandX = rand() % 50; + int reverseRandY = rand() % 50; + add_reverse(reverseRandX, reverseRandY); + } + + for (int i = 0; i < 10; i++) { + int snowflakeRandX = rand() % 50; + int snowflakeRandY = rand() % 50; + add_snowflake(snowflakeRandX, snowflakeRandY); + } + + for (int i = 0; i < 15; i++) { + int goodieRandX = rand() % 50; + int goodieRandY = rand() % 50; + add_goodie(goodieRandX, goodieRandY); + } + + print_map(); } @@ -797,7 +1319,7 @@ return; } - wait(0.2); + //wait(0.2); } void go_up2() { @@ -852,7 +1374,7 @@ return; } - wait(0.2); + //wait(0.2); } void go_down2() { @@ -908,15 +1430,10 @@ return; } - wait(0.2); + //wait(0.2); } void go_left2() { - - if (!(get_here(snake.head_x - 1, snake.head_y)->walkable)) { - pc.printf("SUCCESS!\n\n"); - return; - } add_nothing(snake.tail_x, snake.tail_y); // previous coordinate of the snake head which will be used by the body @@ -970,7 +1487,7 @@ return; } - wait(0.2); + //wait(0.2); } @@ -978,16 +1495,16 @@ int update_game(int action) { snake.head_px = snake.head_x; + snake.head_py = snake.head_y; snake.body_px = snake.body_x; + snake.body_py = snake.body_y; snake.tail_px = snake.tail_x; - snake.head_py = snake.head_y; - snake.body_py = snake.body_y; snake.tail_py = snake.tail_y; //snake.locations[0].x = snake.body_x; //snake.locations[0].y = snake.body_y; - if (score == 20) { + if (score == 15) { draw_game(WIN_GAME); } @@ -1044,7 +1561,51 @@ } } - if (!nextHead->walkable && invincibility == false) { + if (nextHead->type == WALL && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if (nextHead->type == BLUEWALL && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if (nextHead->type == PLANT && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if ((get_here(snake.head_x + 1, snake.head_y))->type == SNAKE_BODY && invincibility == false && ((get_here(snake.head_x - 1, snake.head_y)->type == SNAKE_BODY) || (get_here(snake.head_x, snake.head_y - 1)->type == SNAKE_BODY) || (get_here(snake.head_x, snake.head_y + 1)->type == SNAKE_BODY))) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if ((get_here(snake.head_x, snake.head_y))->type == SNAKE_TAIL && invincibility == false) { if (shieldCounter == 0) { if (lives == 0) { draw_game(GAME_OVER); @@ -1056,7 +1617,8 @@ } if (nextHead->type == LIFE) { - lives += 1; + lives++; + map_erase(snake.head_x, snake.head_y); add_nothing(snake.head_x + 1, snake.head_y); } @@ -1065,8 +1627,8 @@ score++; } - map_erase(snake.head_x, snake.head_y); - add_nothing(snake.head_x + 1, snake.head_y); + map_erase(snake.head_x + 1, snake.head_y); + //add_nothing(snake.head_x + 1, snake.head_y); if (blueCounter == 0) { // if the snake is straight right @@ -1143,7 +1705,7 @@ add_nothing(snake.head_x + 1, snake.head_y); } - if (nextHead->type == SWORD) { + if (nextHead->type == SWORD && invincibility == false) { if (lives == 0 && shieldCounter == 0) { draw_game(GAME_OVER); } @@ -1235,7 +1797,51 @@ } } - if (!nextHead->walkable && invincibility == false) { + if (nextHead->type == WALL && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if (nextHead->type == BLUEWALL && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if (nextHead->type == PLANT && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if ((get_here(snake.head_x - 1, snake.head_y))->type == SNAKE_BODY && invincibility == false && ((get_here(snake.head_x + 1, snake.head_y)->type == SNAKE_BODY) || (get_here(snake.head_x, snake.head_y - 1)->type == SNAKE_BODY) || (get_here(snake.head_x, snake.head_y + 1)->type == SNAKE_BODY))) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if ((get_here(snake.head_x, snake.head_y))->type == SNAKE_TAIL && invincibility == false) { if (shieldCounter == 0) { if (lives == 0) { draw_game(GAME_OVER); @@ -1257,8 +1863,8 @@ score++; } - map_erase(snake.head_x, snake.head_y); - add_nothing(snake.head_x - 1, snake.head_y); // eat the goodie + map_erase(snake.head_x - 1, snake.head_y); + //add_nothing(snake.head_x - 1, snake.head_y); // eat the goodie if (blueCounter == 0) { if ((snake.body_x + 1) == (snake.tail_x)) { @@ -1333,8 +1939,8 @@ add_nothing(snake.head_x - 1, snake.head_y); } - if (nextHead->type == SWORD && shieldCounter == 0) { - if (lives == 0) { + if (nextHead->type == SWORD && invincibility == false) { + if (lives == 0 && shieldCounter == 0) { draw_game(GAME_OVER); } else { @@ -1422,7 +2028,51 @@ } } - if (!nextHead->walkable && invincibility == false) { + if (nextHead->type == WALL && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if (nextHead->type == BLUEWALL && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if (nextHead->type == PLANT && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if ((get_here(snake.head_x, snake.head_y - 1))->type == SNAKE_BODY && invincibility == false && ((get_here(snake.head_x - 1, snake.head_y)->type == SNAKE_BODY) || (get_here(snake.head_x + 1, snake.head_y)->type == SNAKE_BODY) || (get_here(snake.head_x, snake.head_y + 1)->type == SNAKE_BODY))) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if ((get_here(snake.head_x, snake.head_y))->type == SNAKE_TAIL && invincibility == false) { if (shieldCounter == 0) { if (lives == 0) { draw_game(GAME_OVER); @@ -1445,8 +2095,8 @@ score++; } - map_erase(snake.head_x, snake.head_y); - add_nothing(snake.head_x, snake.head_y - 1); // eat the goodie + map_erase(snake.head_x, snake.head_y - 1); + //add_nothing(snake.head_x, snake.head_y - 1); // eat the goodie if (blueCounter == 0) { if ((snake.body_x - 1) == snake.tail_x) { @@ -1519,11 +2169,11 @@ if (nextHead->type == SNOWFLAKE) { slowflakeCounter = 20; map_erase(snake.head_x, snake.head_y); - add_nothing(snake.head_x - 1, snake.head_y); + add_nothing(snake.head_x, snake.head_y - 1); } - if (nextHead->type == SWORD && shieldCounter == 0) { - if (lives == 0) { + if (nextHead->type == SWORD && invincibility == false) { + if (lives == 0 && shieldCounter == 0) { draw_game(GAME_OVER); } else { @@ -1609,7 +2259,51 @@ } } - if (!nextHead->walkable && invincibility == false) { + if (nextHead->type == WALL && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if (nextHead->type == BLUEWALL && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if (nextHead->type == PLANT && invincibility == false) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if ((get_here(snake.head_x, snake.head_y + 1))->type == SNAKE_BODY && invincibility == false && ((get_here(snake.head_x - 1, snake.head_y)->type == SNAKE_BODY) || (get_here(snake.head_x + 1, snake.head_y)->type == SNAKE_BODY) || (get_here(snake.head_x, snake.head_y - 1)->type == SNAKE_BODY))) { + if (shieldCounter == 0) { + if (lives == 0) { + draw_game(GAME_OVER); + } + else { + lives--; + } + } + } + + if ((get_here(snake.head_x, snake.head_y))->type == SNAKE_TAIL && invincibility == false) { if (shieldCounter == 0) { if (lives == 0) { draw_game(GAME_OVER); @@ -1632,8 +2326,8 @@ score++; } - map_erase(snake.head_x, snake.head_y); - add_nothing(snake.head_x, snake.head_y + 1); // eat the goodie + map_erase(snake.head_x, snake.head_y + 1); + //add_nothing(snake.head_x, snake.head_y + 1); // eat the goodie if (blueCounter == 0) { // if the tail is to the left of the body @@ -1708,11 +2402,11 @@ if (nextHead->type == SNOWFLAKE) { slowflakeCounter = 20; map_erase(snake.head_x, snake.head_y); - add_nothing(snake.head_x - 1, snake.head_y); + add_nothing(snake.head_x, snake.head_y + 1); } - if (nextHead->type == SWORD && shieldCounter == 0) { - if (lives == 0) { + if (nextHead->type == SWORD && invincibility == false) { + if (lives == 0 && shieldCounter == 0) { draw_game(GAME_OVER); } else { @@ -1837,6 +2531,15 @@ uLCD.filled_rectangle(0, 0, 255, 255, BLACK); break; + case IN_GAME_MENU: + if (map1 == true) { + ingamemenu1(); + } + if (map2 == true) { + ingamemenu2(); + } + break; + default: break; } @@ -1857,12 +2560,14 @@ { // First things first: initialize hardware ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!"); + srand(time(NULL)); + - //start_game(); - //title_page(); - //helpful_items(); - //harmful_items(); - //additional_info(); + start_game(); + title_page(); + helpful_items(); + harmful_items(); + additional_info(); // loading screen //uLCD.filled_rectangle(0, 0, 255, 255, BLACK); @@ -1876,13 +2581,16 @@ //uLCD.filled_rectangle(0, 0, 255, 255, BLACK); snake_init(&snake); + + + // 0. Initialize the maps -- implement this function: maps_init(); init_main_map(); - //init_map_2(); + //init_map_2(); // Initialize game state @@ -1925,15 +2633,65 @@ } } -int main2() { +int main1() +{ + map1 = true; // First things first: initialize hardware ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!"); - snake_init(&snake); // 0. Initialize the maps -- implement this function: maps_init(); - + init_main_map(); + //init_map_2(); + // Initialize game state + set_active_map(0); + snake.head_x = snake.head_y = 5; + snake.body_x = 4; + snake.body_y = 5; + snake.tail_x = 3; + snake.tail_y = 5; + // Initial drawing + draw_game(FULL_DRAW); + // Main game loop + while(1) { + // Timer to measure game update speed + Timer t; + t.start(); + + // 1. Read inputs -- implement this function: + GameInputs inputs = read_inputs(); + + // 2. Determine action (move, act, menu, etc.) -- implement this function: + int action = get_action(inputs); + + // 3. Update game -- implement this function: + int result = update_game(action); + + // 3b. Check for game over based on result + // and if so, handle game over -- implement this. + + // 4. Draw screen -- provided: + draw_game(result); + + // Compute update time + t.stop(); + int dt = t.read_ms(); + + // Display and wait + // NOTE: Text is 8 pixels tall + if (dt < 100) wait_ms(100 - dt); + } +} +int main2() { + map2 = true; + // First things first: initialize hardware + ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!"); + + uLCD.filled_rectangle(0, 0, 255, 255, BLACK); + snake_init(&snake); + // 0. Initialize the maps -- implement this function: + maps_init(); //init_main_map(); init_map_2();
--- a/map.cpp Fri Nov 20 21:58:45 2020 +0000 +++ b/map.cpp Sat Apr 17 14:09:46 2021 +0000 @@ -23,7 +23,7 @@ #define MAPS_HEIGHT 50 static Map maps[NUM_MAPS]; static int active_map; -unsigned int NUMBUCKETS = 100; +unsigned int NUMBUCKETS = 750; // this is important static const MapItem CLEAR_SENTINEL = { @@ -284,7 +284,7 @@ void add_snake_head(int x, int y) { MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); - w1->type = SNAKE_BODY; + w1->type = SNAKE_HEAD; w1->draw = draw_snake_head; w1->walkable = false; w1->data = NULL; @@ -295,7 +295,7 @@ void add_snake_tail(int x, int y) { MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); - w1->type = SNAKE_BODY; + w1->type = SNAKE_TAIL; w1->draw = draw_snake_tail; w1->walkable = false; w1->data = NULL;
--- a/map.h Fri Nov 20 21:58:45 2020 +0000 +++ b/map.h Sat Apr 17 14:09:46 2021 +0000 @@ -86,6 +86,8 @@ #define BLUEPOTION 24 #define REDPOTION 25 #define PORTAL 26 +#define SNAKE_TAIL 27 +#define SNAKE_HEAD 28 /**