Advertisement
Guest User

Untitled

a guest
May 6th, 2011
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.25 KB | None | 0 0
  1. <?php
  2. error_reporting( ~E_NOTICE );
  3. class myIso {
  4.     private $blocks = array();
  5.     private $maxcoords = array( 8, 8, 4, 'x' => 8, 'y' => 8, 'z' => 4 );
  6.     public function __construct( $x = 8, $y = 8, $z = 4 ) {
  7.         $this->maxcoords = array( $x, $y, $z, 'x' => $x, 'y' => $y, 'z' => $z );
  8.     }
  9.     public function addBlock( $block, $x, $y, $z ) {
  10.         $this->blocks[$x][$y][$z] = $block;
  11.     }
  12.    
  13.     public function flush( ) {
  14.         $image = imagecreatetruecolor(512,512);
  15.         $rendertable = array();
  16.        
  17.         for( $xy = $this->maxcoords['x']; $xy>=0; $xy-- ) {
  18.             for( $z = $this->maxcoords['z']; $z>=0; $z-- ) {
  19.                 for( $xy2 = $xy; $xy2>=0; $xy2-- ) {
  20.                     $myBlock  = $this->blocks[$xy][$xy2][$z];
  21.                     $myBlock2 = $this->blocks[$xy2][$xy][$z];
  22.                     if(isset($myBlock)) {
  23.                         $sides = 0;
  24.                         if( !isset($this->blocks[$xy][$xy2-1][$z]) ) { $sides += 1; }
  25.                         if( !isset($this->blocks[$xy-1][$xy2][$z]) ) { $sides += 2; }
  26.                         if( !isset($this->blocks[$xy][$xy2][$z+1]) ) { $sides += 4; }
  27.                         if( $sides != 0 ) { $rendertable[] = array( $sides, $myBlock, $xy, $xy2, $z ); }
  28.                     }
  29.                     if(isset($myBlock2)) {
  30.                         $sides = 0;
  31.                         if( !isset($this->blocks[$xy2][$xy-1][$z]) ) { $sides += 1; }
  32.                         if( !isset($this->blocks[$xy2-1][$xy][$z]) ) { $sides += 2; }
  33.                         if( !isset($this->blocks[$xy2][$xy][$z+1]) ) { $sides += 4; }
  34.                         if( $sides != 0 ) { $rendertable[] = array( $sides, $myBlock2, $xy2, $xy, $z  ); }
  35.                     }
  36.                 }
  37.             }
  38.         }
  39.         imagealphablending( $image , true );
  40.         imagesavealpha( $image , true );
  41.         $stone = array( imagecreatefrompng( "bloki/stone_t.png" ), imagecreatefrompng( "bloki/stone_l.png" ), imagecreatefrompng( "bloki/stone_r.png" ) );
  42.         foreach( $stone as $v ) { imagealphablending( $v , true ); imagesavealpha( $v , true ); }
  43.         //bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
  44.        
  45.         $tan30 = abs(tan(30));
  46.         $color = imagecolorallocate($image, 220, 245, 255);
  47.         imagefilledrectangle ( $image , 2, 2, 510, 510, $color );
  48.        
  49.         foreach( $rendertable as $k => $v ) {
  50.             if( $v[1] == "stone" ) { $tileset = $stone; }
  51.             $sides = $v[0];
  52.             while( $sides > 0 ) {
  53.                 if( $sides - 4 >= 0 ) {
  54.                 $sides -= 4;
  55.                 $tile = $tileset[0];
  56.                 $dst_x = 255 + $v[2]*22 - $v[3]*22;            
  57.                 $dst_y = 500 - $v[4]*44 - 11 + $v[2]*11 - $v[3]*11;
  58.                 imagecopymerge( $image, $tile, $dst_x, $dst_y, 0, 0, 44, 22, 50 );
  59.             }elseif( $sides - 2 >= 0 ) {
  60.                 $sides -= 2;
  61.                 $tile = $tileset[1];
  62.                 $dst_x = 255 + $v[2]*22 - $v[3]*22;        
  63.                 $dst_y = 500 - $v[4]*44 + $v[2]*11 - $v[3]*11;  
  64.                 imagecopymerge( $image, $tile, $dst_x, $dst_y, 0, 0, 23, 34, 70 );
  65.             }elseif( $sides - 1 >= 0 ) {
  66.                 $sides -= 1;
  67.                 $tile = $tileset[2];
  68.                 $dst_x = 255 + $v[2]*22 - $v[3]*22 + 22;    
  69.                 $dst_y = 500 - $v[4]*44 + $v[2]*11 - $v[3]*11;
  70.                 imagecopymerge( $image, $tile, $dst_x, $dst_y, 0, 0, 23, 34, 70 );
  71.             }
  72.                
  73.             }
  74.         }
  75.        
  76.         header('Content-Type: image/png');
  77.         imagepng($image, null, 9);
  78.         imagedestroy($image);
  79.     }
  80. }
  81. $engine = new myIso();
  82. $engine->addBlock( 'stone', 0, 1, 1 );
  83. $engine->addBlock( 'stone', 0, 2, 2 );
  84. $engine->addBlock( 'stone', 0, 2, 1 );
  85. $engine->addBlock( 'stone', 0, 3, 1 );
  86. $engine->flush();
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement