![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Game codes for Pokemon Academy Yiu Fai Kwok - 201198802 I have read the University Regulations on Plagiarism and state that the work covered by this declaration is my own and does not contain any unacknowledged work from other sources.
Dependencies: mbed FXOS8700CQ mbed-rtos
Diff: main.cpp
- Revision:
- 31:0d2c19a285f6
- Parent:
- 29:75a05e9f0e8d
- Child:
- 32:58def659f463
--- a/main.cpp Mon May 06 20:37:23 2019 +0000 +++ b/main.cpp Wed May 08 03:03:46 2019 +0000 @@ -17,6 +17,7 @@ #include "Game_two.h" #include "Game_three.h" #include "Exam.h" +#include "Grad.h" #include "FXOS8700CQ.h" #include "rtos.h" @@ -29,6 +30,7 @@ Game_two game_2; Game_three game_3; Exam test; +Grad grad; Thread thread; // I2C connection for FXOS8700CQ accelerometer/magnetometer FXOS8700CQ device(I2C_SDA,I2C_SCL); // PTE25/PTE24 @@ -82,6 +84,7 @@ int year = 0; int pass = 0; volatile bool finished = false; +volatile bool end = false; ///////////// functions //////////////// int main(){ @@ -89,7 +92,7 @@ // Initialise parameters int fps = 8; // frames per second - init(); // initialise and then display welcome screen... + init(); // initialise StartStates currentState = TITLE; GameStates currentGame = YEAR_1; @@ -101,7 +104,9 @@ welcome(); wait(1.0f/fps); - currentState = MENU; + currentState = MENU; // Set currentState to MENU to start up the MENU page + currentGame = YEAR_1; // Set currentGame to YEAR_1 so the game starts from the beginning and resets all difficulty parameters + end = false; // Reset end parameter to start the Game loop break; case MENU: @@ -112,15 +117,15 @@ int op = menu(); if (op == 1){currentState = INSTRUCTION;} else { - while(1){ + while(!end){ // Game loop switch (currentGame) { case YEAR_1: // 1. Initiate year 1 screen // 2. Set up the parameters for year 1 - year_one(); - year_one_set(); + year_one(); // Display year title screen + year_one_set(); // Set the difficulties for mini games currentGame = STARTER; break; @@ -129,62 +134,62 @@ // 2. Provide description for the mini game and pokemon // 3. Initiate the mini game according to the pokemon being selected - select = 0; - start.init(pad); - start.starter_draw(lcd); + select = 0; // Reset starter selection parameter to 0 position + start.init(pad); // Initialize the Start class + start.starter_draw(lcd); // Draw the start pokemon selection page wait(1.0f/fps); while(pad.check_event(Gamepad::START_PRESSED) == false) { start.starter_update(pad); start.starter_draw(lcd); if(pad.check_event(Gamepad::A_PRESSED) == true){ - select = start.get_select(start.update_select(pad)); - start.intro(select, pad, lcd); + select = start.get_select(start.update_select(pad)); // Set select parameter to determine which starter pokemon is chosen + start.intro(select, pad, lcd); // Display the description for the pokemon being selected pad.init_input(); } wait(1.0f/fps); } select = start.get_select(start.update_select(pad)); if(select == 1){ - music.congrats(pad, lcd, select, year); + music.congrats(pad, lcd, select, year); // Display congratulation screen for choosing the starter pokemon while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.printString("A",0,5); // Instruct to press A to continue lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); lcd.refresh(); wait(0.3); } - game_1.intro(pad, lcd); - currentGame = SQUIRTLE; + game_1.intro(pad, lcd); // Display Game one description page to introduce the player how the game is played + currentGame = SQUIRTLE; // Move to Squirtle's game loop pad.init_input(); } else if(select == 0){ music.congrats(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.printString("A",0,5); lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); lcd.refresh(); wait(0.3); } - game_3.intro(pad, lcd); - currentGame = BULBASAUR; + game_3.intro(pad, lcd); // Display Game three description page to introduce the player how the game is played + currentGame = BULBASAUR; // Move to Bulbasaur's game loop pad.init_input(); } else if(select == 2){ music.congrats(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.printString("A",0,5); lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); lcd.refresh(); wait(0.3); } - game_2.intro(pad, lcd); - currentGame = CHARMANDER; + game_2.intro(pad, lcd); // Display Game two description page to introduce the player how the game is played + currentGame = CHARMANDER; // Move to Charmander's game loop pad.init_input(); } break; @@ -202,14 +207,12 @@ game_3.init_para(); while(j < 5){ // Game loop for 5 rounds - // Set the ratio between messages vs books - game_3.init(pad, game_3_set); + game_3.init(pad, game_3_set); // Set the ratio between messages vs books according to year game_3.render(lcd, game_3_set); - // Parameter to set the reaction time frame for varying difficulty - wait(game_3_time); + wait(game_3_time); // Parameter to set the reaction time frame for varying difficulty game_3.read_input(pad); game_3.update(pad, game_3_set); - j = game_3.get_count(); + j = game_3.get_count(); // Get count for how many rounds the player has played } i = i++; // determine if win condition is met, return score to proceed to EXAM game loop @@ -239,7 +242,7 @@ if(i == 0) {term_one();} else if(i == 1) {term_two();} else{term_three();} - game_1.init(game_1_speed, game_1_cha, game_1_r); + game_1.init(game_1_speed, game_1_cha, game_1_r); // Set the game difficulty by changing speed of objects and coin to block ratio according to year int j = 0; while(j < 10){ // Game loop for 10 rounds @@ -247,7 +250,7 @@ game_1.update(pad, lcd); game_1.render(lcd, game_1_cha); wait(1.0f/fps); - j = game_1.get_count(); + j = game_1.get_count(); // Get count for how many rounds the player has played } i = i++; // determine if win condition is met, return score to proceed to EXAM game loop @@ -278,7 +281,7 @@ if(i == 0) {term_one();} else if(i == 1) {term_two();} else{term_three();} - game_2.init(game_2_speed, game_2_cha, game_2_r); + game_2.init(game_2_speed, game_2_cha, game_2_r); // Set the game difficulty by changing speed and ratio between YouTube and normal icons according to year int j = 0; while(j < 6){ game_2.read_input(device); @@ -366,42 +369,42 @@ // 4. Enter to game loop for chosen character year_two(); - year_two_set(); + year_two_set(); // Set up the parameters for year 2 if(select == 1){ - music.evolution_music(pad, lcd, select, year); + music.evolution_music(pad, lcd, select, year); // Play the evolution animation and music for the chosen pokemon while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.printString("A",0,5); lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); lcd.refresh(); wait(0.3); } - currentGame = SQUIRTLE; + currentGame = SQUIRTLE; // Go back to game loop } else if(select == 0){ - music.evolution_music(pad, lcd, select, year); + music.evolution_music(pad, lcd, select, year); // Play the evolution animation and music for the chosen pokemon while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.printString("A",0,5); lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); lcd.refresh(); wait(0.3); } - currentGame = BULBASAUR; + currentGame = BULBASAUR; // Go back to game loop } else if(select == 2){ - music.evolution_music(pad, lcd, select, year); + music.evolution_music(pad, lcd, select, year); // Play the evolution animation and music for the chosen pokemon while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.printString("A",0,5); lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); lcd.refresh(); wait(0.3); } - currentGame = CHARMANDER; + currentGame = CHARMANDER; // Go back to game loop } break; case YEAR_3: @@ -415,10 +418,10 @@ if(select == 1){ music.evolution_music(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.printString("A",0,5); lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); lcd.refresh(); wait(0.3); } @@ -427,10 +430,10 @@ else if(select == 0){ music.evolution_music(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.printString("A",0,5); lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); lcd.refresh(); wait(0.3); } @@ -439,10 +442,10 @@ else if(select == 2){ music.evolution_music(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.printString("A",0,5); lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); lcd.refresh(); wait(0.3); } @@ -451,16 +454,24 @@ break; case GRADUATION: // 1. Display congratulation theme for player! - // 2. Return to the title screen + // 2. Return to the TITLE screen - lcd.clear(); - lcd.printString("GRADUATION!",0,0); - lcd.refresh(); - wait(2.0); + grad.Grad_title(pad, lcd, select); + wait(1.0); + while(pad.check_event(Gamepad::A_PRESSED) == false){ + lcd.printString("PRESS A",0,5); + lcd.refresh(); + wait(0.3); + lcd.printString(" ",0,5); + lcd.refresh(); + wait(0.3); + } + end = true; break; } } } + currentState = TITLE; break; case INSTRUCTION: @@ -664,6 +675,7 @@ // function for setting year one game parameters void year_one_set() { + year = 0; game_1_speed = 12; game_1_cha = 1; game_1_r = 5; @@ -721,6 +733,7 @@ // function for setting year two game parameters void year_two_set() { + year = 1; game_1_speed = 14; game_1_cha = 2; game_1_r = 3; @@ -778,6 +791,7 @@ // function for setting year three game parameters void year_three_set() { + year = 2; game_1_speed = 14; game_1_cha = 3; game_1_r = 2;