Thread: php mini map
View Single Post
Old 01-17-2008, 12:17 AM   #5 (permalink)
cosmokramer
The Visitor
 
Join Date: Jan 2008
Posts: 4
Thanks: 0
cosmokramer is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
Hum Interesting. Could you perhaps show us your source code so we can take a closer look?
ok and keep in mind this is straight from the tutorial, just changed mysql stuff,
PHP Code:
<?php
Header
("Content-type: image/png"); // set as png
mysql_connect("myhost""myusername""mypassword") or die("There was an error connecting to the mysql server.");
mysql_select_db("");
// Image Size
$height 247;
$width 247;

// Image Pointer, turn on antialiasing 
$im ImageCreate($width$height); // this is the image
ImageAntiAlias($imtrue); // turn it on, just for fun
// Colors
$grass ImageColorAllocate($im67,154,67);
$enemy ImageColorAllocate($im255,0,0);
$bgcolor ImageColorAllocate($im39,104,39);

// exmaple color, not relevant to program.
$white ImageColorAllocate($im25500);
ImageFill($im00$bgcolor); // Fill the image with the background color
$size 5// size of a block, 5 x 5
$size2 $size 1// don't change this, it is for spacing  


$query "SELECT * FROM `mytable`"// get all user information
$result mysql_query($query);
$userarray// initialize variable
while($row mysql_fetch_array($result))
{
    
$userarray[$row['x'] . ',' $row['y']] = true// load all the user info we need into an array
}
for(
$b=0$b<=40$b++) // the grid is 40 x 40, this will make the Y columns
{
    for(
$i=0$i<=40$i++) // the grid is 40 x 40, this will make the X rows
    
{
        if (
$userarray[$i ',' $b] == true// If the $userarray says that there is sombody in this location
        
{

            
ImageFilledRectangle($im1+$i*$size21+$b*$size2$size+$i*$size2$size+$b*$size2$enemy);

        }
        else
        {
            
// Nobody lives there, draw some grass.
            
ImageFilledRectangle($im1+$i*$size21+$b*$size2$size+$i*$size2$size+$b*$size2$grass);
        }
    }
}
cosmokramer is offline  
Reply With Quote