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:
- 16:e2aaef863d7c
- Parent:
- 15:3f558f8b54ea
- Child:
- 17:cb208b15be5c
--- a/main.cpp Fri May 01 12:54:25 2020 +0000 +++ b/main.cpp Thu May 07 08:58:21 2020 +0000 @@ -21,42 +21,25 @@ // objects Gamepad pad; N5110 lcd; -Objects objects; -Functions functions; + + //functions void initialise(); +void game(); //variables bool game_check = false; +bool game_playing = false; int main() { initialise(); - - while(game_check == false) { - - lcd.clear(); - objects.draw_shots(lcd,pad); - //functions.ball_creater_linear(lcd, objects, pad); - functions.ball_creater_parabolic(lcd,objects,pad); - functions.collision_checker(lcd,objects); - objects.draw_base(lcd); - objects.cannon_position(pad); - objects.draw_cannon(lcd); - - game_check = functions.cannon_smash(lcd, objects); - lcd.refresh(); - wait(0.15); - - lcd.clear(); - objects.cannon_position(pad); - objects.draw_cannon(lcd); - lcd.refresh(); - wait(0.005); + while(1) { + //create the game + game(); } - printf("Score is: %d", functions.get_score()); } void initialise() @@ -67,3 +50,42 @@ } +void game() +{ + + Objects objects; + Functions functions; + while(game_check == false) { + lcd.clear(); + + objects.draw_shots(lcd,pad, true);// draws the shot + //creates the balls and clears the shots + functions.ball_creater_linear(lcd, objects, pad); + functions.ball_creater_parabolic(lcd,objects,pad); + objects.draw_shots(lcd,pad, true);//again draws the shots so they would be visible on the screen + functions.collision_checker(lcd,objects);//cheks for the collisions + + objects.draw_base(lcd);//draws the base of the game + objects.cannon_position(pad);//changes the cannon postion + objects.draw_cannon(lcd);//draws the cannon + game_check = functions.cannon_smash(lcd, objects); //checks if the cannon has been hit by a ball + lcd.refresh(); + wait(0.15); + + lcd.clear(); + //added this so the cannon moves faster than the balls + objects.cannon_position(pad);//eveluates the cannon position + objects.draw_cannon(lcd);//draws the cannon + lcd.refresh(); + wait(0.005); + } + //prints the the score and game over and the continue option + lcd.printString("Game over!", 15,2); + char buf_score[4]; + sprintf(buf_score,"%d",functions.get_score()); + lcd.printString("Score:",0,0); + lcd.printString(buf_score,36,0); + lcd.refresh(); + wait(2); + game_check = false; +}