Mapping systems

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
Gate
Posts: 25
Joined: Tue Jan 25, 2011 2:35 am

Mapping systems

Post by Gate »

Anyone got any projects/code for a mapping system?

Looking for any type of mapping system that people have come across just so i can play with the code and to help make a decision on the best approach for my system.

Cheers
My software never has bugs. It just develops random features.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Mapping systems

Post by Jackolantern »

There are actually a few things known as "mapping systems", ranging from animated, graphical maps that allow the player to walk around, to static maps where the player clicks on where they want to go, to systems for handling application data objects. Can you give us a bit more info on what you are after?
The indelible lord of tl;dr
User avatar
Gate
Posts: 25
Joined: Tue Jan 25, 2011 2:35 am

Re: Mapping systems

Post by Gate »

2d tile based mapping system, each tile would have a 'id' so when a user clicks on it, it moves the user to the location using javascript (javascripts setTimeout() function to manipulate the CSS) and sets the users location to the ID of the tile, then regenerates the map :)

I can think of two ways to achieve this system, one way is with quite a few querys and the other is just using one query and using filenames

Example:

The user clicks on a tile and the GET is:

http://www.somesite.com/nav.php?loc=25

This map would generate as follows

Map:

Code: Select all


================
= 34 = 35 = 36 =
================
= 24 = 25 = 26 =
================
= 14 = 15 = 16 =
================

The system would then first check to make sure the file exist for each of the numbers (example: 34.jpg exists) and then load that into the square complete with it's own link, if the file was not to exist throw an exception

Code: Select all

function exist($x) {
    if (!file_exists($x)) {
        throw new Exception("tile not present');
    }
    else return $x;
}

try {
    echo exist(34.jpg);
} catch (Exception $e) {
    echo 'Map Error: ',  $e->getMessage(), "\n";
}

My software never has bugs. It just develops random features.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Mapping systems

Post by Jackolantern »

Check Hall's Javascript tutorials and both of his named game tutorial series. I believe there is some info about mapping systems in those. Halls could give you a bit more info about where in the tutorials that would be next time he is on. He has also been working on a real-time mapping system and I believe he just released the code recently for it. I will have to look around to remember where it was, though.
The indelible lord of tl;dr
User avatar
Gate
Posts: 25
Joined: Tue Jan 25, 2011 2:35 am

Re: Mapping systems

Post by Gate »

I was looking for his mapping system but couldn't find it :)
My software never has bugs. It just develops random features.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Mapping systems

Post by Jackolantern »

I will probably have to wait until Halls gets on and can answer. I was already a capable programmer before I came across Halls' tutorial series, so I have not actually been through all of them, so I could not really point you to the specific videos.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Mapping systems

Post by hallsofvallhalla »

Urban realms, javascript tutorial, and forsaken sanctum all have click and move mapping systems...well actually they javascript one is wasd movement.
User avatar
Gate
Posts: 25
Joined: Tue Jan 25, 2011 2:35 am

Re: Mapping systems

Post by Gate »

I only came here from google for googling "php mapping system" or something similar.

I checked out your forsaken game halls and i have a few constructive criticisms :)

1) A query for each tile results in 9 querys per page just for the map! i think each page is pulling around 14+ querys, this would actually kill a small web server if you had a decent amount of players!

2) all your code is in procedural format, i checked around and found all of your code is like this, you should take a look at object orientated programming, its much better and more logical!

As for the mapping system i'm currently thinking about storing maps into 'sections', each section would contain 9 tiles which would be stored in a data format constructed by myself, this way you can store 9 tiles/1 section per row of database using an delimiter character between each section of data (in theory it can be any amount of tiles per section not just 9) i could then explode each section to create data segments and explode again to grab the data i need from each segment, finally finishing of with a foreach loop to go through each associate array and print out each tile, with it's link, img and own div.

Any thought's on my idea?
My software never has bugs. It just develops random features.
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Mapping systems

Post by PaxBritannia »

Gate wrote:each page is pulling around 14+ querys, this would actually kill a small web server if you had a decent amount of pl
My pages pull around 60 -> 200 queries per page all from separate databases. :D I haven't felt much effect performance wise.

If you plan on storing the tile data like that, then your database will flop. If you are on tile 06, and move to tile 07, how will you display that?

Code: Select all

    =====================
    = 01 = 02 = 03 = 04 =
    =====================
    = 05 = 06 = 07 = 08 =
    =====================
    = 09 = 10 = 11 = 12 =
    =====================
Your data overlaps. That means you will have to de-normalise your database and then do all sorts of other stuff. For a small game that doesn't need to scale, leave the information on the database layer. And even if it does need to scale, just scale the database.

If it overloads a shared server, then upgrade. Performance wise, 9 database queries is completely ok. If you have a problem with 9 queries, then compact it to one query for those nine spots and then handle it with an array.

pax.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Mapping systems

Post by hallsofvallhalla »

1) A query for each tile results in 9 querys per page just for the map! i think each page is pulling around 14+ querys, this would actually kill a small web server if you had a decent amount of players!
the queries are extremely small, and i have tested this with quite a few players with no performance hit. 14 small queries per page is not uncommon or considered large. In my new mapping system that i am fixing to release it shrinks the queries and data size.
2) all your code is in procedural format, i checked around and found all of your code is like this, you should take a look at object orientated programming, its much better and more logical!
Matter of opinion. What is better is what is easiest and works best for the coder. i know what OOP is but I am teaching people to code in my tutorials. I did not want to be like 99% of the tutorials out there and start out confusing the watcher. I start off slow and leave it up to the individual to learn beyond that.
As for the mapping system i'm currently thinking about storing maps into 'sections', each section would contain 9 tiles which would be stored in a data format constructed by myself, this way you can store 9 tiles/1 section per row of database using an delimiter character between each section of data (in theory it can be any amount of tiles per section not just 9) i could then explode each section to create data segments and explode again to grab the data i need from each segment, finally finishing of with a foreach loop to go through each associate array and print out each tile, with it's link, img and own div.
This is still easily attainable. I have also done this in some of my free code on these forums, I will try to find it
Basically make the data line numbers and use Split() to parse the data ...

so you would have a field called mapdata
example 1/6/3/1/3/6/4/9/1

you then split the data by "/"
you then parse the data with if statements

if mapdata[0] == "1" then tile = grass
if mapdata[1] == "2" then tile = house

ect..

then you can go a step further and add a field call link data that also holds links
if linkdata[0] == "1" then tilelink = "harvest.php"
if linkdata[1] == "2" then tilelink = "enterhouse.php"
Post Reply

Return to “General Development”