Rex Raj / Mbed 2 deprecated el17rrrs

Dependencies:   mbed Gamepad N5110 mbed-rtos

Committer:
RexRoshan
Date:
Thu May 09 09:54:50 2019 +0000
Revision:
7:574c66ebd8b0
Parent:
6:1fcfd331c047
Child:
11:c3817962923d
Documentation has been completed and the code has been slightly modified

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RexRoshan 6:1fcfd331c047 1 /*
RexRoshan 6:1fcfd331c047 2 ELEC2645 Embedded Systems Project
RexRoshan 6:1fcfd331c047 3 School of Electronic & Electrical Engineering
RexRoshan 6:1fcfd331c047 4 University of Leeds
RexRoshan 6:1fcfd331c047 5 Name: Rex Roshan Raj
RexRoshan 6:1fcfd331c047 6 Username: el17rrs
RexRoshan 6:1fcfd331c047 7 Student ID Number: 201184290
RexRoshan 6:1fcfd331c047 8 Start Date: 25/03/2019
RexRoshan 7:574c66ebd8b0 9 End Date: 9/05/2019
RexRoshan 6:1fcfd331c047 10 */
RexRoshan 6:1fcfd331c047 11
RexRoshan 0:99fa5a619081 12 #include "mbed.h"
RexRoshan 0:99fa5a619081 13 #include "N5110.h"
RexRoshan 0:99fa5a619081 14 #include "Gamepad.h"
RexRoshan 0:99fa5a619081 15 #include "Instruction.h"
RexRoshan 0:99fa5a619081 16 #include "Spacecraft.h"
RexRoshan 0:99fa5a619081 17 #include "GameEngine.h"
RexRoshan 7:574c66ebd8b0 18 #include "MiniGame.h"
RexRoshan 0:99fa5a619081 19 #include "Solar.h"
RexRoshan 0:99fa5a619081 20 #include "Music.h"
RexRoshan 6:1fcfd331c047 21 #include "rtos.h"
RexRoshan 0:99fa5a619081 22
RexRoshan 6:1fcfd331c047 23 /** @file main.cpp
RexRoshan 6:1fcfd331c047 24 * @brief Contains the main code of the program.
RexRoshan 6:1fcfd331c047 25 */
RexRoshan 6:1fcfd331c047 26
RexRoshan 6:1fcfd331c047 27 // Structs
RexRoshan 0:99fa5a619081 28 struct UserInput {
RexRoshan 0:99fa5a619081 29 Direction d;
RexRoshan 0:99fa5a619081 30 float mag;
RexRoshan 0:99fa5a619081 31 };
RexRoshan 0:99fa5a619081 32
RexRoshan 7:574c66ebd8b0 33 // enum state for MainPage
RexRoshan 7:574c66ebd8b0 34 enum MainPage { TitleScreen, Menu, Mini_Game, Mission };
RexRoshan 7:574c66ebd8b0 35
RexRoshan 7:574c66ebd8b0 36 // enum state for MiniState
RexRoshan 7:574c66ebd8b0 37 enum MiniState { Dead, Alive };
RexRoshan 7:574c66ebd8b0 38
RexRoshan 4:4d673fb2d9dc 39 // enum state for Mission state
RexRoshan 7:574c66ebd8b0 40 enum MissionState {Mission1,Mission1Pass,Mission1Fail,Mission2,Mission2Pass,Mission2Fail,Mission3,Mission3Pass,Mission3Fail,Congratulations };
RexRoshan 0:99fa5a619081 41
RexRoshan 6:1fcfd331c047 42 // Objects
RexRoshan 0:99fa5a619081 43 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // K64F - pwr from 3V3
RexRoshan 0:99fa5a619081 44 Gamepad pad;
RexRoshan 0:99fa5a619081 45 Music play;
RexRoshan 1:45493d1d0689 46 Instruction instruct;
RexRoshan 0:99fa5a619081 47 Thread thread;
RexRoshan 0:99fa5a619081 48 Spacecraft game;
RexRoshan 0:99fa5a619081 49 GameEngine shoot;
RexRoshan 7:574c66ebd8b0 50 MiniGame mini;
RexRoshan 7:574c66ebd8b0 51
RexRoshan 0:99fa5a619081 52
RexRoshan 6:1fcfd331c047 53 // Prototypes
RexRoshan 0:99fa5a619081 54 void init();
RexRoshan 7:574c66ebd8b0 55 void mini_init();
RexRoshan 0:99fa5a619081 56 void welcome();
RexRoshan 7:574c66ebd8b0 57 void mini_render();
RexRoshan 7:574c66ebd8b0 58 void render_nothing();
RexRoshan 0:99fa5a619081 59 void render();
RexRoshan 0:99fa5a619081 60 void render2();
RexRoshan 1:45493d1d0689 61 void render3();
RexRoshan 7:574c66ebd8b0 62 void mini_rules();
RexRoshan 0:99fa5a619081 63 void intro();
RexRoshan 0:99fa5a619081 64 void instruction();
RexRoshan 7:574c66ebd8b0 65 //void intro_song();
RexRoshan 7:574c66ebd8b0 66
RexRoshan 7:574c66ebd8b0 67 bool end = false;
RexRoshan 7:574c66ebd8b0 68 bool finish = false;
RexRoshan 7:574c66ebd8b0 69 bool music_end = false;
RexRoshan 0:99fa5a619081 70
RexRoshan 0:99fa5a619081 71
RexRoshan 0:99fa5a619081 72 int main()
RexRoshan 0:99fa5a619081 73 {
RexRoshan 7:574c66ebd8b0 74 int fps = 8; // Set the frames per second = 8
RexRoshan 7:574c66ebd8b0 75 lcd.setContrast(0.4); // 0.4 appears to be a good starting point
RexRoshan 7:574c66ebd8b0 76 init(); // Initialise all the parameters in GameEngine
RexRoshan 7:574c66ebd8b0 77
RexRoshan 7:574c66ebd8b0 78 MainPage currentState = TitleScreen; // Initial state of MainPage
RexRoshan 7:574c66ebd8b0 79 MissionState currentMission = Mission3; // Initial state of MissionState
RexRoshan 7:574c66ebd8b0 80 MiniState currentMini = Alive; // Initial state of MiniState
RexRoshan 0:99fa5a619081 81
RexRoshan 1:45493d1d0689 82
RexRoshan 1:45493d1d0689 83 while(1) {
RexRoshan 0:99fa5a619081 84 switch(currentState){
RexRoshan 7:574c66ebd8b0 85 case TitleScreen:
RexRoshan 7:574c66ebd8b0 86 // Draws the Title Screen
RexRoshan 1:45493d1d0689 87 lcd.clear();
RexRoshan 1:45493d1d0689 88 lcd.refresh();
RexRoshan 1:45493d1d0689 89 thread.start(welcome);
RexRoshan 1:45493d1d0689 90 intro();
RexRoshan 7:574c66ebd8b0 91 thread.terminate();
RexRoshan 7:574c66ebd8b0 92 // instruction page for the game
RexRoshan 7:574c66ebd8b0 93 render_nothing();
RexRoshan 1:45493d1d0689 94 wait(1.0f/fps);
RexRoshan 7:574c66ebd8b0 95 currentState = Menu;
RexRoshan 7:574c66ebd8b0 96 break;
RexRoshan 7:574c66ebd8b0 97 case Menu:
RexRoshan 7:574c66ebd8b0 98 // Draws the Menu Page
RexRoshan 7:574c66ebd8b0 99 lcd.clear();
RexRoshan 7:574c66ebd8b0 100 lcd.drawSprite(4,7,9,9, (int*)x_button);
RexRoshan 7:574c66ebd8b0 101 lcd.drawSprite(4,23,9,9, (int*)y_button);
RexRoshan 7:574c66ebd8b0 102 lcd.printString("Mission",20,1);
RexRoshan 7:574c66ebd8b0 103 lcd.printString("Mini Game",20,3);
RexRoshan 7:574c66ebd8b0 104 lcd.refresh();
RexRoshan 7:574c66ebd8b0 105 if (pad.check_event(Gamepad::X_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 106 currentState = Mission;
RexRoshan 7:574c66ebd8b0 107 end = false;
RexRoshan 7:574c66ebd8b0 108 instruction();
RexRoshan 7:574c66ebd8b0 109 } else if (pad.check_event(Gamepad::Y_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 110 currentState = Mini_Game;
RexRoshan 7:574c66ebd8b0 111 finish = false;
RexRoshan 7:574c66ebd8b0 112 mini_rules();
RexRoshan 7:574c66ebd8b0 113 }
RexRoshan 1:45493d1d0689 114 break;
RexRoshan 7:574c66ebd8b0 115
RexRoshan 7:574c66ebd8b0 116 case Mission:
RexRoshan 7:574c66ebd8b0 117 // instruction page for the game
RexRoshan 7:574c66ebd8b0 118 currentMission = Mission3;
RexRoshan 7:574c66ebd8b0 119 while(!end){
RexRoshan 7:574c66ebd8b0 120 switch(currentMission){
RexRoshan 7:574c66ebd8b0 121 case Mission1:
RexRoshan 7:574c66ebd8b0 122 shoot.read_input(pad);
RexRoshan 7:574c66ebd8b0 123 shoot.update_mission_one(pad,lcd);
RexRoshan 7:574c66ebd8b0 124 render();
RexRoshan 7:574c66ebd8b0 125 wait(1.0f/fps);
RexRoshan 7:574c66ebd8b0 126 if(shoot.get_game_stage() == 1){
RexRoshan 7:574c66ebd8b0 127 currentMission = Mission1Fail;
RexRoshan 7:574c66ebd8b0 128 break;
RexRoshan 7:574c66ebd8b0 129 }
RexRoshan 7:574c66ebd8b0 130 else if(shoot.get_game_stage() == 2){
RexRoshan 7:574c66ebd8b0 131 currentMission = Mission1Pass;
RexRoshan 7:574c66ebd8b0 132 break;
RexRoshan 7:574c66ebd8b0 133 }else {
RexRoshan 7:574c66ebd8b0 134 currentMission = Mission1;
RexRoshan 7:574c66ebd8b0 135 }
RexRoshan 7:574c66ebd8b0 136 break;
RexRoshan 7:574c66ebd8b0 137 case Mission1Fail:
RexRoshan 7:574c66ebd8b0 138 lcd.clear();
RexRoshan 7:574c66ebd8b0 139 lcd.drawSprite(6,5,42,73,(int *)mission_fail);
RexRoshan 7:574c66ebd8b0 140 lcd.drawSprite(51,11,7,19,(int *)m_one);
RexRoshan 7:574c66ebd8b0 141 lcd.refresh();
RexRoshan 7:574c66ebd8b0 142 play.mission_fail(pad);
RexRoshan 7:574c66ebd8b0 143 if (pad.check_event(Gamepad::B_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 144 currentMission = Mission1;
RexRoshan 7:574c66ebd8b0 145 shoot.restart_game_stage();
RexRoshan 7:574c66ebd8b0 146 init();
RexRoshan 7:574c66ebd8b0 147 }
RexRoshan 7:574c66ebd8b0 148 break;
RexRoshan 7:574c66ebd8b0 149 case Mission1Pass:
RexRoshan 7:574c66ebd8b0 150 lcd.clear();
RexRoshan 7:574c66ebd8b0 151 lcd.drawSprite(0,0,48,84,(int *)mission_pass);
RexRoshan 7:574c66ebd8b0 152 lcd.drawSprite(51,11,7,19,(int *)m_one);
RexRoshan 7:574c66ebd8b0 153 lcd.refresh();
RexRoshan 7:574c66ebd8b0 154 play.mission_success(pad);
RexRoshan 7:574c66ebd8b0 155 if (pad.check_event(Gamepad::A_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 156 currentMission = Mission2;
RexRoshan 7:574c66ebd8b0 157 shoot.restart_game_stage();
RexRoshan 7:574c66ebd8b0 158 init();
RexRoshan 7:574c66ebd8b0 159 }
RexRoshan 7:574c66ebd8b0 160 break;
RexRoshan 7:574c66ebd8b0 161 case Mission2:
RexRoshan 7:574c66ebd8b0 162 shoot.read_input(pad);
RexRoshan 7:574c66ebd8b0 163 shoot.update_mission_two(pad,lcd);
RexRoshan 7:574c66ebd8b0 164 render2();
RexRoshan 7:574c66ebd8b0 165 wait(1.0f/fps);
RexRoshan 7:574c66ebd8b0 166 if(shoot.get_game_stage() == 3 ){
RexRoshan 7:574c66ebd8b0 167 currentMission = Mission2Fail;
RexRoshan 7:574c66ebd8b0 168 }
RexRoshan 7:574c66ebd8b0 169 if(shoot.get_game_stage() == 4){
RexRoshan 7:574c66ebd8b0 170 currentMission = Mission2Pass;
RexRoshan 7:574c66ebd8b0 171 }
RexRoshan 7:574c66ebd8b0 172 break;
RexRoshan 7:574c66ebd8b0 173 case Mission2Fail:
RexRoshan 7:574c66ebd8b0 174 lcd.clear();
RexRoshan 7:574c66ebd8b0 175 lcd.drawSprite(6,5,42,73,(int *)mission_fail);
RexRoshan 7:574c66ebd8b0 176 lcd.drawSprite(51,12,5,18,(int *)m_two);
RexRoshan 7:574c66ebd8b0 177 lcd.refresh();
RexRoshan 7:574c66ebd8b0 178 play.mission_fail(pad);
RexRoshan 7:574c66ebd8b0 179 if (pad.check_event(Gamepad::B_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 180 currentMission = Mission1;
RexRoshan 7:574c66ebd8b0 181 shoot.restart_game_stage();
RexRoshan 7:574c66ebd8b0 182 init();
RexRoshan 7:574c66ebd8b0 183 }
RexRoshan 7:574c66ebd8b0 184 break;
RexRoshan 7:574c66ebd8b0 185 case Mission2Pass:
RexRoshan 7:574c66ebd8b0 186 lcd.clear();
RexRoshan 7:574c66ebd8b0 187 lcd.drawSprite(0,0,48,84,(int *)mission_pass);
RexRoshan 7:574c66ebd8b0 188 lcd.drawSprite(51,12,5,18,(int *)m_two);
RexRoshan 7:574c66ebd8b0 189 lcd.refresh();
RexRoshan 7:574c66ebd8b0 190 play.mission_success(pad);
RexRoshan 7:574c66ebd8b0 191 if (pad.check_event(Gamepad::A_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 192 currentMission = Mission3;
RexRoshan 7:574c66ebd8b0 193 shoot.restart_game_stage();
RexRoshan 7:574c66ebd8b0 194 init();
RexRoshan 7:574c66ebd8b0 195 }
RexRoshan 7:574c66ebd8b0 196 break;
RexRoshan 7:574c66ebd8b0 197 case Mission3:
RexRoshan 7:574c66ebd8b0 198 shoot.read_input(pad);
RexRoshan 7:574c66ebd8b0 199 shoot.update_mission_three(pad,lcd);
RexRoshan 7:574c66ebd8b0 200 render3();
RexRoshan 7:574c66ebd8b0 201 wait(1.0f/fps);
RexRoshan 7:574c66ebd8b0 202 if(shoot.get_game_stage() == 5 ){
RexRoshan 7:574c66ebd8b0 203 currentMission = Mission3Fail;
RexRoshan 7:574c66ebd8b0 204 }
RexRoshan 7:574c66ebd8b0 205 if(shoot.get_game_stage() == 6){
RexRoshan 7:574c66ebd8b0 206 currentMission = Mission3Pass;
RexRoshan 7:574c66ebd8b0 207 }
RexRoshan 7:574c66ebd8b0 208 break;
RexRoshan 7:574c66ebd8b0 209 case Mission3Fail:
RexRoshan 7:574c66ebd8b0 210 lcd.clear();
RexRoshan 7:574c66ebd8b0 211 lcd.drawSprite(6,5,42,73,(int *)mission_fail);
RexRoshan 7:574c66ebd8b0 212 lcd.drawSprite(48,12,5,29,(int *)m_three);
RexRoshan 7:574c66ebd8b0 213 lcd.refresh();
RexRoshan 7:574c66ebd8b0 214 play.mission_fail(pad);
RexRoshan 7:574c66ebd8b0 215 if (pad.check_event(Gamepad::B_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 216 currentMission = Mission1;
RexRoshan 7:574c66ebd8b0 217 shoot.restart_game_stage();
RexRoshan 7:574c66ebd8b0 218 init();
RexRoshan 7:574c66ebd8b0 219 }
RexRoshan 7:574c66ebd8b0 220 break;
RexRoshan 7:574c66ebd8b0 221 case Mission3Pass:
RexRoshan 7:574c66ebd8b0 222 lcd.clear();
RexRoshan 7:574c66ebd8b0 223 lcd.drawSprite(0,0,48,84,(int *)mission_pass);
RexRoshan 7:574c66ebd8b0 224 lcd.drawSprite(48,12,5,29,(int *)m_three);
RexRoshan 7:574c66ebd8b0 225 lcd.refresh();
RexRoshan 7:574c66ebd8b0 226 play.mission_success(pad);
RexRoshan 7:574c66ebd8b0 227 if (pad.check_event(Gamepad::A_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 228 currentMission = Congratulations;
RexRoshan 7:574c66ebd8b0 229 }
RexRoshan 7:574c66ebd8b0 230 break;
RexRoshan 7:574c66ebd8b0 231 case Congratulations:
RexRoshan 7:574c66ebd8b0 232 for(int i = 0; i < 3; i++){
RexRoshan 7:574c66ebd8b0 233 lcd.clear();
RexRoshan 7:574c66ebd8b0 234 lcd.drawSprite(0,0,48,84,(int *) congrats);
RexRoshan 7:574c66ebd8b0 235 lcd.drawSprite(0,23,25,84,(int *)party_popper);
RexRoshan 7:574c66ebd8b0 236 lcd.refresh();
RexRoshan 7:574c66ebd8b0 237 wait(0.5);
RexRoshan 7:574c66ebd8b0 238 lcd.clear();
RexRoshan 7:574c66ebd8b0 239 lcd.drawSprite(0,0,48,84,(int *) congrats);
RexRoshan 7:574c66ebd8b0 240 lcd.refresh();
RexRoshan 7:574c66ebd8b0 241 wait(0.5);
RexRoshan 7:574c66ebd8b0 242 }
RexRoshan 7:574c66ebd8b0 243 while(pad.check_event(Gamepad::A_PRESSED) == false){
RexRoshan 7:574c66ebd8b0 244 lcd.clear();
RexRoshan 7:574c66ebd8b0 245 lcd.drawSprite(0,0,48,84,(int *) congrats);
RexRoshan 7:574c66ebd8b0 246 lcd.drawSprite(25,28,13,36,(int *) exit1);
RexRoshan 7:574c66ebd8b0 247 lcd.refresh();
RexRoshan 7:574c66ebd8b0 248 if (pad.check_event(Gamepad::A_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 249 end = true;
RexRoshan 7:574c66ebd8b0 250 music_end = false;
RexRoshan 7:574c66ebd8b0 251 break;
RexRoshan 7:574c66ebd8b0 252 }
RexRoshan 7:574c66ebd8b0 253 }
RexRoshan 7:574c66ebd8b0 254 break;
RexRoshan 7:574c66ebd8b0 255 }
RexRoshan 7:574c66ebd8b0 256 }
RexRoshan 7:574c66ebd8b0 257 currentState = TitleScreen;
RexRoshan 7:574c66ebd8b0 258 break;
RexRoshan 7:574c66ebd8b0 259
RexRoshan 7:574c66ebd8b0 260 case Mini_Game:
RexRoshan 7:574c66ebd8b0 261 mini_init();
RexRoshan 7:574c66ebd8b0 262 currentMini = Alive;
RexRoshan 7:574c66ebd8b0 263 while(!finish) {
RexRoshan 7:574c66ebd8b0 264 switch(currentMini){
RexRoshan 7:574c66ebd8b0 265 case Alive:
RexRoshan 7:574c66ebd8b0 266 mini.read_input(pad);
RexRoshan 7:574c66ebd8b0 267 mini.update_minigame(pad,lcd);
RexRoshan 7:574c66ebd8b0 268 mini_render();
RexRoshan 7:574c66ebd8b0 269 wait(1.0f/fps);
RexRoshan 7:574c66ebd8b0 270 if(mini.get_game_stage() == 12){
RexRoshan 7:574c66ebd8b0 271 currentMini = Dead;
RexRoshan 7:574c66ebd8b0 272 break;
RexRoshan 7:574c66ebd8b0 273 }
RexRoshan 7:574c66ebd8b0 274 break;
RexRoshan 7:574c66ebd8b0 275
RexRoshan 7:574c66ebd8b0 276 case Dead:
RexRoshan 7:574c66ebd8b0 277 lcd.clear();
RexRoshan 7:574c66ebd8b0 278 lcd.printString(" Your ",0,1);
RexRoshan 7:574c66ebd8b0 279 lcd.printString(" Spacecraft",4,2);
RexRoshan 7:574c66ebd8b0 280 lcd.printString(" have fallen",0,3);
RexRoshan 7:574c66ebd8b0 281 lcd.drawSprite(72,39,9,9, (int*)x_button);
RexRoshan 7:574c66ebd8b0 282 mini.draw_score(lcd);
RexRoshan 7:574c66ebd8b0 283 lcd.refresh();
RexRoshan 7:574c66ebd8b0 284 wait(1.0f/fps);
RexRoshan 7:574c66ebd8b0 285 if (pad.check_event(Gamepad::X_PRESSED) == true){
RexRoshan 7:574c66ebd8b0 286 finish = true;
RexRoshan 7:574c66ebd8b0 287 music_end = false;
RexRoshan 7:574c66ebd8b0 288 }
RexRoshan 7:574c66ebd8b0 289 break;
RexRoshan 7:574c66ebd8b0 290 }
RexRoshan 7:574c66ebd8b0 291 }
RexRoshan 7:574c66ebd8b0 292 currentState = TitleScreen;
RexRoshan 7:574c66ebd8b0 293 break;
RexRoshan 7:574c66ebd8b0 294 }
RexRoshan 0:99fa5a619081 295 }
RexRoshan 0:99fa5a619081 296 }
RexRoshan 0:99fa5a619081 297
RexRoshan 0:99fa5a619081 298 void init(){
RexRoshan 4:4d673fb2d9dc 299 // need to initialise LCD,Gamepad and the Game
RexRoshan 0:99fa5a619081 300 lcd.init();
RexRoshan 0:99fa5a619081 301 pad.init();
RexRoshan 7:574c66ebd8b0 302 //Initialise (x pos of player spacecraft, y pos of player spacecraft, x pos of enemy stage 1,y pos of enemy stage 1, x pos of enemy1 stage 2, y pos of enemy1 stage 2, x pos of enemy2 stage 2, y pos of enemy2 stage 2, x pos of boss stage 3, y pos of boss stage 3, beam size 1, beam size 2, motion speed)
RexRoshan 7:574c66ebd8b0 303 shoot.init(WIDTH/12,HEIGHT/2-5,16,4,12,10,20,11,3,2,4);
RexRoshan 7:574c66ebd8b0 304
RexRoshan 7:574c66ebd8b0 305 }
RexRoshan 7:574c66ebd8b0 306
RexRoshan 7:574c66ebd8b0 307 void mini_init(){
RexRoshan 7:574c66ebd8b0 308 // need to initialise LCD,Gamepad and the Game
RexRoshan 7:574c66ebd8b0 309 lcd.init();
RexRoshan 7:574c66ebd8b0 310 pad.init();
RexRoshan 7:574c66ebd8b0 311 //Initialise (x pos of player spacecraft, y pos of player spacecraft, beam size 1)
RexRoshan 7:574c66ebd8b0 312 mini.init(WIDTH/12,HEIGHT/2-5,3,66,0,36,30);
RexRoshan 0:99fa5a619081 313
RexRoshan 0:99fa5a619081 314 }
RexRoshan 0:99fa5a619081 315
RexRoshan 4:4d673fb2d9dc 316
RexRoshan 0:99fa5a619081 317 void render()
RexRoshan 0:99fa5a619081 318 {
RexRoshan 0:99fa5a619081 319 // clear screen, re-draw and refresh
RexRoshan 4:4d673fb2d9dc 320 // Mission 1
RexRoshan 0:99fa5a619081 321 lcd.clear();
RexRoshan 2:b5c1bb7a39de 322 shoot.draw_mission_one(pad,lcd);
RexRoshan 0:99fa5a619081 323 lcd.refresh();
RexRoshan 0:99fa5a619081 324 }
RexRoshan 0:99fa5a619081 325
RexRoshan 0:99fa5a619081 326 void render2()
RexRoshan 0:99fa5a619081 327 {
RexRoshan 0:99fa5a619081 328 // clear screen, re-draw and refresh
RexRoshan 4:4d673fb2d9dc 329 // Mission 2
RexRoshan 0:99fa5a619081 330 lcd.clear();
RexRoshan 2:b5c1bb7a39de 331 shoot.draw_mission_two(pad,lcd);
RexRoshan 0:99fa5a619081 332 lcd.refresh();
RexRoshan 0:99fa5a619081 333 }
RexRoshan 0:99fa5a619081 334
RexRoshan 1:45493d1d0689 335 void render3()
RexRoshan 1:45493d1d0689 336 {
RexRoshan 1:45493d1d0689 337 // clear screen, re-draw and refresh
RexRoshan 4:4d673fb2d9dc 338 // Mission 3
RexRoshan 1:45493d1d0689 339 lcd.clear();
RexRoshan 2:b5c1bb7a39de 340 shoot.draw_mission_three(pad,lcd);
RexRoshan 1:45493d1d0689 341 lcd.refresh();
RexRoshan 1:45493d1d0689 342 }
RexRoshan 1:45493d1d0689 343
RexRoshan 4:4d673fb2d9dc 344 void welcome()
RexRoshan 4:4d673fb2d9dc 345 {
RexRoshan 0:99fa5a619081 346
RexRoshan 4:4d673fb2d9dc 347 // draws the sprites until the Start button is pressed
RexRoshan 4:4d673fb2d9dc 348
RexRoshan 0:99fa5a619081 349 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
RexRoshan 0:99fa5a619081 350 if(pad.check_event(Gamepad::START_PRESSED) == true){break;}
RexRoshan 0:99fa5a619081 351 pad.leds_on();
RexRoshan 2:b5c1bb7a39de 352 lcd.drawSprite(6,0,48,71,(int *)screen);
RexRoshan 0:99fa5a619081 353 lcd.drawSprite(21,43,5,40,(int *)start);
RexRoshan 0:99fa5a619081 354 lcd.refresh();
RexRoshan 0:99fa5a619081 355 Thread::wait(800);
RexRoshan 0:99fa5a619081 356 if(pad.check_event(Gamepad::START_PRESSED) == true){break;}
RexRoshan 0:99fa5a619081 357 pad.leds_off();
RexRoshan 2:b5c1bb7a39de 358 lcd.drawSprite(6,0,48,71,(int *)screen);
RexRoshan 0:99fa5a619081 359 lcd.refresh();
RexRoshan 0:99fa5a619081 360 Thread::wait(800);
RexRoshan 0:99fa5a619081 361 if(pad.check_event(Gamepad::START_PRESSED) == true){break;}
RexRoshan 0:99fa5a619081 362
RexRoshan 0:99fa5a619081 363 }
RexRoshan 0:99fa5a619081 364 pad.leds_off();
RexRoshan 0:99fa5a619081 365 }
RexRoshan 7:574c66ebd8b0 366 /*void welcome()
RexRoshan 7:574c66ebd8b0 367 {
RexRoshan 7:574c66ebd8b0 368
RexRoshan 7:574c66ebd8b0 369 // draws the sprites until the Start button is pressed
RexRoshan 7:574c66ebd8b0 370
RexRoshan 7:574c66ebd8b0 371 while (!music_end) {
RexRoshan 7:574c66ebd8b0 372 if(pad.check_event(Gamepad::START_PRESSED) == true){music_end = true; break;}
RexRoshan 7:574c66ebd8b0 373 pad.leds_on();
RexRoshan 7:574c66ebd8b0 374 lcd.drawSprite(6,0,48,71,(int *)screen);
RexRoshan 7:574c66ebd8b0 375 lcd.drawSprite(21,43,5,40,(int *)start);
RexRoshan 7:574c66ebd8b0 376 lcd.refresh();
RexRoshan 7:574c66ebd8b0 377 wait(0.8);
RexRoshan 7:574c66ebd8b0 378 if(pad.check_event(Gamepad::START_PRESSED) == true){music_end = true; break;}
RexRoshan 7:574c66ebd8b0 379 pad.leds_off();
RexRoshan 7:574c66ebd8b0 380 lcd.drawSprite(6,0,48,71,(int *)screen);
RexRoshan 7:574c66ebd8b0 381 lcd.refresh();
RexRoshan 7:574c66ebd8b0 382 wait(0.8);
RexRoshan 7:574c66ebd8b0 383 if(pad.check_event(Gamepad::START_PRESSED) == true){music_end = true; break;}
RexRoshan 7:574c66ebd8b0 384
RexRoshan 7:574c66ebd8b0 385 }
RexRoshan 7:574c66ebd8b0 386 pad.leds_off();
RexRoshan 7:574c66ebd8b0 387 }*/
RexRoshan 7:574c66ebd8b0 388
RexRoshan 0:99fa5a619081 389
RexRoshan 4:4d673fb2d9dc 390 void intro()
RexRoshan 4:4d673fb2d9dc 391 {
RexRoshan 4:4d673fb2d9dc 392 //plays the introduction music for game
RexRoshan 4:4d673fb2d9dc 393 play.intro_song(pad);
RexRoshan 4:4d673fb2d9dc 394 }
RexRoshan 0:99fa5a619081 395
RexRoshan 4:4d673fb2d9dc 396 void instruction()
RexRoshan 4:4d673fb2d9dc 397 {
RexRoshan 4:4d673fb2d9dc 398 // clears, draws the instrcution and game rules page and refreshes the page
RexRoshan 0:99fa5a619081 399 pad.leds_off();
RexRoshan 1:45493d1d0689 400 lcd.clear();
RexRoshan 1:45493d1d0689 401 instruct.rules(lcd,pad);
RexRoshan 1:45493d1d0689 402 lcd.refresh();
RexRoshan 1:45493d1d0689 403
RexRoshan 0:99fa5a619081 404
RexRoshan 1:45493d1d0689 405 }
RexRoshan 7:574c66ebd8b0 406
RexRoshan 7:574c66ebd8b0 407 void mini_rules()
RexRoshan 7:574c66ebd8b0 408 {
RexRoshan 7:574c66ebd8b0 409 lcd.clear();
RexRoshan 7:574c66ebd8b0 410 instruct.mini_rules(lcd,pad);
RexRoshan 7:574c66ebd8b0 411 lcd.refresh();
RexRoshan 7:574c66ebd8b0 412 }
RexRoshan 4:4d673fb2d9dc 413
RexRoshan 7:574c66ebd8b0 414 void mini_render()
RexRoshan 7:574c66ebd8b0 415 {
RexRoshan 7:574c66ebd8b0 416 // Mini Game
RexRoshan 7:574c66ebd8b0 417 // clear screen, re-draw and refresh
RexRoshan 7:574c66ebd8b0 418 lcd.clear();
RexRoshan 7:574c66ebd8b0 419 mini.draw_minigame(pad,lcd);
RexRoshan 7:574c66ebd8b0 420 lcd.refresh();
RexRoshan 7:574c66ebd8b0 421 }
RexRoshan 7:574c66ebd8b0 422
RexRoshan 7:574c66ebd8b0 423 void render_nothing()
RexRoshan 7:574c66ebd8b0 424 {
RexRoshan 7:574c66ebd8b0 425 lcd.clear();
RexRoshan 7:574c66ebd8b0 426 lcd.refresh();
RexRoshan 7:574c66ebd8b0 427 }
RexRoshan 7:574c66ebd8b0 428
RexRoshan 7:574c66ebd8b0 429 /*void intro_song() // introduction song for the game
RexRoshan 7:574c66ebd8b0 430 {
RexRoshan 7:574c66ebd8b0 431 while(!music_end){
RexRoshan 7:574c66ebd8b0 432 pad.tone(293.665, 2);
RexRoshan 7:574c66ebd8b0 433 if(music_end == true){break;} // break if start button has been pressed
RexRoshan 7:574c66ebd8b0 434 thread.wait(1000); // thread wait so that two loops can simulatneously run
RexRoshan 7:574c66ebd8b0 435 pad.tone(311.127, 2);
RexRoshan 7:574c66ebd8b0 436 if(music_end == true){break;}
RexRoshan 7:574c66ebd8b0 437 thread.wait(1000);
RexRoshan 7:574c66ebd8b0 438 pad.tone(329.628, 2);
RexRoshan 7:574c66ebd8b0 439 if(music_end == true){break;}
RexRoshan 7:574c66ebd8b0 440 thread.wait(1000);
RexRoshan 7:574c66ebd8b0 441 pad.tone(349.228, 2);
RexRoshan 7:574c66ebd8b0 442 if(music_end == true){break;}
RexRoshan 7:574c66ebd8b0 443 thread.wait(1000);
RexRoshan 7:574c66ebd8b0 444 }
RexRoshan 7:574c66ebd8b0 445 }*/
RexRoshan 7:574c66ebd8b0 446