Grid movement system
Posted: Tue Jun 30, 2009 2:01 pm
				
				Someone asked for a grid movement system, well here ya go! This came from my first browser version of my game Forsaken Sanctum
Map.php .... basically the index file, try not to get too overwhelmed, its not as bad as it seems.
this is basically what it looks like

			Map.php .... basically the index file, try not to get too overwhelmed, its not as bad as it seems.
Code: Select all
<?php
include 'connect.php';
session_start();
unset($_SESSION["name"]);
?>
 <?php
if (isset($_SESSION['player'])) 
  {
    $player=$_SESSION['player'];
    $playerinfo="SELECT * from players where name='$player'";
    $playerinfo2=mysql_query($playerinfo) or die("Could not get user stats");
    $playerinfo3=mysql_fetch_array($playerinfo2);
      print "<input type='hidden' name='id' value='$playerinfo3[id]'>";
	
	 }
	else
	{
	print "Sorry, not logged in  please <A href='/login.php'>Login</a><br>";
 exit;
  }
 
  
  $area = "p7";
$row = $_GET['row'];
$column = $_GET['column'];
if ($row == NULL)
{
$row = $playerinfo3[mapr];
$column = $playerinfo3[mapc];
 $id = $playerinfo3[id];
}
  
  $mapinfo="SELECT * from map where mapr='$row' AND mapc='$column'";
    $mapinfo2=mysql_query($mapinfo) or die("Could not map");
    $mapinfo3=mysql_fetch_array($mapinfo2);
			$creature = $mapinfo3[creature];
  			$treasure = $mapinfo3[treasure];
  			$merchant = $mapinfo3[merchant];
  			////Crafting 
  			$mining = $mapinfo3[mining];
  			$fishing =$mapinfo3[fishing];
  			$harvest = $mapinfo3[harvest];
  			$lumber = $mapinfo3[lumber];  
?>
 <link href="../style.css" rel="stylesheet" type="text/css" />
 
<div id="logo"><img src="../images/logo.jpg" width="500" height="120" /></div>
<p><div id="weaponsbutt"><a href="../equip.php"><img src="../images/weaponsbutt.png" width="150" height="50" border="0" /></a></div>
<div id="armorbutt"><a href="../equiparmor.php"><img src="../images/armorbutt.png" width="150" height="50" border="0" /></a></div>
<div id="backpackbutt"><a href="../backpack.php"><img src="../images/backpackbutt.png" width="150" height="50" border="0" /></a></div>
<div id="statsbutt"><a href="../stats.php"><img src="../images/statsbutt.png" width="150" height="50" border="0"/></a></div>
<div id="forumbutt"><a href="http:\\forsakensantum.com\forums"><img src="../images/forumbutt.png" width="150" height="50" border="0"/></a></div> 
<div id="topbutt"><a href="../topplayers.php"><img src="../images/top.png" width="150" height="50" border="0"/></a></div>
<div id="resting">  
<?php
if ($playerinfo3[local] == 1){echo "<center><big>You are in the ruins";echo "<A href='/ruins/map.php'>Travel back there</a><br>";exit;} 
//////////////////////////////////////////////////if dead////////////////////////////////
if ($playerinfo3[hp] < 1)
{
echo "<big><center>You are currently incapacitated.<br>You will have to wait until your hit points are above 0. Currently you can go to your back for healing but only during beta.<br>Players heal over time. </center>";
echo "<center><br><A href='/logout.php'>Logout</a><br></big>";
exit;
}
////////////////////////////////////////////if resting in inn or house/////////////////////////////////////
if ($playerinfo3[resting] == 1)
{
echo "<big><center>You are currently resting in and inn or house. In this state you are safe from player attacks. You will stay this way even if you log out. Would you like to leave the inn or house?</center>";
echo "<center><br><A href='/leavesafe.php'>Leave and continue playing</a><br>";
echo "<center><br><A href='/logout.php'>Logout</a><br></big>";
exit;
}  
///////////////////////////////////////////////////////////////////////////////////////////////////////////
?>
</div>
<?php
if ($playerinfo3[mapr]!=$row||$playerinfo3[mapc]!=$column)
{
$updatenewloc="Update players set mapr=$row,mapc=$column where name='$player'";
	    mysql_query($updatenewloc) or die("Could not update new location");
$playerinfo3[mapr] = $row;
$playerinfo3[mapc] = $column;		
}
?>
 <div id="housebutt">
  <?php
  /////////////////////housing button//////////////////
   $house="SELECT id,special from housing where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]' AND local = 0";
    $house2=mysql_query($house) or die("Could get housing");
    $house3=mysql_fetch_array($house2);	
  if ($house3[id] != NULL)
  {
 	echo "<a href='/whoishousing.php'><img src='/images/housebutt.png' width='150' height='50' border='0'/></a>";
  }
  if ($house3[special] == 0)
  {
  echo "<a href='/build/build.php'><img src='/images/build.jpg' width='150' height='50' border='0'/></a>";
  }
  ?>
    </div>
    <div id="chatbox">
