# Thread: collision not taking affect

1. ## collision not taking affect

When the bullet comes in contact with the enemy nothing happens, why isn't it?

this is my code.

Code:
```if(collision_x(shoot.coll, enemy.coll) == 2){
enemy.alive = false;
}```
the is the collision_x function
Code:
```int collision_x(SDL_Rect A, SDL_Rect B){
if(A.x <= B.w){
return 1;
}
if(A.w >= B.x){
return 2;
}
return 0;
}```
thank you

2. You are only checking if A's x position is lesser than the width of B and vice versa. For proper colission checking in one axis you need to check some other parameters. Try it out with a pen and paper first.

3. Try to test what isn't true as opposed to what is for collision.

4. Comparing absolute and relative values makes no sense.
Simply substituting distance with time, those tests are like comparing if 4/06/2010 is less than or equal to 13 days.

5. Bounding box collision detection
Code:
```bool CCollisionDetection::DetectBoundingBox(const CSprite &spriteOne, const CSprite &spriteTwo)
{
//
//Grab the bounds of the sprites
//
const BoundingBox &boundOne = spriteOne.Bounds();
const BoundingBox &boundTwo = spriteTwo.Bounds();

//if the left is greater than the right no collison
if(boundOne.left > boundTwo.right){
return false;
}//if

//if the right is less than the left no collision
if(boundOne.right < boundTwo.left){
return false;
}//if

//if the bottom is less than the top no collision
if(boundOne.bottom < boundTwo.top){
return false;
}//if

//if the top is greater than the bottom no collision
if(boundOne.top > boundTwo.bottom){
return false;
}//if

//if all the checks failed that means they are colliding
return true;
}```
BoundingBox is just a simple struct defined as:
Code:
```struct BoundingBox
{
int top;
int bottom;
int left;
int right;
};```