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: ModeA/ModeA.cpp
- Revision:
- 20:d9987ed262c7
- Parent:
- 19:5e3ee84d9233
--- a/ModeA/ModeA.cpp Thu May 09 03:28:09 2019 +0000
+++ b/ModeA/ModeA.cpp Thu May 09 03:53:43 2019 +0000
@@ -17,7 +17,7 @@
y_position = 18; //y coordinate of square
speed = 1; // speed of square
gravity = 1; //gravitational force
- screen_width = 70; // pixel at which bar begins
+ screen_width = 70; // pixel at which bar begins (x coordinate)
bar_width = 10; // width of the bar
bar_speed = 2; // spped of the bar
score = 0; // score
@@ -67,7 +67,7 @@
}
speed = speed + gravity; //increment the speed by the value of gravity
- y_position = y_position + speed; // y coordinate changes with speed
+ y_position = y_position + speed; // as the square moves up, the position changes
wait(0.1);
//draw the 2 bars
@@ -77,7 +77,7 @@
lcd.drawRect(screen_width,48-size_bottom,bar_width,size_bottom,FILL_BLACK);
lcd.refresh();
- // if the bar and square have the same x coordinates and
+ // if the bar and square have the same x coordinates and
// their y coordinates don't intersect, score increases by 1
if ((screen_width == x_position) && (size_top < y_position)) {
score = score + 1;
@@ -88,16 +88,17 @@
wait(1.0);
}
- //if X is pressed random hights of the bars are genetrated
+ //if X is pressed random hights of the bars are genetrated
if ( pad.check_event(Gamepad::X_PRESSED) == true) {
srand(time(NULL));
size_top = rand() % 15;
srand(time(NULL));
size_bottom = rand() % 15;
-
}
//if the bar and ball collide, Game Over
+ //redifine all parameters to 0, clear screen
+ //press back to play again
if ((screen_width == x_position)&& (size_top > y_position)) {
lcd.clear();
lcd.printString("GAME OVER",6,2);
@@ -111,25 +112,12 @@
bar_width = 0;
size_top = 0;
size_bottom = 0;
-
-
-
wait(0.5);
-
}
-
- // if (score == 2) {
- // lcd.clear();
- // lcd.printString("Press Reset",6,2);
- // }
-
-
+ //as the bar travels to the left, its position changes
screen_width = screen_width - bar_speed;
wait(0.1);
-
-
-
}