carte.php <?php
// ================= base de donnée
include("configg9.php");
//================= initialisation des variables:
$xtaillecarte=450;
$ytaillecarte=300;
$yy = $nbcase; // nbcase et definit dans le fichier config
$taille=64*$xtaillecarte/(($nbcase+1)*64);
$taille2=32*$ytaillecarte/(($nbcase+2)*32);
// =================== verification de session
if ($nums== '' ){
// =================== soucis on fait une image erreur
$xxxm = @imagecreate(100, 50) or die ("Cannot Initialize new GD image stream");
$bg = ImageColorAllocate ($xxxm, 255, 255, 255);
imagecolortransparent($xxxm, $bg);
$couleurnoms = ImageColorAllocate ($xxxm, 20, 20, 20);
ImageString ($xxxm, 1, 10, 10, "probléme de login", $couleurnoms);
ImageString ($xxxm, 1, 10, 20, "reconnectez vous", $couleurnoms);
header ("Content-type: image/png");
imagepng ($xxxm);
ImageDestroy ($xxxm);
}
else
{
// =================== ok on continu
dbconnect();
// =================== on cherche notre smiles
$result = mysql_query ("SELECT ki FROM smi_ses where nums= $nums ");
$row = mysql_fetch_array($result);
$su= $row[0];
if ($su<>'' )
{
// =================== on cherche où il est
$resultcarte = mysql_query("SELECT x,y FROM smi_perso where 1 and nom = '".$su."' ");
$row = mysql_fetch_array($resultcarte);
$x = $row["x"];
$y = $row["y"];
// =================== on crée la variable image
$xxxm = @imagecreate($xtaillecarte, $ytaillecarte) or die ("Cannot Initialize new GD image stream");
// =================== un peu de transparent en fond :)
$bg = ImageColorAllocate ($xxxm, 255, 255, 255);
imagecolortransparent($xxxm, $bg);
function LoadGif ($xxxmgname) {
// =================== petite fonction permettant de charger un fichier png
$xxxm = @ImageCreateFromPNG ($xxxmgname);
return $xxxm;
}
//==================== on charge les elements
$sable=loadgif ("img/sable.png");$inc=loadgif ("img/0.png");$inc1=loadgif ("img/1.png");$inc2=loadgif ("img/2.png");
$blue = ImageColorAllocate ($xxxm, 200, 200, 100);
$couleurnoms = ImageColorAllocate ($xxxm, 250, 250, 250);
$msg="x:$x y:$y ";
$xperso = $x;
$yperso = $y;
// ======= on limite la zone à regarder
$petitx=$xperso-$nbcase/2;
$petity=$yperso-$nbcase/2;
$grandx=$xperso+$nbcase/2;
$grandy=$yperso+$nbcase/2;
// =========== on place le quadrillage au sol
while ($yy >= 0) {$yy--;
for ($xx = 0; $xx <= $nbcase; $xx++)
{
$xiso=($xx+$yy)*$taille/2+$taille/2;
$yiso=($xx-$yy)*$taille2/2+($nbcase)*$taille2/2-10;
ImageCopy ($xxxm,$sable, $xiso, $yiso, 0, 0, 64, 64);
}
}
// ============== on regarde se qu'il y a dans le coin au niveau personnages
$resultcarte = mysql_query("SELECT nom,x,y,type FROM smi_perso where 1 and x >= ".$petitx." and y >= ".$petity." and x <= ".$grandx." and y <= ".$grandy." ORDER BY (x-y) ASC,x ASC, y DESC");
while(list( $koi,$x, $y, $type) = mysql_fetch_array($resultcarte))
{
$xx=$x-$xperso+3; $yy=$y-$yperso+2;
$xiso=($xx+$yy)*$taille/2+$taille/2;
$yiso=($xx-$yy)*$taille2/2+(2+$nbcase)*$taille2/2;
$truc[$type]=loadgif ("img/$type.png");
ImageCopy ($xxxm,$truc[$type], $xiso, $yiso-48, 1, 1, 63, 63); }
}
// ================== on se déconnecte de la base de données
dbdeconnect()
;
// ================== création image
header ("Content-type: image/png");
imagepng ($xxxm);
// ================== destruction fichier (on s'en reservira jamais :) )
ImageDestroy ($xxxm);
}
?>
par jouer.org
dernière mise à jour:12/01/2005