![](/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:
- 32:58def659f463
- Parent:
- 31:0d2c19a285f6
- Child:
- 33:f7ec806e14b6
diff -r 0d2c19a285f6 -r 58def659f463 main.cpp --- a/main.cpp Wed May 08 03:03:46 2019 +0000 +++ b/main.cpp Wed May 08 15:14:55 2019 +0000 @@ -23,15 +23,15 @@ /////////////// objects /////////////// N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // K64F - pwr from 3V3 -Gamepad pad; -Score music; -Start start; -Game_one game_1; -Game_two game_2; -Game_three game_3; -Exam test; -Grad grad; -Thread thread; +Gamepad pad; // Gamepad class +Score music; // Score class for music files +Start start; // Start class for choosing starter +Game_one game_1; // Game_one class for mini game 1 +Game_two game_2; // Game_two class for mini game 2 +Game_three game_3; // Game_three class for mini game 3 +Exam test; // Exam class for exam questions +Grad grad; // Grad class for graduation credit scene +Thread thread; // Thread class for running functions in parallel // I2C connection for FXOS8700CQ accelerometer/magnetometer FXOS8700CQ device(I2C_SDA,I2C_SCL); // PTE25/PTE24 @@ -71,20 +71,31 @@ }; //Global variables -int score = 0; -int game_1_speed = 0; -int game_1_cha = 0; -int game_1_r = 1; -int game_2_speed = 0; -int game_2_cha = 0; -int game_2_r = 1; -int game_3_set = 1; -float game_3_time = 1.0; -int select = 0; -int year = 0; -int pass = 0; -volatile bool finished = false; -volatile bool end = false; +int score = 0; // Score to take note of number of missions passed +int game_1_speed = 0; // Setting the speed for the objects in Game 1 +int game_1_cha = 0; // Setting which evolution to draw in Game 1 +int game_1_r = 1; // Setting the ratio between coins and blocks in Game 1 +int game_2_speed = 0; // Setting the speed for the objects in Game 2 +int game_2_cha = 0; // Setting which evolution to draw in Game 2 +int game_2_r = 1; // Setting the ratio between YouTube and other social medias in Game 2 +int game_3_set = 1; // Setting the number of messages vs books in Game 3 +float game_3_time = 1.0; // Setting the reaction time for Game 3 +int select = 0; // Setting the starter selection parameter +int year = 0; // Setting the year that it is currently in +int pass = 0; // Setting the pass parameters for exam +volatile bool finished = false; // Setting the music loop for Exam +volatile bool end = false; // Setting the game loop +int button_A[9][8] = { + {0,0,1,1,1,1,0,0}, + {0,1,0,0,0,0,1,0}, + {1,0,1,1,1,1,0,1}, + {1,0,1,0,0,1,0,1}, + {1,0,1,1,1,1,0,1}, + {1,0,1,0,0,1,0,1}, + {1,1,0,0,0,0,1,1}, + {0,1,1,1,1,1,1,0}, + {0,0,1,1,1,1,0,0}, +}; // Sprite for button_A ///////////// functions //////////////// int main(){ @@ -153,10 +164,11 @@ if(select == 1){ music.congrats(pad, lcd, select, year); // Display congratulation screen for choosing the starter pokemon while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("A",0,5); // Instruct to press A to continue + lcd.drawSprite(2,39,9,8,(int*)button_A); // Instruct to press A to continue lcd.refresh(); wait(0.3); lcd.printString(" ",0,5); + lcd.printString(" ",4,5); lcd.refresh(); wait(0.3); } @@ -167,10 +179,11 @@ else if(select == 0){ music.congrats(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("A",0,5); + lcd.drawSprite(2,39,9,8,(int*)button_A); lcd.refresh(); wait(0.3); lcd.printString(" ",0,5); + lcd.printString(" ",4,5); lcd.refresh(); wait(0.3); } @@ -181,10 +194,11 @@ else if(select == 2){ music.congrats(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("A",0,5); + lcd.drawSprite(2,39,9,8,(int*)button_A); lcd.refresh(); wait(0.3); lcd.printString(" ",0,5); + lcd.printString(" ",4,5); lcd.refresh(); wait(0.3); } @@ -333,7 +347,7 @@ thread.join(); // End the thread - // Check for number of correct answerws to determine if proceed to next year or not + // Check for number of correct answers to determine if proceed to next year or not if(pass > 2){ passed(); music.win(pad); @@ -373,7 +387,7 @@ if(select == 1){ 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("A",0,5); + lcd.drawSprite(0,40,8,8,(int*)button_A); lcd.refresh(); wait(0.3); lcd.printString(" ",0,5); @@ -385,7 +399,7 @@ else if(select == 0){ 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("A",0,5); + lcd.drawSprite(0,40,8,8,(int*)button_A); lcd.refresh(); wait(0.3); lcd.printString(" ",0,5); @@ -397,7 +411,7 @@ else if(select == 2){ 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("A",0,5); + lcd.drawSprite(0,40,8,8,(int*)button_A); lcd.refresh(); wait(0.3); lcd.printString(" ",0,5); @@ -418,10 +432,11 @@ if(select == 1){ music.evolution_music(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("A",0,5); + lcd.drawSprite(2,39,9,8,(int*)button_A); lcd.refresh(); wait(0.3); lcd.printString(" ",0,5); + lcd.printString(" ",4,5); lcd.refresh(); wait(0.3); } @@ -430,10 +445,11 @@ else if(select == 0){ music.evolution_music(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("A",0,5); + lcd.drawSprite(2,39,9,8,(int*)button_A); lcd.refresh(); wait(0.3); lcd.printString(" ",0,5); + lcd.printString(" ",4,5); lcd.refresh(); wait(0.3); } @@ -442,10 +458,11 @@ else if(select == 2){ music.evolution_music(pad, lcd, select, year); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("A",0,5); + lcd.drawSprite(2,39,9,8,(int*)button_A); lcd.refresh(); wait(0.3); lcd.printString(" ",0,5); + lcd.printString(" ",4,5); lcd.refresh(); wait(0.3); } @@ -459,10 +476,11 @@ grad.Grad_title(pad, lcd, select); wait(1.0); while(pad.check_event(Gamepad::A_PRESSED) == false){ - lcd.printString("PRESS A",0,5); + lcd.drawSprite(2,39,9,8,(int*)button_A); lcd.refresh(); wait(0.3); - lcd.printString(" ",0,5); + lcd.printString(" ",0,5); + lcd.printString(" ",4,5); lcd.refresh(); wait(0.3); } @@ -496,7 +514,7 @@ lcd.setContrast(0.4); } -// simple splash screen displayed on start-up +// Simple splash screen displayed on start-up void welcome() { lcd.clear(); @@ -537,7 +555,7 @@ {0,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,0,1,1,1,1,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, }; - + // Title "Pokemon ACADEMY" lcd.drawSprite(10, 3, 35, 65, (int*)title_data); int start_data[5][41] = { @@ -547,25 +565,25 @@ {1,0,0,0,1,1,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,1,0,1,0,1,1,0,0,0,1,0}, {1,0,0,0,1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,1,1,1,0,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0}, }; - + // Instruct to press start lcd.drawSprite(22, 41, 5, 41, (int*)start_data); lcd.refresh(); music.title_music(pad); } -// function for displaying the menu screen +// Function for displaying the menu screen int menu() { // clear screen, re-draw and refresh lcd.clear(); - int pos_y = 5; + int pos_y = 5; // Set position for menu pointer while(pad.check_event(Gamepad::A_PRESSED) == false){ lcd.clear(); if(pad.get_direction() == N){ - pos_y = 5; + pos_y = 5; // Set position for menu pointer to top option }else if(pad.get_direction() == S){ - pos_y = 16; + pos_y = 16; // Set position for menu pointer to bottom option } int arrow_data[7][5] = { {1,1,0,0,0}, @@ -628,7 +646,7 @@ } -// function for drawing year one title screen +// Function for drawing year one title screen void year_one() { lcd.clear(); @@ -664,15 +682,16 @@ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, }; + // Draw year 1 title lcd.drawSprite(4, 9, 30, 78,(int *) instruct_data); lcd.refresh(); - music.level_up(pad); + music.level_up(pad); // Play level up tone from music file wait(1.0); } -// function for setting year one game parameters +// Function for setting year one game parameters void year_one_set() { year = 0; @@ -686,7 +705,7 @@ game_3_time = 0.5; } -// function for drawing year two title screen +// Function for drawing year two title screen void year_two() { lcd.clear(); @@ -722,15 +741,16 @@ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, }; + // Draw year 2 title lcd.drawSprite(4, 9, 30, 78, (int *)year_two_data); lcd.refresh(); - music.level_up(pad); + music.level_up(pad); // Play level up tone from music file wait(1.0); } -// function for setting year two game parameters +// Function for setting year two game parameters void year_two_set() { year = 1; @@ -744,7 +764,7 @@ game_3_time = 0.4; } -// function for drawing year three title screen +// Function for drawing year three title screen void year_three() { lcd.clear(); @@ -780,15 +800,16 @@ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, }; + // Draw year 3 title lcd.drawSprite(4, 9, 30, 78,(int*) year_three_data); lcd.refresh(); - music.level_up(pad); + music.level_up(pad); // Play level up tone from music file wait(1.0); } -// function for setting year three game parameters +// Function for setting year three game parameters void year_three_set() { year = 2; @@ -802,7 +823,7 @@ game_3_time = 0.3; } -// function for displaying the game information +// Function for displaying the game information void instruction() { Page currentPage = PAGE_1; @@ -825,7 +846,7 @@ lcd.printString("life of three",0,4); lcd.drawSprite(39, 44, 4, 7, instruct_data); lcd.refresh(); - if(pad.get_direction() == S){currentPage = PAGE_2;} + if(pad.get_direction() == S){currentPage = PAGE_2;} // Move to next page in joystick moved down wait(1.0f/fps); break; case PAGE_2: @@ -837,7 +858,7 @@ lcd.printString("brings forth.",0,4); lcd.drawSprite(39, 44, 4, 7, instruct_data); lcd.refresh(); - if(pad.get_direction() == S){currentPage = PAGE_3;} + if(pad.get_direction() == S){currentPage = PAGE_3;} // Move to next page in joystick moved down wait(1.0f/fps); break; case PAGE_3: @@ -847,7 +868,7 @@ lcd.printString("frustration,",0,2); lcd.printString("anger and ",0,3); lcd.printString("despair! ",0,4); - lcd.printString("Press BACK",12,5); + lcd.printString("Press BACK",12,5); // Instruct the user to press BACK_button to return to MENU lcd.refresh(); wait(1.0f/fps); break; @@ -855,7 +876,7 @@ } } -// function for drawing term one title screen +// Function for drawing term one title screen void term_one() { lcd.clear(); @@ -900,7 +921,7 @@ wait(1.0); } -// function for drawing term two title screen +// Function for drawing term two title screen void term_two() { lcd.clear(); @@ -945,7 +966,7 @@ wait(1.0); } -// function for drawing term three title screen +// Function for drawing term three title screen void term_three() { lcd.clear(); @@ -990,7 +1011,7 @@ wait(1.0); } -// function for drawing mission success screen +// Function for drawing mission success screen void win() { int instruct_data[22][63] = { @@ -1022,7 +1043,7 @@ lcd.refresh(); } -// function for drawing mission failure screen +// Function for drawing mission failure screen void lose() { int instruct_data[22][58] = { @@ -1054,7 +1075,7 @@ lcd.refresh(); } -// function for drawing you passed screen +// Function for drawing you passed screen void passed() { int instruct_data[10][83] = { @@ -1074,7 +1095,7 @@ lcd.refresh(); } -// function for drawing you failed screen +// Function for drawing you failed screen void failed() { int instruct_data[10][77] = { @@ -1094,44 +1115,14 @@ lcd.refresh(); } -// INTENSE music played in background during exams +// INTENSE music played in background during exams, music originally from Pokemon (R/B/Y) during GYM leader battle 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); - pad.tone(NOTE_B3,0.33/2); - wait(0.33/2); - pad.tone(NOTE_FS4,0.33/2); - wait(0.33/2); - pad.tone(NOTE_B3,0.33/2); - wait(0.33/2); - pad.tone(NOTE_FS4,0.33/2); - wait(0.33/2); - pad.tone(NOTE_B3,0.33/2); - wait(0.33/2); - pad.tone(NOTE_FS4,0.33/2); - wait(0.33/2); - pad.tone(NOTE_B4,0.33/2); - wait(0.33/2); - pad.tone(NOTE_FS4,0.33/2); - wait(0.33/2); - pad.tone(NOTE_B3,0.33/2); - wait(0.33/2); - pad.tone(NOTE_FS4,0.33/2); - wait(0.33/2); - pad.tone(NOTE_B3,0.33/2); - wait(0.33/2); - pad.tone(NOTE_C5,0.33*1.5); - wait(0.33*1.5); - // bar 3 - pad.tone(NOTE_B4,0.33/2); Thread::wait(330/2); - if (finished == true) {return;} pad.tone(NOTE_FS4,0.33/2); wait(0.33/2); pad.tone(NOTE_B3,0.33/2); @@ -1147,7 +1138,8 @@ pad.tone(NOTE_FS4,0.33/2); wait(0.33/2); pad.tone(NOTE_B4,0.33/2); - wait(0.33/2); + if (finished == true) {return;} + Thread::wait(330/2); pad.tone(NOTE_FS4,0.33/2); wait(0.33/2); pad.tone(NOTE_B3,0.33/2); @@ -1156,12 +1148,12 @@ wait(0.33/2); pad.tone(NOTE_B3,0.33/2); wait(0.33/2); - pad.tone(NOTE_AS4,0.33*1.5); + pad.tone(NOTE_C5,0.33*1.5); wait(0.33*1.5); - // bar 5 + // bar 3 pad.tone(NOTE_B4,0.33/2); + if (finished == true) {return;} Thread::wait(330/2); - if (finished == true) {return;} pad.tone(NOTE_FS4,0.33/2); wait(0.33/2); pad.tone(NOTE_B3,0.33/2); @@ -1175,6 +1167,39 @@ pad.tone(NOTE_B3,0.33/2); wait(0.33/2); pad.tone(NOTE_FS4,0.33/2); + if (finished == true) {return;} + Thread::wait(330/2); + pad.tone(NOTE_B4,0.33/2); + wait(0.33/2); + pad.tone(NOTE_FS4,0.33/2); + wait(0.33/2); + pad.tone(NOTE_B3,0.33/2); + wait(0.33/2); + pad.tone(NOTE_FS4,0.33/2); + wait(0.33/2); + pad.tone(NOTE_B3,0.33/2); + if (finished == true) {return;} + Thread::wait(330/2); + pad.tone(NOTE_AS4,0.33*1.5); + wait(0.33*1.5); + // bar 5 + pad.tone(NOTE_B4,0.33/2); + if (finished == true) {return;} + Thread::wait(330/2); + pad.tone(NOTE_FS4,0.33/2); + wait(0.33/2); + pad.tone(NOTE_B3,0.33/2); + wait(0.33/2); + pad.tone(NOTE_FS4,0.33/2); + wait(0.33/2); + pad.tone(NOTE_B3,0.33/2); + wait(0.33/2); + pad.tone(NOTE_FS4,0.33/2); + wait(0.33/2); + pad.tone(NOTE_B3,0.33/2); + if (finished == true) {return;} + Thread::wait(330/2); + pad.tone(NOTE_FS4,0.33/2); wait(0.33/2); pad.tone(NOTE_B4,0.33/2); wait(0.33/2); @@ -1185,13 +1210,14 @@ pad.tone(NOTE_FS4,0.33/2); wait(0.33/2); pad.tone(NOTE_B3,0.33/2); - wait(0.33/2); + if (finished == true) {return;} + Thread::wait(330/2); pad.tone(NOTE_C5,0.33*1.5); wait(0.33*1.5); // bar 7 pad.tone(NOTE_B4,0.33/2); + if (finished == true) {return;} Thread::wait(330/2); - if (finished == true) {return;} pad.tone(NOTE_FS4,0.33/2); wait(0.33/2); pad.tone(NOTE_B3,0.33/2); @@ -1201,7 +1227,8 @@ pad.tone(NOTE_B3,0.33/2); wait(0.33/2); pad.tone(NOTE_FS4,0.33/2); - wait(0.33/2); + if (finished == true) {return;} + Thread::wait(330/2); pad.tone(NOTE_B3,0.33/2); wait(0.33/2); pad.tone(NOTE_FS4,0.33/2); @@ -1215,8 +1242,8 @@ pad.tone(NOTE_FS4,0.33/2); wait(0.33/2); pad.tone(NOTE_B3,0.33/2); + if (finished == true) {return;} Thread::wait(330/2); - if (finished == true) {return;} pad.tone(NOTE_CS5,0.33*1.5); wait(0.33*1.5);