Rex Raj / Mbed 2 deprecated el17rrrs

Dependencies:   mbed Gamepad N5110 mbed-rtos

Committer:
RexRoshan
Date:
Sat Apr 20 00:08:00 2019 +0000
Revision:
2:b5c1bb7a39de
Parent:
1:45493d1d0689
Child:
3:bf9624e5b0c3
Moving to next page doesnt work in Instruction class. Also playerbeam has been changed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RexRoshan 0:99fa5a619081 1 #include "mbed.h"
RexRoshan 0:99fa5a619081 2 #include "N5110.h"
RexRoshan 0:99fa5a619081 3 #include "Gamepad.h"
RexRoshan 0:99fa5a619081 4 #include "Instruction.h"
RexRoshan 0:99fa5a619081 5 #include "Spacecraft.h"
RexRoshan 0:99fa5a619081 6 #include "GameEngine.h"
RexRoshan 0:99fa5a619081 7 #include "Solar.h"
RexRoshan 0:99fa5a619081 8 #include "Music.h"
RexRoshan 0:99fa5a619081 9 #include "rtos.h"
RexRoshan 0:99fa5a619081 10
RexRoshan 0:99fa5a619081 11 struct UserInput {
RexRoshan 0:99fa5a619081 12 Direction d;
RexRoshan 0:99fa5a619081 13 float mag;
RexRoshan 0:99fa5a619081 14 };
RexRoshan 0:99fa5a619081 15
RexRoshan 1:45493d1d0689 16 enum States { Life1,Life2,Life3,Life4,Life5,Life6,Life7,Life8,Life9,Life10,Life11 };
RexRoshan 1:45493d1d0689 17 enum MissionState {Mission1,Mission1Pass,Mission1Fail,Mission2,Mission2Pass,Mission2Fail,Mission3,Mission3Pass,Mission3Fail,Congratulations,Intro };
RexRoshan 0:99fa5a619081 18
RexRoshan 0:99fa5a619081 19 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // K64F - pwr from 3V3
RexRoshan 0:99fa5a619081 20 Gamepad pad;
RexRoshan 0:99fa5a619081 21 Music play;
RexRoshan 1:45493d1d0689 22 Instruction instruct;
RexRoshan 0:99fa5a619081 23 Thread thread;
RexRoshan 0:99fa5a619081 24 Spacecraft game;
RexRoshan 0:99fa5a619081 25 GameEngine shoot;
RexRoshan 0:99fa5a619081 26
RexRoshan 0:99fa5a619081 27 void init();
RexRoshan 0:99fa5a619081 28 void welcome();
RexRoshan 1:45493d1d0689 29 void rend();
RexRoshan 0:99fa5a619081 30 void render();
RexRoshan 0:99fa5a619081 31 void render2();
RexRoshan 1:45493d1d0689 32 void render3();
RexRoshan 0:99fa5a619081 33 void intro();
RexRoshan 0:99fa5a619081 34 void instruction();
RexRoshan 0:99fa5a619081 35 //void games();
RexRoshan 0:99fa5a619081 36
RexRoshan 0:99fa5a619081 37
RexRoshan 0:99fa5a619081 38 int main()
RexRoshan 0:99fa5a619081 39 {
RexRoshan 2:b5c1bb7a39de 40 MissionState currentState = Mission1;
RexRoshan 0:99fa5a619081 41 // first need to initialise display
RexRoshan 0:99fa5a619081 42 int fps = 8;
RexRoshan 0:99fa5a619081 43 lcd.setContrast(0.4);
RexRoshan 0:99fa5a619081 44 // It will return 0 by default and a 1 when pressed i.e. cause a rising edge
RexRoshan 0:99fa5a619081 45 init();
RexRoshan 0:99fa5a619081 46 // 0.4 appears to be a good starting point
RexRoshan 1:45493d1d0689 47 // thread.start(welcome);
RexRoshan 1:45493d1d0689 48 // intro();
RexRoshan 1:45493d1d0689 49 // thread.terminate();
RexRoshan 0:99fa5a619081 50 instruction();
RexRoshan 0:99fa5a619081 51 render();
RexRoshan 1:45493d1d0689 52 wait(1.0f/fps);
RexRoshan 0:99fa5a619081 53
RexRoshan 1:45493d1d0689 54
RexRoshan 1:45493d1d0689 55 while(1) {
RexRoshan 0:99fa5a619081 56 switch(currentState){
RexRoshan 0:99fa5a619081 57 case Mission1:
RexRoshan 0:99fa5a619081 58 shoot.read_input(pad);
RexRoshan 2:b5c1bb7a39de 59 shoot.update_mission_one(pad,lcd);
RexRoshan 0:99fa5a619081 60 render();
RexRoshan 0:99fa5a619081 61 wait(1.0f/fps);
RexRoshan 0:99fa5a619081 62 if(shoot.get_game_stage() == 1){
RexRoshan 0:99fa5a619081 63 currentState = Mission1Fail;
RexRoshan 0:99fa5a619081 64 break;
RexRoshan 0:99fa5a619081 65 }
RexRoshan 0:99fa5a619081 66 else if(shoot.get_game_stage() == 2){
RexRoshan 0:99fa5a619081 67 currentState = Mission1Pass;
RexRoshan 0:99fa5a619081 68 break;
RexRoshan 0:99fa5a619081 69 } else {
RexRoshan 0:99fa5a619081 70 currentState = Mission1;
RexRoshan 0:99fa5a619081 71 }
RexRoshan 0:99fa5a619081 72 break;
RexRoshan 0:99fa5a619081 73 case Mission1Fail:
RexRoshan 0:99fa5a619081 74 lcd.clear();
RexRoshan 2:b5c1bb7a39de 75 lcd.drawSprite(6,5,42,73,(int *)mission_fail);
RexRoshan 2:b5c1bb7a39de 76 lcd.drawSprite(53,12,7,19,(int *)m_one);
RexRoshan 0:99fa5a619081 77 lcd.refresh();
RexRoshan 0:99fa5a619081 78 if (pad.check_event(Gamepad::B_PRESSED) == true){
RexRoshan 0:99fa5a619081 79 currentState = Mission1;
RexRoshan 0:99fa5a619081 80 shoot.restart_game_stage();
RexRoshan 0:99fa5a619081 81 init();
RexRoshan 0:99fa5a619081 82 }
RexRoshan 0:99fa5a619081 83 break;
RexRoshan 0:99fa5a619081 84 case Mission1Pass:
RexRoshan 0:99fa5a619081 85 lcd.clear();
RexRoshan 2:b5c1bb7a39de 86 lcd.drawSprite(0,0,48,84,(int *)mission_pass);
RexRoshan 2:b5c1bb7a39de 87 lcd.drawSprite(53,12,7,19,(int *)m_one);
RexRoshan 0:99fa5a619081 88 lcd.refresh();
RexRoshan 0:99fa5a619081 89 if (pad.check_event(Gamepad::A_PRESSED) == true){
RexRoshan 0:99fa5a619081 90 currentState = Mission2;
RexRoshan 0:99fa5a619081 91 shoot.restart_game_stage();
RexRoshan 0:99fa5a619081 92 }
RexRoshan 0:99fa5a619081 93 break;
RexRoshan 0:99fa5a619081 94 case Mission2:
RexRoshan 0:99fa5a619081 95 shoot.read_input(pad);
RexRoshan 2:b5c1bb7a39de 96 shoot.update_mission_two(pad,lcd);
RexRoshan 0:99fa5a619081 97 render2();
RexRoshan 0:99fa5a619081 98 wait(1.0f/fps);
RexRoshan 0:99fa5a619081 99 if(shoot.get_game_stage() == 3 ){
RexRoshan 0:99fa5a619081 100 currentState = Mission2Fail;
RexRoshan 0:99fa5a619081 101 }
RexRoshan 0:99fa5a619081 102 if(shoot.get_game_stage() == 4){
RexRoshan 0:99fa5a619081 103 currentState = Mission2Pass;
RexRoshan 0:99fa5a619081 104 }
RexRoshan 0:99fa5a619081 105 break;
RexRoshan 0:99fa5a619081 106 case Mission2Fail:
RexRoshan 0:99fa5a619081 107 lcd.clear();
RexRoshan 2:b5c1bb7a39de 108 lcd.drawSprite(6,5,42,73,(int *)mission_fail);
RexRoshan 2:b5c1bb7a39de 109 lcd.drawSprite(53,13,5,18,(int *)m_two);
RexRoshan 0:99fa5a619081 110 lcd.refresh();
RexRoshan 0:99fa5a619081 111 if (pad.check_event(Gamepad::B_PRESSED) == true){
RexRoshan 0:99fa5a619081 112 currentState = Mission1;
RexRoshan 0:99fa5a619081 113 shoot.restart_game_stage();
RexRoshan 0:99fa5a619081 114 init();
RexRoshan 0:99fa5a619081 115 }
RexRoshan 0:99fa5a619081 116 break;
RexRoshan 0:99fa5a619081 117 case Mission2Pass:
RexRoshan 0:99fa5a619081 118 lcd.clear();
RexRoshan 2:b5c1bb7a39de 119 lcd.drawSprite(0,0,48,84,(int *)mission_pass);
RexRoshan 2:b5c1bb7a39de 120 lcd.drawSprite(53,13,5,18,(int *)m_two);
RexRoshan 0:99fa5a619081 121 lcd.refresh();
RexRoshan 1:45493d1d0689 122 if (pad.check_event(Gamepad::A_PRESSED) == true){
RexRoshan 1:45493d1d0689 123 currentState = Mission3;
RexRoshan 1:45493d1d0689 124 shoot.restart_game_stage();
RexRoshan 1:45493d1d0689 125 init();
RexRoshan 1:45493d1d0689 126 }
RexRoshan 0:99fa5a619081 127 break;
RexRoshan 1:45493d1d0689 128 case Mission3:
RexRoshan 1:45493d1d0689 129 shoot.read_input(pad);
RexRoshan 2:b5c1bb7a39de 130 shoot.update_mission_three(pad,lcd);
RexRoshan 1:45493d1d0689 131 render3();
RexRoshan 1:45493d1d0689 132 wait(1.0f/fps);
RexRoshan 1:45493d1d0689 133 if(shoot.get_game_stage() == 5 ){
RexRoshan 1:45493d1d0689 134 currentState = Mission3Fail;
RexRoshan 1:45493d1d0689 135 }
RexRoshan 1:45493d1d0689 136 if(shoot.get_game_stage() == 6){
RexRoshan 1:45493d1d0689 137 currentState = Mission3Pass;
RexRoshan 1:45493d1d0689 138 }
RexRoshan 1:45493d1d0689 139 break;
RexRoshan 1:45493d1d0689 140 case Mission3Fail:
RexRoshan 1:45493d1d0689 141 lcd.clear();
RexRoshan 2:b5c1bb7a39de 142 lcd.drawSprite(6,5,42,73,(int *)mission_fail);
RexRoshan 2:b5c1bb7a39de 143 lcd.drawSprite(51,13,5,29,(int *)m_three);
RexRoshan 1:45493d1d0689 144 lcd.refresh();
RexRoshan 1:45493d1d0689 145 if (pad.check_event(Gamepad::B_PRESSED) == true){
RexRoshan 1:45493d1d0689 146 currentState = Mission1;
RexRoshan 1:45493d1d0689 147 shoot.restart_game_stage();
RexRoshan 1:45493d1d0689 148 init();
RexRoshan 1:45493d1d0689 149 }
RexRoshan 1:45493d1d0689 150 break;
RexRoshan 1:45493d1d0689 151 case Mission3Pass:
RexRoshan 1:45493d1d0689 152 lcd.clear();
RexRoshan 2:b5c1bb7a39de 153 lcd.drawSprite(0,0,48,84,(int *)mission_pass);
RexRoshan 2:b5c1bb7a39de 154 lcd.drawSprite(51,13,5,29,(int *)m_three);
RexRoshan 1:45493d1d0689 155 lcd.refresh();
RexRoshan 1:45493d1d0689 156 if (pad.check_event(Gamepad::A_PRESSED) == true){
RexRoshan 1:45493d1d0689 157 currentState = Congratulations;
RexRoshan 1:45493d1d0689 158 }
RexRoshan 1:45493d1d0689 159 break;
RexRoshan 1:45493d1d0689 160 case Congratulations:
RexRoshan 1:45493d1d0689 161 for(int i = 0; i < 3; i++){
RexRoshan 1:45493d1d0689 162 lcd.clear();
RexRoshan 1:45493d1d0689 163 lcd.drawSprite(0,0,48,84,(int *) congrats);
RexRoshan 1:45493d1d0689 164 lcd.drawSprite(0,23,25,84,(int *)party_popper);
RexRoshan 1:45493d1d0689 165 lcd.refresh();
RexRoshan 1:45493d1d0689 166 wait(0.5);
RexRoshan 1:45493d1d0689 167 lcd.clear();
RexRoshan 1:45493d1d0689 168 lcd.drawSprite(0,0,48,84,(int *) congrats);
RexRoshan 1:45493d1d0689 169 lcd.refresh();
RexRoshan 1:45493d1d0689 170 wait(0.5);
RexRoshan 1:45493d1d0689 171 }
RexRoshan 1:45493d1d0689 172 while(pad.check_event(Gamepad::A_PRESSED) == false){
RexRoshan 1:45493d1d0689 173 lcd.clear();
RexRoshan 1:45493d1d0689 174 lcd.drawSprite(0,0,48,84,(int *) congrats);
RexRoshan 1:45493d1d0689 175 lcd.drawSprite(25,28,13,36,(int *) exit1);
RexRoshan 1:45493d1d0689 176 lcd.refresh();
RexRoshan 1:45493d1d0689 177 if (pad.check_event(Gamepad::A_PRESSED) == true){
RexRoshan 1:45493d1d0689 178 currentState = Intro;
RexRoshan 1:45493d1d0689 179 break;
RexRoshan 1:45493d1d0689 180 }
RexRoshan 1:45493d1d0689 181 }
RexRoshan 1:45493d1d0689 182 break;
RexRoshan 1:45493d1d0689 183 case Intro:
RexRoshan 1:45493d1d0689 184 int fps = 8;
RexRoshan 1:45493d1d0689 185 lcd.setContrast(0.4);
RexRoshan 1:45493d1d0689 186 // It will return 0 by default and a 1 when pressed i.e. cause a rising edge
RexRoshan 1:45493d1d0689 187 init();
RexRoshan 1:45493d1d0689 188 // 0.4 appears to be a good starting point
RexRoshan 1:45493d1d0689 189 thread.start(welcome);
RexRoshan 1:45493d1d0689 190 intro();
RexRoshan 1:45493d1d0689 191 thread.terminate();
RexRoshan 1:45493d1d0689 192 instruction();
RexRoshan 1:45493d1d0689 193 render();
RexRoshan 1:45493d1d0689 194 wait(1.0f/fps);
RexRoshan 1:45493d1d0689 195 currentState = Mission1;
RexRoshan 1:45493d1d0689 196 break;
RexRoshan 0:99fa5a619081 197 }
RexRoshan 0:99fa5a619081 198 }
RexRoshan 0:99fa5a619081 199 }
RexRoshan 0:99fa5a619081 200
RexRoshan 0:99fa5a619081 201
RexRoshan 0:99fa5a619081 202 void init(){
RexRoshan 0:99fa5a619081 203 // need to initialise LCD and Gamepad
RexRoshan 0:99fa5a619081 204 lcd.init();
RexRoshan 0:99fa5a619081 205 pad.init();
RexRoshan 1:45493d1d0689 206 shoot.init(WIDTH/12,HEIGHT/2-5,12,4,12,10,20,7,3,2,4);
RexRoshan 0:99fa5a619081 207
RexRoshan 0:99fa5a619081 208 }
RexRoshan 0:99fa5a619081 209
RexRoshan 1:45493d1d0689 210 void rend()
RexRoshan 1:45493d1d0689 211 {
RexRoshan 1:45493d1d0689 212 lcd.clear();
RexRoshan 1:45493d1d0689 213 }
RexRoshan 0:99fa5a619081 214 void render()
RexRoshan 0:99fa5a619081 215 {
RexRoshan 0:99fa5a619081 216 // clear screen, re-draw and refresh
RexRoshan 0:99fa5a619081 217 lcd.clear();
RexRoshan 2:b5c1bb7a39de 218 shoot.draw_mission_one(pad,lcd);
RexRoshan 0:99fa5a619081 219 lcd.refresh();
RexRoshan 0:99fa5a619081 220 }
RexRoshan 0:99fa5a619081 221
RexRoshan 0:99fa5a619081 222 void render2()
RexRoshan 0:99fa5a619081 223 {
RexRoshan 0:99fa5a619081 224 // clear screen, re-draw and refresh
RexRoshan 0:99fa5a619081 225 lcd.clear();
RexRoshan 2:b5c1bb7a39de 226 shoot.draw_mission_two(pad,lcd);
RexRoshan 0:99fa5a619081 227 lcd.refresh();
RexRoshan 0:99fa5a619081 228 }
RexRoshan 0:99fa5a619081 229
RexRoshan 1:45493d1d0689 230 void render3()
RexRoshan 1:45493d1d0689 231 {
RexRoshan 1:45493d1d0689 232 // clear screen, re-draw and refresh
RexRoshan 1:45493d1d0689 233 lcd.clear();
RexRoshan 2:b5c1bb7a39de 234 shoot.draw_mission_three(pad,lcd);
RexRoshan 1:45493d1d0689 235 lcd.refresh();
RexRoshan 1:45493d1d0689 236 }
RexRoshan 1:45493d1d0689 237
RexRoshan 0:99fa5a619081 238 void welcome() {
RexRoshan 0:99fa5a619081 239
RexRoshan 0:99fa5a619081 240
RexRoshan 0:99fa5a619081 241
RexRoshan 0:99fa5a619081 242 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
RexRoshan 0:99fa5a619081 243 if(pad.check_event(Gamepad::START_PRESSED) == true){break;}
RexRoshan 0:99fa5a619081 244 pad.leds_on();
RexRoshan 2:b5c1bb7a39de 245 lcd.drawSprite(6,0,48,71,(int *)screen);
RexRoshan 0:99fa5a619081 246 lcd.drawSprite(21,43,5,40,(int *)start);
RexRoshan 0:99fa5a619081 247 lcd.refresh();
RexRoshan 0:99fa5a619081 248 Thread::wait(800);
RexRoshan 0:99fa5a619081 249 if(pad.check_event(Gamepad::START_PRESSED) == true){break;}
RexRoshan 0:99fa5a619081 250 pad.leds_off();
RexRoshan 2:b5c1bb7a39de 251 lcd.drawSprite(6,0,48,71,(int *)screen);
RexRoshan 0:99fa5a619081 252 lcd.refresh();
RexRoshan 0:99fa5a619081 253 Thread::wait(800);
RexRoshan 0:99fa5a619081 254 if(pad.check_event(Gamepad::START_PRESSED) == true){break;}
RexRoshan 0:99fa5a619081 255
RexRoshan 0:99fa5a619081 256 }
RexRoshan 0:99fa5a619081 257 pad.leds_off();
RexRoshan 0:99fa5a619081 258 }
RexRoshan 0:99fa5a619081 259
RexRoshan 0:99fa5a619081 260 void intro() {
RexRoshan 0:99fa5a619081 261 play.intro_song(pad);
RexRoshan 0:99fa5a619081 262 }
RexRoshan 0:99fa5a619081 263
RexRoshan 0:99fa5a619081 264 void instruction(){
RexRoshan 0:99fa5a619081 265
RexRoshan 0:99fa5a619081 266 pad.leds_off();
RexRoshan 1:45493d1d0689 267 lcd.clear();
RexRoshan 1:45493d1d0689 268 instruct.rules(lcd,pad);
RexRoshan 1:45493d1d0689 269 lcd.refresh();
RexRoshan 1:45493d1d0689 270
RexRoshan 0:99fa5a619081 271
RexRoshan 1:45493d1d0689 272 }
RexRoshan 1:45493d1d0689 273 //draw.instruction3(lcd,pad);
RexRoshan 1:45493d1d0689 274 //draw.instruction4(lcd,pad);
RexRoshan 1:45493d1d0689 275 //draw.instruction5(lcd,pad);
RexRoshan 1:45493d1d0689 276 //draw.instruction6(lcd,pad);
RexRoshan 1:45493d1d0689 277 //draw.instruction7(lcd,pad);
RexRoshan 1:45493d1d0689 278
RexRoshan 0:99fa5a619081 279
RexRoshan 0:99fa5a619081 280 //void games(){
RexRoshan 0:99fa5a619081 281 // lcd.clear();
RexRoshan 0:99fa5a619081 282 // game.background(lcd);
RexRoshan 0:99fa5a619081 283 // game.character(lcd);
RexRoshan 0:99fa5a619081 284 // game.enemy(lcd);
RexRoshan 0:99fa5a619081 285 // game.move_update(pad.get_direction(), pad.get_mag());
RexRoshan 0:99fa5a619081 286 // lcd.refresh();
RexRoshan 0:99fa5a619081 287 //}
RexRoshan 0:99fa5a619081 288