Ben Evans University Second Year Project. Game Called Defender.
Embed:
(wiki syntax)
Show/hide line numbers
CheckCollision.cpp
00001 #include "CheckCollision.h" 00002 00003 bool CheckCollision::check_collision(Weapons bullet) { 00004 bool collision = false; 00005 Vector2D bullet_pos = bullet.get_pos(); 00006 // printf ("Collision 1 = %d\n", collision); 00007 00008 // Checks collision if bullet is going in east direction 00009 if (bullet.get_direction()) { 00010 // int bullet_pos_twox = bullet_pos.x; 00011 // int bullet_pos_twoy = bullet_pos.y; 00012 // printf ("alien x = %d, bullet x = %d\n", position_x_,bullet_pos_twox); 00013 // printf ("alien y = %d, bullet y = %d\n", position_y_,bullet_pos_twoy); 00014 00015 // Collision if the bullet is inside of the xy ranges of sprite drawing 00016 if ((bullet_pos.x + 1) >= position_x_ && 00017 (bullet_pos.x + 1) <= (position_x_ + sprite_x_length ) && 00018 position_y_ <= bullet_pos.y && 00019 bullet_pos.y <= (position_y_ + sprite_y_length )) { 00020 collision = true; 00021 } 00022 00023 // printf ("Collision 2 = %d\n", collision); 00024 00025 // Checks collision if bullet is going in west direction 00026 }else if (!bullet.get_direction()) { 00027 00028 if (bullet_pos.x <= (position_x_ + sprite_x_length ) && 00029 bullet_pos.x >= position_x_ && 00030 position_y_ <= bullet_pos.y && 00031 bullet_pos.y <= (position_y_ + sprite_y_length )) { 00032 collision = true; 00033 } 00034 00035 // printf ("Collision 3 = %d\n", collision); 00036 } 00037 00038 // printf ("Collision 4 = %d\n", collision); 00039 return collision; 00040 } 00041
Generated on Fri Aug 5 2022 06:55:07 by
1.7.2