Author Topic: 2D map  (Read 1288 times)

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
2D map
« on: October 12, 2007, 11:48:55 AM »
I wanna ask if someone have tutorial how to make 2D maps with x and y positions width mysql suport or some simple source code. I will realy prisuited for help. because i tryd to make but widthout luck  :'(.
« Last Edit: October 12, 2007, 11:51:22 AM by Aliss »

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: 2D map
« Reply #1 on: October 13, 2007, 07:57:13 AM »
I don't have any tutorials for you, but I can help. They're farily simple:

Do you need help with the code to display a map, or the code to move a player around?

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Re: 2D map
« Reply #2 on: October 13, 2007, 08:05:29 AM »
I need to a code to display the map.

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: 2D map
« Reply #3 on: October 13, 2007, 08:55:30 AM »
Here's a simple code that will display a 10x10 map:

<?php
echo "<table border=\"0\">";
for (
$y=0$y<10$y++)
{
	
echo 
"<tr>";
	
for (
$x=0$x<10$x++)
	
{
	
	
if (
$player['x'] == $x && $player['y'] == $y)
	
	
{
	
	
	
echo 
"<td><img src=\"images/player.JPG\" border=\"0\" /></td>";
	
	
}
	
	
else
	
	
{
	
	
	
echo 
"<td><img src=\"images/grass.JPG\" border=\"0\" /></td>";
	
	
}
	
}
	
echo 
"</tr>";
}
echo 
"</table>";
?>


It will check the co-ordinates of the map with $player['x'] and $player['y'] which are the player's x and y positions.

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Re: 2D map
« Reply #4 on: October 13, 2007, 09:01:16 AM »
And how about to get around a player map about to rows or one.

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: 2D map
« Reply #5 on: October 13, 2007, 10:19:20 AM »
Look for $y<10 or $x<10 in the for loops.

The y is the number of rows, and x is the number of columns.
So if you want 2 rows, change it to $y<2, or 1 column, change to $x<1.

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Re: 2D map
« Reply #6 on: October 13, 2007, 11:48:50 AM »
Thx for help now i have something to start  :)

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal