hgftf

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Files at this revision

API Documentation at this revision

Comitter:
ajorgih3
Date:
Fri Nov 20 21:58:45 2020 +0000
Parent:
8:34fd253d0fa5
Child:
10:0b2f37cef9b9
Commit message:
yes;

Changed in this revision

graphics.cpp Show annotated file Show diff for this revision Revisions of this file
graphics.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
map.cpp Show annotated file Show diff for this revision Revisions of this file
map.h Show annotated file Show diff for this revision Revisions of this file
--- a/graphics.cpp	Fri Nov 20 03:15:35 2020 +0000
+++ b/graphics.cpp	Fri Nov 20 21:58:45 2020 +0000
@@ -27,6 +27,7 @@
         else if (img[i] == 'M') colors[i] = 0xFFD700;
         else if (img[i] == 'D') colors[i] = 0xD2691E; // "Dirt"
         else if (img[i] == 'C') colors[i] = 0x84563C;
+        else if (img[i] == 'L') colors[i] = 0xADD8E6;
         else if (img[i] == '5') colors[i] = LGREY; // 50% grey
         else if (img[i] == '3') colors[i] = DGREY;
         else colors[i] = BLACK;
@@ -176,8 +177,14 @@
     draw_img(u, v, redpotion);
 } 
 
+void draw_portal(int u, int v) {
+    char portal[122] = "BBBBSSSBBBBBBBSLLLSBBBBBSLLLLLSBBBSLLLLLLLSBBSLLLLLLLSBBSLLLLLLLSBBSLLLLLLLSBBSLLLLLLLSBBBSLLLLLSBBBBBSLLLSBBBBBBBSSSBBB";  
+    draw_img(u, v, portal);  
+
+}
 
 
 
 
 
+
--- a/graphics.h	Fri Nov 20 03:15:35 2020 +0000
+++ b/graphics.h	Fri Nov 20 21:58:45 2020 +0000
@@ -47,5 +47,6 @@
 void draw_reverse(int u, int v);
 void draw_red_potion(int u, int v);
 void draw_blue_potion(int u, int v);
+void draw_portal(int u, int v);
 
 #endif // GRAPHICS_H
\ No newline at end of file
--- a/main.cpp	Fri Nov 20 03:15:35 2020 +0000
+++ b/main.cpp	Fri Nov 20 21:58:45 2020 +0000
@@ -492,6 +492,46 @@
    
 }
 
+void helpful_items2() {
+   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(2, 3);
+   uLCD.color(0xFFFF00);
+   uLCD.printf("HELPFUL ITEMS++");
+    
+   uLCD.text_width(1);
+   uLCD.text_height(1);
+   uLCD.locate(4, 4);
+   uLCD.color(0xFFFFFF);
+   uLCD.printf("Extra Life!");
+    
+   draw_life(u, 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(4, 11);
+   uLCD.printf("to go back!\n");
+    
+   do {
+      input = read_inputs();    
+   } while(input.b2);
+   uLCD.filled_rectangle(0, 0, 255, 255, BLACK);
+   additional_info(); 
+}
+
+
 void harmful_items2() {
    int u = 58;
    int v = 56; 
@@ -533,21 +573,33 @@
    uLCD.color(0xFFFFFF);
    uLCD.text_width(1);
    uLCD.text_height(1);
-   uLCD.locate(3, 11);
+   uLCD.locate(4, 11);
    uLCD.printf("Press  'B2'\n");
-   uLCD.locate(3, 12);
+   uLCD.locate(4, 12);
    uLCD.printf("to continue!\n");
     
    do {
       input = read_inputs();    
    } while(input.b2);
    uLCD.filled_rectangle(0, 0, 255, 255, BLACK);
+   helpful_items2();
 }
 
 void additional_info() {
+    
+    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, RED); // Top
+   uLCD.filled_rectangle(0,    13,   2, 114, GREEN); // Left
+   uLCD.filled_rectangle(0,   114, 127, 117, 0x0000FF); // Bottom
+   uLCD.filled_rectangle(124,  14, 127, 117, 0xFFFF00); // Right 
 
-   input = read_inputs();
-   
    uLCD.text_width(1);
    uLCD.text_height(1);
    uLCD.locate(1, 3);
@@ -556,19 +608,39 @@
    
    uLCD.text_width(1);
    uLCD.text_height(1);
-   uLCD.locate(2, 6);
+   uLCD.locate(4, 5);
    uLCD.color(0xFFFFFF);
-   uLCD.printf("B2: DIFFICULTY MODES!");
+   uLCD.printf("B2: MAPS!");
    
-   if (!input.b1) {
-        harmful_items2();
-   }
+   uLCD.text_width(1);
+   uLCD.text_height(1);
+   uLCD.locate(4, 7);
+   uLCD.color(0xFFFFFF);
+   uLCD.printf("B3: START!");
    
    do {
-      input = read_inputs();    
-   } while(input.b3);
+    input = read_inputs();
+   } while (input.b1 && input.b2 && input.b3);
    
