Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- JamesCummins
- Date:
- 2019-04-18
- Revision:
- 22:4e305ff8a050
- Parent:
- 20:4a39a1a2be51
- Child:
- 23:61fa82f76808
File content as of revision 22:4e305ff8a050:
/* ELEC2645 Embedded Systems Project School of Electronic & Electrical Engineering University of Leeds Name: James Nathan Cummins Username: el17jnc Student ID Number: 201096364 Date: 22/03/19 */ #include "Gamepad.h" #include "mbed.h" #include "N5110.h" #include "BrickBreakerEngine.h" #include "OptionsEngine.h" #define RADIUS 3 //Objects Gamepad gamepad; N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); BrickBreakerEngine brick; OptionsEngine opt; AnalogIn randnoise(PTB0); FXOS8700CQ accelerometer(I2C_SDA,I2C_SCL); //Enumeric class and struct for game mode selection menu enum StartOption{ CLASSIC, BRICKBREAKER, OPTIONS }; struct StartSelection{ int output; StartOption next_state[3]; }; //Methods void startscreen(); StartOption menu(); void init(); void print_start_menu(int output); ////////////////Main Function///////////////// int main(){ int fps = 30; init(); startscreen(); while(1){ StartOption choice_selected = menu(); if(choice_selected == CLASSIC){ /*engine.classic_mode(accelerometer, gamepad, lcd, fps);*/} if(choice_selected == BRICKBREAKER){ brick.brickbreaker_mode(accelerometer, gamepad, lcd, randnoise, fps);} if(choice_selected == OPTIONS){ opt.options_menu(gamepad, lcd);} } } //////////////Start up functions/////////////////// void init(){ gamepad.init(); lcd.init(); lcd.setContrast(0.55); brick.init(RADIUS); opt.init(); accelerometer.init(); wait(1); } void startscreen() { lcd.clear(); char gamename[] = {'L', 'A', 'B', 'Y', 'R', 'I', 'N', 'T', 'H', ' ', ' ', '\0'}; int i = 0; for(int a = 0; a < 35; a++){ lcd.clear(); lcd.drawCircle(24+2*a, 21, 3, FILL_BLACK); for (i = 0; i < a/3; i++) { lcd.printChar(gamename[i], 15+i*6, 2); lcd.refresh(); } wait_ms(50); } lcd.printString("Press start", 9, 4); lcd.printString("to play >", 15, 5); lcd.refresh(); bool advance = false; while (!advance){ if (gamepad.check_event(gamepad.START_PRESSED)){ lcd.clear(); lcd.refresh(); advance = true; } else { advance = false; } } } StartOption menu(){ StartSelection fsm[3] = { {0,{OPTIONS,BRICKBREAKER,CLASSIC}}, {2,{CLASSIC,OPTIONS,BRICKBREAKER}}, {4,{BRICKBREAKER,CLASSIC,OPTIONS}} }; StartOption state = CLASSIC; //start with the arrow on the top option int next = 2; //next_state = 2 so that by default it doesn't change arrow position while(!(gamepad.check_event(gamepad.A_PRESSED))){ //select choice by pushing joystick to the right state = fsm[state].next_state[next]; lcd.clear(); if(gamepad.get_direction() == N){ next = 0;} else if(gamepad.get_direction() == S){ next = 1;} else {next = 2;} print_start_menu(fsm[state].output); lcd.refresh(); wait(0.25); } lcd.clear(); lcd.refresh(); return state; } void print_start_menu(int output){ lcd.printString(">", 0, output); lcd.printString("Classic", 36, 0); lcd.printString("BrickBreak", 18, 2); lcd.printString("Options", 36, 4); lcd.printString("(A = Select)", 12, 5); }