I'm stuck constructing a class hierarchyfor ideas on classes in game programming. This is probably more of an opinion based question. I'm looking for information that is proving hard to find on the internet.
Say I have classesa class called Bullet
andor Mob
. (The names are unimportant; they're, the name doesn't really matter it's just examplesan example.) With this, there are two options I can think of two approaches:.
Centralised: Classes are Have the class purely as a way to storeof storing data and nothing else. So I could have, for example, properties such as
EntityID
,Velocity
,HealthPoints
,NumberOfAttacks
properties. SomeI would then have some other part of the game could then iteratewhich iterates through every instance of every object and update itsthe properties from there.Example Example: During such anthe iteration, depending on theit checks what type of object it is, such as (
Bullet
etc.), its movement is handled differently. (Bullet
s fly forwardOnce it has checked this, it will calculate where the bullet should move to next based upon theMobVelocity
AI is applied, etcproperty.)Decentralised: Each class contains its own Or, have the same properties and alsowithin the class, but also have all the code for updating itsit's own properties in there too.
Example Example: The
Bullet
bullet has some kind ofUpdate()
method which get's called periodically by the game engine calls periodically. ThisUpdate
method would then take it upon itself to calculate athe newVelocity
, and update it's position, etc.Some combination of the both? Something else I haven't thought of?
Are there combinations of these or other alternatives I haven't thought of?
Which of these options is the more commonly used approach in game programming? What are the benefits or disadvantages of these different methods?
Have I got it all completely wrong?