+   uLCD.filled_rectangle(0, 0, 255, 255, BLACK);
+   if (!input.b1) {
+       harmful_items2();
+    }
+    
     uLCD.filled_rectangle(0, 0, 255, 255, BLACK);
+    if (!input.b2) {
+       main2();
+    }
+    
+    if (!input.b3) {
+    uLCD.filled_rectangle(0, 0, 255, 255, BLACK);
+    return;    
+    }
+   
+}
+
+void bruh() {
+return;    
 }
 
 
@@ -581,35 +653,56 @@
     // "Random" plants
    Map* map = set_active_map(0);
    pc.printf("plants\r\n");
-
-   add_sword(10, 10);
-   add_goodie(8, 4);
-   add_goodie(11, 3);
-   add_goodie(5, 3);
-   add_shield(8, 7);
-   add_life(14,15);
-   add_snowflake(20, 20);
-   add_plant(7, 19);
-   add_snake_head(5, 4);
-   add_goodie(16, 5);
-   add_lightspeed(15, 6);
-   add_goodie(7, 5);
-   //add_reverse(18, 5);
-   //add_blue_potion(20,5);
-   add_red_potion(22, 5);
-   add_goodie(27, 5);
-   add_goodie(27, 4);
-   add_goodie(27, 3); 
-   add_goodie(26, 3);
-   add_goodie(25, 3);
-   add_goodie(24, 3);
-   add_blue_potion(8, 5);
-   for (int i = 0; i < 40; i++) {
-   add_goodie(i, 6);    
-    }
+   
+   add_portal(7, 5);
+   
+   for (int i = 0; i < 20; i++) {
+   int goodieRandX = rand() % 50;
+   int goodieRandY = rand() % 50;
+   add_goodie(goodieRandX, goodieRandY);
+   }
+   
+   for (int i = 0; i < 30; i++) {
+   int goodieRandX = rand() % 50;
+   int goodieRandY = rand() % 50;
+   add_goodie(goodieRandX, goodieRandY);
+   }
    
+   for (int i = 0; i < 10; i++) {
+   int redRandX = rand() % 50;
+   int redRandY = rand() % 50;
+   add_red_potion(redRandX, redRandY);
+   }
+//   
+   for (int i = 0; i < 10; i++) {
+   int swordRandX = rand() % 50;
+   int swordRandY = rand() % 50;
+   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;
+   add_shield(shieldRandX, shieldRandY);
+   }
    
-   
+   for (int i = 0; i < 10; i++) {
+   int reverseRandX = rand() % 50;
+   int reverseRandY = rand() % 50;
+   add_reverse(reverseRandX, reverseRandY);
+   }
     
    pc.printf("Adding walls!\r\n");
    add_wall(0,              0,              HORIZONTAL, map_width());
@@ -622,11 +715,11 @@
    add_snake_body(snake.locations[1].x, snake.locations[1].y);
    add_snake_tail(snake.locations[2].x, snake.locations[2].y);
     
-   pc.printf("Add extra chamber\r\n");
-   add_wall(30, 0, VERTICAL, 10);
-   add_wall(30, 10, HORIZONTAL, 10);
-   add_wall(39, 0, VERTICAL, 10);
-   pc.printf("Added!\r\n");
+  // pc.printf("Add extra chamber\r\n");
+//   add_wall(30, 0, VERTICAL, 10);
+//   add_wall(30, 10, HORIZONTAL, 10);
+//   add_wall(39, 0, VERTICAL, 10);
+//   pc.printf("Added!\r\n");
     
     
 
@@ -647,7 +740,8 @@
    add_blue_wall(0,              map_height()-1, HORIZONTAL, map_width());
    add_blue_wall(0,              0,              VERTICAL,   map_height());
    add_blue_wall(map_width()-1,  0,              VERTICAL,   map_height());
-   pc.printf("Walls done!\r\n");   
+   pc.printf("Walls done!\r\n"); 
+   print_map();  
     
 }
 
@@ -902,6 +996,7 @@
         uLCD.filled_rectangle(0,   114, 127, 117, 0xFFFFFF); // Bottom
         uLCD.filled_rectangle(124,  14, 127, 117, 0xFFFFFF); // Right
         draw_nothing(102, 100);
