Managing collision detection in games

前端 未结 2 937
天涯浪人
天涯浪人 2021-02-02 14:40

So my question isn\'t about the how-to of collision detection, but is more of a broad \'what code should own collision detection\'. I\'ve written some game in the past(relativel

2条回答
  •  野性不改
    2021-02-02 15:29

    Questions specific to game development are best suited to https://gamedev.stackexchange.com/ by the way.

    So in the past I've had say an EnemyManager class

    I consider any SomethingManager class to be a sign that your code isn't organised accurately yet. For the most part, objects should manage themselves. If they can't, that implies there is some external information about them, and that information probably has a representation more specific than 'manager'. 3 game-specific examples might be GameWorld, GameRegion, or GameLevel. Enemies exist within a world, or a region of the world, or a current game level, so have such an object maintain its list of enemies.

    and likewise for the player projectiles had a PlayerProjectilesManager class

    Projectiles too would live in some sort of game space, a world, region, or level.

    By now, you can probably guess that one of the above objects can (and probably should) be responsible for owning all the above objects (perhaps indirectly, via a container class, but not via a heavyweight manager of any sort) and responsible for detecting collisions and resolving them.

提交回复
热议问题