(SOLVED) Map System [Based on X,Y Locations for each player]

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

(SOLVED) Map System [Based on X,Y Locations for each player]

Post by vitinho444 »

Hey all :)

I wanna know if there's some way of doing a "map system", bascily i need a image (dynamic (clickable)) with some dots (representing each village of a player) and then i would like to store a X and a Y to each dot like a $_POST to redirect to attack.php?x=y= so the player can attack other village..

Not sure if im explaining well, any questions reply :)

Anyone knows something?
Last edited by vitinho444 on Wed Apr 25, 2012 12:29 pm, edited 1 time in total.
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Map System [Based on X,Y Locations for each player]

Post by Chris »

This could be a very simple system, or a very complex system.

Could you explain in some more detail exactly what you want to achieve, how does the user interact with the map? Can the user see other players moving on the map? There are lots of things that need to be considered before starting something like this.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Map System [Based on X,Y Locations for each player]

Post by vitinho444 »

well, its something simple.
Actually its not for players, its for "villages" of the players.

Basicly a image with several points representing the players villages (i got the X,Y values for each one inside my database), then i want each dot with a $_POST so it can redirect to other page and catch at least the X and Y so i can make a query to identify the village.
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Map System [Based on X,Y Locations for each player]

Post by Chris »

using post won't have any security benefits.

Code: Select all

<!DOCTYPE html>
<html>
    <head>
        <style type="text/css">
        #map {
            height: 600px;
            width: 800px;
            border: 1px dashed #000;
            margin: auto;
            overflow: hidden;
        }
        #map .village {
            position: relative;
            height: 50px;
            width: 50px;
        }
        #map .village a {
            height: 50px;
            width: 50px;
            background: #F00;
            border: #F00 1px solid;
            display: block;
        }
        </style>
    </head>

    <body>
    <?php
    $mapDiv = '<div id="map">';

    /*$villageQuery = mysql_query("SELECT * FROM `villages`");
    while( $village = mysql_fetch_assoc($villageQuery) )
    {
        // village div should be aligned to center of its axes, not to the top right corner
        // therefore we take half the div height and width of its position

        $mapVillageX = $village['x'] - 25; // 25 = 50/2 (50px)
        $mapVillageY = $village['y'] - 25; // 25 = 50/2 (50px)

        $mapDiv .= '<div class="village" style="top: '. $mapVillageY .'px; left: '. $mapVillageX .'px">
                        <a href="village.php?x='. $village['x'] .'&y='. $village['y'] .'">Village</a>
                    </div>';
    }*/


    // randomized example
    $villageArray = array();
    for( $i=0; $i<=rand(1,25); $i++ )
    {
        $villageArray[] = array( 'x' => rand(0,800), 'y' => rand(0,600) );
    }
    foreach( $villageArray as $village )
    {
        // village div should be aligned to center of its axes, not to the top right corner
        // therefore we take half the div height and width of its position

        $mapVillageX = $village['x'] - 25; // 25 is half 50 (50px)
        $mapVillageY = $village['y'] - 25; // 25 is half 50 (50px)

        $mapDiv .= '<div class="village" style="top: '. $mapVillageY .'px; left: '. $mapVillageX .'px">
                        <a href="village.php?x='. $village['x'] .'&y='. $village['y'] .'">Village</a>
                    </div>';
    }
    echo $mapDiv . '</div>';
    ?>
    </body>
</html>
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Map System [Based on X,Y Locations for each player]

Post by vitinho444 »

oK I used that code inside my index.php where for now its just the news.

Here's a pic:
PIC: http://imageshack.us/f/813/mapqu.jpg/

And there are some problems.

Ok first, forget the "style" i fixed it after taking the print.

But there is one problem: I got only 3 villages registred and there are other ones "ghost" villages that aren't created.

I removed the /* */ from your code and added, but without the code between the comments the actual villages disappear from the map and there are only the ghosts ones...


Not sure why this is happening here's the code:

Code: Select all

<!DOCTYPE html>
<center>
<html>
    <head>
        <style type="text/css">
        #map {
            height: 600px;
            width: 800px;
            border: 1px dashed #000;
            margin: auto;
            overflow: hidden;
        }
        #map .village {
            position: relative;
            height: 50px;
            width: 50px;
        }
        #map .village a {
            height: 50px;
            width: 50px;
            background: #F00;
            border: #F00 1px solid;
            display: block;
        }
        </style>
    </head>
<title>Village Wars</title>

    <body>

<?php
include 'config.php';
session_start();
require "languages/index.lang.php";
echo "<a href='index.php'><img src='images/banner.jpg'></a>"; //Banner



?>

