Jump to content

Map Grid help - So close!


HCProfessionals

Recommended Posts

Trying to figure out my game map. Here is what's going on: Any player can view themself on the map and also the user at this location: x:50, y50. For some reason the map will not show anyone else.

 

If you would like to see it, just go to http://www.gglegends.net/map.php and login with the credentials below (only 1 user can be logged in at a time):

 

Credential for Demo Account - (I have restricted areas that affect others gameplay and areas that change the demo account)

Username: demo

Password: pass

 

Other map locations to try out:

x:60, y:60

x:19, y:79

x:98, y:72

x:75, y:51

x:97, y:26

x:66, y:12

 

 

Here is the complete code to my map:

<?php
require 'includes/header.php';

//Check to see if user exists in the map table, if not redirect location to get coordinates
$user_map_check_results = $db->query ("SELECT * FROM map WHERE uID=".$user['uID']."");
$user_map_check = mysql_num_rows($user_map_check_results);	
if ($user_map_check == 0){
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=firstrun.php">';
die();
}

//Fetch the largest x coordinate in the map table.
$map_size_x_result = $db->query( "SELECT MAX(x) AS map_max_x FROM map" );
$map_size_x = $db->fetch( $map_size_x_result );

//Fetch the largest y coordinate in the map table.
$map_size_y_result = $db->query( "SELECT MAX(y) AS map_max_y FROM map" );
$map_size_y = $db->fetch( $map_size_y_result );

//Set map size. Determined by largest x and y coordinates.
$grid_x = (int)$map_size_x['map_max_x'];
$grid_y = (int)$map_size_y['map_max_y'];

//x and y rows to display at a time.
$display_rows = (int)10;

//Fetch all user locations.
$users_map_result = $db->query( "SELECT * FROM map LEFT JOIN users ON map.uID=users.uID" );
$users_map = $db->fetch( $users_map_result );

//Fetch user map location from database.
$user_location_result = $db->query( "SELECT * FROM map LEFT JOIN users ON map.uID=users.uID WHERE map.uID=".$user['uID']."" );
$user_location = $db->fetch( $user_location_result );

//default display coordinate if none specified - will be user map location.
$x = (int)$user_location['x'];
$y = (int)$user_location['y'];

$param_x = $_REQUEST["xcord"];
$param_y = $_REQUEST["ycord"];

if (isset($param_x) && isset($param_y)) {
    //validate that the parameter is a legit point.
    if (($param_x <= $grid_x) && ($param_x >= 1) && ($param_y <= $grid_y) &&($param_y >= 1)) {
        $x = (int)$param_x;
        $y = (int)$param_y;
    }
}

//set map location to the center of the map.
$display_half = round($display_rows / 2);
$other_half = $display_rows - $display_half;

//display the target in the middle.
$start_x = ($x - $display_half) +1;
$end_x = $x + $other_half;

//if the $start_x variable is less than 1 the grid would be in the negatives. so set it to 1.
if ($start_x < 1) {
    $start_x = 1;
    $end_x = $display_rows;
} else
//if $end_x is off the grid we have to compensate and add the remaining rows to the start.
if ($end_x > $grid_x) {
    $extra = $end_x - $grid_x;
    $end_x = $grid_x;
    $start_x = $start_x - $extra;
}

//same applies for the y axis.
$start_y = ($y - $display_half) +1;
$end_y = $y + $other_half;

//if the $start_y variable is less than 1 the grid would be in the negatives. so set it to 1.
if ($start_y < 1) {
    $start_y = 1;
    $end_y = $display_rows;
} else
//if $end_y is off the grid we have to compensate and add the remaining rows to the start.
if ($end_y > $grid_y) {
    $extra = $end_y - $grid_y;
    $end_y = $grid_y;
    $start_y = $start_y - $extra;
}
?>

<b><tl>World Map</tl></b><br />
<img alt="" src="images/seperator.gif" /><br />
Click anywhere on the map to begin moving around. You can click on players name's to view their profile.<br /><br />
Move to Map Location or <a href="map.php"><u>Return to base</u></a>. <?php echo "Current Map Coordinates: X $x - Y $y"; ?><br />
<!-- Search custom coordinates -->
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="GET">
<input name="xcord" type="text" size="3" maxlength="2" onblur="if ( this.value == '' ) this.value = this.defaultValue" onfocus="if ( this.value == this.defaultValue ) this.value = ''" value="x"> <input name="ycord" type="text" size="3" maxlength="2" onblur="if ( this.value == '' ) this.value = this.defaultValue" onfocus="if ( this.value == this.defaultValue ) this.value = ''" value="y"> <input type="submit" value="Submit">
</form>
<br /><br />

<!-- Show map -->
<table width="750" cellspacing="0" cellpadding="1" border="0">
<?php
//these 2 for loops represent the y and x axis
//using the data collected above the loops will properly display the grid.
for ($Ty = $start_y; $Ty <= $end_y; $Ty++) {
    //start new row
    echo '<tr>';
    for ($Tx = $start_x; $Tx <= $end_x; $Tx++) {
        //show grid
        DisplayGrid($Tx,$Ty);
    }
    echo '</tr>';
}
?>
</table>


