Sign in to follow this  
Net-Ninja

Coordinate system

Recommended Posts

What is the best way to make a coordinate system on a small 2D enviroment. Im making a small virtual pet simulation and i want my "Pet" to be able to move around. Im thinking of a grid size of 1000x1000 and with a few objects that the pet can interact with. the two models I'm torn between is if the coordinates is stored by the objects themselves and then go through them in sequens and se if their coordinates match the coordinates I'm looking for. The other is if I make a 2D vactor with pointers, pointing to the diffrent objects. I'm working in C++, don't know if any of these approaches are any good. Please lend me you guidance.

Share this post


Link to post
Share on other sites
I am not sure the scope of your game but you should be considering a few things.

Personally, I am using essentially a grid full of 'tiles' which hold pointers to whatever objects can walk on them, but that works well for me because movement and such is all tile based.

Can objects be at intermediate values such as 500.52, 301.29 or is it whole numbers only where the object 'snaps' to the next point?

I think the model (if I am understanding it) where each 'pet' has a pointer to every object probably wont work too well because the 'pet' shouldn't keep track of every object, even those way too far away. Also, if you plan for expansion (i.e., a bigger world) it would begin to get more difficult to maintain.

Share this post


Link to post
Share on other sites
Storing positions per-object should work fine, really. Once you start working with large numbers of objects, you may want to look into some kind of space partitioning, such as a grid or quadtree, but you probably won't need that for now.

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