The title is a bit confusing, but I couln't think of how to explain my question in a short phrase. So here it is:
Whenever I'm writing game engines, wheter it's physics/tilebased etc, I always get to the point where I'm not sure how I should manage things. Should objectsentities in the world handle on their own, or should theirthere be some global system managing them?
Here's an easy example: Moving things. Should each object see the world around him (check for collisions) and move based on that.
[note, this is a tile based game where object move per tile, so I'm not using physics to move from tile to tile]
public class Actor : GameObject
{
private void MoveTo(Vector2 location)
{
if (world.getTile(location) != solid && world.objAtTile(location) == null)
{
Tweener.addTween(this, location);
}
}
}
Or should the movement of each object be handeled in the world, where the world checks everything?
public class Actor : GameObject
{
private void MoveTo(Vector2 location)
{
world.moveTo(location);
}
}
public class World
{
public void moveObject(GameObject obj, Vector2 location)
{
//called from object
if (getTile(location) != solid && objAtTile(location) == null)
{
Tweener.addTween(obj, location);
}
}
}
It doesn't really matter that much for this example I suppose, but I can see myself getting into trouble later on. Thanks in advance.