<link href="style.css" rel="stylesheet" type="text/css"/> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
echo "<div id='vwmain'>";
if (isset($_POST['LOGIN-NOW']))
{
  $player=$_POST['player'];
  $password=$_POST['password'];
  $player=strip_tags($player);
  $password=md5($password);
  

  $query = "select username,password from players where username='$player' and '$password'";
  $result = mysql_query($query) or die("Internal Error 432551 - Login Status: OFFLINE");
  $result2 = mysql_fetch_array($result);
  if ($result2)
  { 
    $_SESSION['player']= $player;
    echo '<meta http-equiv="refresh" content="0; URL=index.php"></center></div>';
  }
  else
  {
	if(isset($language))
	{
		echo "<h2>". $lang['LoginError1']['$language'] . "</h2>";
	}
  else 
  {
  echo "<h2>" . $lang['LoginError1']['en'] . "</h2>";
  }
  
    echo '<meta http-equiv="refresh" content="2; URL=index.php">';
  }
}
else
{
echo "</div>";

if (isset($_SESSION['player']))
{


  $player=$_SESSION['player'];
  $info=mysql_fetch_array(mysql_query("SELECT * from players where username='$player'"));
  $language = $info['language'];
  $gold = $info['gold'];
  
  $username = $info['username'];
  include_once "runcron.php";  
  include_once "runcron2.php";  
  
}
else
{

include 'register.php';
include 'login.php';

exit;
}
}

include 'menu.php';

/*
METER ISTO EM TODAS AS PAGS:
*/

if(isset($_SESSION['player']))
{

echo '
<div id="playerinfotop"><center>
' . $lang["Username"][$language] . ' ' . $player . '     ' . $lang["Gold"][$language] . ' ' . $gold . '
</div></center>
';

include 'pub.php';


echo '<div id="igactivemenu">';

include 'news.php';

$mapDiv = '<div id="map">';

  /* $villageQuery = mysql_query("SELECT * FROM `aldeias`");
    while( $village = mysql_fetch_assoc($villageQuery) )
    {
        // village div should be aligned to center of its axes, not to the top right corner
        // therefore we take half the div height and width of its position

        $mapVillageX = $village['x'] - 25; // 25 = 50/2 (50px)
        $mapVillageY = $village['y'] - 25; // 25 = 50/2 (50px)

        $mapDiv .= '<div class="village" style="top: '. $mapVillageY .'px; left: '. $mapVillageX .'px">
                        <a href="village.php?x='. $village['x'] .'&y='. $village['y'] .'">Village</a>
                    </div>';
    }
*/

    // randomized example
    $villageArray = array();
    for( $i=0; $i<=rand(1,25); $i++ )
    {
        $villageArray[] = array( 'x' => rand(0,400), 'y' => rand(0,500) );
    }
    foreach( $villageArray as $village )
    {
        // village div should be aligned to center of its axes, not to the top right corner
        // therefore we take half the div height and width of its position

        $mapVillageX = $village['x'] - 25; // 25 is half 50 (50px)
        $mapVillageY = $village['y'] - 25; // 25 is half 50 (50px)

        $mapDiv .= '<div class="village" style="top: '. $mapVillageY .'px; left: '. $mapVillageX .'px">
                        <a href="village.php?x='. $village['x'] .'&y='. $village['y'] .'">Village</a>
                    </div>';
    }
    echo $mapDiv . '</div>';
    
	
	echo '</div>';
  

}

?>
</body>
</html>
Your part is the last part of the code, and the igactivemenu is the area of the news and the area where the map should be displayed.

Thanks a lot for your code i see it works but just need to fix this problems.
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Map System [Based on X,Y Locations for each player]

Post by Chris »

Read the code and learn how it works. It's not all that difficult. The beauty of programming is that there's nearly never any harm in trial and error.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Map System [Based on X,Y Locations for each player]

Post by vitinho444 »

Well, im not understanding very well...

Can you explain me what part of the code is what?

Sorry for the time...
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Map System [Based on X,Y Locations for each player]

Post by vitinho444 »

Ok i got it working like i want to.

But i got one last problem. I added the village name to each village showed on the map but i want to show the name only if i put my mouse over the village so it doesnt use too much space.

How can i do it?

Here's the new code:

Code: Select all

$mapDiv = '<div id="map">';

   $villageQuery = mysql_query("SELECT * FROM `aldeias`");
    while( $village = mysql_fetch_assoc($villageQuery) )
    {
        // village div should be aligned to center of its axes, not to the top right corner
        // therefore we take half the div height and width of its position

        $mapVillageX = $village['x'] - 25; // 25 = 50/2 (50px)
        $mapVillageY = $village['y'] - 25; // 25 = 50/2 (50px)
		
		$name = $village['nome'];

        $mapDiv .= '<div class="village" style="top: '. $mapVillageY .'px; left: '. $mapVillageX .'px">
                        <a href="village.php?x='. $village['x'] .'&y='. $village['y'] .'">'.$name.'<br>' . $village['x'] . "," . $village['y'] . '</a>
                    </div>';
    }
	
	echo $mapDiv . '</div>';
Thanks a lot for your help
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
Post Reply

Return to “Advanced Help and Support”