Adventure game written for ECE2035 at the Georgia Institute of Technology
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Revision 5:93a4c396c1af, committed 2019-10-26
- Comitter:
- trmontgomery
- Date:
- Sat Oct 26 15:44:26 2019 +0000
- Parent:
- 4:cdc54191ff07
- Commit message:
- test
Changed in this revision
--- a/ingamemenu.cpp Tue May 22 19:13:03 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,303 +0,0 @@
-// Project includes
-#include "globals.h"
-#include "hardware.h"
-#include "map.h"
-#include "graphics.h"
-#include "speech.h"
-
-// Functions in this file
-int get_ingamemenu_action (GameInputs inputs);
-int update_ingamemenu (int action);
-void draw_ingamemenu (int init);
-void init_ingame_menu ();
-int ingamemenu (int quest);
-void status();
-
-//global variables
-int view_status;
-int inventory;
-int view_status_color;
-int inventory_color;
-int config_color;
-int quit_color1;
-int current_item1 = 0;
-int quit1 = 0;
-int quest_complete;
-static int switch_ax = 0;
-Player* p;
-
-int status(int quest_complete){
- uLCD.filled_rectangle(0, 128, 128, 80, PINK1);
- uLCD.locate(1,12);
- uLCD.textbackground_color(YELLOW);
- uLCD.color(BLACK);
-
- if (quest_complete){
- uLCD.printf("Congrats! You have completed your quest!");
- } else{
- uLCD.printf("Quest is not completed");
- }
-
- uLCD.locate(10,15);
- uLCD.color(GREEN);
- uLCD.printf("Back");
-
- GameInputs inp = read_inputs();
- while(1){
- if(!inp.b3){
- uLCD.filled_rectangle(0, 128, 128, 80, PINK1); //erase option
- wait(1);
- return 0;
- }
- inp = read_inputs();
- wait(1);
- }
-}
-
-
-int invent(int gems){
- uLCD.filled_rectangle(0, 128, 128, 80, PINK1);
- uLCD.locate(1,12);
- uLCD.textbackground_color(YELLOW);
- uLCD.color(BLACK);
-
- char str[30];
- sprintf(str, "You have %d gems.", gems);
- uLCD.printf(str);
-
- uLCD.locate(10,15);
- uLCD.color(GREEN);
- uLCD.printf("Back");
-
- GameInputs inp = read_inputs();
- while(1){
- if(!inp.b3){
- uLCD.filled_rectangle(0, 128, 128, 80, PINK1); //erase option
- wait(1);
- return 0;
- }
- inp = read_inputs();
- wait(1);
- }
-}
-
-int config(){
- uLCD.filled_rectangle(0, 128, 128, 80, PINK1);
- uLCD.locate(1,12);
- uLCD.textbackground_color(YELLOW);
- uLCD.color(BLACK);
-
- uLCD.printf("Press Button 2 to Switch Axis.");
-
- uLCD.locate(10,15);
- uLCD.color(GREEN);
- uLCD.printf("Back");
-
- int switch1;
- GameInputs inp = read_inputs();
- while(1){
- if(!inp.b2){
- uLCD.filled_rectangle(0, 128, 128, 80, PINK1);
- uLCD.locate(1,12);
- uLCD.printf("Axis switched.");
- uLCD.color(BLACK);
- uLCD.locate(10,15);
- uLCD.color(GREEN);
- uLCD.printf("Back");
- int switch1 = !switch_ax;
- }
- if(!inp.b3){
- uLCD.filled_rectangle(0, 128, 128, 80, PINK1); //erase option
- wait(1);
- return switch1;
- }
- inp = read_inputs();
- wait(1);
- }
-}
-
-
-/**
- * Given the game inputs, determine what kind of update needs to happen.
- * Possbile return values are defined below.
- */
-#define NO_ACTION 0
-#define CHANGE_OPTION 1
-#define SELECT 2
-
-int get_ingamemenu_action(GameInputs inputs)
-{
- if (!inputs.b2){
- return CHANGE_OPTION;
- } if (!inputs.b3){
- return SELECT;
- }
- return NO_ACTION;
-}
-
-
-#define NO_RESULT 0
-#define FULL_DRAW 2
-int update_ingamemenu(int action)
-{
- switch(action)
- {
- case CHANGE_OPTION:
- //if button 1 pressed move to next menu item
- current_item1 = current_item1++;
- break;
- case SELECT:
- if (current_item1%4 == 0) {//Start game
- view_status = true;
- status(quest_complete);
- } else if (current_item1%4 == 1){ //Quit (screen cut to black)
- inventory = true;
- invent(p->gems);
- }else if (current_item1%4 == 2){ //Quit (screen cut to black)
- //inventory = true;
- switch_ax = config();
- } else { //screen go white
- quit1 = true;
- }
- break;
- }
- return NO_RESULT;
-}
-
-/**
- * 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
- * bars. Unless init is nonzero, this function will optimize drawing by only
- * drawing tiles that have changed from the previous frame.
- */
-void draw_ingamemenu(int init)
-{
-
- if (current_item1%4 == 0){
- view_status_color = GREEN;
- } else if (current_item1%4 == 1){
- inventory_color = GREEN;
- }else if (current_item1%4 == 2){
- config_color = GREEN;
- } else{
- quit_color1 = GREEN;
- }
-
- uLCD.locate(1,11);
- uLCD.textbackground_color(YELLOW);
- uLCD.color(BLACK);
- uLCD.printf("Game Paused");
-
- uLCD.locate(1,12);
- uLCD.color(view_status_color);
- uLCD.printf("View Status");
-
- uLCD.locate(1,13);
- uLCD.color(inventory_color);
- uLCD.printf("Inventory");
-
- uLCD.locate(1,14);
- uLCD.color(config_color);
- uLCD.printf("Config");
-
- uLCD.locate(1,15);
- uLCD.color(quit_color1);
- uLCD.printf("Exit");
-
-
- view_status_color = BLACK;
- inventory_color = BLACK;
- config_color = BLACK;
- quit_color1 = BLACK;
-
-}
-
-/**
- * Initialize the main world map. Add walls around the edges, interior chambers,
- * and plants in the background so you can see motion.
- */
-void init_ingame_menu()
-{
- uLCD.locate(1,11);
- //draw pink rectangle on whole screen
- uLCD.filled_rectangle(0, 128, 128, 70, PINK1);
- // write title
- uLCD.textbackground_color(YELLOW);
- uLCD.color(BLACK);
- uLCD.printf("Game Paused");
-
- if (current_item1%4 == 0){
- view_status_color = GREEN;
- } else if (current_item1%4 == 1){
- inventory_color = GREEN;
- } else if (current_item1%4 == 2){
- config_color = GREEN;
- } else{
- quit_color1 = GREEN;
- }
-
- uLCD.locate(1,12);
- uLCD.color(view_status_color);
- uLCD.printf("View Status");
-
- uLCD.locate(1,13);
- uLCD.color(inventory_color);
- uLCD.printf("Inventory");
-
- uLCD.locate(1,14);
- uLCD.color(inventory_color);
- uLCD.printf("Config");
-
- uLCD.locate(1,15);
- uLCD.color(quit_color1);
- uLCD.printf("Exit");
-
-}
-
-/**
- * Program entry point! This is where it all begins.
- * This function orchestrates all the parts of the game. Most of your
- * implementation should be elsewhere - this holds the game loop, and should
- * read like a road map for the rest of the code.
- */
-int ingamemenu(Player* player)
-{
- p = player;
- quest_complete = p->quest_complete;
- // Initialize the maps
- init_ingame_menu();
-
- // Initial drawing
- draw_ingamemenu(true);
-
- // Main game loop
- while(1)
- {
- // Timer to measure game update speed
- Timer t; t.start();
-
- // Actually do the game update:
- // 1. Read inputs
- GameInputs in = read_inputs();
- // 2. Determine action (get_action)
- int a = get_ingamemenu_action(in);
- // 3. Update game (update_game)
- int u = update_ingamemenu(a);
- // 4. Draw frame (draw_game)
- draw_ingamemenu(u);
-
- //check for start
- if (quit1){
- //erase menu
- uLCD.filled_rectangle(0, 128, 128, 80, 0x000000);
- current_item1 = 0;
- quit1 = false;
- return switch_ax;
- }
-
- // 5. Frame delay
- t.stop();
- int dt = t.read_ms();
- if (dt < 500) wait_ms(500 - dt);
- }
-}
--- a/ingamemenu.h Tue May 22 19:13:03 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#ifndef INGAMEMENU_H -#define INGAMEMENU_H - -int ingamemenu(Player* player); - -#endif \ No newline at end of file
--- a/main.cpp Tue May 22 19:13:03 2018 +0000
+++ b/main.cpp Sat Oct 26 15:44:26 2019 +0000
@@ -5,7 +5,7 @@
#include "graphics.h"
#include "speech.h"
#include "startmenu.h"
-#include "ingamemenu.h"
+#include "pausemenu.h"
#include "gameover.h"
// Functions in this file
@@ -309,7 +309,10 @@
}
break;
case MENU_BUTTON:
- switch_axis = ingamemenu(&p1);
+ PauseMenu pause_m(&p1);
+ pause_m.display();
+ switch_axis = pause_m.get_config();
+ //switch_axis = ingamemenu(&p1);
break;
default: break;
@@ -500,8 +503,9 @@
*/
int main()
{
- Menu start_m = Menu(3);
- int start = start_m.display();
+
+ StartMenu start_m = StartMenu();
+ int st = start_m.display();
// First things first: initialize hardware
ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pausemenu.cpp Sat Oct 26 15:44:26 2019 +0000
@@ -0,0 +1,175 @@
+// Project includes
+#include "globals.h"
+#include "hardware.h"
+#include "map.h"
+#include "graphics.h"
+#include "speech.h"
+#include "pausemenu.h"
+
+int PauseMenu::switch_ax = 0;
+
+PauseMenu::PauseMenu(Player* player) :
+ p(player),
+ quest_complete(player->quest_complete)
+{
+
+ //draw pink rectangle on whole screen
+ uLCD.filled_rectangle(0, 128, 128, 70, PINK1);
+
+ // write title
+ uLCD.locate(1,11);
+ uLCD.textbackground_color(YELLOW);
+ uLCD.color(BLACK);
+ uLCD.printf("Game Paused");
+
+}
+
+int PauseMenu::update(int action){
+ switch(action)
+ {
+ case 1:
+ //if button 1 pressed move to next menu item
+ button_presses = button_presses++;
+ break;
+ case 2:
+ if (button_presses%4 == 0) {//Start game
+ o_status();
+ } else if (button_presses%4 == 1){ //Quit (screen cut to black)
+ o_inventory();
+ }else if (button_presses%4 == 2){ //Quit (screen cut to black)
+ set_config(o_config());
+ } else { //screen go white
+ exit_en = true;
+ terminate = true;
+ }
+ break;
+ }
+ return 0;
+ }
+
+void PauseMenu::draw(int){
+ if (button_presses%4 == 0){
+ status_color = GREEN;
+ } else if (button_presses%4 == 1){
+ inventory_color = GREEN;
+ }else if (button_presses%4 == 2){
+ config_color = GREEN;
+ } else{
+ exit_color = GREEN;
+ }
+
+ uLCD.locate(1,11);
+ uLCD.textbackground_color(YELLOW);
+ uLCD.color(BLACK);
+ uLCD.printf("Game Paused");
+
+ uLCD.locate(1,12);
+ uLCD.color(status_color);
+ uLCD.printf("View Status");
+
+ uLCD.locate(1,13);
+ uLCD.color(inventory_color);
+ uLCD.printf("Inventory");
+
+ uLCD.locate(1,14);
+ uLCD.color(config_color);
+ uLCD.printf("Config");
+
+ uLCD.locate(1,15);
+ uLCD.color(exit_color);
+ uLCD.printf("Exit");
+
+
+ status_color = BLACK;
+ inventory_color = BLACK;
+ config_color = BLACK;
+ exit_color = BLACK;
+ }
+
+int PauseMenu::o_status(){
+ uLCD.filled_rectangle(0, 128, 128, 80, PINK1);
+ uLCD.locate(1,12);
+ uLCD.textbackground_color(YELLOW);
+ uLCD.color(BLACK);
+
+ if (quest_complete){
+ uLCD.printf("Congrats! You have completed your quest!");
+ } else{
+ uLCD.printf("Quest is not completed");
+ }
+
+ uLCD.locate(10,15);
+ uLCD.color(GREEN);
+ uLCD.printf("Back");
+
+ GameInputs inp = read_inputs();
+ while(1){
+ if(!inp.b3){
+ uLCD.filled_rectangle(0, 128, 128, 80, PINK1); //erase option
+ wait(1);
+ return 0;
+ }
+ inp = read_inputs();
+ wait(1);
+ }
+ }
+int PauseMenu::o_inventory(){
+ uLCD.filled_rectangle(0, 128, 128, 80, PINK1);
+ uLCD.locate(1,12);
+ uLCD.textbackground_color(YELLOW);
+ uLCD.color(BLACK);
+
+ char str[30];
+ sprintf(str, "You have %d gems.", p->gems);
+ uLCD.printf(str);
+
+ uLCD.locate(10,15);
+ uLCD.color(GREEN);
+ uLCD.printf("Back");
+
+ GameInputs inp = read_inputs();
+ while(1){
+ if(!inp.b3){
+ uLCD.filled_rectangle(0, 128, 128, 80, PINK1); //erase option
+ wait(1);
+ return 0;
+ }
+ inp = read_inputs();
+ wait(1);
+ }
+}
+int PauseMenu::o_config(){
+ uLCD.filled_rectangle(0, 128, 128, 80, PINK1);
+ uLCD.locate(1,12);
+ uLCD.textbackground_color(YELLOW);
+ uLCD.color(BLACK);
+
+ uLCD.printf("Press Button 2 to Switch Axis.");
+
+ uLCD.locate(10,15);
+ uLCD.color(GREEN);
+ uLCD.printf("Back");
+
+ int switch1;
+ GameInputs inp = read_inputs();
+ while(1){
+ if(!inp.b2){
+ uLCD.filled_rectangle(0, 128, 128, 80, PINK1);
+ uLCD.locate(1,12);
+ uLCD.printf("Axis switched.");
+ uLCD.color(BLACK);
+ uLCD.locate(10,15);
+ uLCD.color(GREEN);
+ uLCD.printf("Back");
+ int switch1 = !switch_ax;
+ }
+
+ if(!inp.b3){
+ uLCD.filled_rectangle(0, 128, 128, 80, PINK1); //erase option
+ wait(1);
+ return switch1;
+ }
+ inp = read_inputs();
+ wait(1);
+ }
+ }
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pausemenu.h Sat Oct 26 15:44:26 2019 +0000
@@ -0,0 +1,27 @@
+#ifndef INGAMEMENU_H
+#define INGAMEMENU_H
+
+#include "startmenu.h"
+class PauseMenu : public Menu{
+ private:
+ int status_color;
+ int inventory_color;
+ int config_color;
+ int exit_color;
+ int exit_en;
+ int quest_complete;
+ static int switch_ax;
+ Player* p;
+
+ public:
+ void draw(int);
+ int update(int);
+ PauseMenu(Player* player);
+ int o_status();
+ int o_inventory();
+ int o_config();
+ static int get_config(){return switch_ax;}
+ static void set_config(int s){switch_ax = s;}
+};
+
+#endif
\ No newline at end of file
--- a/startmenu.cpp Tue May 22 19:13:03 2018 +0000
+++ b/startmenu.cpp Sat Oct 26 15:44:26 2019 +0000
@@ -20,28 +20,102 @@
#define GAME_OVER 10
#define FULL_DRAW 11
-/*This initializes the menu. i.e. this is the first drawing on the screen.*/
-Menu::Menu(int num_options){
-
- this->num_options = num_options;
- this->start = 0;
- this->quit = 0;
- uLCD.locate(1,2);
+
+int Menu::get_action(GameInputs inputs){
+ if(!inputs.b1){
+ return 1;
+ }
+ if(!inputs.b2){
+ return 2;
+ }
+ if (!inputs.b3){
+ return BUTTON3;
+ }
+ return NO_ACTION;
+}
+
+
+int Menu::display(){
+ ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!");
+ // Menu loop
+ while(1)
+ {
+ // Timer to measure game update speed
+ Timer t; t.start();
+
+ // Actually do the game update:
+ // 1. Read inputs
+ GameInputs in = read_inputs();
+ // 2. Determine action (get_action)
+ int a = this->get_action(in);
+ // 3. Update game (update_game)
+ int u = this->update(a);
+
+ // 4. Draw frame (draw_game)
+ this->draw(u);
+
+ //check for start
+ if (terminate){
+ uLCD.filled_rectangle(0, 127, 127, 0, 0x000000);
+ return terminate;
+ }
+
+ // 5. Frame delay
+ t.stop();
+ int dt = t.read_ms();
+ if (dt < 500) wait_ms(500 - dt);
+ }
+}
+
+StartMenu::StartMenu() : start(0), quit(0), start_color(BLACK), quit_color(BLACK), third_color(BLACK){
+
//draw pink rectangle on whole screen
uLCD.filled_rectangle(0, 127, 127, 0, PINK1);
+
// write title
+ uLCD.locate(1,2);
uLCD.textbackground_color(YELLOW);
uLCD.color(BLACK);
uLCD.printf("Issa Quest");
- if (current_item%3 == 0){
+}
+
+
+int StartMenu::update(int action){ //this might need to rewritten
+
+ switch(action)
+ {
+ case 1:
+ //if button 1 pressed move to next menu item
+ button_presses = button_presses++;
+ break;
+ case 2:
+ //if button 2 pressed select menu item
+ if (button_presses > 0 && button_presses%3 == 0) { //Start game
+ start = true;
+ terminate = true;
+ } else if (button_presses%3 == 1){ //Quit (screen cut to black)
+ quit = true;
+ } else {
+ o_instructions();
+ }
+ break;
+ }
+ return NO_RESULT;
+}
+
+void StartMenu::draw(int init){
+
+ //if statement selects which option will be highlighted
+ if (button_presses%3 == 0){
start_color = GREEN;
- } else if (current_item%3 == 1){
+ } else if (button_presses%3 == 1){
quit_color = GREEN;
} else{
third_color = GREEN;
}
+ //draws the options on the screen
uLCD.locate(1,4);
uLCD.color(start_color);
uLCD.printf("Start da game");
@@ -53,10 +127,15 @@
uLCD.locate(1,8);
uLCD.color(third_color);
uLCD.printf("Instructions");
+
+ start_color = BLACK;
+ quit_color = BLACK;
+ third_color = BLACK;
}
+
//Option Definition//
-int Menu::o_instructions(){
+int StartMenu::o_instructions(){
uLCD.filled_rectangle(0, 128, 128, 80, PINK1);
uLCD.locate(1,4);
uLCD.textbackground_color(YELLOW);
@@ -80,108 +159,8 @@
}
}
-int Menu::get_action(GameInputs inputs){
- if(!inputs.b1){
- uLCD.locate(1,2);
- char but[5];
- sprintf(but, "%d: %d\n", !inputs.b1, inputs.b1);
- uLCD.printf(but);
- return 1;
- }
- if(!inputs.b2){
- return 2;
- }
- if (!inputs.b3){
- return BUTTON3;
- }
- return NO_ACTION;
-}
-
-int Menu::update(int action){ //this might need to rewritten
-
- switch(action)
- {
- case 1:
- //if button 1 pressed move to next menu item
- current_item = current_item++;
- break;
- case 2:
- //if button 2 pressed select menu item
- //b2presses++;
- if (current_item > 0 && current_item%this->num_options == 0) {//Start game
- start = true;
- } else if (current_item%this->num_options == 1){ //Quit (screen cut to black)
- quit = true;
- } else { //screen go white
- o_instructions();
- }
- break;
- case MENU_BUTTON:
- break;
- default: break;
- }
- return NO_RESULT;
+int StartMenu::display(){
+ int result = Menu::display();
+ return result;
}
-void Menu::draw(int init){
- if (current_item%this->num_options == 0){
- start_color = GREEN;
- } else if (current_item%this->num_options == 1){
- quit_color = GREEN;
- } else{
- third_color = GREEN;
- }
-
- uLCD.locate(1,4);
- uLCD.color(start_color);
- uLCD.printf("Start da game");
-
- uLCD.locate(1,6);
- uLCD.color(quit_color);
- uLCD.printf("Quit?");
-
- uLCD.locate(1,8);
- uLCD.color(third_color);
- uLCD.printf("Instructions");
-
- start_color = BLACK;
- quit_color = BLACK;
- third_color = BLACK;
-}
-
-int Menu::display(){
- ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!");
- // Menu loop
- while(1)
- {
- // Timer to measure game update speed
- Timer t; t.start();
-
- // Actually do the game update:
- // 1. Read inputs
- GameInputs in = read_inputs();
- // 2. Determine action (get_action)
- int a = this->get_action(in);
- char act[5];
- sprintf(act, "%d", a);
- uLCD.printf(act);
- // 3. Update game (update_game)
- int u = this->update(a);
-
- // 4. Draw frame (draw_game)
- this->draw(u);
-
- //check for start
- if (start){
- uLCD.filled_rectangle(0, 127, 127, 0, 0x000000);
- return start;
- }
-
- // 5. Frame delay
- t.stop();
- int dt = t.read_ms();
- if (dt < 500) wait_ms(500 - dt);
- }
-}
-
-
--- a/startmenu.h Tue May 22 19:13:03 2018 +0000
+++ b/startmenu.h Sat Oct 26 15:44:26 2019 +0000
@@ -3,28 +3,32 @@
class Menu
{
-private:
+
+public:
int button_presses;
- int num_options;
- //std::vector <int> option_colors;
- //std::vector <int> option_enable;
- int b2presses;
+ int terminate;
+ Menu() : terminate(0), button_presses(0){}
+ int get_action(GameInputs);
+ virtual int update(int) = 0;
+ virtual void draw(int) = 0;
+ int display();
+
+};
+
+
+class StartMenu : public Menu{
+private:
int start;
int quit;
int start_color;
int quit_color;
int third_color;
- int current_item;
-
-public:
- Menu(int);
- int get_action(GameInputs);
+public:
+ StartMenu();
+ int o_instructions();
int update(int);
void draw(int);
int display();
- int o_instructions();
- //you can just implement the options in the new classes
- //void add_option(char[], Func*); //second argument needs to be a function pointer
};
#endif //STARTMENU_H
\ No newline at end of file