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: CrossyChicken/CrossyChicken.cpp
- Revision:
- 6:e285eaf8bdcd
- Parent:
- 5:6e3afee7eac3
- Child:
- 7:1dce07fd0867
--- a/CrossyChicken/CrossyChicken.cpp Thu May 07 05:35:50 2020 +0000
+++ b/CrossyChicken/CrossyChicken.cpp Mon May 11 21:16:12 2020 +0000
@@ -17,7 +17,7 @@
//make one object of chicken
//use this to move around the lcd
-Chicken chicken((84/2)-4/2, 48-4, 4);
+Chicken chicken((84/2)-grid/2, 48-grid, grid);
Chicken *chickenptr= &chicken;
//there will be multiple cars
@@ -62,7 +62,7 @@
for(int i = 0; i < 2; i++){
moveCar(&firstLane[i], 2, (-2)); // change x position (moving)
- collision(&firstLane[i]);
+ // collision(&firstLane[i]);
}
for(int x = 0; x < 2; x++){
@@ -71,14 +71,18 @@
for(int t = 0; t < 3; t++){
moveCar(&thirdLane[t], 2, 1);
- collision(&thirdLane[t]);
+ //collision(&thirdLane[t]);
}
graphics.showCar(firstLane);
graphics.showCar(secondLane);
graphics.showCar(thirdLane);
-
+
+ for(int t = 0; t < 3; t++){
+ collision(&thirdLane[t]);
+ }
+
graphics.refresh();
wait_ms(100);
}
@@ -109,6 +113,11 @@
//increment the top side by a value of grid sizw
chicken.y += yWay * 4;
+ chicken.left_side = chicken.x;
+ chicken.right_side = grid + chicken.x;
+ chicken.up = chicken.y;
+ chicken.down = grid + chicken.y;
+
//display the new state of the chicken
graphics.showChicken();
@@ -131,6 +140,8 @@
void CrossyChicken::collision(Car *car){
float other_bottom = car->vehicle.height + car->vehicle.y;
+
+
if(!(chicken.up >= other_bottom ||
(chicken.right_side <= car->vehicle.x) ||
(chicken.down <= car->vehicle.y) ||