Mbed project for a FRDM-K64F microcontroller. Game made out of five sub-games including flappy birds, snake, stack, trivia and space invaders.

Dependencies:   mbed

Fork of The_Children_of_Cronos_el15mggr by ELEC2645 (2016/17)

Committer:
matirc
Date:
Tue Jul 18 09:55:49 2017 +0000
Revision:
5:4111d3255f24
Parent:
3:151ac98b6252
Final version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matirc 2:8b95be711648 1 #include "mbed.h"
matirc 2:8b95be711648 2 #include "N5110.h"
matirc 2:8b95be711648 3 #include "Bitmap.h"
matirc 2:8b95be711648 4 #include "Gamepad.h"
matirc 3:151ac98b6252 5 #include "hydralib.h"
matirc 3:151ac98b6252 6 #include "Stymphalianlib.h"
matirc 3:151ac98b6252 7 #include "aurigaslib.h"
matirc 3:151ac98b6252 8 #include "cerinealib.h"
matirc 3:151ac98b6252 9 #include "taurolib.h"
matirc 3:151ac98b6252 10 #include "array.h"
matirc 2:8b95be711648 11
matirc 2:8b95be711648 12
matirc 3:151ac98b6252 13 /** Selector */
matirc 3:151ac98b6252 14 struct State {
matirc 3:151ac98b6252 15 int position; /**< position */
matirc 3:151ac98b6252 16 int nextstate[2];/**< next state */
matirc 3:151ac98b6252 17 };
matirc 3:151ac98b6252 18
matirc 3:151ac98b6252 19 /**
matirc 3:151ac98b6252 20 @file game.h
matirc 3:151ac98b6252 21 @brief Header file for the function prototyps and variables of the main game file
matirc 3:151ac98b6252 22 @author Mateo Randulfe
matirc 3:151ac98b6252 23 @date May 2017
matirc 3:151ac98b6252 24 */
matirc 3:151ac98b6252 25
matirc 3:151ac98b6252 26 /**
matirc 3:151ac98b6252 27 * x button connection
matirc 3:151ac98b6252 28 * @param x
matirc 3:151ac98b6252 29 */
matirc 2:8b95be711648 30 DigitalOut x (PTC17);
matirc 3:151ac98b6252 31 /**
matirc 3:151ac98b6252 32 * y button connection
matirc 3:151ac98b6252 33 * @param y
matirc 3:151ac98b6252 34 */
matirc 2:8b95be711648 35 DigitalOut y (PTC12);
matirc 3:151ac98b6252 36 /**
matirc 3:151ac98b6252 37 * a button connection
matirc 3:151ac98b6252 38 * @param a
matirc 3:151ac98b6252 39 */
matirc 2:8b95be711648 40 DigitalOut a (PTB9);
matirc 3:151ac98b6252 41 /**
matirc 3:151ac98b6252 42 * b button connection
matirc 3:151ac98b6252 43 * @param b
matirc 3:151ac98b6252 44 */
matirc 2:8b95be711648 45 DigitalOut b (PTD0);
matirc 3:151ac98b6252 46 /**
matirc 3:151ac98b6252 47 * l button connection
matirc 3:151ac98b6252 48 * @param l
matirc 3:151ac98b6252 49 */
matirc 2:8b95be711648 50 DigitalOut l (PTB18);
matirc 3:151ac98b6252 51 /**
matirc 3:151ac98b6252 52 * r button connection
matirc 3:151ac98b6252 53 * @param r
matirc 3:151ac98b6252 54 */
matirc 2:8b95be711648 55 DigitalOut r (PTB3);
matirc 3:151ac98b6252 56 /**
matirc 3:151ac98b6252 57 * start button connection
matirc 3:151ac98b6252 58 * @param start
matirc 3:151ac98b6252 59 */
matirc 2:8b95be711648 60 DigitalOut start (PTC5);
matirc 3:151ac98b6252 61 /**
matirc 3:151ac98b6252 62 * back button connection
matirc 3:151ac98b6252 63 * @param back
matirc 3:151ac98b6252 64 */
matirc 2:8b95be711648 65 DigitalOut back(PTB19);
matirc 3:151ac98b6252 66 /**
matirc 3:151ac98b6252 67 * lcd objct for interacting with the screen library
matirc 3:151ac98b6252 68 * @param lcd
matirc 3:151ac98b6252 69 */
matirc 3:151ac98b6252 70
matirc 2:8b95be711648 71 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
matirc 3:151ac98b6252 72 /**
matirc 3:151ac98b6252 73 * gamepad objct for interacting with the gamepad library
matirc 3:151ac98b6252 74 * @param pad
matirc 3:151ac98b6252 75 */
matirc 2:8b95be711648 76 Gamepad pad;
matirc 3:151ac98b6252 77 /**
matirc 3:151ac98b6252 78 * hydralib objct for interacting with the first game library(the snake)
matirc 3:151ac98b6252 79 * @param hyd
matirc 3:151ac98b6252 80 */
matirc 2:8b95be711648 81 hydralib hyd;
matirc 3:151ac98b6252 82 /**
matirc 3:151ac98b6252 83 * Stymphalianlib objct for interacting with the second game library(space invaders)
matirc 3:151ac98b6252 84 * @param stym
matirc 3:151ac98b6252 85 */
matirc 3:151ac98b6252 86 Stymphalianlib stym;
matirc 3:151ac98b6252 87 /**
matirc 3:151ac98b6252 88 * aurigaslib objct for interacting with the third game library(flappy birds)
matirc 3:151ac98b6252 89 * @param aurig
matirc 3:151ac98b6252 90 */
matirc 2:8b95be711648 91 aurigaslib aurig;
matirc 3:151ac98b6252 92 /**
matirc 3:151ac98b6252 93 * cerinealib objct for interacting with the fourth game library(stack)
matirc 3:151ac98b6252 94 * @param cer
matirc 3:151ac98b6252 95 */
matirc 2:8b95be711648 96 cerinealib cer;
matirc 3:151ac98b6252 97 /**
matirc 3:151ac98b6252 98 * taurolib objct for interacting with the fith game library(quesions and answers)
matirc 3:151ac98b6252 99 * @param tau
matirc 3:151ac98b6252 100 */
matirc 2:8b95be711648 101 taurolib tau;
matirc 2:8b95be711648 102
matirc 3:151ac98b6252 103 /**
matirc 3:151ac98b6252 104 * ticker object for switching on progressively the lights in the intro
matirc 3:151ac98b6252 105 */
matirc 2:8b95be711648 106 Ticker introlights;
matirc 3:151ac98b6252 107 /**
matirc 3:151ac98b6252 108 * ticker object for moving the aliens each second in th space invaders game
matirc 3:151ac98b6252 109 */
matirc 2:8b95be711648 110 Ticker alienmove;
matirc 2:8b95be711648 111
matirc 3:151ac98b6252 112 /**
matirc 3:151ac98b6252 113 * initialises all the objects like gamepad and lcd
matirc 3:151ac98b6252 114 * it also performs h init function of all the games
matirc 3:151ac98b6252 115 */
matirc 2:8b95be711648 116 void init();
matirc 3:151ac98b6252 117 /**
matirc 3:151ac98b6252 118 * brief intro with the game name in a fancy way using bitmaps
matirc 3:151ac98b6252 119 */
matirc 2:8b95be711648 120 void intro();
matirc 3:151ac98b6252 121 /**
matirc 3:151ac98b6252 122 * switchs on progressivly the lights in the intro screen
matirc 3:151ac98b6252 123 */
matirc 2:8b95be711648 124 void lights();
matirc 3:151ac98b6252 125 /**
matirc 3:151ac98b6252 126 * displays the different games selector screen and allows to switch between them
matirc 3:151ac98b6252 127 */
matirc 2:8b95be711648 128 void game();
matirc 3:151ac98b6252 129 /**
matirc 3:151ac98b6252 130 * function that allows to select the five different games in an up down selector using a sructure
matirc 3:151ac98b6252 131 */
matirc 2:8b95be711648 132 void select();
matirc 3:151ac98b6252 133 /**
matirc 3:151ac98b6252 134 * executes the screen where the player can select the option he wants like tutoria,story of the game,the games screen or the scores
matirc 3:151ac98b6252 135 */
matirc 2:8b95be711648 136 void menuscreen();
matirc 3:151ac98b6252 137 /**
matirc 3:151ac98b6252 138 * function that allows to select the different menu options the player have
matirc 3:151ac98b6252 139 */
matirc 3:151ac98b6252 140 void menuselect();
matirc 3:151ac98b6252 141 /**
matirc 3:151ac98b6252 142 * draws the screen that selects beween the five different games(which is inside itself of the menuselct screen
matirc 3:151ac98b6252 143 */
matirc 2:8b95be711648 144 void drawselectmenu();
matirc 3:151ac98b6252 145 /**
matirc 3:151ac98b6252 146 * draws the screen that selects beween opions in the menu
matirc 3:151ac98b6252 147 */
matirc 2:8b95be711648 148 void drawselectscreen();
matirc 3:151ac98b6252 149
matirc 3:151ac98b6252 150 /** selects between different games */
matirc 2:8b95be711648 151 void selected();
matirc 3:151ac98b6252 152 /**
matirc 3:151ac98b6252 153 * displays the tutorial screen and the selecor of it.The player can choose to read the instructions of the different levels
matirc 3:151ac98b6252 154 */
matirc 2:8b95be711648 155 void tutorial();
matirc 3:151ac98b6252 156 /**
matirc 3:151ac98b6252 157 * displays the game sory screen and the selecor of it.The player can scrolls to keep reading the story.
matirc 3:151ac98b6252 158 */
matirc 2:8b95be711648 159 void story();
matirc 3:151ac98b6252 160 /**
matirc 3:151ac98b6252 161 * displays the highest scores
matirc 3:151ac98b6252 162 */
matirc 2:8b95be711648 163 void highscores();
matirc 3:151ac98b6252 164 /**
matirc 3:151ac98b6252 165 * saves the score if pressed and if its bigger than the thid position
matirc 3:151ac98b6252 166 */
matirc 2:8b95be711648 167 void savescore();
matirc 3:151ac98b6252 168
matirc 3:151ac98b6252 169 /** performs the aliens movement */
matirc 2:8b95be711648 170 void aliens();
matirc 3:151ac98b6252 171 /**
matirc 3:151ac98b6252 172 * executes the screen where the player can select the game he wants
matirc 3:151ac98b6252 173 */
matirc 2:8b95be711648 174 void newgame();
matirc 3:151ac98b6252 175 /**
matirc 3:151ac98b6252 176 * function that assemblies the first game
matirc 3:151ac98b6252 177 */
matirc 2:8b95be711648 178 void gameone();
matirc 3:151ac98b6252 179
matirc 3:151ac98b6252 180 //if false the game is not running i true it will be running
matirc 2:8b95be711648 181 bool game1=false;
matirc 3:151ac98b6252 182 /**
matirc 3:151ac98b6252 183 * function that assemblies the second game
matirc 3:151ac98b6252 184 */
matirc 2:8b95be711648 185 void gametwo();
matirc 3:151ac98b6252 186 // if false the game is not running i true it will be running
matirc 2:8b95be711648 187 bool game2=false;
matirc 3:151ac98b6252 188 /**
matirc 3:151ac98b6252 189 * function that assemblies the third game
matirc 3:151ac98b6252 190 */
matirc 2:8b95be711648 191 void gamethree();
matirc 3:151ac98b6252 192 //if false the game is not running i true it will be running
matirc 2:8b95be711648 193 bool game3=false;
matirc 3:151ac98b6252 194 /**
matirc 3:151ac98b6252 195 * function that assemblies the fourth game
matirc 3:151ac98b6252 196 */
matirc 2:8b95be711648 197 void gamefour();
matirc 3:151ac98b6252 198 // if false the game is not running i true it will be running
matirc 2:8b95be711648 199 bool game4=false;
matirc 3:151ac98b6252 200 /**
matirc 3:151ac98b6252 201 * function that assemblies the fith game
matirc 3:151ac98b6252 202 */
matirc 2:8b95be711648 203 void gamefive();
matirc 3:151ac98b6252 204 // if false the game is not running i true it will be running
matirc 2:8b95be711648 205 bool game5=false;
matirc 3:151ac98b6252 206 // if false the menu screen will not be displayed if true it will
matirc 2:8b95be711648 207 bool menuselection=true;
matirc 3:151ac98b6252 208 // if false the games selector screen will not be displayed if true it will
matirc 2:8b95be711648 209 bool selection=true;
matirc 3:151ac98b6252 210 // if false the tutorial screen will not be displayed if true it will
matirc 2:8b95be711648 211 bool tut=false;
matirc 3:151ac98b6252 212 // if false the story screen will not be displayed if true it will
matirc 2:8b95be711648 213 bool stor=false;
matirc 3:151ac98b6252 214 // if false the highscore screen will not be displayed if true it will
matirc 2:8b95be711648 215 bool highscr=false;
matirc 3:151ac98b6252 216 // if false the save screen will not be displayed if true it will
matirc 2:8b95be711648 217 bool savescr=false;
matirc 2:8b95be711648 218
matirc 2:8b95be711648 219
matirc 3:151ac98b6252 220 /** structure array for the different games*/
matirc 2:8b95be711648 221 State games[5]= {
matirc 2:8b95be711648 222 {0,{4,1}},
matirc 2:8b95be711648 223 {1,{0,2}},
matirc 2:8b95be711648 224 {2,{1,3}},
matirc 2:8b95be711648 225 {3,{2,4}},
matirc 2:8b95be711648 226 {4,{3,0}}
matirc 2:8b95be711648 227 };
matirc 3:151ac98b6252 228 /** structure array for the different menu options*/
matirc 3:151ac98b6252 229 State menu[4]= {
matirc 3:151ac98b6252 230 {0,{3,1}},
matirc 2:8b95be711648 231 {1,{0,2}},
matirc 2:8b95be711648 232 {2,{1,3}},
matirc 3:151ac98b6252 233 {3,{2,0}}
matirc 2:8b95be711648 234 };
matirc 3:151ac98b6252 235 /** structure array for the tutorial options*/
matirc 2:8b95be711648 236 State tuto[5]= {
matirc 2:8b95be711648 237 {0,{4,1}},
matirc 2:8b95be711648 238 {1,{0,2}},
matirc 2:8b95be711648 239 {2,{1,3}},
matirc 2:8b95be711648 240 {3,{2,4}},
matirc 2:8b95be711648 241 {4,{3,0}}
matirc 2:8b95be711648 242 };
matirc 2:8b95be711648 243
matirc 3:151ac98b6252 244 //arrays for displaying scores
matirc 3:151ac98b6252 245 char buffer0[20];
matirc 3:151ac98b6252 246 char buffer1[20];
matirc 3:151ac98b6252 247 char buffer2[20];
matirc 3:151ac98b6252 248 char buffer3[20];
matirc 3:151ac98b6252 249 char buffer4[20];
matirc 3:151ac98b6252 250 char buffer5[20];
matirc 3:151ac98b6252 251
matirc 2:8b95be711648 252 int statetutorial=0;
matirc 2:8b95be711648 253 int outpututorial=0;
matirc 2:8b95be711648 254
matirc 2:8b95be711648 255 int statemenu=0;
matirc 2:8b95be711648 256 int outputmenu=0;
matirc 2:8b95be711648 257
matirc 2:8b95be711648 258
matirc 2:8b95be711648 259 int statestory=0;
matirc 2:8b95be711648 260 int outputstory=0;
matirc 2:8b95be711648 261
matirc 2:8b95be711648 262 int state=0;
matirc 2:8b95be711648 263 int output=0;
matirc 2:8b95be711648 264
matirc 3:151ac98b6252 265 //???
matirc 2:8b95be711648 266 int lit=0;
matirc 3:151ac98b6252 267 //??
matirc 2:8b95be711648 268 int k=1;
matirc 3:151ac98b6252 269
matirc 2:8b95be711648 270 int totalscore;
matirc 3:151ac98b6252 271 //different scores for the games
matirc 2:8b95be711648 272 int scoreg1, scoreg2,scoreg3,scoreg4,scoreg5;
matirc 2:8b95be711648 273
matirc 2:8b95be711648 274 #define NOTE_B0 31
matirc 2:8b95be711648 275 #define NOTE_C1 33
matirc 2:8b95be711648 276 #define NOTE_CS1 35
matirc 2:8b95be711648 277 #define NOTE_D1 37
matirc 2:8b95be711648 278 #define NOTE_DS1 39
matirc 2:8b95be711648 279 #define NOTE_E1 41
matirc 2:8b95be711648 280 #define NOTE_F1 44
matirc 2:8b95be711648 281 #define NOTE_FS1 46
matirc 2:8b95be711648 282 #define NOTE_G1 49
matirc 2:8b95be711648 283 #define NOTE_GS1 52
matirc 2:8b95be711648 284 #define NOTE_A1 55
matirc 2:8b95be711648 285 #define NOTE_AS1 58
matirc 2:8b95be711648 286 #define NOTE_B1 62
matirc 2:8b95be711648 287 #define NOTE_C2 65
matirc 2:8b95be711648 288 #define NOTE_CS2 69
matirc 2:8b95be711648 289 #define NOTE_D2 73
matirc 2:8b95be711648 290 #define NOTE_DS2 78
matirc 2:8b95be711648 291 #define NOTE_E2 82
matirc 2:8b95be711648 292 #define NOTE_F2 87
matirc 2:8b95be711648 293 #define NOTE_FS2 93
matirc 2:8b95be711648 294 #define NOTE_G2 98
matirc 2:8b95be711648 295 #define NOTE_GS2 104
matirc 2:8b95be711648 296 #define NOTE_A2 110
matirc 2:8b95be711648 297 #define NOTE_AS2 117
matirc 2:8b95be711648 298 #define NOTE_B2 123
matirc 2:8b95be711648 299 #define NOTE_C3 131
matirc 2:8b95be711648 300 #define NOTE_CS3 139
matirc 2:8b95be711648 301 #define NOTE_D3 147
matirc 2:8b95be711648 302 #define NOTE_DS3 156
matirc 2:8b95be711648 303 #define NOTE_E3 165
matirc 2:8b95be711648 304 #define NOTE_F3 175
matirc 2:8b95be711648 305 #define NOTE_FS3 185
matirc 2:8b95be711648 306 #define NOTE_G3 196
matirc 2:8b95be711648 307 #define NOTE_GS3 208
matirc 2:8b95be711648 308 #define NOTE_A3 220
matirc 2:8b95be711648 309 #define NOTE_AS3 233
matirc 2:8b95be711648 310 #define NOTE_B3 247
matirc 2:8b95be711648 311 #define NOTE_C4 262
matirc 2:8b95be711648 312 #define NOTE_CS4 277
matirc 2:8b95be711648 313 #define NOTE_D4 294
matirc 2:8b95be711648 314 #define NOTE_DS4 311
matirc 2:8b95be711648 315 #define NOTE_E4 330
matirc 2:8b95be711648 316 #define NOTE_F4 349
matirc 2:8b95be711648 317 #define NOTE_FS4 370
matirc 2:8b95be711648 318 #define NOTE_G4 392
matirc 2:8b95be711648 319 #define NOTE_GS4 415
matirc 2:8b95be711648 320 #define NOTE_A4 440
matirc 2:8b95be711648 321 #define NOTE_AS4 466
matirc 2:8b95be711648 322 #define NOTE_B4 494
matirc 2:8b95be711648 323 #define NOTE_C5 523
matirc 2:8b95be711648 324 #define NOTE_CS5 554
matirc 2:8b95be711648 325 #define NOTE_D5 587
matirc 2:8b95be711648 326 #define NOTE_DS5 622
matirc 2:8b95be711648 327 #define NOTE_E5 659
matirc 2:8b95be711648 328 #define NOTE_F5 698
matirc 2:8b95be711648 329 #define NOTE_FS5 740
matirc 2:8b95be711648 330 #define NOTE_G5 784
matirc 2:8b95be711648 331 #define NOTE_GS5 831
matirc 2:8b95be711648 332 #define NOTE_A5 880
matirc 2:8b95be711648 333 #define NOTE_AS5 932
matirc 2:8b95be711648 334 #define NOTE_B5 988
matirc 2:8b95be711648 335 #define NOTE_C6 1047
matirc 2:8b95be711648 336 #define NOTE_CS6 1109
matirc 2:8b95be711648 337 #define NOTE_D6 1175
matirc 2:8b95be711648 338 #define NOTE_DS6 1245
matirc 2:8b95be711648 339 #define NOTE_E6 1319
matirc 2:8b95be711648 340 #define NOTE_F6 1397
matirc 2:8b95be711648 341 #define NOTE_FS6 1480
matirc 2:8b95be711648 342 #define NOTE_G6 1568
matirc 2:8b95be711648 343 #define NOTE_GS6 1661
matirc 2:8b95be711648 344 #define NOTE_A6 1760
matirc 2:8b95be711648 345 #define NOTE_AS6 1865
matirc 2:8b95be711648 346 #define NOTE_B6 1976
matirc 2:8b95be711648 347 #define NOTE_C7 2093
matirc 2:8b95be711648 348 #define NOTE_CS7 2217
matirc 2:8b95be711648 349 #define NOTE_D7 2349
matirc 2:8b95be711648 350