Okay, I am adding the new bomb-hit detection to my Kaboom! game, and I am just wanting to make sure it makes sense and is the right was to do hit detection for the game. I also searched and nothing really went into sprite hit detection so I am going to hope somebody else can fall back on this topic later on when they run into the same thing. This will only focus on Y hit detection, but technically, the X position hit detection would function the same exact way. Okay, here's the way I had my program going to run in this basic order:
Get bomb Y location on the screen.
Add (bomb height-1) to the bombs.
Subtract with the location of the Bomb Y after the addition to the Y location of the paddles on the screen.
If Carry is set, that means the bomb would be in the Y-location range to maybe hit the paddle, so we'd subtract to make sure it isn't past it with (Paddle hit height+Bomb Height)
If Carry is clear, bomb does hit. If not, it doesn't hit the paddle since it would be past it.
Here's some illustrations below:
The paddle hit box is $40 big in this example. The bomb is $10 tall in this example, I hope you guys can okay on this with these images, never illustrated an idea before. :/
Box is outside of zone, right next to top bucket/paddle.
Add 15, it will be one less then the paddle Y position, so when subtracted the carry will be cleared.
Box is hitting paddle by one pixel.
Add bomb height-1 (15). It will be equal to the value of the top paddle so when subtracted, Carry will stay set, and also equal code will be set, although that doesn't matter here.
Bomb is hitting the last pixel in the paddle.
So that means when we add Bomb height-1 (15), it won't be in range of the hit box we set up for the bomb. So to fix that, we add the height of the bomb-1 to the bottom of the paddles hit box. The grey box represents that.
Does this all make sense like it's supposed to happen for the hit detection? I also hope somebody else finds this useful for hit detection, no topics that I could browse to mentioned anything like this for a while so I hope this helps somebody else, too.
Well thanks for looking, tell me what you think.
Get bomb Y location on the screen.
Add (bomb height-1) to the bombs.
Subtract with the location of the Bomb Y after the addition to the Y location of the paddles on the screen.
If Carry is set, that means the bomb would be in the Y-location range to maybe hit the paddle, so we'd subtract to make sure it isn't past it with (Paddle hit height+Bomb Height)
If Carry is clear, bomb does hit. If not, it doesn't hit the paddle since it would be past it.
Here's some illustrations below:
The paddle hit box is $40 big in this example. The bomb is $10 tall in this example, I hope you guys can okay on this with these images, never illustrated an idea before. :/
Box is outside of zone, right next to top bucket/paddle.
Add 15, it will be one less then the paddle Y position, so when subtracted the carry will be cleared.
Box is hitting paddle by one pixel.
Add bomb height-1 (15). It will be equal to the value of the top paddle so when subtracted, Carry will stay set, and also equal code will be set, although that doesn't matter here.
Bomb is hitting the last pixel in the paddle.
So that means when we add Bomb height-1 (15), it won't be in range of the hit box we set up for the bomb. So to fix that, we add the height of the bomb-1 to the bottom of the paddles hit box. The grey box represents that.
Does this all make sense like it's supposed to happen for the hit detection? I also hope somebody else finds this useful for hit detection, no topics that I could browse to mentioned anything like this for a while so I hope this helps somebody else, too.
Well thanks for looking, tell me what you think.