Jump to content
  • Advertisement
Sign in to follow this  
bionic_atom

2D Matrix for game help please?

This topic is 4437 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

Hi, I am trying to make a space game, and my idea for the game is have this 2D matrix for the background map each dimension representing an x, and y, and having each objects x & y coordinate corespond to that 2D array, so I don't have arrays for each objects x&y I just have one. Is there any way? I was wanting the 2D map to generate some random coordinates for the beginning of the game depending on what level, and depending on what each array was in the 2d map matrix have certain game object rather it be enemies, rockets, health boxes, or stars be at that specific location. Can anyone give me any help, or tutorial on how to do this please? If I confused you, or you still have no idea of what I am looking for I can repost.

Share this post


Link to post
Share on other sites
Advertisement
If I understand correctly you want to somehow have a 2xM sized matrix, M being the number of objects in the scene? Basically you want to have an array of 2d position vectors for each object.

If that is so, I'd say it's not a very good idea. It would be sort of complicated and it would actually take more memory, as each object would also have to hold an index to it's position vector's place in the array. Giving each object it's own x and y coordinate makes more sense. Those x and y coords can be randomly assigned at the beginning of each level as well. And if you want you could have this array of 2d vectors of possible positions stored and at the start of the game you set each object's x and y value to the value at a random index of the array of 2d vectors.

If I completely mis-interpretted please tell me and I'll try to help again.

Share this post


Link to post
Share on other sites
Thanx, I'll give each objects their own x&y, and put them in the map, and have one integer just generate random numbers like crazy. Depending on that number, you'll have a different object. Thanx for the help, but when is the best time to use a 2D array, and how do they work?

Share this post


Link to post
Share on other sites
You might mean two things when you say "2D array"

1: An array with 2 elements representing two spatial dimensions, array = { x, y }; This would just be a 1D array with two elements. This would mostly be used whenever you want to use two values for something.
2: Or you might mean a more conventional 2d array, as in an array of arrays. An array of arrays is a matrix. There are lots and lots of different uses for matrices, you might want to look it up, I know there are plenty of good articles on matrix math and the sort here at this site.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!