test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
Revision 31:17b4ee41bdc5, committed 2016-12-12
- Comitter:
- th_mbed
- Date:
- Mon Dec 12 11:42:03 2016 +0000
- Parent:
- 30:f26dcbaa946d
- Child:
- 33:442498e281b1
- Commit message:
- add corrision
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
models.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Dec 12 11:17:22 2016 +0000 +++ b/main.cpp Mon Dec 12 11:42:03 2016 +0000 @@ -76,16 +76,23 @@ } } +int line_judge(int a, int b, int c, int d){ + //if corrision, return 1 + if(b < c){ + return 0; + }else if(d < a){ + return 0; + }else{ + return 1; + } +} + int corrision_judge(point p_person, point p_bullet){ printf("bullet x: %d, y: %d \n", p_bullet.x,p_bullet.y); printf("person x: %d, y: %d \n", p_person.x,p_person.y); - if((p_person.x + 2 >= p_bullet.x) && (p_person.x + 2 <= p_bullet.x + 5)){ - printf("aaaaa"); - if((p_person.y + 2 >= p_bullet.y + 1) && (p_person.y + 2 <= p_bullet.y + 4)){ - printf("gameover\n"); - } - } - return 0; + return (line_judge(p_person.x, p_person.x + PERSON_SIZE, p_bullet.x, p_bullet.x + BULLET_SIZE) + && line_judge(p_person.y, p_person.y + PERSON_SIZE, p_bullet.y - 1, p_bullet.x - 4)); + } int main(){
--- a/models.h Mon Dec 12 11:17:22 2016 +0000 +++ b/models.h Mon Dec 12 11:42:03 2016 +0000 @@ -23,6 +23,7 @@ #define GAME_OVER -1 //Bullet params +#define BULLET_SIZE 5 //bullet is 5*5 #define HIGH_SPEED 5 #define NOMAL_SOEED 3 #define LOW_SPEED 1