test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
Diff: main.cpp
- Revision:
- 31:17b4ee41bdc5
- Parent:
- 29:7784b098ef1d
- Child:
- 33:442498e281b1
--- 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(){