Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
pausemenu.cpp
00001 // Project includes 00002 #include "globals.h" 00003 #include "hardware.h" 00004 #include "map.h" 00005 #include "graphics.h" 00006 #include "speech.h" 00007 #include "pausemenu.h" 00008 00009 int PauseMenu::switch_ax = 0; 00010 00011 PauseMenu::PauseMenu(Player* player) : 00012 p(player), 00013 quest_complete(player->quest_complete) 00014 { 00015 00016 //draw pink rectangle on whole screen 00017 uLCD.filled_rectangle(0, 128, 128, 70, PINK1); 00018 00019 // write title 00020 uLCD.locate(1,11); 00021 uLCD.textbackground_color(YELLOW); 00022 uLCD.color(BLACK); 00023 uLCD.printf("Game Paused"); 00024 00025 } 00026 00027 int PauseMenu::update(int action){ 00028 switch(action) 00029 { 00030 case 1: 00031 //if button 1 pressed move to next menu item 00032 button_presses = button_presses++; 00033 break; 00034 case 2: 00035 if (button_presses%4 == 0) {//Start game 00036 o_status(); 00037 } else if (button_presses%4 == 1){ //Quit (screen cut to black) 00038 o_inventory(); 00039 }else if (button_presses%4 == 2){ //Quit (screen cut to black) 00040 set_config(o_config()); 00041 } else { //screen go white 00042 exit_en = true; 00043 terminate = true; 00044 } 00045 break; 00046 } 00047 return 0; 00048 } 00049 00050 void PauseMenu::draw(int){ 00051 if (button_presses%4 == 0){ 00052 status_color = GREEN; 00053 } else if (button_presses%4 == 1){ 00054 inventory_color = GREEN; 00055 }else if (button_presses%4 == 2){ 00056 config_color = GREEN; 00057 } else{ 00058 exit_color = GREEN; 00059 } 00060 00061 uLCD.locate(1,11); 00062 uLCD.textbackground_color(YELLOW); 00063 uLCD.color(BLACK); 00064 uLCD.printf("Game Paused"); 00065 00066 uLCD.locate(1,12); 00067 uLCD.color(status_color); 00068 uLCD.printf("View Status"); 00069 00070 uLCD.locate(1,13); 00071 uLCD.color(inventory_color); 00072 uLCD.printf("Inventory"); 00073 00074 uLCD.locate(1,14); 00075 uLCD.color(config_color); 00076 uLCD.printf("Config"); 00077 00078 uLCD.locate(1,15); 00079 uLCD.color(exit_color); 00080 uLCD.printf("Exit"); 00081 00082 00083 status_color = BLACK; 00084 inventory_color = BLACK; 00085 config_color = BLACK; 00086 exit_color = BLACK; 00087 } 00088 00089 int PauseMenu::o_status(){ 00090 uLCD.filled_rectangle(0, 128, 128, 80, PINK1); 00091 uLCD.locate(1,12); 00092 uLCD.textbackground_color(YELLOW); 00093 uLCD.color(BLACK); 00094 00095 if (quest_complete){ 00096 uLCD.printf("Congrats! You have completed your quest!"); 00097 } else{ 00098 uLCD.printf("Quest is not completed"); 00099 } 00100 00101 uLCD.locate(10,15); 00102 uLCD.color(GREEN); 00103 uLCD.printf("Back"); 00104 00105 GameInputs inp = read_inputs(); 00106 while(1){ 00107 if(!inp.b3){ 00108 uLCD.filled_rectangle(0, 128, 128, 80, PINK1); //erase option 00109 wait(1); 00110 return 0; 00111 } 00112 inp = read_inputs(); 00113 wait(1); 00114 } 00115 } 00116 int PauseMenu::o_inventory(){ 00117 uLCD.filled_rectangle(0, 128, 128, 80, PINK1); 00118 uLCD.locate(1,12); 00119 uLCD.textbackground_color(YELLOW); 00120 uLCD.color(BLACK); 00121 00122 char str[30]; 00123 sprintf(str, "You have %d gems.", p->gems); 00124 uLCD.printf(str); 00125 00126 uLCD.locate(10,15); 00127 uLCD.color(GREEN); 00128 uLCD.printf("Back"); 00129 00130 GameInputs inp = read_inputs(); 00131 while(1){ 00132 if(!inp.b3){ 00133 uLCD.filled_rectangle(0, 128, 128, 80, PINK1); //erase option 00134 wait(1); 00135 return 0; 00136 } 00137 inp = read_inputs(); 00138 wait(1); 00139 } 00140 } 00141 int PauseMenu::o_config(){ 00142 uLCD.filled_rectangle(0, 128, 128, 80, PINK1); 00143 uLCD.locate(1,12); 00144 uLCD.textbackground_color(YELLOW); 00145 uLCD.color(BLACK); 00146 00147 uLCD.printf("Press Button 2 to Switch Axis."); 00148 00149 uLCD.locate(10,15); 00150 uLCD.color(GREEN); 00151 uLCD.printf("Back"); 00152 00153 int switch1; 00154 GameInputs inp = read_inputs(); 00155 while(1){ 00156 if(!inp.b2){ 00157 uLCD.filled_rectangle(0, 128, 128, 80, PINK1); 00158 uLCD.locate(1,12); 00159 uLCD.printf("Axis switched."); 00160 uLCD.color(BLACK); 00161 uLCD.locate(10,15); 00162 uLCD.color(GREEN); 00163 uLCD.printf("Back"); 00164 int switch1 = !switch_ax; 00165 } 00166 00167 if(!inp.b3){ 00168 uLCD.filled_rectangle(0, 128, 128, 80, PINK1); //erase option 00169 wait(1); 00170 return switch1; 00171 } 00172 inp = read_inputs(); 00173 wait(1); 00174 } 00175 }
Generated on Fri Jul 15 2022 03:29:10 by
