![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
Diff: main.cpp
- Revision:
- 33:442498e281b1
- Parent:
- 32:abb3086c210d
- Parent:
- 31:17b4ee41bdc5
- Child:
- 36:b88fa8ff0be9
- Child:
- 37:f5d98f22b6bd
--- a/main.cpp Mon Dec 12 11:48:19 2016 +0000 +++ b/main.cpp Mon Dec 12 11:50:02 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\n"); - 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(){