<?php
include("../shout/shoutbox.inc.php");
?>
</div>
<?php
///random creature engine//////////
if ($mapinfo3[crname] == "")
{
$encount = rand(0,100);
if ($encount >= 90)
{
$crlevel = $playerinfo3[level]+2;
$crinfo="SELECT * from creatures where level<='$crlevel' AND type='any' order by rand() limit 1";
    $crinfo2=mysql_query($crinfo) or die("Could not map");
   $crinfo3=mysql_fetch_array($crinfo2);
    $updatemap="Update map set crname='$crinfo3[name]',crhp='$crinfo3[hp]' where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
	    mysql_query($updatemap) or die("Could not update map");
}
else
{}
}
else
{
$crinfo="SELECT * from creatures where name='$mapinfo3[crname]'";
    $crinfo2=mysql_query($crinfo) or die("Could not map");
   $crinfo3=mysql_fetch_array($crinfo2);
   }
 
//////////////////////////////////////////////
$rowminus1 = $playerinfo3[mapr] -1;
$rowplus1 = $playerinfo3[mapr] + 1;
$columnminus1 = $playerinfo3[mapc] -1;
$columnplus1 = $playerinfo3[mapc] +1;
/////////////north.......////////////
$northr =  $rowminus1;
$northc =  $playerinfo3[mapc];
 $northinfo="SELECT tile from map where mapr='$northr' AND mapc='$northc'";
    $northinfo2=mysql_query($northinfo) or die("Could not map");
    $northinfo3=mysql_fetch_array($northinfo2);
if ($northr < 1 || $northr > 45 || $northc < 1 || $northc > 45){$northinfo3[tile] = "boundry";}
////////////south.......////////////
$southr =  $rowplus1;
$southc =  $playerinfo3[mapc];
 $southinfo="SELECT tile from map where mapr='$southr' AND mapc='$southc'";
    $southinfo2=mysql_query($southinfo) or die("Could not map");
    $southinfo3=mysql_fetch_array($southinfo2);
	if ($southr < 1 || $southr > 45 || $southc < 1 || $southc > 45){$southinfo3[tile] = "boundry";}
	////////////east.......////////////
$eastr =  $playerinfo3[mapr];
$eastc =  $columnplus1;
 $eastinfo="SELECT tile from map where mapr='$eastr' AND mapc='$eastc'";
    $eastinfo2=mysql_query($eastinfo) or die("Could not map");
    $eastinfo3=mysql_fetch_array($eastinfo2);
	if ($eastr < 1 || $eastr > 45 || $eastc < 1 || $eastc > 45){ $eastinfo3[tile] = "boundry";}
	////////////west.......////////////
$westr =  $playerinfo3[mapr];
$westc =  $columnminus1;
 $westinfo="SELECT tile from map where mapr='$westr' AND mapc='$westc'";
    $westinfo2=mysql_query($westinfo) or die("Could not map");
    $westinfo3=mysql_fetch_array($westinfo2);	
	if ($westr < 1 || $westr > 45 || $westc < 1 || $westc > 45){ $westinfo3[tile] = "boundry";}
		////////////North west.......////////////
$nwestr =  $rowminus1;
$nwestc =  $columnminus1;
 $nwestinfo="SELECT tile from map where mapr='$nwestr' AND mapc='$nwestc'";
    $nwestinfo2=mysql_query($nwestinfo) or die("Could not map");
    $nwestinfo3=mysql_fetch_array($nwestinfo2);	
	if ($nwestr  < 1 || $nwestr  > 45 || $nwestc < 1 || $nwestc > 45){ $nwestinfo3[tile] = "boundry";}
			////////////North east.......////////////
