Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting( ~E_NOTICE );
- class myIso {
- private $blocks = array();
- private $maxcoords = array( 8, 8, 4, 'x' => 8, 'y' => 8, 'z' => 4 );
- public function __construct( $x = 8, $y = 8, $z = 4 ) {
- $this->maxcoords = array( $x, $y, $z, 'x' => $x, 'y' => $y, 'z' => $z );
- }
- public function addBlock( $block, $x, $y, $z ) {
- $this->blocks[$x][$y][$z] = $block;
- }
- public function flush( ) {
- $image = imagecreatetruecolor(512,512);
- $rendertable = array();
- for( $xy = $this->maxcoords['x']; $xy>=0; $xy-- ) {
- for( $z = $this->maxcoords['z']; $z>=0; $z-- ) {
- for( $xy2 = $xy; $xy2>=0; $xy2-- ) {
- $myBlock = $this->blocks[$xy][$xy2][$z];
- $myBlock2 = $this->blocks[$xy2][$xy][$z];
- if(isset($myBlock)) {
- $sides = 0;
- if( !isset($this->blocks[$xy][$xy2-1][$z]) ) { $sides += 1; }
- if( !isset($this->blocks[$xy-1][$xy2][$z]) ) { $sides += 2; }
- if( !isset($this->blocks[$xy][$xy2][$z+1]) ) { $sides += 4; }
- if( $sides != 0 ) { $rendertable[] = array( $sides, $myBlock, $xy, $xy2, $z ); }
- }
- if(isset($myBlock2)) {
- $sides = 0;
- if( !isset($this->blocks[$xy2][$xy-1][$z]) ) { $sides += 1; }
- if( !isset($this->blocks[$xy2-1][$xy][$z]) ) { $sides += 2; }
- if( !isset($this->blocks[$xy2][$xy][$z+1]) ) { $sides += 4; }
- if( $sides != 0 ) { $rendertable[] = array( $sides, $myBlock2, $xy2, $xy, $z ); }
- }
- }
- }
- }
- imagealphablending( $image , true );
- imagesavealpha( $image , true );
- $stone = array( imagecreatefrompng( "bloki/stone_t.png" ), imagecreatefrompng( "bloki/stone_l.png" ), imagecreatefrompng( "bloki/stone_r.png" ) );
- foreach( $stone as $v ) { imagealphablending( $v , true ); imagesavealpha( $v , true ); }
- //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 )
- $tan30 = abs(tan(30));
- $color = imagecolorallocate($image, 220, 245, 255);
- imagefilledrectangle ( $image , 2, 2, 510, 510, $color );
- foreach( $rendertable as $k => $v ) {
- if( $v[1] == "stone" ) { $tileset = $stone; }
- $sides = $v[0];
- while( $sides > 0 ) {
- if( $sides - 4 >= 0 ) {
- $sides -= 4;
- $tile = $tileset[0];
- $dst_x = 255 + $v[2]*22 - $v[3]*22;
- $dst_y = 500 - $v[4]*44 - 11 + $v[2]*11 - $v[3]*11;
- imagecopymerge( $image, $tile, $dst_x, $dst_y, 0, 0, 44, 22, 50 );
- }elseif( $sides - 2 >= 0 ) {
- $sides -= 2;
- $tile = $tileset[1];
- $dst_x = 255 + $v[2]*22 - $v[3]*22;
- $dst_y = 500 - $v[4]*44 + $v[2]*11 - $v[3]*11;
- imagecopymerge( $image, $tile, $dst_x, $dst_y, 0, 0, 23, 34, 70 );
- }elseif( $sides - 1 >= 0 ) {
- $sides -= 1;
- $tile = $tileset[2];
- $dst_x = 255 + $v[2]*22 - $v[3]*22 + 22;
- $dst_y = 500 - $v[4]*44 + $v[2]*11 - $v[3]*11;
- imagecopymerge( $image, $tile, $dst_x, $dst_y, 0, 0, 23, 34, 70 );
- }
- }
- }
- header('Content-Type: image/png');
- imagepng($image, null, 9);
- imagedestroy($image);
- }
- }
- $engine = new myIso();
- $engine->addBlock( 'stone', 0, 1, 1 );
- $engine->addBlock( 'stone', 0, 2, 2 );
- $engine->addBlock( 'stone', 0, 2, 1 );
- $engine->addBlock( 'stone', 0, 3, 1 );
- $engine->flush();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement