Jump to content

Player location and tile not display and loaded correctly


jch02140

Recommended Posts

I am able to make the map shift to the direction as intended but I got a few other problems:

 

1.

 

The player location isn't properly loaded, eventhough it saved to the database successfully (I use locationX and locationY as XY coordinate individually).

The X and Y corrdinates shows up on the URL itself like this ".../main.php?x=#&y=#". But if I remove them and then hit enter again the it will reset the position back to the original location of the map.

 

2.

 

The player tile does not appears in center of the map tiles.

 

Here is the page I uploaded my PHP script:

http://student18.gamfe.com.hk/facebook/main.php

 

Here is the map portion of the code:

 

<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
mysql_query("SET NAMES 'utf-8'");

mysql_select_db($dbname) or die(mysql_error());

$query = "SELECT * FROM game_user WHERE game_id = '00001'";
$result = mysql_query($query) or die(mysql_error());

if  ((!empty($_GET["x"])) && (!empty($_GET["y"])))
{
$updateString = "UPDATE game_user SET locationX=".$_GET["x"].", locationY=" .$_GET["y"]. " WHERE game_id = '00001'";
mysql_query($updateString);
}
else
{
$x = 2;
$y = 2;
}

?>
...
// Phrasing map tiles and player tile code
<?php 
$file = file_get_contents('./images/maps/33/map.txt', true);
$entries = explode("\n", $file);

for($i=$x-2;$i<=$x+2;$i++){

	$data = explode(",", $entries[$i]);	
	for($j=$y-2;$j<=$y+2;$j++){
  		echo "<td align=\"center\" background=\"images/maps/33/33_";
  		echo $data[$j];
		echo ".gif\" width=\"65\" height=\"65\">
            	<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"65\" height=\"65\">
            		<tbody><tr>
                		<td>
                			<center>";							

							while($rows = mysql_fetch_array($result))
							{
								if(($rows['locationX'] == $_GET["x"]) && ($rows['locationY'] == $_GET["y"]))
								{
									echo "<img src=\"../images/player_tile.gif\" title=\"You are here\">";
								}
							}
		echo		   "</center>
                    	</td>
                	</tr></tbody>
            	</table>
            	</td>";
	}
	echo "</tr><tr>";
}
?>

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.