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
Diff: ingamemenu.cpp
- Revision:
- 5:93a4c396c1af
- Parent:
- 4:cdc54191ff07
diff -r cdc54191ff07 -r 93a4c396c1af ingamemenu.cpp
--- 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);
- }
-}