skycoin / cx-game

Game Prototype
7 stars 15 forks source link

Remove WorldCollider Interface #573

Open ted537 opened 2 years ago

ted537 commented 2 years ago

The WorldCollider interface was added because physics code needs to be able to check for collisions on the World. We cannot pass a World to the physics engine due to a circular import.

    imports github.com/skycoin/cx-game/game
    imports github.com/skycoin/cx-game/components
    imports github.com/skycoin/cx-game/components/agents
    imports github.com/skycoin/cx-game/physics
    imports github.com/skycoin/cx-game/world
    imports github.com/skycoin/cx-game/components/agents: import cycle not allowed
ted537 commented 2 years ago

Agents need to access physics. Physics needs to access World. World needs to access Agents.

These dependencies must be altered if we wish to resolve the circular imports and eliminate the WorldCollider interface.

One possible solution would be to separate the World struct from the methods that operate on the World struct. The package containing the World struct would be inherited everywhere and the package containing the World methods would only be imported by high-level packages like game/.