Page 1 of 1
Mapping systems
Posted: Sat Jan 29, 2011 4:47 am
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
Re: Mapping systems
Posted: Sat Jan 29, 2011 5:05 am
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?
Re: Mapping systems
Posted: Sat Jan 29, 2011 5:23 am
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";
}
Re: Mapping systems
Posted: Sat Jan 29, 2011 5:45 am
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.
Re: Mapping systems
Posted: Mon Jan 31, 2011 9:42 am
by Gate
I was looking for his mapping system but couldn't find it

Re: Mapping systems
Posted: Mon Jan 31, 2011 6:24 pm
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.
Re: Mapping systems
Posted: Mon Jan 31, 2011 11:18 pm
by hallsofvallhalla
Urban realms, javascript tutorial, and forsaken sanctum all have click and move mapping systems...well actually they javascript one is wasd movement.
Re: Mapping systems
Posted: Tue Feb 01, 2011 11:09 am
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?
Re: Mapping systems
Posted: Tue Feb 01, 2011 11:58 am
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.

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.
Re: Mapping systems
Posted: Tue Feb 01, 2011 2:15 pm
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"