Mbed project for a FRDM-K64F microcontroller. Game made out of five sub-games including flappy birds, snake, stack, trivia and space invaders.
Fork of The_Children_of_Cronos_el15mggr by
main.cpp
- Committer:
- matirc
- Date:
- 2017-04-29
- Revision:
- 1:101e060118fa
- Parent:
- 0:1ed3f8d98beb
- Child:
- 2:8b95be711648
File content as of revision 1:101e060118fa:
#include "mbed.h" #include "N5110.h" #include "Bitmap.h" #include "Gamepad.h" #include "hydralib.h" #include "Stymphalianlib.h" #include "aurigaslib.h" #include "cerinealib.h" #include "taurolib.h" #include "array.h" DigitalOut x (PTC17); DigitalOut y (PTC12); DigitalOut a (PTB9); DigitalOut b (PTD0); DigitalOut l (PTB18); DigitalOut r (PTB3); DigitalOut start (PTC5); DigitalOut mute(PTB18); DigitalOut notmute(PTB3); DigitalOut back(PTB19); Stymphalianlib stym; N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; hydralib hyd; aurigaslib aurig; cerinealib cer; taurolib tau; Ticker alienmove; void init(); void intro(); void game(); void drawselectscreen(); void selected(); void gameone(); bool game1=true; void gametwo(); bool game2=true; void gamethree(); bool game3=true; void gamefour(); bool game4=true; void gamefive(); bool game5=true; struct State{ int position; int nextstate[2]; }; State games[5]={ {0,{4,1}}, {1,{0,2}}, {2,{1,3}}, {3,{2,4}}, {4,{3,0}} }; int state=0; int output=0; int direction=1; int main() { wait(2); init(); intro(); gamefive(); } void intro() { Bitmap sprite(randulfe,15,72); sprite.render(lcd,6,0); sprite.print(); lcd.printString("presents",5,4); lcd.refresh(); wait(2); lcd.printString(".",60,4); lcd.refresh(); wait(2); lcd.printString(".",65,4); lcd.refresh(); wait(2); lcd.printString(".",70,4); lcd.refresh(); wait(2); } void game(){ drawselectscreen(); Direction d = pad.get_direction(); if (d==E){state = games[state].nextstate[1];wait(0.1);} if (d==W){state = games[state].nextstate[0];wait(0.1);} if(pad.check_event(pad.B_PRESSED)){state = games[state].nextstate[1];wait(0.1);} if(pad.check_event(pad.X_PRESSED)){state = games[state].nextstate[0];wait(0.1);} output=games[state].position; } void gamefive() { while(game5){ tau.game(lcd,pad,a,start);}} void gamefour() { while(game4) { float pott=pad.read_pot(); lcd.setBrightness(pott); if(!cer.die()) { cer.commands(pad); cer.updatescr(); cer.draw(lcd); cer.velocities(); } else if(cer.die()) { cer.gameover(lcd,start,pad); } } } void gamethree() { while(game3) { float pott=pad.read_pot(); lcd.setBrightness(pott); if(aurig.touch()) { srand( time( NULL ) ); aurig.pipegenerator(pad,start); aurig.updatescr(a,b,x,y); aurig.draw(lcd); wait(0.05); } else { aurig.gameover(lcd,pad,back); } } } void gametwo() { //alienmove.attach(&move, 1.0); while(game2) { float pott=pad.read_pot(); lcd.setBrightness(pott); if (!stym.die()) { stym.leds(pad); stym.commands(pad,l,b,x,r); stym.updatescr(); srand(time(NULL)); stym.auxiliar(); stym.touch(); stym.draw(lcd); wait(0.08); } else if(stym.die()) { stym.gameover(lcd,start,pad); } } } void gameone() { while(game1) { if (hyd.border()) { hyd.leds(pad); hyd.commands(pad,a,b,x,y); if (hyd.eat()) { srand( time( NULL ) ); hyd.auxiliar(); } hyd.updatescr(); hyd.draw(lcd); hyd.touch(); hyd.velocities(); } else { hyd.gameover(lcd,start,pad); } } } void drawselectscreen(){ lcd.clear(); lcd.drawRect(7,3,20,15,FILL_TRANSPARENT); lcd.drawRect(32,3,20,15,FILL_TRANSPARENT); lcd.drawRect(57,3,20,15,FILL_TRANSPARENT); lcd.drawRect(20,21,20,15,FILL_TRANSPARENT); lcd.drawRect(45,21,20,15,FILL_TRANSPARENT); if(output==0){lcd.drawRect(7,3,20,15,FILL_BLACK);} if(output==1){lcd.drawRect(32,3,20,15,FILL_BLACK);} if(output==2){lcd.drawRect(57,3,20,15,FILL_BLACK);} if(output==3){lcd.drawRect(18,21,20,15,FILL_BLACK);} if(output==4){lcd.drawRect(43,21,20,15,FILL_BLACK);} lcd.printChar('1',14,1); lcd.printChar('2',39,1); lcd.printChar('3',64,1); lcd.printChar('4',27,3); lcd.printChar('5',52,3); lcd.refresh(); } void init() { tau.init(); cer.init(); aurig.init(); stym.init(); hyd.init(); pad.init(); lcd.init(); lcd.normalMode(); lcd.setBrightness(0.5); }