Healthbar structure for a game?

Started by
6 comments, last by null; 8 years ago

Should I have the healthbar itself in the player class or make a separate class for it?

Sorry this isn't a really long question and it's not very specific or detailed, but I just had a quick question.

Advertisement

The Health Bar is nothing more then the visual of the Health of the player. So within the player class you would have the health value then the User interface would use that value to display the current health in the form of a health bar.

The health it's self can be in the player class.

However the "health bar" as in the visual format, should not be in the player class. It is a graphical element that scales the player's health from a range of 0.0 to 1.0, which is a percentage range.

This way the visual health bar is self contained and easier to debug.

visual components should be separate from game logic. They only need to be updated once, before rendering, while game objects may be updated several times during a single frame's logic. Mixing visual components with game logic at best leads to needlessly cluttered code, and more likely will lead to many unnecessary updates of the visual components. Store health with the player, have health logic with the player class (if there isnt a more appropriate one), but keep all logic and data specific to the healthbar (not needed for game logic) separate.

Oh alright. So the actual math and health logic could be in the player class (prior assumption) and the visuals in a separate class. Got it.

I could see how this would apply to other stuff, too.


I could see how this would apply to other stuff, too.

and thus the first step on the path to righteousness is taken.

keep thinking that way, it will take you far.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Oh alright. So the actual math and health logic could be in the player class (prior assumption) and the visuals in a separate class. Got it.

I could see how this would apply to other stuff, too.

Yeah. I had to make sure to specify because who knows what you might be thinking if we all just said "keep the healthbar separate".

Oh alright. So the actual math and health logic could be in the player class (prior assumption) and the visuals in a separate class. Got it.

I could see how this would apply to other stuff, too.

Yeah. I had to make sure to specify because who knows what you might be thinking if we all just said "keep the healthbar separate".

Well, that would have already kind of been implied in a way, but I get what you mean.

This topic is closed to new replies.

Advertisement