liamallan
08-14-2010, 08:47 PM
hey guys, im trying to make a game map, which will be like a x,y grid, a query will get the information stored in the 'x' and 'y' columns of the database table and project them onto the map.
im having a small problem though, the image created by php doesnt show(like the image url isnt right), i think it may be because of the header reference at start of code.
here is the code:
<?php
header("Content-type: image/png"); // set as png
mysql_connect("localhost", "uname", "pass") or die("Mysql Error");
mysql_select_db("dbname") or die("Database error.");
// Image Size
$height = 247;
$width = 247;
// Image Pointer, turn on antialiasing
$im = ImageCreate($width, $height); // this is the image
ImageAntiAlias($im, true); // turn it on, just for fun
// Colors
$grass = ImageColorAllocate($im, 67,154,67);
$enemy = ImageColorAllocate($im, 255,0,0);
$bgcolor = ImageColorAllocate($im, 39,104,39);
// exmaple color, not relevant to program.
$white = ImageColorAllocate($im, 255, 0, 0);
ImageFill($im, 0, 0, $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 `addhit`"; // 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($im, 1+$i*$size2, 1+$b*$size2, $size+$i*$size2, $size+$b*$size2, $enemy);
}
else
{
// Nobody lives there, draw some grass.
ImageFilledRectangle($im, 1+$i*$size2, 1+$b*$size2, $size+$i*$size2, $size+$b*$size2, $grass);
}
}
}
?>
can anyone help, i been working to get this for a while now.
thanks
:)
im having a small problem though, the image created by php doesnt show(like the image url isnt right), i think it may be because of the header reference at start of code.
here is the code:
<?php
header("Content-type: image/png"); // set as png
mysql_connect("localhost", "uname", "pass") or die("Mysql Error");
mysql_select_db("dbname") or die("Database error.");
// Image Size
$height = 247;
$width = 247;
// Image Pointer, turn on antialiasing
$im = ImageCreate($width, $height); // this is the image
ImageAntiAlias($im, true); // turn it on, just for fun
// Colors
$grass = ImageColorAllocate($im, 67,154,67);
$enemy = ImageColorAllocate($im, 255,0,0);
$bgcolor = ImageColorAllocate($im, 39,104,39);
// exmaple color, not relevant to program.
$white = ImageColorAllocate($im, 255, 0, 0);
ImageFill($im, 0, 0, $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 `addhit`"; // 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($im, 1+$i*$size2, 1+$b*$size2, $size+$i*$size2, $size+$b*$size2, $enemy);
}
else
{
// Nobody lives there, draw some grass.
ImageFilledRectangle($im, 1+$i*$size2, 1+$b*$size2, $size+$i*$size2, $size+$b*$size2, $grass);
}
}
}
?>
can anyone help, i been working to get this for a while now.
thanks
:)