<?php
//Function to disaply the map.
function DisplayGrid($grid_x,$grid_y) {
    global $x, $y, $user_location, $users_map;
    
    $bgimg = 'grass.gif';
$building = '';
	if ($grid_x == $user_location['x'] &&  $grid_y == $user_location['y']) {
	$building = '<img src="images/map/building.gif" alt="" border="0" /><br />';
	$user_map_name = '<br /><a href="player_profile.php?id='.$user_location['uID'].'" target="_blank"><u><b>'.$user_location['uLogin'].'</b></u></a><br />';
	}

	if ($grid_x == $users_map['x'] && $grid_y == $users_map['y']) {
	$building = '<img src="images/map/building.gif" alt="" border="0" /><br />';
	$user_map_name = '<br /><a href="player_profile.php?id='.$users_map['uID'].'" target="_blank"><u><b>'.$users_map['uLogin'].'</b></u></a><br />';
	}
    
    echo "<td width=\"75\" height=\"75\" style=\"background-image: url('images/map/$bgimg');background-repeat: repeat;\" align=center valign=center onclick=\"window.location.href='map.php?xcord=$grid_x&ycord=$grid_y'\">$building $user_map_name</td>";
}

require 'includes/footer.php';
?>

Link to comment
Share on other sites

I have a feeling it has something to do with this area:

 

function DisplayGrid($grid_x,$grid_y) {
   global $x, $y, $user_location, $users_map;

   $bgimg = 'grass.gif';
   $building = '';

if ($grid_x == $user_location['x'] &&  $grid_y == $user_location['y']) {
   $building = '<img src="images/map/building.gif" alt="" border="0" /><br />';
   $user_map_name = '<br /><a href="player_profile.php?id='.$user_location['uID'].'" target="_blank"><u><b>'.$user_location['uLogin'].'</b></u></a><br />';
}

if ($grid_x == $users_map['x'] && $grid_y == $users_map['y']) {
   $building = '<img src="images/map/building.gif" alt="" border="0" /><br />';
   $user_map_name = '<br /><a href="player_profile.php?id='.$users_map['uID'].'" target="_blank"><u><b>'.$users_map['uLogin'].'</b></u></a><br />';
}
    
    echo "<td width=\"75\" height=\"75\" style=\"background-image: url('images/map/$bgimg');background-repeat: repeat;\" align=center valign=center onclick=\"window.location.href='map.php?xcord=$grid_x&ycord=$grid_y'\">$building $user_map_name</td>";
}

Link to comment
Share on other sites

Ok, i tried adding the while loop in the function below, but when i view the page, it just sits there and times out. It must be doing something, lol!

 

//Function to display the map.
function DisplayGrid($grid_x,$grid_y) {
    global $x, $y, $user_location, $users_map_world;
    
    $bgimg = 'grass.gif';
$building = '';

	//Display current user location on the displayable grid if exists.
        if ($grid_x == $user_location['x'] &&  $grid_y == $user_location['y']) {
	     $building = '<img src="images/map/building.gif" alt="" border="0" /><br />';
	     $user_map_name = '<br /><a href="player_profile.php?id='.$user_location['uID'].'" target="_blank"><u><b>'.$user_location['uLogin'].'</b></u></a><br />';
	}

	//Fetch all player locations within the displayable grid.
	while($users_map = mysql_fetch_array(mysql_query("SELECT * FROM map LEFT JOIN users ON map.uID=users.uID"))){
		if ($grid_x == $users_map['x'] && $grid_y == $users_map['y']) {
		$building = '<img src="images/map/building.gif" alt="" border="0" /><br />';
		$user_map_name = '<br /><a href="player_profile.php?id='.$users_map['uID'].'" target="_blank"><u><b>'.$users_map['uLogin'].'</b></u></a><br />';
		}
	}
    
    echo "<td width=\"75\" height=\"75\" style=\"background-image: url('images/map/$bgimg');background-repeat: repeat;\" align=center valign=center onclick=\"window.location.href='map.php?xcord=$grid_x&ycord=$grid_y'\">$building $user_map_name</td>";
}

Link to comment
Share on other sites

Looks like the chance of me getting any help on here is slim to none.

 

Anyway, I also just tried this and the page just sits there trying to load:

//Fetch all player locations within the displayable grid.
while($users_map = mysql_fetch_array(mysql_query("SELECT * FROM map LEFT JOIN users ON map.uID=users.uID WHERE map.x=$grid_x AND map.y=$grid_y"))){
$building = '<img src="images/map/building.gif" alt="" border="0" /><br />';
$user_map_name = '<br /><a href="player_profile.php?id='.$users_map['uID'].'" target="_blank"><u><b>'.$users_map['uLogin'].'</b></u></a><br />';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.