Page 1 of 1

Map design, how?

Posted: Sun Jan 10, 2010 12:59 am
by RolsenRoyce
I have been googling on how to make a map like this:
Image

Now, some dude pasted code:

Code: Select all

<?php

set_time_limit(10800);

    for($y=40;$y>=1;$y--)
    {
        for($x=1;$x<=40;$x++)
        {
            require_once('includes/db/DbConnector.php');
            $connector = new DbConnector();
            $result = $connector->query('SELECT * FROM harta WHERE x = "'.$x.'" AND y = "'.$y.'" ');
            while($row = $connector->fetchArray($result))

            echo '<img src="images/harta/lan_'.$row['tip'].$row['subtip'].'.gif" title="('.$row['x'].'|'.$row['y'].')" style="float: left;margin: 0;padding:0;">';
        }
    }

?>

Code: Select all

<?php

set_time_limit(10800);

    if(!$_POST)
    {
    for($y=40;$y>=34;$y--)
    {
        for($x=1;$x<=7;$x++)
        {
            require_once('includes/db/DbConnector.php');
            $connector = new DbConnector();
            $result = $connector->query('SELECT * FROM harta WHERE x = "'.$x.'" AND y = "'.$y.'" ');
            while($row = $connector->fetchArray($result))

            echo '<img src="images/harta/lan_'.$row['tip'].$row['subtip'].'.gif" style="float: left;margin: 0;padding:0;">';
        }
    }

    echo '<div style="margin-top: 380px;">';
        echo '<form method="POST" action="hartamica.php">';
        echo 'x: <input type="text" style="width:50px;" name="x"><br>';
        echo 'y: <input type="text" style="width:50px;" name="y"><br>';
        echo '<input type="submit" name="submit" value="Cauta!"><br>';
        echo '</form>';
    echo '</div>';

    }
    else
    {
    $cx = $_POST['x'];
    $cy = $_POST['y'];

    $cy1 = $cy+3;
    $cx1 = $cx-3;

    $cy2 = $cy-3;
    $cx2 = $cx+3;

    for($y=$cy1;$y>=$cy2;$y--)
    {
        for($x=$cx1;$x<=$cx2;$x++)
        {
            require_once('includes/db/DbConnector.php');
            $connector = new DbConnector();
            $result = $connector->query('SELECT * FROM harta WHERE x = "'.$x.'" AND y = "'.$y.'" ');
            while($row = $connector->fetchArray($result))

            echo '<img src="images/harta/lan_'.$row['tip'].$row['subtip'].'.gif" title="('.$row['x'].'|'.$row['y'].')" style="float: left;margin: 0;padding:0;">';
        }
    }

    echo '<div style="margin-top: 380px;">';
        echo '<form method="POST" action="hartamica.php">';
        echo 'x: <input type="text" style="width:50px;" name="x" value="'.$_POST['x'].'"><br>';
        echo 'y: <input type="text" style="width:50px;" name="y" value="'.$_POST['y'].'"><br>';
        echo '<input type="submit" name="submit" value="Cauta!"><br>';
        echo '</form>';
    echo '</div>';
    }

?>
I would like to use the code, but I have no idea how it works.
I do not know why there are two codes either.

So, I wondered if someone could take some time to explain this valuable code to the rest of us?

Source: http://www.dreamincode.net/forums/showtopic76140.htm

Re: Map design, how?

Posted: Sun Jan 10, 2010 3:08 pm
by hallsofvallhalla
moved topic out of browser tutorial...


Well this is the basic build code of the design. Still seems like it is missing a few things but just throw it on a test page and make sure you have the image files where it looks for them at. You can remove the connector crap and include your own connect.php

Re: Map design, how?

Posted: Sun Jan 10, 2010 10:06 pm
by MAruz
Hm, nice find! I haven't got the energy to look much into this now, but I'll do tomorrow! :) Dunno if I can help you or not, but I'm looking into using something like this for my own project so I hope I can get something out of it.

Re: Map design, how?

Posted: Tue Jan 12, 2010 6:41 pm
by jpoisson
I cheated when I created my map. Unfortunetly It is all done by hand :P but it is less then 50 lines of code :P