Skip to main content
2 of 6
added 146 characters in body
Manji
  • 79
  • 8

Collision Error

Hi I am making a game for android. I am having trouble with collision detection part of the game. I am using touch events to fire the gun as you will see in the video . When ever the user touches (represented by clicks in the video)the bullet appears and kills random sprites. As you can see it never touches the sprites it kills or kill the sprites it does touch.
My Question is how do I fix it, so that the sprite dies when the bullet hits it.
Any help is greatly appreciated and Thanks in advance.

Collision Code snippet:
//Handles Collision private void CheckCollisions(){
synchronized(mSurfaceHolder){ for (int i = sprites.size() - 1; i >= 0; i--){ Sprite sprite = sprites.get(i); if(sprite.isCollision(bullet)){ sprites.remove(sprite); mScore++; if(sprites.size() == 0){ mLevel = mLevel +1; currentLevel++; initLevel();
} break; }
} } }

Sprite Class Code Snippet
//bounding box leftbottom int left ; int right ; int top ; int bottom ; public boolean isCollision(Beam other) { // TODO Auto-generated method stub
if(this.left>other.right || other.left<other.right)return false; if(this.bottom>other.top || other.bottom<other.top)return false;

        return true;
    }

Side Note: The Icon image represents the bullet and yes I know the graphics are crappy but I am now concerned with them at all right now. I am more concerned about getting the codding right first.
[Game Play][3]
Manji
  • 79
  • 8