![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Adventure game written for ECE2035 at the Georgia Institute of Technology
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Diff: startmenu.cpp
- Revision:
- 4:cdc54191ff07
- Parent:
- 2:0876296d9473
- Child:
- 5:93a4c396c1af
--- a/startmenu.cpp Wed Apr 18 20:18:51 2018 +0000 +++ b/startmenu.cpp Tue May 22 19:13:03 2018 +0000 @@ -1,35 +1,12 @@ -// Project includes #include "globals.h" #include "hardware.h" #include "map.h" #include "graphics.h" #include "speech.h" - -// Functions in this file -int get_menu_action (GameInputs inputs); -int update_menu (int action); -void draw_menu (int init); -void init_start_menu (); -int menu (); +#include "startmenu.h" +#include <vector> -int b2presses = 0; -int start; -int quit; -int start_color; -int quit_color; -int third_color; -int current_item = 0; - -/** - * The main game state. Must include Player locations and previous locations for - * drawing to work properly. Other items can be added as needed. - */ - - -/** - * Given the game inputs, determine what kind of update needs to happen. - * Possbile return values are defined below. - */ +//note when you define stuff up here like this the methods of the class cant see it I think #define NO_ACTION 0 #define BUTTON1 1 #define BUTTON2 2 @@ -39,121 +16,23 @@ #define GO_RIGHT 6 #define GO_UP 7 #define GO_DOWN 8 -int get_menu_action(GameInputs inputs) -{ - if(!inputs.b1){ - return BUTTON1; - } - if(!inputs.b2){ - return BUTTON2; - } - if (!inputs.b3){ - return BUTTON3; - } - if ((inputs.ay > 0.05 && inputs.ay < 0.5) && abs(inputs.ax) < .5){ - return GO_LEFT; - } else if ((inputs.ay < -0.05 && inputs.ay > -0.5) && abs(inputs.ax) < .5){ - return GO_RIGHT; - }else if (inputs.ax > 0.05 && inputs.ax < 0.5){ - return GO_DOWN; - }else if (inputs.ax < -0.05 && inputs.ax > -0.5){ - return GO_UP; - } - return NO_ACTION; -} +#define NO_RESULT 9 +#define GAME_OVER 10 +#define FULL_DRAW 11 -/** - * Update the game state based on the user action. For example, if the user - * requests GO_UP, then this function should determine if that is possible by - * consulting the map, and update the Player position accordingly. - * - * Return values are defined below. FULL_DRAW indicates that for this frame, - * draw_game should not optimize drawing and should draw every tile, even if - * the player has not moved. - */ -#define NO_RESULT 0 -#define GAME_OVER 1 -#define FULL_DRAW 2 -int update_menu(int action) -{ +/*This initializes the menu. i.e. this is the first drawing on the screen.*/ +Menu::Menu(int num_options){ - // Do different things based on the each action. - // You can define functions like "go_up()" that get called for each case. - switch(action) //have a function called for each type of object. Pass a pointer to the object to the interact function - { - case BUTTON1: - //if button 1 pressed move to next menu item - current_item = current_item++; - break; - case BUTTON2: - //if button 2 pressed select menu item - //b2presses++; - if (current_item%3 == 0) {//Start game - start = true; - } else if (current_item%3 == 1){ //Quit (screen cut to black) - quit = true; - } else { //screen go white - - } - break; - case MENU_BUTTON: - break; - default: 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_menu(int init) -{ - - - if (current_item%3 == 0){ - start_color = GREEN; - } else if (current_item%3 == 1){ - quit_color = GREEN; - } else{ - third_color = GREEN; - } - - - - uLCD.locate(1,4); - uLCD.color(start_color); - uLCD.printf("Start"); - - uLCD.locate(1,6); - uLCD.color(quit_color); - uLCD.printf("Quit"); - - uLCD.locate(1,8); - uLCD.color(third_color); - uLCD.printf("Thrid Option"); - - start_color = BLACK; - quit_color = BLACK; - third_color = 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_start_menu() -{ + this->num_options = num_options; + this->start = 0; + this->quit = 0; uLCD.locate(1,2); //draw pink rectangle on whole screen uLCD.filled_rectangle(0, 127, 127, 0, PINK1); // write title uLCD.textbackground_color(YELLOW); uLCD.color(BLACK); - uLCD.printf("The Game"); + uLCD.printf("Issa Quest"); if (current_item%3 == 0){ start_color = GREEN; @@ -165,39 +44,114 @@ uLCD.locate(1,4); uLCD.color(start_color); - uLCD.printf("Start"); + uLCD.printf("Start da game"); uLCD.locate(1,6); uLCD.color(quit_color); - uLCD.printf("Quit"); + uLCD.printf("Quit?"); uLCD.locate(1,8); uLCD.color(third_color); - uLCD.printf("Thrid Option"); + uLCD.printf("Instructions"); +} + +//Option Definition// +int Menu::o_instructions(){ + uLCD.filled_rectangle(0, 128, 128, 80, PINK1); + uLCD.locate(1,4); + uLCD.textbackground_color(YELLOW); + uLCD.color(BLACK); + uLCD.printf("Go into the house and talk to the red man to start your quest. Be careful not to step on the spikes."); + + uLCD.locate(10,15); + uLCD.color(GREEN); + uLCD.printf("Back"); - - + GameInputs inp = read_inputs(); + while(1){ + if(!inp.b2){ + uLCD.filled_rectangle(0, 128, 128, 30, PINK1); //erase option + wait(1); + return 0; + } + inp = read_inputs(); + wait(1); + } +} + +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; } -/** - * 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 menu() -{ - // First things first: initialize hardware +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; +} + +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!"); - - // Initialize the maps - init_start_menu(); - - // Initial drawing - draw_menu(true); - - // Main game loop + // Menu loop while(1) { // Timer to measure game update speed @@ -207,22 +161,27 @@ // 1. Read inputs GameInputs in = read_inputs(); // 2. Determine action (get_action) - int a = get_menu_action(in); + int a = this->get_action(in); + char act[5]; + sprintf(act, "%d", a); + uLCD.printf(act); // 3. Update game (update_game) - int u = update_menu(a); + int u = this->update(a); // 4. Draw frame (draw_game) - draw_menu(u); + 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); } } + +