$neastr =  $rowminus1;
$neastc =  $columnplus1;
 $neastinfo="SELECT tile from map where mapr='$neastr' AND mapc='$neastc'";
    $neastinfo2=mysql_query($neastinfo) or die("Could not map");
    $neastinfo3=mysql_fetch_array($neastinfo2);
	if ($neastr  < 1 || $neastr  > 45 || $neastc < 1 || $neastc > 45){ $neastinfo3[tile] = "boundry";}	
	////////////south west.......////////////
$southwr =  $rowplus1;
$southwc =  $columnminus1;
 $southwinfo="SELECT tile from map where mapr='$southwr' AND mapc='$southwc'";
    $southwinfo2=mysql_query($southwinfo) or die("Could not map");
    $southwinfo3=mysql_fetch_array($southwinfo2);
	if ($southwr  < 1 || $southwr  > 45 || $southwc < 1 || $southwc > 45){  $southwinfo3[tile] = "boundry";}
	////////////south east......////////////
$souther =  $rowplus1;
$southec =  $columnplus1;
 $southeinfo="SELECT tile from map where mapr='$souther' AND mapc='$southec'";
    $southeinfo2=mysql_query($southeinfo) or die("Could not map");
    $southeinfo3=mysql_fetch_array($southeinfo2);
	if ($souther  < 1 || $souther  > 45 || $southec < 1 || $southec > 45){  $southeinfo3[tile] = "boundry";}
$currentbar = ($playerinfo3[stamina]/$playerinfo3[maxstamina]) * 100;
$healthbar = ($playerinfo3[hp]/$playerinfo3[maxhp]) * 100;
?>
 <div id="grid1"><a href="/<?php if ($nwestinfo3[tile] == "boundry"){echo "locations/map.php";}else {echo "locations/map.php?row=$rowminus1&column=$columnminus1";} ?>"><img src="/images/<?php echo $nwestinfo3[tile]; ?>.png"width="130" height="130" border="0"/></a></div>
 
<div id="grid2"><a href="/<?php if ($northinfo3[tile] == "boundry"){echo "locations/map.php";}else {echo "locations/map.php?row=$rowminus1&column=$playerinfo3[mapc]"; }?>"><img src="/images/<?php echo $northinfo3[tile]; ?>.png" width="130" height="130" border="0"/></a></div>
 
<div id="grid3"><a href="/<?php if ($neastinfo3[tile] == "boundry"){echo "locations/map.php";}else {echo "locations/map.php?row=$rowminus1&column=$columnplus1"; }?>"><img src="/images/<?php echo $neastinfo3[tile]; ?>.png" width="130" height="130" border="0"/></a></div>
 
<div id="grid4"><a href="/<?php  if ($westinfo3[tile] == "boundry"){echo "locations/map.php";}else {echo "locations/map.php?row=$playerinfo3[mapr]&column=$columnminus1"; }?>"><img src="/images/<?php echo $westinfo3[tile]; ?>.png" width="130" height="130" border="0"/></a></div>
 
<div id="grid5"><img src="/images/<?php echo $mapinfo3[tile]; ?>.png" width="130" height="130" /></div>
 
<div id="grid6"><a href="/<?php  if ($eastinfo3[tile] == "boundry"){echo "locations/map.php";}else {echo "locations/map.php?row=$playerinfo3[mapr]&column=$columnplus1"; }?>"><img src="/images/<?php echo $eastinfo3[tile]; ?>.png" width="130" height="130" border="0"/></a></div>
 
<div id="grid7"><a href="/<?php if ($southwinfo3[tile] == "boundry"){echo "locations/map.php";}else {echo "locations/map.php?row=$rowplus1&column=$columnminus1"; }?>"><img src="/images/<?php echo $southwinfo3[tile]; ?>.png" width="130" height="130" border="0"/></a></div>
<div id="grid8"><a href="/<?php if ($southinfo3[tile] == "boundry"){echo "locations/map.php";}else {echo "locations/map.php?row=$rowplus1&column=$playerinfo3[mapc]"; }?>"><img src="/images/<?php echo $southinfo3[tile]; ?>.png" width="130" height="130" border="0"/></a></div>
<div id="grid9"><a href="/<?php if ($southeinfo3[tile] == "boundry"){echo "locations/map.php";}else {echo "locations/map.php?row=$rowplus1&column=$columnplus1"; }?>"><img src="/images/<?php echo $southeinfo3[tile]; ?>.png" width="130" height="130" border="0"/></a></div>
 
