I'm stuck for 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 a class called Bullet
or Mob
, the name doesn't really matter it's just an example. With this, there are two options I can think of.
Have the class purely as a way of storing data and nothing else. So I could have, for example, properties such as
EntityID
,Velocity
,HealthPoints
,NumberOfAttacks
. I would then have some other part of the game which iterates through every instance of every object and update the properties from there.Example: During the iteration, it checks what type of object it is, such as
Bullet
etc. Once it has checked this, it will calculate where the bullet should move to next based upon theVelocity
property.Or, have the same properties within the class, but also have all the code for updating it's own properties in there too. Example: The bullet has some kind of
Update()
method which get's called periodically by the game engine. ThisUpdate
method would then take it upon itself to calculate the newVelocity
and update it's position etc.Some combination of the both? Something else 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?