October 15th, 2013, 01:00 AM
Gamemap - Saving in SQL?
I am very sorry if I fail to describe this properly, if anything is unclear please tell me.
I want to work on a simple text based browser game. As a part of that game, players should be able to buy pieces of the map. This map is divided by lots. When a player clicks on a button called "map" or something like that, he should visually see the map and a designation whether it is owned or not.
Each lot has a number with X and Y coordinate, ranging between 001-001 to 999-999.
Now my main question is:
- What would be the most efficient way to store this information in a MySQL database? Especially with the coordinates. Just in 1 variable in a whole number "001001 - 999999" or in two seperate variables ("001-999" and "001-999")?
Thanks in advance for helping.
October 15th, 2013, 03:25 AM
Basically you should never store data that the database itself cannot process. And that's simply because it's way too slow to load the data into your application to process it.
It's difficult to work out if 3,3 is inside the shape defined by 1,1 - 1,10 - 10,10 - 10,1 unles your database has functionalitiy for that.
So my gut feeling is: use separate columns for the X and Y coordinates, unles you are using something like PostgreSQL which has functions for dealing with shapes and coordinates.
Comments on this post
October 15th, 2013, 03:40 AM
October 15th, 2013, 03:44 AM
October 15th, 2013, 03:57 AM
Thanks for the answers! What about this?
- A unique primary key as a "name" for a lot (3)
- A X-coordinate (001)
- A Y-coordinate (003)
- Additional information like who owns the lot (Player A)?
October 15th, 2013, 04:00 AM
" What about this?"
Depends, have a look at the link that r937 posted. If you can store your coordinates in a true spatial format that allows you to use geometric functions which is exactly what you'd want to be able to do.