<div id="gridplayer"><img src="/images/305.png" width="32" height="32" /></div>
 
<div id="lbar"><img src="../images/lbar.png" width="194" height="358" /></div>
<div id="rbar"><img src="../images/lbar.png" width="194" height="288" /></div>
<div id="mstatback"><img src="../images/mstatback.png" width="300" height="450" /></div>
<div id="playback"><img src="/images/playerback.png" width="170" height="370" /></div>
<div id="mapback"><img src="/images/mapback.png" width="450" height="450" /></div>
<div id="mapstats"><img src="/images/mapstats.png" width="200" height="50" /></div>
<div id="staminacase"><img src="/images/staminacase.gif" width="103" height="20" /></div>
<div id="staminabar"><img src="/images/staminabar.gif" width="<?php echo $currentbar; ?>" height="13" /></div>
<div id="healthcase"><img src="/images/staminacase.gif" width="103" height="20" /></div>
<div id="healthbar"><img src="/images/healthbar.gif" width="<?php echo $healthbar; ?>" height="13" /></div>
   
   
   
<div id="playerstats">
   
    <?php
   
 $expneeded = ($playerinfo3[level] * 100) * $playerinfo3[level];
  echo "Player: " . $playerinfo3[name] . "<br />";
 echo "Level: " . $playerinfo3[level] . "<br />";
 echo $playerinfo3[proname] . "<br />";
 echo "Credits: " . $playerinfo3[credits] . "<br />";
 echo "Exp: " . $playerinfo3[expe] . "/" . $expneeded .  "<br />";
  echo "Strength: " . $playerinfo3[strength] . "<br />";
  echo "Agilty: " . $playerinfo3[agility] . "<br />";
  echo "Intellect: " . $playerinfo3[iq] . "<br />";
   echo "Endurance: " . $playerinfo3[endurance] . "<br />";
    echo "Body: " . $playerinfo3[body] . "<br />";
   echo "Location: R" . $playerinfo3[mapr] . " C" . $playerinfo3[mapc] ."<br />";
  echo "<br />";
 echo ". Stamina" . "<br />";
 echo "<br />";
   echo ". Health";
  if ($playerinfo3[expe] >= $expneeded)
 {	echo "<br><br><a href='/levelup.php'><img src='/images/levelup.png' width='150' height='50' border='0'/></a>";}
 if ($playerinfo3[killer] != ""){echo "<br><br>Last Attacked by: " . $playerinfo3[killer];}
 
    //this builds initial MAP table! run only once//////////////
  //for ($i = 1; $i <= 30; $i+= 1)
  //{
  //for ($c = 1; $c <= 30; $c+= 1)
  //{
  ///$test = "INSERT INTO map (mapr,mapc)Values('$i','$c')";
   ///$test2=mysql_query($test) or die("Could not get user stats");
  //}
  //}
  ?> 
  <div id="login">
  <?php
    echo "<br><big><br><A href='/logout.php'>Logout</a></big><br>";
  ?>
  </div>
  </div>  
<div id="playerbutt">
<?php
  $otherplayers="SELECT name from players where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]' AND name !='$playerinfo3[name]' AND local = 0";
    $otherplayers2=mysql_query($otherplayers) or die("Could not get user stats");
   $otherplayers3=mysql_fetch_array($otherplayers2);
    if ($otherplayers3[name] != NULL)
  {
 	echo "<A href='/locations/otherplayers.php'>Other players are in this location</a><br>";
  }
?>
  
</div>      
    
<div id="rsidestas2">
 <?php
	 if ($mapinfo3[harvest] < 15){$harvname="Excellent";$hfont="3300ff";}
	  elseif ($mapinfo3[harvest] < 30){$harvname="Good";$hfont="3399ff";}
	  elseif ($mapinfo3[harvest] < 50){$harvname="Fair";$hfont="cccccc";}
	  elseif ($mapinfo3[harvest] < 70){$harvname="Poor";$hfont="cc3366";}
	  elseif ($mapinfo3[harvest] >= 70){$harvname="Horrid";$hfont="cc0000";}
	  
	  if ($mapinfo3[mining] < 15){$minename="Excellent";$mfont="3300ff";}
	  elseif ($mapinfo3[mining] < 30){$minename="Good";$mfont="3399ff";}
	  elseif ($mapinfo3[mining] < 50){$minename="Fair";$mfont="cccccc";}
	  elseif ($mapinfo3[mining] < 70){$minename="Poor";$mfont="cc99cc";}
	  elseif ($mapinfo3[mining] >= 70){$minename="Horrid";$mfont="cc0000";}
	  
	   if ($mapinfo3[lumber] < 15){$lumbername="Excellent";$lfont="3300ff";}
	  elseif ($mapinfo3[lumber] < 30){$lumbername="Good";$lfont="3399ff";}
	  elseif ($mapinfo3[lumber] < 50){$lumbername="Fair";$lfont="cccccc";}
	  elseif ($mapinfo3[lumber] < 70){$lumbername="Poor";$lfont="cc99cc";}
	  elseif ($mapinfo3[lumber] >= 70){$lumbername="Horrid";$lfont="cc0000";}
	  
	    if ($mapinfo3[fishing] < 15){$fishingname="Excellent";$ffont="3300ff";}
	  elseif ($mapinfo3[fishing] < 30){$fishingname="Good";$ffont="3399ff";}
	  elseif ($mapinfo3[fishing] < 50){$fishingname="Fair";$ffont="cccccc";}
	  elseif ($mapinfo3[fishing] < 70){$fishingname="Poor";$ffont="cc99cc";}
	  elseif ($mapinfo3[fishing] >= 70){$fishingname="Horrid";$ffont="cc0000";}
	  
	   if ($mapinfo3[hunting] < 15){$huntingname="Excellent";$hufont="3300ff";}
	  elseif ($mapinfo3[hunting] < 30){$huntingname="Good";$hufont="3399ff";}
	  elseif ($mapinfo3[hunting] < 50){$huntingname="Fair";$hufont="cccccc";}
	  elseif ($mapinfo3[hunting] < 70){$huntingname="Poor";$hufont="cc99cc";}
	  elseif ($mapinfo3[hunting] >= 70){$huntingname="Horrid";$hufont="cc0000";}
	  
	  
	
	  echo "<big><big>Harvesting: </big><font color='$hfont'>" . $harvname . "<br></big></font>";
	   echo "<big><big>Mining:  </big><font color='$mfont'>" . $minename . "<br></big></font>";
	   echo "<big><big>Lumbering: </big><font color='$lfont'>" . $lumbername . "<br></big></font>";
	   echo "<big><big>Fishing: </big><font color='$ffont'>" . $fishingname . "<br></big></font>";
	   echo "<big><big>Hunting: </big><font color='$hufont'>" . $huntingname . "<br></big></font>";
	 
 //echo "<center><u>_________________________</u>";
	
	
  ?>
 </div>
     
  
<div id="playerhouse"><?php
	 
     
     
     ?></div>
<div id="creature">
     <?php
	 if ($mapinfo3[crname] != "")
	 {
	  echo "<center><big><big>There is a " .  $crinfo3[name] . " in the area. You must kill it before you can harvest here.</big></big></center>"; 
	  echo "<center><br><big><big><A href='/combat/battle.php?name=$mapinfo3[crname]&f=121'>Attack it</big></big></a><br>";
	 
	 exit;
	 }
	 else
	 {
	 }
	 ?>
     </div>
<div id="harvestbutt"><a href="harvest.php"><img src="../images/harvestbutt.png" width="150" height="50" border="0"/></a></div>
<div id="minebutt"><a href="mining.php"><img src="../images/minebutt.png" width="150" height="50" border="0"/></a></div>
<div id="huntbutt"><a href="hunting.php"><img src="../images/huntbutt.png" width="150" height="50" border="0"/></a></div>
<div id="lumberbutt"><a href="lumber.php"><img src="../images/lumberbutt.png" width="150" height="50" border="0"/></a></div>
<div id="fishbutt"><a href="fishing.php"><img src="../images/fishbutt.png" width="150" height="50" border="0"/></a></div>

 
 