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
Obstacles/Car.cpp@3:648c9d5001be, 2020-05-04 (annotated)
- Committer:
- el19tb
- Date:
- Mon May 04 03:55:03 2020 +0000
- Revision:
- 3:648c9d5001be
- Child:
- 4:aae7f8d4ab78
added a lane system with cars so the chicken can avoid
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el19tb | 3:648c9d5001be | 1 | #include "Car.h" |
| el19tb | 3:648c9d5001be | 2 | #include "CrossyChicken.h" |
| el19tb | 3:648c9d5001be | 3 | |
| el19tb | 3:648c9d5001be | 4 | Car::Car(){ |
| el19tb | 3:648c9d5001be | 5 | this->x = 8; |
| el19tb | 3:648c9d5001be | 6 | this->y = 4; |
| el19tb | 3:648c9d5001be | 7 | this->width= 8; |
| el19tb | 3:648c9d5001be | 8 | this->height = 8; |
| el19tb | 3:648c9d5001be | 9 | |
| el19tb | 3:648c9d5001be | 10 | left = x; |
| el19tb | 3:648c9d5001be | 11 | right = width + x; |
| el19tb | 3:648c9d5001be | 12 | top = y; |
| el19tb | 3:648c9d5001be | 13 | bottom = height + y; |
| el19tb | 3:648c9d5001be | 14 | } |
| el19tb | 3:648c9d5001be | 15 | |
| el19tb | 3:648c9d5001be | 16 | void Car::update(){ |
| el19tb | 3:648c9d5001be | 17 | left += 1.5; |
| el19tb | 3:648c9d5001be | 18 | } |
| el19tb | 3:648c9d5001be | 19 | |
| el19tb | 3:648c9d5001be | 20 | void Car::stop(){ |
| el19tb | 3:648c9d5001be | 21 | bottom = 40; |
| el19tb | 3:648c9d5001be | 22 | |
| el19tb | 3:648c9d5001be | 23 | } |
| el19tb | 3:648c9d5001be | 24 | |
| el19tb | 3:648c9d5001be | 25 | bool Car::collision(Chicken *chicken){ |
| el19tb | 3:648c9d5001be | 26 | left = x; |
| el19tb | 3:648c9d5001be | 27 | right = width + x; |
| el19tb | 3:648c9d5001be | 28 | top = y; |
| el19tb | 3:648c9d5001be | 29 | bottom = height + y; |
| el19tb | 3:648c9d5001be | 30 | |
| el19tb | 3:648c9d5001be | 31 | //set up the rectangle of the other square |
| el19tb | 3:648c9d5001be | 32 | int otherLeft = chicken->x; |
| el19tb | 3:648c9d5001be | 33 | int otherRight = chicken->x + chicken->width; |
| el19tb | 3:648c9d5001be | 34 | int otherTop = chicken->y; |
| el19tb | 3:648c9d5001be | 35 | int otherBottom = chicken->y + chicken->height; |
| el19tb | 3:648c9d5001be | 36 | |
| el19tb | 3:648c9d5001be | 37 | //return the inverse of the result |
| el19tb | 3:648c9d5001be | 38 | return !(left >= otherRight || right <= otherLeft |
| el19tb | 3:648c9d5001be | 39 | || bottom <= otherTop || top >= otherBottom); |
| el19tb | 3:648c9d5001be | 40 | } |
| el19tb | 3:648c9d5001be | 41 | |
| el19tb | 3:648c9d5001be | 42 | |
| el19tb | 3:648c9d5001be | 43 |