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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 7:f61ac963eb07
- Parent:
- 6:b393cfe4e0a7
- Child:
- 8:5f0190b282f7
--- a/main.cpp Thu May 28 01:11:47 2020 +0000
+++ b/main.cpp Fri May 29 02:55:37 2020 +0000
@@ -8,10 +8,10 @@
# include "tests.h"
#endif
-#define PADDLE_WIDTH 2
-#define PADDLE_HEIGHT 8
-#define BALL_SIZE 2
-#define BALL_SPEED 3
+#define BOARD_WIDTH 2
+#define BOARD_LENGTH 8
+#define BULLET_SIZE 2
+#define BULLET_SPEED 3
/////////////// structs /////////////////
struct UserInput {
@@ -33,52 +33,51 @@
{
#ifdef WITH_TESTING
int number_of_failures = run_all_tests();
-
+ //test part
if(number_of_failures > 0) return number_of_failures;
#endif
- int fps = 6; // frames per second
- init(); // initialise and then display welcome screen...
- welcome(); // waiting for the user to start
- //lcd.drawRect(0,0,84,24,FILL_BLACK);
- render(); // first draw the initial frame
- //lcd.drawRect(0,0,84,24,FILL_BLACK);
- wait(1.0f/fps); // and wait for one frame period
-
- //lcd.drawRect(0,0,84,24,FILL_BLACK);
- // game loop - read input, update the game state and render the display
- while (1) {
- // pong.read_input(pad);
- // pong.read_input(pad);
- touch.read_input(pad);
- touch.update(pad);
+ int fps = 6; // frames per second
+ init(); ` // initialise
+ welcome(); // welcome screen for user to start
+ render(); // first draw the initial frame
+ wait(1.0f/fps); // and wait for one frame period
+ pad.leds_on(); //turn on all leds as 'lives' showing
+
+
+ while (1) //while loop, execute reading, updating, drawing,juding part frequentrly
+ {
+ touch.reading(pad);
+ touch.update(pad,lcd);
render();
- //lcd.drawRect(0,0,84,24,FILL_BLACK);
+ if(touch._leds>=6)
+ {
+ break; // if all lives finish , you will lsot game
+ }
wait(1.0f/fps);
}
+ lcd.init();
+ pad.init();
+ lcd.printString(" You fail ",0,1);
+ lcd.printString(" Press reset ",0,4); // the reminder of game lost
+ lcd.refresh(); //function to refresh the display
}
// initialies all classes and libraries
void init()
{
- // need to initialise LCD and Gamepad
lcd.init();
pad.init();
-
- // initialise the game with correct ball and paddle sizes
- touch.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED);
-
+ touch.init(BOARD_WIDTH,BOARD_LENGTH,BULLET_SIZE,BULLET_SPEED,lcd);
}
-
-// this function draws each frame on the LCD
+//clearing record before and drawing frames
void render()
{
- // clear screen, re-draw and refresh
+
lcd.clear();
touch.draw(lcd);
lcd.refresh();
}
-
-// simple splash screen displayed on start-up
+//welcome screen
void welcome() {
lcd.printString(" touch! ",0,1);