+        
     
     //pc.printf("Shield Counter: %d\n", shieldCounter);
    switch(action) {
@@ -909,7 +1004,7 @@
       case GO_RIGHT:
          nextHead = get_east(snake.head_x, snake.head_y);
          pc.printf("GO RIGHT\n");
-         if (nextHead->walkable && nextHead->type != LIFE && nextHead->type != GOODIE && nextHead->type != SWORD && nextHead->type != REVERSE && nextHead->type != LIGHTSPEED && nextHead->type != SHIELD && nextHead->type != SNOWFLAKE && nextHead->type != BLUEPOTION && nextHead->type !=REDPOTION && nextHead->type != BLUEPOTION) {
+         if (nextHead->walkable && nextHead->type != LIFE && nextHead->type != GOODIE && nextHead->type != SWORD && nextHead->type != REVERSE && nextHead->type != LIGHTSPEED && nextHead->type != SHIELD && nextHead->type != SNOWFLAKE && nextHead->type != BLUEPOTION && nextHead->type !=REDPOTION && nextHead->type != BLUEPOTION && nextHead->type != PORTAL) {
             pc.printf("Before:\n");
             pc.printf("head_x: %d, head_y: %d\n", snake.head_x, snake.head_y);
             pc.printf("body_x: %d, body_y: %d\n", snake.body_x, snake.body_y);
@@ -1091,6 +1186,10 @@
          add_nothing(snake.head_x + 1, snake.head_y);  
          }
          
+         if (nextHead->type == PORTAL) {
+         main2();  
+         }
+         
          break;
         
       case GO_LEFT:
@@ -1107,7 +1206,7 @@
              pc.printf("slowflakeCounter: %d", slowflakeCounter);
              pc.printf("blueCounter: %d", blueCounter);
              pc.printf("redCounter: %d", redCounter);
-            if (reverseCounter == 0) {
+            if (reverseCounter == 0 && nextHead->walkable) {
             go_left2();
             draw_arrow_left(113, 100);
             }
@@ -1688,6 +1787,44 @@
       uLCD.printf("Press  'B2'\n");
       uLCD.locate(5, 11);
       uLCD.printf("to unpause!\n");
+      uLCD.locate(0, 0);
+      uLCD.color(0xFFFFFF);
+      uLCD.printf("STATUS:");
+     
+      if (shieldCounter == 0) {
+        draw_nothing(0, 11);
+        }
+      else {
+        draw_shield(0, 11);
+        }
+        
+      if (speedCounter == 0) {
+        draw_nothing(11, 11);
+        }
+      else {
+        draw_lightspeed(11, 11);
+        }
+        
+      if (redCounter == 0) {
+        draw_nothing(22, 11);
+        }
+      else {
+        draw_red_potion(22, 11);
+        }
+        
+       if (blueCounter == 0) {
+        draw_nothing(33, 11);
+        }
+      else {
+        draw_blue_potion(33, 11);
+        }
+        
+       if (slowflakeCounter == 0) {
+        draw_nothing(44, 11);
+        }
+      else {
+        draw_snowflake(44, 11);
+        }
          
       do {
         input = read_inputs();    
@@ -1792,31 +1929,14 @@
     // First things first: initialize hardware
    ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!");
     
-    //start_game();
-    //title_page();
-    //helpful_items();
-    //harmful_items();
-    //additional_info();
-    
-    // loading screen
-    //uLCD.filled_rectangle(0, 0, 255, 255, BLACK);
-    //uLCD.textbackground_color(BLACK);
-    //uLCD.color(0xFFFFFF);
-    //uLCD.locate(4,7);
-    //uLCD.printf("GOOD LUCK!");
-    //uLCD.locate(4,8);
-    //uLCD.printf("Loading...");
-    //wait(4);
-    //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_main_map();
+   init_map_2();
     
 
     // Initialize game state
@@ -1826,6 +1946,7 @@
    snake.body_y = 5;
    snake.tail_x = 3;
    snake.tail_y = 5;
+   //snake.length = bodyLength;
     // Initial drawing
    draw_game(FULL_DRAW);
     // Main game loop
--- a/map.cpp	Fri Nov 20 03:15:35 2020 +0000
+++ b/map.cpp	Fri Nov 20 21:58:45 2020 +0000
@@ -460,3 +460,14 @@
     void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
     if (val) free(val); // If something is already there, free it
 }
+
+void add_portal(int x, int y) 
+{
+    MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
+    w1->type = PORTAL;
+    w1->draw = draw_portal;
+    w1->walkable = true;
+    w1->data = NULL;
+    void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
+    if (val) free(val); // If something is already there, free it
+}
--- a/map.h	Fri Nov 20 03:15:35 2020 +0000
+++ b/map.h	Fri Nov 20 21:58:45 2020 +0000
@@ -85,6 +85,7 @@
 #define REVERSE 23
 #define BLUEPOTION 24
 #define REDPOTION 25
+#define PORTAL 26
 
 
 /**
@@ -201,5 +202,6 @@
 void add_reverse(int x, int y);
 void add_blue_potion(int x, int y);
 void add_red_potion(int x, int y);
+void add_portal(int x, int y);
 
 #endif //MAP_H
\ No newline at end of file