11. april 2001 - 12:36
#3
her er koden så...
<?
Header (\"Content-type: image/gif\");
header (\"Expires: Mon, 26 Jul 1997 05:00:00 GMT\"); // Date in the past
header (\"Last-Modified: \" . gmdate(\"D, d M Y H:i:s\") . \" GMT\"); // always modified
header (\"Cache-Control: no-cache, must-revalidate\"); // HTTP/1.1
header (\"Pragma: no-cache\"); // HTTP/1.0
////////////////////////////////////////////////////////////////////////////////////
// Includes
include(\"gui_functions.php\");
////////////////////////////////////////////////////////////////////////////////////
// Defines
$im = ImageCreate(482,512); // Create Main Image
$im_width = imagesx($im); // Get some measurements
$im_height = imagesy($im);
// Colors
$black = ImageColorAllocate ($im, 0, 0, 0); // First defined color is background
$white = ImageColorAllocate ($im, 255, 255, 255);
$gray = ImageColorAllocate ($im, 128, 128, 128);
$ltgray = ImageColorAllocate ($im, 209, 209, 209);
$ltgreen = ImageColorAllocate ($im, 210,253,196);
$green = ImageColorAllocate ($im, 0, 117, 58);
$red = ImageColorAllocate ($im, 255, 0, 0);
$orange = ImageColorAllocate ($im, 255, 128, 0);
$cyan = ImageColorAllocate ($im, 213, 255, 255);
$ltyellow = ImageColorAllocate ($im, 255, 255, 202);
$ltred = ImageColorAllocate ($im, 255, 187, 187);
$navy = ImageColorAllocate ($im, 64, 0, 128);
////////////////////////////////////////////////////////////////////////////////////
// Functions
////////////////////////////////////////////////////////////////////////////////////
// Main
dbconnect(); // Lets be connected
if(!isset($current)) // Make sure we have the coordinates
{
$current = \"0,0\"; // This will prolly be replaced with a DB call
}
else
{
$sector = $current; // Load current sector
}
list ($ix, $iy) = split (\',\', $sector); // Parse coordinates
// Get sector list
$xysector_list = \" (\";
$step = 1;
for($x = -3; $x <= 3; $x++)
{
if($step == 0)
{
$step = 1;
$gx = 40;
$y_start = -2;
$y_end = 2;
}
else
{
$step = 0;
$gx = 0;
$y_start = -2;
$y_end = 3;
}
for($y = $y_start; $y <= $y_end; $y++)
{
$xysector = \"\'\".($ix-$x).\",\".($iy-$y).\"\', \";
$xysector_list .= $xysector;
if($current == \"\".($ix-$x).\",\".($iy-$y).\"\")
{
$tstep = $step;
}
}
}
$xysector_list .= \")\";
$xysector_list = ereg_replace (\", )\", \")\", $xysector_list);
$query = \"select sector_x,sector_y,dead,item_list FROM universe WHERE CONCAT(sector_x,\',\',sector_y) IN $xysector_list\";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$sectors[\"$row[sector_x],$row[sector_y]\"] = $row;
}
mysql_free_result ($result);
// Start to draw
$gx = 0;
$gy = 0;
$step = 1;
for($x = -3; $x <= 3; $x++)
{ if($step == 0)
{
$step = 1;
$gx = 40;
$y_start = -2;
$y_end = 2;
}
else
{
$step = 0;
$gx = 0;
$y_start = -2;
$y_end = 3;
}
for($y = $y_start; $y <= $y_end; $y++)
{ // Build coordinates
if($step == 0)
{
$xysector = \"\".($ix-$x).\",\".($iy-($y)).\"\";
}
else
{
$xysector = \"\".($ix-$x).\",\".($iy-($y)).\"\";
}
// Show Map graphics
$planet_type = $sectors[\"$xysector\"][item_list];
// Parse out what object should be shown
switch($planet_type)
{ // Planets / Asteroids etc
case 0: break;
case 1: if(!isset($planet1))
{ $planet1 = @ImageCreateFromGif (\"planet1-big.gif\"); }
imagecopy($im, $planet1, $gx+18, $gy+20,0,0,48,48);
break;
case 2: if(!isset($planet2))
{ $planet2 = @ImageCreateFromGif (\"planet2-big.gif\"); }
imagecopy($im, $planet2, $gx+18, $gy+20,0,0,48,48); break;
case 3: if(!isset($planet3))
{ $planet3 = @ImageCreateFromGif (\"planet3-big.gif\"); }
imagecopy($im, $planet3, $gx+18, $gy+20,0,0,48,48); break;
case 4: if(!isset($planet4))
{ $planet4 = @ImageCreateFromGif (\"planet4-big.gif\"); }
imagecopy($im, $planet4, $gx+18, $gy+20,0,0,48,48); break;
case 5: if(!isset($planet5))
{ $planet5 = @ImageCreateFromGif (\"planet5-big.gif\"); }
imagecopy($im, $planet5, $gx+18, $gy+20,0,0,48,48); break;
case 6: if(!isset($planet6))
{ $planet6 = @ImageCreateFromGif (\"planet6-big.gif\"); }
imagecopy($im, $planet6, $gx+18, $gy+20,0,0,48,48); break;
case 7: if(!isset($planet7))
{ $planet7 = @ImageCreateFromGif (\"planet7-big.gif\"); }
imagecopy($im, $planet7, $gx+18, $gy+20,0,0,48,48); break;
case 8: if(!isset($planet1))
{ $planet8 = @ImageCreateFromGif (\"planet8-big.gif\"); }
imagecopy($im, $planet8, $gx+18, $gy+20,0,0,48,48); break;
case 9: if(!isset($planet9))
{ $planet9 = @ImageCreateFromGif (\"planet9-big.gif\"); }
imagecopy($im, $planet9, $gx+18, $gy+20,0,0,48,48); break;
// Man made objects
case 10: if(!isset($starbase))
{ $starbase = @ImageCreateFromPNG (\"starbase.png\"); }
imagecopy($im, $starbase, $gx+18, $gy+20,0,0,48,48); break;
case 11: if(!isset($shipwreck))
{ $shipwreck = @ImageCreateFromPNG (\"shipwreck.png\"); }
imagecopy($im, $shipwreck, $gx+18, $gy+20,0,0,48,48); break;
case 12: if(!isset($bar))
{ $bar = @ImageCreateFromPNG (\"bar.png\"); }
imagecopy($im, $bar, $gx+18, $gy+20,0,0,48,48); break;
default: imagestring($im,2,$gx+15,$gy+25,\"Type $planet_type\",$red); break;
}
// Are we in current sector
if($sector != $xysector)
{
ImagePolygon ($im, translate_poly($a, 0, 0, 0,$gx,$gy), 7, $navy );
}
else
{ // Get current sector coordinates
$cx = $gx;
$cy = $gy;
}
// Debug Info
if($DEBUG)
{
imagestring($im,4,5,5,\"Debugging Session In Progress - Be patient :)\",$red);
imagestring($im,1,$gx+2,$gy+40,\"gx:$gx,gy:$gy\",$red);
imagestring($im,1,$gx+2,$gy+52,\"x:$x,y:$y\",$red);
imagestring($im,1,$gx+2,$gy+62,\"xysector:$xysector\",$red);
}
// Increment
$gx = $gx + 80;
}
$gy = $gy + 70;
}
// Ok Now draw crosshairs :)
ImagePolygon ($im, translate_poly($a, 0, 0, 0,$cx-40,$cy-70), 7, $green );
ImagePolygon ($im, translate_poly($a, 0, 0, 0,$cx+40,$cy-70), 7, $green );
ImagePolygon ($im, translate_poly($a, 0, 0, 0,$cx-40,$cy+70), 7, $green );
ImagePolygon ($im, translate_poly($a, 0, 0, 0,$cx+40,$cy+70), 7, $green );
ImagePolygon ($im, translate_poly($a, 0, 0, 0,$cx-80,$cy), 7, $green );
ImagePolygon ($im, translate_poly($a, 0, 0, 0,$cx+80,$cy), 7, $green );
ImagePolygon ($im, translate_poly($a, 0, 0, 0,$cx,$cy), 7, $red );
// Output Image
ImageGif ($im);
// destroy the image to free memory
ImageDestroy ($im);
// EOF ////////////////////////////////////////////////////////////////////////////
?>