Chuong Dong / Mbed 2 deprecated rpg_game_shell

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Files at this revision

API Documentation at this revision

Comitter:
cdong49
Date:
Sat Apr 13 21:11:27 2019 +0000
Parent:
2:3caab2cc0476
Child:
4:3883ea0930ec
Commit message:
Final

Changed in this revision

SDFileSystem/FATFileSystem/FATFileSystem.cpp Show annotated file Show diff for this revision Revisions of this file
globals.h Show annotated file Show diff for this revision Revisions of this file
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
hardware.cpp Show annotated file Show diff for this revision Revisions of this file
hardware.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
wave_player.lib Show annotated file Show diff for this revision Revisions of this file
--- a/SDFileSystem/FATFileSystem/FATFileSystem.cpp	Thu Apr 11 18:13:32 2019 +0000
+++ b/SDFileSystem/FATFileSystem/FATFileSystem.cpp	Sat Apr 13 21:11:27 2019 +0000
@@ -48,7 +48,7 @@
         if(_ffs[i] == 0) {
             _ffs[i] = this;
             _fsid = i;
-            debug_if(FFS_DBG, "Mounting [%s] on ffs drive [%d]\n", _name, _fsid);
+           //debug_if(FFS_DBG, "Mounting [%s] on ffs drive [%d]\n", _name, _fsid);
             f_mount(i, &_fs);
             return;
         }
@@ -66,7 +66,7 @@
 }
 
 FileHandle *FATFileSystem::open(const char* name, int flags) {
-    debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%d]\n", name, _name, _fsid);
+   // debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%d]\n", name, _name, _fsid);
     char n[64];
     sprintf(n, "%d:/%s", _fsid, name);
     
@@ -96,7 +96,7 @@
     if (flags & O_APPEND) {
         f_lseek(&fh, fh.fsize);
     }
-    return new FATFileHandle(fh);
+    //return new FATFileHandle(fh);
 }
     
 int FATFileSystem::remove(const char *filename) {
@@ -123,7 +123,7 @@
     if (res != 0) {
         return NULL;
     }
-    return new FATDirHandle(dir);
+    //return new FATDirHandle(dir);
 }
 
 int FATFileSystem::mkdir(const char *name, mode_t mode) {
--- a/globals.h	Thu Apr 11 18:13:32 2019 +0000
+++ b/globals.h	Sat Apr 13 21:11:27 2019 +0000
@@ -16,7 +16,7 @@
 
 // Declare the hardware interface objects
 extern uLCD_4DGL uLCD;      // LCD Screen
-extern SDFileSystem sd;     // SD Card
+//extern SDFileSystem sd;     // SD Card
 extern Serial pc;           // USB Console output
 extern MMA8452 acc;       // Accelerometer
 extern DigitalIn button1;   // Pushbuttons
--- a/graphics.cpp	Thu Apr 11 18:13:32 2019 +0000
+++ b/graphics.cpp	Sat Apr 13 21:11:27 2019 +0000
@@ -12,7 +12,13 @@
         draw_img(u, v, "LLDDDDDDDLLLLDYYDYDDLLLDYYLYLYYDLLDYYYYYYYDLLDLYYLYYLDLLLLLGGGLLLLLLLYYYYYLLLLLGGGGGGGLLLLYYYYYYYLLLLLGGGGGLLLLLLLDLDLLLL");
     }
 }
+void draw_leaf(int u, int v) {
 
+    draw_img(u, v, "LLLLGGGLLLLLLGGGGGGGLLLGGGGGGGGGLLLGGGGGGGGGLGGGGGGGGGGGGGGGGGGGGGLGGGGGGGGGLGGGGGGGGGGGLGGGGGGGGGLLLGGGGGGGLLLLLGGGGGLLL");
+}
+void draw_wood(int u, int v) {
+    draw_img(u, v, "LLLDDDDDLLLLLDDDDDDDLLLDDDDDDDDDLLDDDDDDDDDLLDDDDDDDDDLLDDDDDDDDDLLDDDDDDDDDLLDDDDDDDDDLLDDDDDDDDDLDDDDDDDDDDDDDDDDDDDDDD");
+}
 #define YELLOW 0xFFFF00
 #define BROWN  0xD2691E
 #define BLUE   0x0000FF
@@ -92,26 +98,50 @@
     uLCD.locate(5,12);
     uLCD.printf("@cpeterr");
 }
+void draw_game_over() {
+    uLCD.cls();
+    uLCD.color(GREEN);
+    uLCD.text_bold(TEXTBOLD);
+    uLCD.locate(5, 4);
+    uLCD.printf("GAME OVER");
+    uLCD.locate(0, 6);
+    uLCD.printf("Thanks for playing");
+    uLCD.locate(9, 9);
+    uLCD.printf("Peter");
+    wait_ms(5000);
+}
 
-void draw_menu(char* task, char* hint, int health) {
+void draw_menu(char* a, char* b, int health_count, int key, int chest, int run) {
     uLCD.cls();
     uLCD.color(GREEN);
     uLCD.text_bold(TEXTBOLD);
     uLCD.locate(0, 4);
-    uLCD.printf("task: %s", task);
+    uLCD.printf("task: %s", a);
     
     uLCD.color(RED);
     uLCD.text_bold(TEXTBOLD);
     uLCD.locate(0, 7);
-    uLCD.printf("hint: %s", hint);
-    if (health == 3) {
+    uLCD.printf("hint: %s", b);
+    if(key == 1) {
+        uLCD.color(WHITE);
+        uLCD.text_bold(TEXTBOLD);
+        uLCD.locate(0, 10);
+        uLCD.printf("inventory: Chara's shirt");
+        if(chest==1) {
+            uLCD.printf(", Treasure chest");   
+        }
+        if(run == 1) {
+            uLCD.printf(", Running shoes");   
+        }
+    } 
+    if (health_count == 3) {
         draw_img(85, 10, "LRRRLLLRRRLRRRRRLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRRRRRRRLLRRRRRRRRRLLLRRRRRRRLLLLRRRRRRRLLLLLRRRRRLLLLLLLRRRLLLL");
         draw_img(50, 10, "LRRRLLLRRRLRRRRRLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRRRRRRRLLRRRRRRRRRLLLRRRRRRRLLLLRRRRRRRLLLLLRRRRRLLLLLLLRRRLLLL");
         draw_img(20, 10, "LRRRLLLRRRLRRRRRLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRRRRRRRLLRRRRRRRRRLLLRRRRRRRLLLLRRRRRRRLLLLLRRRRRLLLLLLLRRRLLLL");
-    } else if(health == 2) {
+    } else if(health_count == 2) {
         draw_img(50, 10, "LRRRLLLRRRLRRRRRLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRRRRRRRLLRRRRRRRRRLLLRRRRRRRLLLLRRRRRRRLLLLLRRRRRLLLLLLLRRRLLLL");
         draw_img(20, 10, "LRRRLLLRRRLRRRRRLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRRRRRRRLLRRRRRRRRRLLLRRRRRRRLLLLRRRRRRRLLLLLRRRRRLLLLLLLRRRLLLL");           
-    } else if(health == 1) {
+    } else if(health_count == 1) {
         draw_img(20, 10, "LRRRLLLRRRLRRRRRLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRRRRRRRLLRRRRRRRRRLLLRRRRRRRLLLLRRRRRRRLLLLLRRRRRLLLLLLLRRRLLLL");   
     }
     wait_ms(3000);
@@ -165,7 +195,9 @@
 void draw_green_button(int u, int v) {
     draw_img(u, v, "LLGGGGGGGLLLGGGGGGGGGLGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGLGGGGGGGGGLLLGGGGGGGLLLLLGGGGGLLLLLLGGGGGLLLLGGGGGGGGGLGGGGGGGGGGG");
 }
-
+void draw_chest(int u, int v) {
+    draw_img(u, v, "LLLYYYYYLLLLLYDDDDDYLLLYDDDDDDDYLYDDDDDDDDDYYDDDYYYDDDYYDDDDYDDDDDLLLLLLLLLLLYDDDDDDDDDYYDDDDDDDDDYYYDDDDDDDYYYYYYYYYYYYY");   
+}
 void draw_blue_button(int u, int v) {
     draw_img(u, v, "LLBBBBBBBLLLBBBBBBBBBLBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBLBBBBBBBBBLLLBBBBBBBLLLLLBBBBBLLLLLLBBBBBLLLLBBBBBBBBBLBBBBBBBBBBB");   
 }
--- a/graphics.h	Thu Apr 11 18:13:32 2019 +0000
+++ b/graphics.h	Sat Apr 13 21:11:27 2019 +0000
@@ -44,7 +44,11 @@
 void draw_river_man(int u, int v);
 void draw_heart(int u, int v);
 void draw_start();
-void draw_menu(char* task, char* hint);
+void draw_chest(int u, int v);
+void draw_menu(char* task, char* hint, int health_count, int key, int chest, int run);
+void draw_game_over();
+void draw_leaf(int u, int v);
+void draw_wood(int u, int v);
 /**
  * Draw the upper status bar.
  */
--- a/hardware.cpp	Thu Apr 11 18:13:32 2019 +0000
+++ b/hardware.cpp	Sat Apr 13 21:11:27 2019 +0000
@@ -16,6 +16,7 @@
 DigitalIn button1(p21);                 // Pushbuttons (pin)
 DigitalIn button2(p22);
 DigitalIn button3(p23);
+DigitalIn button4(p24);
 AnalogOut DACout(p18);                  // Speaker (pin)
 PwmOut speaker(p26);
 wave_player waver(&DACout);
@@ -32,6 +33,7 @@
     button1.mode(PullUp); 
     button2.mode(PullUp);
     button3.mode(PullUp);
+    button3.mode(PullUp);
     acc.activate();
     return ERROR_NONE;
 }
@@ -43,6 +45,7 @@
     in.b1 = button1; // top button
     in.b2 = button2; // second button 
     in.b3 = button3; // third button
+    in.b4 = button4; // fourth, run button
     acc.readXGravity(&in.ax); // x axis acce
     acc.readYGravity(&in.ay); // y axis acce
     acc.readZGravity(&in.az); // z axis acce
--- a/hardware.h	Thu Apr 11 18:13:32 2019 +0000
+++ b/hardware.h	Sat Apr 13 21:11:27 2019 +0000
@@ -6,7 +6,7 @@
  * If additional hardware is added, new elements should be added to this struct.
  */
 struct GameInputs {
-    int b1, b2, b3;     // Button presses
+    int b1, b2, b3, b4;     // Button presses
     double ax, ay, az;  // Accelerometer readings
 };
 
--- a/main.cpp	Thu Apr 11 18:13:32 2019 +0000
+++ b/main.cpp	Sat Apr 13 21:11:27 2019 +0000
@@ -5,24 +5,79 @@
 #include "graphics.h"
 #include "speech.h"
 
+#include <stdlib.h>
 int menu = 0;
-int health = 2;
-char* task[4] = {"talk to the dog to start quest", "go to Snowdin", "go into the room to start the puzzle", "come back to the castle"};
-char* hint[4] = {"... just talk to him", "talk to the riverman", "you've better hurry", "talk to the riverman"};
+int health = 3;
+int omni_pressed = 0;
+int run = 0;
+int quest = 0; // 0 is before quest, 1 is during quest no key, 2 is with key, 3 is back talking 
+int door = 0; // 1 if door unlocked, 0 if door locked
+int chest = 0;
+int game_over = 0;
+char* task[5] = {"talk to the dog to start quest", "go to Snowdin", "go into the room to start the puzzle", "come back to the castle", "go to the castle"};
+char* hint[5] = {"Just talk to him", "talk to the riverman", "read the sign", "talk to the riverman", "walk down south"};
+
+char* flowey_wink[4] = {"Howdy!", "I'm FLOWEY", "FLOWEY THE", "FLOWER"};
+char* flowey_creepy[4] = {"In this","world...","It's KILL","or BE killed!"};
+char* flowey_friendly1[4] = {"That shirt...", "it seems familiar", "reminds me of", "someone"};
+char* flowey_friendly2[4] = {"are you sure", "it's yours?", "ugh I hate", "that dog"};
+char** flowey_friendly[2] = {flowey_friendly1, flowey_friendly2};
+
+char* sign1[4] = {"Welcome to","Snowdin!", "here you have to","solve a puzzle"};
+char* sign2[4] = {"Choose the right", "button. One will", "take you to", "the next level"};
+char* sign3[4] = {"Two will kick you","out of the room", "Three strikes", "and you're out"};
+char** sign[3] = {sign1, sign2, sign3};
 
+char* toby_pre1[4] = {"ruff ruff", "yo!", "I'm just a dog"};
+char* toby_pre2[4] = {"how are ya", "you must be", "new here!", "This is the"};
+char* toby_pre3[4] = {"the ruins! We", "have monsters and", "all kind of"};
+char* toby_pre4[4] = {"stuff down here", "...", "There is not", "much to do tho"};
+char* toby_pre5[4] = {"... oh wait", "there is!! I'm", "hungry.. can you", "get me some bone?"};
+char* toby_pre6[4] = {"Where? Snowdin!","it's quite a", "distance from here", "so i suggest"};
+char* toby_pre7[4] = {"you get going!", "Bring me a bone", "asap, and ill" };
+char* toby_pre8[4] = {"give you something","in return!","good luck!!","..."};
+char** toby_pre[8] = {toby_pre1, toby_pre2, toby_pre3,toby_pre4,toby_pre5,toby_pre6,toby_pre7,toby_pre8};
+char* toby_bone1[4] = {"Om nom nom", "nom..", "oh hey!", "look at ya"};
+char* toby_bone2[4] = {"How did you get", "here so fast?", ".. nom nom", "nom"};
+char* toby_bone3[4] = {"what's with the", "look? Didnt", "I tell you I", "could teleport?"};
+char* toby_bone4[4] = {"Yea!Like the dude", "on the boat", "pretty nice,","isnt it?"};
+char* toby_bone5[4] = {"You just came", "here for nothing!", "bamboozled!","..."};
+char* toby_bone6[4] = {"Lol don't be mad", "I'll give ya", "this pretty dope", "shirt!"};
+char* toby_bone7[4] = {"The old prince", "threw it away", "you can", "basically go"};
+char* toby_bone8[4] = {"anywhere with it", "...", "It's", "pretty nice!"};
+char* toby_bone9[4] = {"imma go!", "baiiii", "i'll see ya at", "the starting point"};
+char** toby_bone[9] = {toby_bone1, toby_bone2,toby_bone3,toby_bone4,toby_bone5,toby_bone6,toby_bone7,toby_bone8,toby_bone9};
+
+char* river_man_line1[4] = {"Tra la la", "The waters are", "wild today.", "That is bad luck"};
+char* river_man_line2[4] = {"Tra la la", "The waters are", "wild today.", "That is good luck"};
+char* river_man_line3[4] = {"Tra la la", "What's inside an", "acorn? It's" ,"just a mystery."};
+char* river_man_line4[4] = {"Tra la la", "Dancing on a boat","is danger.", "But good exercise"};
+char* river_man_line5[4] = {"Tra la la", "Why don't you", "sing with me.", "Tra la la."};
+char* river_man_line6[4] = {"Tra la la", "Uh oh.", "Suddenly, feeling" ,"tropical..."};
+char* river_man_line7[4] = {"Tra la la", "The water is", "very dry", "today"};
+char* river_man_line8[4] = {"Tra la la", "The water is", "very wet", "today"};
+char* river_man_line9[4] = {"Tra la la", "Tri li li.", "Tre le le.", "..."};
+char* river_man_line10[4] = {"Tra la la", "What's my name?" ,"It doesn't", "really matter..."};
+char* river_man_line11[4] = {"Tra la la." "I heard dogs" "have a favorite" "food. It's bone!"};
+char* river_man_line12[4] = {"Tra la la. You", "can never have", "too many hot dogs", "This is not true"};
+char* river_man_line13[4] = {"Tra la la.", "Beware of", "the man who", "speaks in hands"};
+char* river_man_line14[4] = {"Tra la la.", "Beware of the", "man who came from", "the other world"};
+char* river_man_line15[4] = {"Tra la la.", "Humans, monsters", "...", "flowers"};
+char** river_man_line[15] = {river_man_line13, river_man_line3,river_man_line14, river_man_line1, river_man_line15, river_man_line6, river_man_line11, river_man_line8, river_man_line9, river_man_line10,river_man_line7,river_man_line12,river_man_line2,river_man_line4,river_man_line5};
 // Functions in this file
 int get_action (GameInputs inputs);
 int update_game (int action);
 void draw_game (int init);
 void init_main_map ();
 void intit_start();
-void init_menu(char* task, char* hint, int health);
+void init_menu(char* task, char* hint, int health, int key, int chest, int run);
 int go_up(int x, int y);
 int go_down(int x, int y);
 int go_left(int x, int y);
 int go_right(int x, int y);
 int main ();
-
+int interact(int x, int y);
+void check_health();
 /**
  * The main game state. Must include Player locations and previous locations for
  * drawing to work properly. Other items can be added as needed.
@@ -44,6 +99,7 @@
 #define GO_RIGHT 4
 #define GO_UP 5
 #define GO_DOWN 6
+#define RUN 7
 int get_action(GameInputs inputs)
 {
     if(!inputs.b1) {
@@ -64,6 +120,9 @@
     if(inputs.ay <= -0.45) {
         return GO_DOWN;   
     }
+    if (!inputs.b3) {
+        omni_pressed = !omni_pressed;
+    }
     return NO_ACTION;
 }
 
@@ -114,12 +173,14 @@
                 break;
             }
         case ACTION_BUTTON:
-            speech("test","test");
-            draw_game(true);
-            return FULL_DRAW;
+            if(interact(Player.x,Player.y)) {
+                return FULL_DRAW;
+            } else {
+                break;   
+            }
         case MENU_BUTTON: 
             uLCD.cls();
-            init_menu(task[0], hint[0], health);
+            init_menu(task[menu], hint[menu], health, Player.has_key, chest, run);
             wait_ms(300);
             draw_game(true);
             return FULL_DRAW;
@@ -128,6 +189,386 @@
     return NO_RESULT;
 }
 
+int interact(int x, int y) {
+    MapItem *item = get_south(x, y);
+
+    if(item->type == CHEST) {
+        speech("you found a", "chest!!!");
+        draw_game(true);
+        wait_ms(150);
+        map_erase(x,y+1);
+        draw_game(true);
+        wait_ms(150);
+        chest = 1;
+        map_erase(x,y-2);
+        draw_game(true);
+        quest = 99;
+        wait_ms(150);
+        
+        add_leaf(11, 10);
+        add_wood(11, 11);
+        add_wood(11, 12);
+        return 1;  
+    }
+    
+    if(item->type == WOOD) {
+        if(run == 0) {
+            speech("Hi kid!,","Im a tree");
+            draw_game(true);
+            wait_ms(150);
+            speech("...","uhm so...");
+            draw_game(true);
+            wait_ms(150);
+            speech("some kid left", "their running");
+            draw_game(true);
+            wait_ms(150);
+            speech("shoes here, imma", "give it to you");
+            draw_game(true);
+            wait_ms(150);
+            run = 1;
+        } else {
+            speech("oh you dont", "want the shoes");  
+            draw_game(true);
+            wait_ms(150);
+            speech("no mo? Ill", "take it back then");
+            draw_game(true);
+            wait_ms(150);
+            run = 0;
+        }       
+    }
+    if(item->type == TOBY) {
+        if(quest == 0) {
+            for(int i =0; i<8;i++) {
+                for(int j = 0; j < 4;j+=2) {
+                    speech(toby_pre[i][j], toby_pre[i][j+1]);
+                    draw_game(true);   
+                }   
+            }
+            wait_ms(150);  
+            quest=1;
+            menu = 1;
+            menu++;
+        } else if(quest == 1) {
+            speech("well..","what are you waiting for!");
+            draw_game(true);
+            wait_ms(300);
+            menu = 1;
+        } else if(quest == 3) {
+            speech("ruff ruff,","looking good!!");
+            draw_game(true);
+            wait_ms(300); 
+            speech("you can go to", "the castle");
+            draw_game(true);
+            wait_ms(300);
+            speech("down south now!", "Have fun");
+            draw_game(true);
+            wait_ms(300);
+            menu = 4;  
+        } else if(quest == 99) {
+            speech("congrats! you","finish the game");
+            draw_game(true);
+            wait_ms(300);
+            game_over = 1;
+        }
+        
+        return 1;  
+    }
+    if(item->type == FLOWWINK) {
+    // generate a 500Hz tone using PWM hardware output
+        speaker.period(1.0/500.0); // 500hz period
+        speaker =0.5; //50% duty cycle - max volume
+        wait(1);
+        speaker=0.0; // turn off audio
+        wait(1);
+        if(quest == 2) {
+            add_flowey_friendly(x, y+1);
+            draw_game(true);
+            wait_ms(100);
+            for(int i = 0; i <2;i++) {
+                for(int j = 0; j < 4;j+=2) {
+                    speech(flowey_friendly[i][j], flowey_friendly[i][j+1]);
+                    draw_game(true);
+                }
+            }
+            draw_nothing(x,y+1);
+            draw_game(true);
+            wait_ms(100); 
+        } else {
+            for(int i = 0; i < 4;i+=2) {
+                speech(flowey_wink[i], flowey_wink[i+1]);
+                draw_game(true);   
+            }
+            add_flowey_creepy(x, y+1);
+            draw_game(true);
+            return 1;
+        }
+        return 1;
+    }
+    if(item->type == FLOWCREEPY) {
+    // generate a 500Hz tone using PWM hardware output
+        speaker.period(1.0/500.0); // 500hz period
+        speaker =0.5; //50% duty cycle - max volume
+        wait(1);
+        speaker=0.0; // turn off audio
+        wait(1);
+ 
+        if(quest != 2) {
+            for(int i = 0; i < 4;i+=2) {
+                speech(flowey_creepy[i], flowey_creepy[i+1]);
+                draw_game(true);   
+            }  
+            add_flowey_wink(x, y+1);
+            draw_game(true);
+            return 1;
+        } else {
+            add_flowey_friendly(x, y+1);
+            draw_game(true);
+            wait_ms(100);
+            for(int i = 0; i <2;i++) {
+                for(int j = 0; j < 4;j+=2) {
+                    speech(flowey_friendly[i][j], flowey_friendly[i][j+1]);
+                    draw_game(true);
+                }
+            }  
+            draw_nothing(x,y+1);
+            draw_game(true);
+            wait_ms(100);
+        }
+        return 1;
+    }
+    if(item->type == FLOWFRIEND) {
+    // generate a 500Hz tone using PWM hardware output
+        speaker.period(1.0/500.0); // 500hz period
+        speaker =0.5; //50% duty cycle - max volume
+        wait(1);
+        speaker=0.0; // turn off audio
+        wait(1);
+        for(int i = 0; i <2;i++) {
+            for(int j = 0; j < 4;j+=2) {
+                speech(flowey_friendly[i][j], flowey_friendly[i][j+1]);
+                draw_game(true);
+            }
+        }
+        wait_ms(100);
+        draw_nothing(x,y+1);
+        draw_game(true);
+        wait_ms(100);
+        return 1;
+    }
+    if(item->type == SIGN) {
+        door = 1;
+        for(int i = 0; i < 3;i++) {
+            for(int j = 0; j < 4;j+=2) {
+                speech(sign[i][j], sign[i][j+1]);
+                draw_game(true);   
+                wait_ms(200);
+            }   
+        }
+        return 1;
+    }
+    
+    if(item->type == DOORLOCKED) {
+        if(x == 2) {
+            speech("Door locked", "Not a royalty");
+            draw_game(true);
+            wait_ms(150);
+        } else if(x== map_width()-3) {
+            speech("You use the","key you just found");
+            draw_game(true);
+            wait_ms(150);
+            add_door_unlocked(x,y+1);
+            draw_game(true);
+            menu = 2;
+        } else {
+            if(door == 0) {
+                speech("door locked", "read the sign");
+                draw_game(true);
+                wait_ms(300);
+                speech("first to unlock", "this door!"); 
+                draw_game(true);
+                wait_ms(300);
+            } else if(door == 1) {
+                speech("You hear the", "door opens");
+                draw_game(true);
+                wait_ms(150);
+                add_door_unlocked(x, y+1);
+                draw_game(true);   
+            }  
+        }
+        return 1;
+    }
+    
+    if(item->type == DOORUNLOCKED){
+        wait_ms(150); 
+        Player.y += 2;
+        draw_game(true);
+        return 1;
+    }
+    
+    if(item->type == REDBUTTON) {
+        if(y+1 == map_height()-38) {
+            waver.dac_out();
+            speech("uh oh", "wrong one");
+            draw_game(true);
+            wait_ms(150);
+            Player.x = map_width()-35;
+            Player.y = map_height()-43;
+            draw_game(true);
+            health--;
+            return 1;
+        } else if(y+1 == map_height()-34) {
+            speech("uh oh", "wrong one");
+            draw_game(true);
+            wait_ms(150);
+            Player.x = map_width()-35;
+            Player.y = map_height()-43;
+            draw_game(true);
+            health--;
+            return 1;
+        } else if(y+1 == map_height()-31) {
+            speech("You hear", "a click!");
+            draw_game(true);
+            wait_ms(150);
+            Player.y += 3;
+            draw_game(true);
+        } else if(y+1 == map_height()-27) {
+            speech("You hear", "a click!");
+            draw_game(true);
+            wait_ms(150);
+            Player.y += 3;
+            draw_game(true);
+            wait_ms(300);
+    
+        }
+        return 1;
+    }
+    if(item->type == GREENBUTTON) {
+        if(y+1 == map_height()-38) {
+            speech("You hear", "a click!");
+            draw_game(true);
+            wait_ms(150);
+            Player.y += 3;
+            draw_game(true);
+        } else if(y+1 == map_height()-34) {
+            speech("uh oh", "wrong one");
+            draw_game(true);
+            wait_ms(150);
+            Player.x = map_width()-35;
+            Player.y = map_height()-43;
+            draw_game(true);
+            health--;
+        } else if(y+1 == map_height()-31) {
+            speech("uh oh", "wrong one");
+            draw_game(true);
+            wait_ms(150);
+            Player.x = map_width()-35;
+            Player.y = map_height()-43;
+            draw_game(true);
+            health--;
+        } else if(y+1 == map_height()-27) {
+            speech("uh oh", "wrong one");
+            draw_game(true);
+            wait_ms(150);
+            Player.x = map_width()-35;
+            Player.y = map_height()-43;
+            draw_game(true);
+            health--;
+        }
+        return 1;
+    }
+    if(item->type == BLUEBUTTON) {
+        if(y+1 == map_height()-38) {
+            speech("uh oh", "wrong one");
+            draw_game(true);
+            wait_ms(150);
+            Player.x = map_width()-35;
+            Player.y = map_height()-43;
+            draw_game(true);
+            health--;
+        } else if(y+1 == map_height()-34) {
+            speech("You hear", "a click!");
+            draw_game(true);
+            wait_ms(150);
+            Player.y += 3;
+            draw_game(true);
+        } else if(y+1 == map_height()-31) {
+            speech("uh oh", "wrong one");
+            draw_game(true);
+            wait_ms(150);
+            Player.x = map_width()-35;
+            Player.y = map_height()-43;
+            draw_game(true);
+            health--;
+        } else if(y+1 == map_height()-27) {
+            speech("uh oh", "wrong one");
+            draw_game(true);
+            wait_ms(150);
+            Player.x = map_width()-35;
+            Player.y = map_height()-43;
+            draw_game(true);
+            health--;
+        }
+        return 1;
+    }
+    if(item->type == TOBYBONE) {
+        for(int i = 0; i < 9; i++) {
+            for(int j = 0; j < 4;j+=2) {
+                speech(toby_bone[i][j], toby_bone[i][j+1]);
+                draw_game(true);
+                wait_ms(150);   
+            }   
+        }
+        map_erase(x,y+1);
+        draw_game(true);
+        wait_ms(300);
+        Player.has_key = 1;
+        quest=2;
+        
+        draw_game(true); 
+        wait_ms(300);
+        map_erase(x-3, y+2);
+        menu = 3;
+        return 1;   
+    }
+    
+    if(item->type == RIVERMAN) {
+        if(quest == 1) { // head to snowdin
+            speech("Tra la la", "Everything is");
+            draw_game(true);
+            wait_ms(150);
+            speech("not how they", "seem to be");
+            draw_game(true);
+            wait_ms(150);
+            menu = 2;
+            Player.x = map_width()-36;
+            Player.y = map_height()-45;
+            draw_game(true);
+            wait_ms(150);
+        } else if(quest==2) { // got the keys
+            speech("Tra la la", "Did I");
+            draw_game(true);
+            wait_ms(150);
+            speech("not warn", "ya...");
+            draw_game(true);
+            wait_ms(150);
+            uLCD.cls();
+            Player.x = 5;
+            Player.y = 5;
+            draw_game(true);
+            wait_ms(300);
+            quest++;
+        } else {
+            int index = rand()%15;
+            for(int i = 0; i <4;i+=2 ) {
+                speech(river_man_line[index][i], river_man_line[index][i+1]);
+                draw_game(true);
+                wait_ms(150);   
+            }
+        }   
+    }
+    return 0;
+}
+
 void init_start() {
     GameInputs in = read_inputs();
     draw_start();
@@ -141,12 +582,17 @@
     uLCD.cls();
 }
 
-void init_menu(char *task, char *hint, int health) {
+void init_menu(char *a, char *b, int health_count, int key, int chest, int run) {
         GameInputs in = read_inputs();
-        draw_menu(task, hint);  
+        draw_menu(a, b, health_count, key, chest, run);  
         uLCD.cls(); 
 }
 
+void init_game_over() {
+    GameInputs in = read_inputs();
+    draw_game_over();
+    uLCD.cls();   
+}
 /**
  * Entry point for frame drawing. This should be called once per iteration of
  * the game loop. This draws all tiles on the screen, followed by the status 
@@ -227,7 +673,16 @@
     
     for(int i = map_width() + 3; i < map_area(); i += 40)
     {
-        add_plant(i % map_width(), i / map_width());
+        if((i%map_width() > (map_width()-40)) && (i%map_width() < (map_width()-20))) {
+            if((i/map_height() > (map_height()-40)) && (i/map_width() < (map_height()-20))) {
+                
+            } else {
+                add_plant(i % map_width(), i / map_width());
+            }   
+        } else {
+            add_plant(i % map_width(), i / map_width());   
+        }
+        
         
     }
     pc.printf("plants\r\n");
@@ -239,13 +694,48 @@
     add_wall(map_width()-1,  0,              VERTICAL,   map_height());
     pc.printf("Walls done!\r\n"); 
 
+    add_river_man(1, 3);
+    
+    add_toby(4, 8);
+    add_river_man(map_width()-36,map_height()-44);
 
-    add_wall(map_width()-40, map_height()-40, HORIZONTAL, 20);
+    add_wall(map_width()-40, map_height()-40, HORIZONTAL, 20); //add puzzle room
     add_wall(map_width()-40, map_height()-40, VERTICAL, 20);
     add_wall(map_width()-40, map_height()-20, HORIZONTAL, 20);
     add_wall(map_width()-20, map_height()-40, VERTICAL, 20);
     
-    add_river_man(3, 4);
+    add_wall(map_width()-40, map_height()-37, HORIZONTAL,20); // add floor
+    add_wall(map_width()-40, map_height()-33, HORIZONTAL,20);
+    add_wall(map_width()-40, map_height()-30, HORIZONTAL,20);
+    add_wall(map_width()-40, map_height()-26, HORIZONTAL,20);
+    
+ 
+    add_red_button(map_width()-37, map_height()-38); // first floor button
+    add_green_button(map_width()-31, map_height()-38);
+    add_blue_button(map_width()-23, map_height()-38);
+    
+    add_red_button(map_width()-37, map_height()-34); // second floor button
+    add_green_button(map_width()-31, map_height()-34);
+    add_blue_button(map_width()-23, map_height()-34);
+    
+    add_red_button(map_width()-37, map_height()-31); // third floor button
+    add_green_button(map_width()-31, map_height()-31);
+    add_blue_button(map_width()-23, map_height()-31);
+    
+    add_red_button(map_width()-37, map_height()-27); // fourth floor button
+    add_green_button(map_width()-31, map_height()-27);
+    add_blue_button(map_width()-23, map_height()-27);
+    
+    add_toby_bone(map_width()-23, map_height()-21);
+    add_door_locked(map_width()-35, map_height()-40);
+    add_sign(map_width()-36, map_height()-41);
+    
+    add_wall(0, map_height()-5, HORIZONTAL, 5);
+    add_wall(5, map_height()-5, VERTICAL, 5);
+    
+    add_door_locked(3, map_height()-5);
+    add_chest(2, map_height()-2);
+
     print_map();
 }
 
@@ -267,8 +757,8 @@
     
     // Initialize game state
     set_active_map(0);
-    Player.x = map_width()-43;
-    Player.y = map_height()-43;
+    Player.x = 5;
+    Player.y = 5;
 
     // Initial drawing
     draw_game(true);
@@ -278,7 +768,7 @@
     int action;
     int update;
     // Main game loop
-    while(1)
+    while(!game_over)
     {
         // Timer to measure game update speed
         Timer t; t.start();
@@ -290,6 +780,7 @@
         action = get_action(in);  
         // 3. Update game (update_game)
         update = update_game(action);
+        check_health();
         // 3b. Check for game over
         // 4. Draw frame (draw_game)
         draw_game(update);
@@ -298,12 +789,30 @@
         int dt = t.read_ms();
         if (dt < 100) wait_ms(100 - dt);
     }
+    init_game_over();
 }
 
+void check_health() {
+    if(health == 0) {
+        uLCD.cls();
+        init_main_map();
+        Player.x = 5;
+        Player.y = 5;
+        menu = 0; 
+        health = 3;
+        quest = 0;
+        door = 0;
+        draw_game(true);
+    }
+}
 int go_up(int x, int y) {
     MapItem *item = get_north(x,y);
-    if(item->walkable) {
-        Player.y--;
+    if(item->walkable || omni_pressed) {
+        if(run) {
+            Player.y -= 2;   
+        } else {
+            Player.y--;
+        }
         return 1;   
     }  else {
         return 0;   
@@ -312,8 +821,12 @@
 
 int go_down(int x, int y) {
     MapItem *item = get_south(x,y);
-    if(item->walkable) {
-        Player.y++;
+    if(item->walkable || omni_pressed) {
+        if(run) {
+            Player.y += 2;   
+        } else {
+            Player.y++;
+        }
         return 1;   
     } else {
         return 0;   
@@ -322,8 +835,12 @@
 
 int go_left(int x, int y) {
     MapItem *item = get_west(x,y);
-    if(item->walkable) {
-        Player.x--;
+    if(item->walkable || omni_pressed) {
+        if(run==1) {
+            Player.x -= 2;   
+        } else {
+            Player.x--;
+        }
         return 1;   
     } else {
         return 0;   
@@ -332,8 +849,12 @@
 
 int go_right(int x, int y) {
     MapItem *item = get_east(x,y);
-    if(item->walkable) {
-        Player.x++;
+    if(item->walkable || omni_pressed) {
+        if(run == 1) {
+            Player.x += 2;   
+        } else {
+            Player.x++;
+        }
         return 1;   
     } else {
         return 0;   
--- a/map.cpp	Thu Apr 11 18:13:32 2019 +0000
+++ b/map.cpp	Sat Apr 13 21:11:27 2019 +0000
@@ -131,7 +131,7 @@
 void map_erase(int x, int y)
 {
     Map *map = get_active_map();
-    int key = XY_KEY(x, y-1);
+    int key = XY_KEY(x, y);
     deleteItem(map->items, key);
 }
 
@@ -155,8 +155,8 @@
 void add_plant(int x, int y)
 {
     MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
-    w1->type = PLANT;
-    w1->draw = draw_plant;
+    w1->type = FLOWWINK;
+    w1->draw = draw_flowey_wink;
     w1->walkable = false;
     w1->data = NULL;
 
@@ -177,6 +177,17 @@
 
 void add_door_locked(int x, int y) {
     MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
+    w1->type = DOORLOCKED;
+    w1->draw = draw_door_locked;
+    w1->walkable = false;
+    w1->data = NULL;
+
+    void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
+    if (val) free(val);    
+}
+
+void add_door_unlocked(int x, int y) {
+    MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
     w1->type = DOORUNLOCKED;
     w1->draw = draw_door_unlocked;
     w1->walkable = false;
@@ -186,6 +197,7 @@
     if (val) free(val);    
 }
 
+
 void add_flowey_friendly(int x, int y) {
     MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
     w1->type = FLOWFRIEND;
@@ -284,4 +296,35 @@
     void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
     if (val) free(val);    
 }
+
+void add_chest(int x, int y) {
+    MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
+    w1->type = CHEST;
+    w1->draw = draw_chest;
+    w1->walkable = false;
+    w1->data = NULL;
+
+    void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
+    if (val) free(val);     
+}
+void add_leaf(int x, int y) {
+     MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
+    w1->type = LEAF;
+    w1->draw = draw_leaf;
+    w1->walkable = true;
+    w1->data = NULL;
+
+    void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
+    if (val) free(val);    
+}
+void add_wood(int x, int y) {
+     MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
+    w1->type = WOOD;
+    w1->draw = draw_wood;
+    w1->walkable = false;
+    w1->data = NULL;
+
+    void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
+    if (val) free(val);    
+}
 // add toby, tobybone, riverman, doorlocked, doorunlocked, 
\ No newline at end of file
--- a/map.h	Thu Apr 11 18:13:32 2019 +0000
+++ b/map.h	Sat Apr 13 21:11:27 2019 +0000
@@ -67,6 +67,9 @@
 #define BLUEBUTTON 11
 #define GREENBUTTON 12
 #define RIVERMAN 13
+#define CHEST 14
+#define LEAF  15
+#define WOOD 16
 /**
  * Initializes the internal structures for all maps. This does not populate
  * the map with items, but allocates space for them, initializes the hash tables, 
@@ -173,6 +176,7 @@
 void add_blue_button(int x, int y);
 void add_green_button(int x, int y);
 void add_river_man(int x, int y);
-
-
+void add_chest(int x, int v);
+void add_leaf(int x, int y);
+void add_wood(int x, int y);
 #endif //MAP_H
\ No newline at end of file
--- a/mbed.bld	Thu Apr 11 18:13:32 2019 +0000
+++ b/mbed.bld	Sat Apr 13 21:11:27 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/f37f3b9c9f0b
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
--- a/wave_player.lib	Thu Apr 11 18:13:32 2019 +0000
+++ b/wave_player.lib	Sat Apr 13 21:11:27 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/sravet/code/wave_player/#acc3e18e77ad
+http://mbed.org/users/sravet/code/wave_player/#0c466f3ca46a