Skip to main content

The fireball is a 'box' of width and height 200. And it's at a given position. Add a rectangle (Rectangle boundingRect = new Rectangle(position.X, position.Y, 200, 200);

Rectangle boundingRect = new Rectangle(position.X, position.Y, 200, 200); 

to your fireball class.

Make sure to update the rectangle with the new position of the fireball every frame (so in the fireball's update or draw method)

Do the same thing for your player class.

Now you can check if the fireball has hit the player like this in your game's update method: if(fireball.boundingRect.Intersects(player.boundingRect)) { //hit }

if(fireball.boundingRect.Intersects(player.boundingRect)) {
    //hit
}

The fireball is a 'box' of width and height 200. And it's at a given position. Add a rectangle (Rectangle boundingRect = new Rectangle(position.X, position.Y, 200, 200); to your fireball class.

Make sure to update the rectangle with the new position of the fireball every frame (so in the fireball's update or draw method)

Do the same thing for your player class.

Now you can check if the fireball has hit the player like this in your game's update method: if(fireball.boundingRect.Intersects(player.boundingRect)) { //hit }

The fireball is a 'box' of width and height 200. And it's at a given position. Add a rectangle

Rectangle boundingRect = new Rectangle(position.X, position.Y, 200, 200); 

to your fireball class.

Make sure to update the rectangle with the new position of the fireball every frame (so in the fireball's update or draw method)

Do the same thing for your player class.

Now you can check if the fireball has hit the player like this in your game's update method:

if(fireball.boundingRect.Intersects(player.boundingRect)) {
    //hit
}
Source Link
Roy T.
  • 10.2k
  • 36
  • 57

The fireball is a 'box' of width and height 200. And it's at a given position. Add a rectangle (Rectangle boundingRect = new Rectangle(position.X, position.Y, 200, 200); to your fireball class.

Make sure to update the rectangle with the new position of the fireball every frame (so in the fireball's update or draw method)

Do the same thing for your player class.

Now you can check if the fireball has hit the player like this in your game's update method: if(fireball.boundingRect.Intersects(player.boundingRect)) { //hit }