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
Revision 10:e81aacef805b, committed 2018-05-06
- Comitter:
- el16a2t
- Date:
- Sun May 06 21:45:41 2018 +0000
- Parent:
- 9:514c6f98ca5a
- Child:
- 11:4907e6e7e855
- Commit message:
- randomised when the next car spawns down the screen by using a range of values in an array that selects at which y value the next car spawns
Changed in this revision
| engine/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| engine/main.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/engine/main.cpp Sun May 06 20:18:10 2018 +0000
+++ b/engine/main.cpp Sun May 06 21:45:41 2018 +0000
@@ -53,7 +53,7 @@
x_car = 4;
y_car = 0;
x_car2 = 24;
- y_car2 = -40;
+ y_car2 = -50;
//(re)set score to 0
@@ -83,7 +83,10 @@
int arr[3] = {4, 24, 44}; //array corresponding to the x values of the 3 lanes of traffic
int random_number = arr[Index]; //pick number at Index value from array, assign to random_number
printf ("random_number = %d\n", random_number);
+
+
+
lcd.clear();
lcd.drawSprite(x_player,y_player,20,15,(int*) player); //print the player sprite
@@ -127,13 +130,19 @@
// re-generate cars continously
- if (y_car2 == 50) {
+
+ int YIndex = rand() % 4;
+ int array[5] = {50, 55, 60, 65, 70};
+ int nextCar = array[YIndex];
+
+ if (y_car2 == nextCar) {
x_car2 = random_number;
y_car2 = -24;
- }
- if (y_car == 50) {
+ }
+
+ if (y_car == nextCar) {
x_car = random_number;
y_car = -24;
@@ -212,17 +221,17 @@
{
printf("reached gameover\n");
if (lives ==0){
-
while ( pad.check_event(Gamepad::START_PRESSED) == false) {
printf("gameoverlives=%d\n", lives);
lcd.clear();
- lcd.refresh();
+
lcd.printString(str,64,1);
lcd.printString ("GAME OVER", 3,1);
lcd.printString ("PRESS START", 3,3);
+ lcd.refresh();
wait(0.2);
}
init ();
--- a/engine/main.h Sun May 06 20:18:10 2018 +0000 +++ b/engine/main.h Sun May 06 21:45:41 2018 +0000 @@ -10,4 +10,5 @@ int difficulty; char str[14]; int lives; -int Index; \ No newline at end of file +int Index; +int YIndex; \ No newline at end of file