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.
Diff: main.cpp
- Revision:
- 25:b52aa23df120
- Parent:
- 24:c6415cc74b17
- Child:
- 26:0dc10374546f
--- a/main.cpp Fri Apr 19 11:16:19 2019 +0000 +++ b/main.cpp Sun Apr 21 13:20:12 2019 +0000 @@ -25,6 +25,7 @@ AnalogIn randnoise(PTB0); FXOS8700CQ accelerometer(I2C_SDA,I2C_SCL); Ball ball; +Pause pause; SDFileSystem sd(PTE3,PTE1,PTE2,PTE4,"sd"); //Enumeric class and struct for game mode selection menu @@ -44,20 +45,22 @@ StartOption menu(); void init(); void print_start_menu(int output); +void brickbreaker_mode(); +void options_menu(); ////////////////Main Function///////////////// +int fps = 30; 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, ball);} - if(choice_selected == OPTIONS){ opt.options_menu(gamepad, lcd, ball, sd);} + if(choice_selected == BRICKBREAKER){ brickbreaker_mode();} + if(choice_selected == OPTIONS){ options_menu();} } } @@ -71,6 +74,7 @@ lcd.setContrast(0.55); brick.init(RADIUS, ball); opt.init(); + pause.init(); accelerometer.init(); sd.disk_initialize(); wait(1); @@ -132,4 +136,38 @@ lcd.printString("BrickBreak", 18, 2); lcd.printString("Options", 36, 4); lcd.printString("(A = Select)", 12, 5); -} \ No newline at end of file +} + +void brickbreaker_mode(){ + for(int i = 0; i < 45*fps; i++){ + if(i == 1){ brick.set_score(0); } //reset score when game restarts + ball.read_input(accelerometer); + ball.update(); + /*Vector2D position = _ball.get_position(); + printf("ball_x = %f | ball_y = %f\n", position.x, position.y); //note: running with tests causes the game to run slow and take ~2min30s*/ + brick.check_square_collision(randnoise, ball); + lcd.clear(); + brick.brickbreaker_draw(lcd, ball); + lcd.refresh(); + wait_ms(1000/fps); + if(gamepad.check_event(gamepad.BACK_PRESSED)){ + int choice = pause.pause_menu(gamepad, lcd, fps, i, BRICKBREAKER_MODE); + i = choice; + } + } + brick.check_high_score(sd); +} + +void options_menu(){ + Option choice = BRIGHTNESS; + while(!(gamepad.check_event(gamepad.A_PRESSED))){ + lcd.clear(); + opt.display_options(lcd); + choice = opt.option_selection(gamepad, lcd); + lcd.refresh(); + wait(0.2); + } + if(choice == BRIGHTNESS){ opt.change_brightness(gamepad, lcd); } + if(choice == BALL_SPEED){ opt.change_ball_speed(gamepad, lcd, ball); } + if(choice == HIGH_SCORES){ opt.view_high_scores(gamepad, lcd, sd); } +}