#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Location
    The Netherlands
    Posts
    12
    Rep Power
    0

    Gamemap - Saving in SQL?


    Hello,

    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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    158
    Rep Power
    10
    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

    • RS496 agrees : Great help
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,026
    Rep Power
    4210
    Originally Posted by Vinny42
    ...unles you are using something like PostgreSQL which has functions for dealing with shapes and coordinates.
    you mean like this?

    http://dev.mysql.com/doc/refman/5.0/...s-polygon.html

    r937.com | rudy.ca
    please visit Simply SQL and buy my book
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    158
    Rep Power
    10
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Location
    The Netherlands
    Posts
    12
    Rep Power
    0
    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)?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    158
    Rep Power
    10
    " 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.

IMN logo majestic logo threadwatch logo seochat tools logo