Sorry, I know my questions have been appearing a lot lately - but I think this COULD be the last one for a little while.
I just wanted to know if this structure for damage was good. So, I have a main class, a UI/Graphics class, a player class, and a healthbar class. In my player class, the logic for the health, etc. is applied, and a visual delineation of that logic is displayed in the healthbar class.
If one of the player presses 'j' as the two players are intersecting, damage is done. Same thing with 'f' for the other player. How this works, is in my UI class, I check if the player rectangle belonging the the instance of my player (or my player object, if you will) is intersecting with the player rectangle belonging to the other player.
It goes a little something like this:
NOTE: p1 is my player object, and the '.player' part is referencing the rectangle which my player is drawn to.
This is in my UI/Graphics class:
if(p1.player.intersects(p2.player) {
Player.damageDetected = true //this makes a boolean I have in my player class true, which allows the players to do damage to each other when intersecting and when the appropriate key is pressed
}else{
Player.damageDetected = false;
}
Then in my player class, in the area where key presses are handled, I have something like this:
NOTE: 'k' is the keycode, and e is the keyevent
if(k == e.VK_J && damageDetected = true) {
do damage, etc, etc.
}
My question is: Is this structure correct? This isn't EXACTLY how the code looks, but it's pretty much the same idea.
Thank you!