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:
- 26:c60becf3f840
- Parent:
- 23:4a070960817a
- Child:
- 27:4bcdfb212467
diff -r 31111e6e13ad -r c60becf3f840 main.cpp --- a/main.cpp Mon Apr 29 20:59:49 2019 +0000 +++ b/main.cpp Tue Apr 30 09:40:35 2019 +0000 @@ -92,17 +92,19 @@ while(1){ switch (currentState) { case TITLE: - //1. Display title screen and play title music - //2. Proceed to Start screen by pressing start + // 1. Display title screen and play title music + // 2. Proceed to Start screen by pressing start + welcome(); wait(1.0f/fps); currentState = MENU; break; case MENU: - //1. Display starting menu - //2. If Start is selected, initiate year 1 game state - //3. If Instruction is selected, give instruction + // 1. Display starting menu + // 2. If Start is selected, initiate year 1 game state + // 3. If Instruction is selected, give instruction + int op = menu(); if (op == 1){currentState = INSTRUCTION;} else { @@ -112,6 +114,7 @@ case YEAR_1: // 1. Initiate year 1 screen // 2. Set up the parameters for year 1 + year_one(); year_one_set(); currentGame = STARTER; @@ -121,6 +124,7 @@ // 1. Provide selection screen for starter pokemon to select which mini game to initiate // 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); @@ -174,6 +178,7 @@ lcd.refresh(); wait(0.3); } + game_2.intro(pad, lcd); currentGame = CHARMANDER; pad.init_input(); } @@ -229,6 +234,7 @@ i = 0; score = 0; while (i < 3) { + // Indicate for which term the current game is in if(i == 0) {term_one();} else if(i == 1) {term_two();} else{term_three();} @@ -242,6 +248,7 @@ j = game_2.get_count(); } i = i++; + // determine if win condition is met, return score to proceed to EXAM game loop if(game_2.get_count() == 6) { win(); music.win(pad); @@ -261,14 +268,29 @@ // Game loop for EXAM case EXAM: + // 1. Display the exam questions according to year. + // 2. Display the answers according to how many mini games the player passed. + // 3. If player manages to answer 2 or 3 questions correctly, enter to next year/GRADUATION. + // 4. If player fails, repeat the year. + + // Reset background music control parameter finished = false; + + // Draw exam title screen test.exam_title(pad, lcd); + + // Using thread to run music and exam functions in parallel thread.start(gym); + + // Check for which year's exam questions need to be fetched if(year == 0) {pass = test.exam_q_one(pad, lcd, score); finished = true;} else if(year == 1) {pass = test.exam_q_two(pad, lcd, score); finished = true;} else if(year == 2) {pass = test.exam_q_three(pad, lcd, score); finished = true;} Thread::wait(1000); thread.join(); + // End the thread + + // Check for number of correct answerws to determine if proceed to next year or not if(pass >= 2){ passed(); music.win(pad); @@ -298,6 +320,11 @@ } break; case YEAR_2: + // 1. Initiate year 2 screen + // 2. Set up the parameters for year 2 + // 3. Initiate evolution animation for chosen character + // 4. Enter to game loop for chosen character + year_two(); year_two_set(); if(select == 1){ @@ -338,6 +365,11 @@ } break; case YEAR_3: + // 1. Initiate year 3 screen + // 2. Set up the parameters for year 3 + // 3. Initiate evolution animation for chosen character + // 4. Enter to game loop for chosen character + year_three(); year_three_set(); if(select == 1){ @@ -378,6 +410,9 @@ } break; case GRADUATION: + // 1. Display congratulation theme for player! + // 2. Return to the title screen + lcd.clear(); lcd.printString("GRADUATION!",0,0); lcd.refresh(); @@ -389,6 +424,9 @@ break; case INSTRUCTION: + // 1. Display instruction + // 2. Return to MENU screen + instruction(); currentState = MENU; break; @@ -465,11 +503,11 @@ } +// function for displaying the menu screen int menu() { // clear screen, re-draw and refresh lcd.clear(); - pad.init(); int pos_y = 5; while(pad.check_event(Gamepad::A_PRESSED) == false){ lcd.clear(); @@ -487,6 +525,7 @@ {0,1,1,0,0}, {1,1,0,0,0}, }; + // draw pointer for selection lcd.drawSprite(5, pos_y, 7, 5, (int *)arrow_data); int op_one_data[7][26] = { @@ -498,6 +537,7 @@ {0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0}, {1,1,1,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0}, }; + // draw "START" lcd.drawSprite(18, 5, 7, 26, (int *)op_one_data); int op_two_data[7][18] = { @@ -509,6 +549,7 @@ {0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0,1}, {1,1,1,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1}, }; + // draw "INFO" lcd.drawSprite(18, 16, 7, 18, (int*) op_two_data); int instruct_data[7][75] = { @@ -520,6 +561,7 @@ {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,1,0,1,0,0,1}, {1,0,0,0,0,1,0,0,0,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,1,1,1,1,0,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1}, }; + // draw instruction lcd.drawSprite(5, 38, 7, 75,(int *) instruct_data); lcd.refresh(); @@ -535,6 +577,7 @@ } +// function for drawing year one title screen void year_one() { lcd.clear(); @@ -578,6 +621,7 @@ wait(1.0); } +// function for setting year one game parameters void year_one_set() { game_1_speed = 7; @@ -588,6 +632,7 @@ game_2_r = 6; } +// function for drawing year two title screen void year_two() { lcd.clear(); @@ -631,6 +676,7 @@ wait(1.0); } +// function for setting year two game parameters void year_two_set() { game_1_speed = 12; @@ -641,6 +687,7 @@ game_2_r = 5; } +// function for drawing year three title screen void year_three() { lcd.clear(); @@ -684,6 +731,7 @@ wait(1.0); } +// function for setting year three game parameters void year_three_set() { game_1_speed = 14; @@ -694,6 +742,7 @@ game_2_r = 3; } +// function for displaying the game information void instruction() { Page currentPage = PAGE_1; @@ -746,6 +795,7 @@ } } +// function for drawing term one title screen void term_one() { lcd.clear(); @@ -790,6 +840,7 @@ wait(1.0); } +// function for drawing term two title screen void term_two() { lcd.clear(); @@ -834,6 +885,7 @@ wait(1.0); } +// function for drawing term three title screen void term_three() { lcd.clear(); @@ -878,6 +930,7 @@ wait(1.0); } +// function for drawing mission success screen void win() { int instruct_data[22][63] = { @@ -909,6 +962,7 @@ lcd.refresh(); } +// function for drawing mission failure screen void lose() { int instruct_data[22][58] = { @@ -940,6 +994,7 @@ lcd.refresh(); } +// function for drawing you passed screen void passed() { int instruct_data[10][83] = { @@ -959,6 +1014,7 @@ lcd.refresh(); } +// function for drawing you failed screen void failed() { int instruct_data[10][77] = { @@ -978,11 +1034,13 @@ lcd.refresh(); } +// INTENSE music played in background during exams void gym() { // bar 1 pad.tone(NOTE_B4,0.33/2); Thread::wait(330/2); + // to break out of the function if (finished == true) {return;} pad.tone(NOTE_FS4,0.33/2); wait(0.33/2); @@ -1113,6 +1171,7 @@ wait(0.33); pad.tone(NOTE_E5,0.33/2); Thread::wait(330/2); + // to break out of the function if(finished == true) {break;} pad.tone(NOTE_FS5,0.33); wait(0.33);