Sign in to follow this  
KevArnold

2d game boundaries

Recommended Posts

I am building a 2d game with movement similar to Double Dragon and wondering what others thought a good way to handle defining the level boundaries would be. My first plan was to make a list of linked polygons that any entity could move in but then started to think maybe it would be better to just create blocking entities. All entities could then go anywhere by default but would limited by invisible wall entities. The reason I like the second idea more now is because I could then use one system of collision for all entities instead of having to test against a list of boundaries during movement and then collisions with other entities later. The only reason I am hesitant to just leave the first idea was I was able to group objects based on the bounding box they were in but I'm not sure that was buying me anything. Sorry if this seems to be an amateurish question but this is the first full game I have built so I have yet to realize all the pitfalls and am worried if I let this go to far my engine may be fundamentally broken.

Share this post


Link to post
Share on other sites
I find blocking entities to be the most intuitive solution.

Depending on your collision detection algorithm, the only real drawback of this method is that of having to deal with fast-moving objects potentially passing "through" these entities.

Share this post


Link to post
Share on other sites
I typically find the structure that provides me the best of both worlds something more like this.

class Object;
class Entity : public Object; //Entity IS An Object
class Boundry : public Object; //Boundries are NOT Entities.

The collision procedure checks Object -> Object. This gives you the benefit of having one collision system like you wanted, Object->Object collision but also to have entities as a separate 'type'. I look at entities as the characters in the game, not just anything. So a coffee pot, even if it can make coffee, be moved from one counter to another - it is an object. (Unless of course you have a game where unusual objects are characters...) An entity/character can walk up and use or move the coffee pot object.




Finally I leave with this:

Quote:
This is the first full game I have built so I have yet to realize all the pitfalls and am worried if I let this go to far my engine may be fundamentally broken.


I learned from trial and error. i am not saying this is the best way to learn for everyone, though trying new things out, watching it fail - and understanding why the design failed was among the largest motivations for me. Knowing why something doesn't work is as important (in my opinion) as knowing why something does. So my advice here, is keep trying things. If it doesn't work, you learn something - and you might even learn when that technique _would_ work, even if it doesn't on the current project. Of course for something more than a hobby/education project, trial and error may not be suitable.

I hope that helps, happy programming.

Share this post


Link to post
Share on other sites
Hey blackbird04217,
Quote:

class Object;
class Entity : public Object; //Entity IS An Object
class Boundry : public Object; //Boundries are NOT Entities.


I like this. If I could expound a bit to see if I understand you. An Entity can be considered an "Actor" where there may be animations applied like arm raising gun to eye level and walking. Where a coffee pot being an Object not an Entity implies it isn't an Actor, its just a thing that has a position in the world and can be movable or not.

Steve

Share this post


Link to post
Share on other sites
Exactly that, yes. Although animations may/may not apply to the Object as well. I think you are on the right track that Entities/Actors can do/act upon things, while objects might, but in a much different way. Hmm, I am finding it hard to describe the actual separation, but I distinguish it between the player, enemies, npcs - "characters" of the game would be considered Entities/Actors while the CoffeePot, Puddle, Door or Tree would be considered objects. Even if the door can play an "open/close" animation, or a puddle can affect a robots electronics, it does so differently than the robot collecting rocks. (In this situation the robot is an Entity, and the rocks and puddle are Objects in the world.)

Hope that clarifies it all, happy programming.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this