Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

Keep Bullet functionality in the Bullet class.

This just sounded like nails against a chalkboard to me:

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 the Velocity property.

Aaagh. D:

It's not the base Entity class' responsibility to check if it's a Bullet -- that's what method overriding is for!

I like to do this (and I know many other developers who do):

Have a base Entity class that defines properties like speed, position and id that all entities will need anyway, along with an Update(dt) method that computes its position in the next step. All entities (such as Bullet or Player) then inherit from Entity. If necessary, they override Update(dt) to add functionality such as consider keyboard input or resolve collisions, then probably call super to do the actual movement, so there's no code duplication.

Your Method 2 sounds just like this. I'd go with that.

Whether each entity should render itself or whether rendering should be done globally is a related consideration that has been discussed at lengthdiscussed at length. The answers there might be helpful too.

Keep Bullet functionality in the Bullet class.

This just sounded like nails against a chalkboard to me:

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 the Velocity property.

Aaagh. D:

It's not the base Entity class' responsibility to check if it's a Bullet -- that's what method overriding is for!

I like to do this (and I know many other developers who do):

Have a base Entity class that defines properties like speed, position and id that all entities will need anyway, along with an Update(dt) method that computes its position in the next step. All entities (such as Bullet or Player) then inherit from Entity. If necessary, they override Update(dt) to add functionality such as consider keyboard input or resolve collisions, then probably call super to do the actual movement, so there's no code duplication.

Your Method 2 sounds just like this. I'd go with that.

Whether each entity should render itself or whether rendering should be done globally is a related consideration that has been discussed at length. The answers there might be helpful too.

Keep Bullet functionality in the Bullet class.

This just sounded like nails against a chalkboard to me:

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 the Velocity property.

Aaagh. D:

It's not the base Entity class' responsibility to check if it's a Bullet -- that's what method overriding is for!

I like to do this (and I know many other developers who do):

Have a base Entity class that defines properties like speed, position and id that all entities will need anyway, along with an Update(dt) method that computes its position in the next step. All entities (such as Bullet or Player) then inherit from Entity. If necessary, they override Update(dt) to add functionality such as consider keyboard input or resolve collisions, then probably call super to do the actual movement, so there's no code duplication.

Your Method 2 sounds just like this. I'd go with that.

Whether each entity should render itself or whether rendering should be done globally is a related consideration that has been discussed at length. The answers there might be helpful too.

Source Link
Anko
  • 13.4k
  • 10
  • 55
  • 82

Keep Bullet functionality in the Bullet class.

This just sounded like nails against a chalkboard to me:

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 the Velocity property.

Aaagh. D:

It's not the base Entity class' responsibility to check if it's a Bullet -- that's what method overriding is for!

I like to do this (and I know many other developers who do):

Have a base Entity class that defines properties like speed, position and id that all entities will need anyway, along with an Update(dt) method that computes its position in the next step. All entities (such as Bullet or Player) then inherit from Entity. If necessary, they override Update(dt) to add functionality such as consider keyboard input or resolve collisions, then probably call super to do the actual movement, so there's no code duplication.

Your Method 2 sounds just like this. I'd go with that.

Whether each entity should render itself or whether rendering should be done globally is a related consideration that has been discussed at length. The answers there might be helpful too.