• Advertisement
Sign in to follow this  

Where to place what

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a class called level that contains: leveldata (where do i have ground) static objects and now my player and enemies i am trying to decide where to have the code that makes my player and enemies drop down to the ground. Should i place it in my player class or in my level class. If it is in my player class i have to query the level if i have hit the ground and then stop. If i use the level class i will have to send messages to the players and enemies. What is the smartest thing here?

Share this post


Link to post
Share on other sites
Advertisement
As I just said in another thread, encapsulation is important. Here you are dealing with the separate issues of collision detection, player movement, physics, and level representation.

How to organize all this isn't always trivial - there are a variety of approaches you can take.

In your case, though, I would start by making physics and collision response a behavior of the player class (or perhaps a more general class higher up the chain). Or, you could make it part of a physics object that the player 'knows' or 'owns' rather than 'is'. These are the sorts of design decisions you have to make in an object-oriented structure.

So I would suggest putting the code in your player class, and querying the level for collision information. But there are many ways you could do it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement