Jump to content

Recommended Posts

I've created a topic before about making this game in php and mysql, which would be on a -250x250 grid but would only display 11x11, displaying your character in the center/middle of the table and being able to click the surrounding squares to change coordinates. I thought I'd realized how to make one of these map explore games but I've really got no ideas for some bits, so if anyone has any general hints or any tutorials for learning how to make something like this it would be greatly appreciated. Thanks in advance people :)

Link to comment
https://forums.phpfreaks.com/topic/122474-map-coordinates/
Share on other sites

  • 3 years later...

I know this is a bit of a thread necro, but I saw this while looking for something else and thought it couldn't be too hard to work with.

 

Anyway, I came up with this:

<?php
$horitiles = 5; // how many tiles wide
$verttiles = 5; // how many tiles high
$v = 0;
$h = 0;
$maxmovesize = 1; // hos many tiles can you move per-move (not perfect though, change it to 2 or 3 and see)

// there is treasure in the map for you to find, you can find it easy by looking at the querystring
// if theres no querystring setting treasure it'll be at tile 2,2
if(isset($_REQUEST['th']) && isset($_REQUEST['tv'])) {
  $treasureh = $_REQUEST['th'];
  $treasurev = $_REQUEST['tv'];
}else {
  $treasureh = 2;
  $treasurev = 2;
}

// current position, default if nothing in querystring is 1,1
if(isset($_REQUEST['v'])) {
  $currentv = $_REQUEST['v'];
}else {
  $currentv = 1;
}
if(isset($_REQUEST['h'])) {
  $currenth = $_REQUEST['h'];
}else {
  $currenth = 1;
}

echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\">";
while($v < $verttiles) {
  echo "<tr>";
  while($h< $horitiles) {
    if($v == $currentv && $h == $currenth) {
  if($h == $treasureh && $v ==$treasurev) {
        echo "<td><img src=\"tile-treasure.jpg\"></td>";
	$treasure = "You found the treasure!<br>";
	$treasureh = rand(1,$horitiles)-1;
	$treasurev = rand(1,$verttiles)-1;
	$link="<a href=\"map.php?h=$h&v=$v&th=$treasureh&tv=$treasurev\">Reset!</a>";
  }else {
        echo "<td><img src=\"tile-on.jpg\"></td>";
	$treasure = "";
	$link="";
  }
}else {
  $gol = $currenth-$maxmovesize;
  $gor = $currenth+$maxmovesize;
  $gou = $currentv-$maxmovesize;
  $god = $currentv+$maxmovesize;
  if($h >= $gol && $h <= $gol+$maxmovesize && $v == $currentv
  || $h >= $gol && $h <= $gol+$maxmovesize && $v == $currentv+1
  || $h >= $gol && $h <= $gol+$maxmovesize && $v == $currentv-1
  || $h <= $gor && $h >= $gol+$maxmovesize && $v == $currentv
  || $h <= $gor && $h >= $gor-$maxmovesize && $v == $currentv+1
  || $h <= $gor && $h >= $gor-$maxmovesize && $v == $currentv-1) {
	echo "<td><a href=\"map.php?h=$h&v=$v&th=$treasureh&tv=$treasurev\"><img src=\"tile-move.jpg\" border=\"0\"></a></td>";
      }else if($v >= $gou && $v <= $gou+$maxmovesize && $h == $currenth
        || $v >= $gou && $v <= $gou+$maxmovesize && $h == $currenth+1
        || $v >= $gou && $v <= $gou+$maxmovesize && $h == $currenth-1
        || $v <= $god && $v >= $god-$maxmovesize && $h == $currenth
        || $v <= $god && $v >= $god-$maxmovesize && $h == $currenth+1
        || $v <= $god && $v >= $god-$maxmovesize && $h == $currenth-1) {
	echo "<td><a href=\"map.php?h=$h&v=$v&th=$treasureh&tv=$treasurev\"><img src=\"tile-move.jpg\" border=\"0\"></a></td>";
  }else {
    echo "<td><img src=\"tile.jpg\"></td>";
  }
}
$h++;
  }
  $h = 0;
  echo "</tr>";
  $v++;
}
echo "</table>";

echo "<br>";
echo $treasure."<br>";
echo $link;
?>

 

I've attached the images I've used as tiles 32x32 icon size.

 

This is a very simple take on it and some code is redundent, would've used a database but didn't have access to one on the machine I was using. Though it could easily be converted to use a database (and even have multiplayer support over a larger 'map').

 

Something fun to play with, was a lot of fun to make as I've been out of PHP for about 12 months and am starting my return at the moment!

 

Could be done a lot better, but hey, it's an idea.

post-12188-13482403269045_thumb.jpg

post-12188-13482403269079_thumb.jpg

post-12188-13482403269106_thumb.jpg

post-12188-13482403269214_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/122474-map-coordinates/#findComment-1321801
Share on other sites

Wow, 4 years ago!? Really?

 

Even though the information you provided is very detailed and downright relevant to the OP, you shouldn't necro.  I see your intentions are good, but 4 years??  Well, 3 years and some change.

 

Anyway. I'm locking this.

Link to comment
https://forums.phpfreaks.com/topic/122474-map-coordinates/#findComment-1321805
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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.