
coucou747
|
un petit exemple qui montre en même temps la puissance de GD :
index.php
RPG
\n");
}
$joueur=1;
include("joueur$joueur.php");
$a=$_GET['deplace'];
switch($a){
case 4:
$xscrool-=100;
break;
case 6:
$xscrool+=100;
break;
case 8:
$yscrool-=100;
break;
case 2:
$yscrool+=100;
break;
}
if ($a!=0){
save($xscrool,$yscrool, $case, $joueur, $anglex, $angley);
}
echo "
|
";
?>
images.php
function poly($pt1, $pt2, $pt3, $pt4, $x, $y, $terrain, $max, $im, $black, $couleurs){
$centerx=($x[$pt1]+$x[$pt2]+$x[$pt3])/3;
$centery=($y[$pt1]+$y[$pt2]+$y[$pt3])/3;
poly2($pt1, $pt2, $centerx, $centery, $x, $y, $terrain, $max, $im, $black, $couleurs);
poly2($pt3, $pt2, $centerx, $centery, $x, $y, $terrain, $max, $im, $black, $couleurs);
poly2($pt3, $pt4, $centerx, $centery, $x, $y, $terrain, $max, $im, $black, $couleurs);
poly2($pt1, $pt4, $centerx, $centery, $x, $y, $terrain, $max, $im, $black, $couleurs);
imagepolygon($im, array($x[$pt1], $y[$pt1], $x[$pt2], $y[$pt2], $x[$pt3], $y[$pt3], $x[$pt4], $y[$pt4]), 4, $black );
}
function poly2($pt1, $pt2, $centerx, $centery, $x, $y, $terrain, $max, $im, $black, $couleurs){
$v=round(($terrain[$pt1]+$terrain[$pt2])/$max/2*10);
imagefilledpolygon($im, array($x[$pt1], $y[$pt1], $x[$pt2], $y[$pt2], $centerx, $centery), 3, $couleurs[$v] );
}
mt_srand(microtime() * 1000000);
header ("Content-type: image/png");
$terrain=1;
include("terrain$terrain.php");
$im = ImageCreate (640, 480)
or die ("Erreur lors de la création de l'image");
$couleur_fond = ImageColorAllocate ($im, 0, 0, 0);
$angley=$_GET['angley'];
$anglex=$_GET['anglex'];
$case=$_GET['case'];
$xscrool=$_GET['xscrool'];
$yscrool=$_GET['yscrool'];
$hauteur=50;
$black = imagecolorallocate($im, 0,0,0);
for ($a=0;$a<$dimx;$a++){
for ($b=0;$b<$dimy;$b++){
$x[$a+$b*$dimx]=($a+$b*$angley)*$case-$xscrool;
$y[$a+$b*$dimx]=($b+$a*$anglex-$terrain[$a+$b*$dimx]/$hauteur)*$case-$yscrool;
if ($x[$a+$b*$dimx]<0){
$x[$a+$b*$dimx]=0;
}
if ($y[$a+$b*$dimx]<0){
$y[$a+$b*$dimx]=0;
}
}
}
$couleurs[0] = imagecolorallocate($im, 0,0,128);
for ($i=1;$i<10;$i++){
$couleurs[$i] = imagecolorallocate($im, 0,$i*25,0);
}
for ($b=0;$b<$dimy-1;$b++){
for ($a=0;$a<$dimx-1;$a++){
if ($x[$a+$b*$dimx]<640 && $x[$a+1+($b+1)*$dimx]>0 && $y[$a+$b*$dimx]<480 && $y[$a+1+($b+1)*$dimx]>0){
poly(
$a+$b*$dimx,
$a+1+$b*$dimx,
$a+1+($b+1)*$dimx,
$a+($b+1)*$dimx,
$x, $y, $terrain, $max, $im, $black, $couleurs);
}
}
}
imagePng ($im);
?>
joueur1.php
terrain1.php
$dimx=20;
$dimy=20;
$max=35;
$terrain=array(
5, 5, 10, 10, 10, 10, 10, 10, 5, 0, 0, 0, 5, 10, 20, 5, 5, 5, 5, 10,
5, 10, 20, 10, 20, 10, 20, 10, 20, 0, 0, 0, 10, 20, 30, 25, 20, 15, 10, 10,
5, 5, 10, 20, 10, 20, 10, 20, 10, 0, 0, 5, 15, 20, 30, 30, 20, 15, 10, 10,
5, 10, 20, 10, 20, 20, 20, 10, 20, 0, 0, 10, 20, 35, 30, 30, 25, 20, 10, 10,
5, 5, 10, 20, 10, 20, 10, 20, 10, 0, 0, 0, 5, 10, 10, 15, 10, 10, 5, 5,
5, 10, 20, 10, 20, 10, 20, 10, 20, 0, 0, 0, 0, 0, 5, 5, 10, 10, 5, 5,
5, 5, 20, 20, 10, 10, 10, 20, 10, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0,
5, 10, 20, 10, 20, 10, 20, 10, 20, 0, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0,
5, 5, 10, 20, 10, 20, 10, 20, 10, 0, 0, 0, 0, 5, 10, 10, 10, 10, 5, 0,
5, 5, 10, 15, 20, 25, 20, 30, 5, 0, 0, 0, 5, 10, 10, 10, 15, 15, 10, 0,
5, 10, 15, 20, 20, 20, 20, 25, 10, 0, 0, 0, 10, 15, 20, 20, 20, 20, 20, 10,
5, 5, 10, 20, 10, 20, 10, 10, 10, 0, 0, 5, 15, 20, 30, 25, 20, 15, 10, 10,
5, 10, 20, 10, 20, 10, 10, 10, 20, 0, 0, 10, 20, 35, 30, 30, 25, 20, 10, 10,
5, 5, 10, 20, 10, 10, 10, 20, 10, 0, 0, 0, 5, 10, 10, 15, 10, 10, 5, 5,
5, 10, 20, 20, 20, 10, 20, 20, 20, 0, 0, 0, 0, 0, 5, 5, 10, 10, 5, 5,
5, 5, 10, 20, 10, 20, 10, 20, 10, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0,
5, 10, 20, 10, 20, 20, 20, 10, 20, 0, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0,
5, 5, 10, 20, 10, 20, 10, 20, 10, 0, 0, 0, 0, 5, 10, 10, 10, 10, 5, 0,
5, 5, 10, 15, 20, 25, 20, 30, 5, 0, 0, 0, 5, 10, 10, 10, 15, 15, 10, 5,
10, 10, 15, 20, 20, 20, 20, 25, 10, 0, 0, 0, 10, 15, 20, 20, 20, 20, 20, 10);
?>
la tu devrais avoir un joli terrain en 3d
In a dream, I saw me, drop dead... U was here, U cried... It was just a deam, if I die, U won't cry, maybe, U'll be happyhttp://coucou747.hopto.org
|
|