make island


= 23 && $n <= 25) // sand return 1; if($n >= 26 && $n <= 37) // sand and grass return 2; if($n >= 0 && $n <= 7) // grass return 0; if($n == 52) return 3; if($n >= 53 && $n <= 64) // watter and sand return 4; } function is_sandborder($n) { if($n >= 53 && $n <= 64) // watter and sand return false; if($n >= 23 && $n <= 25) // sand return false; return true; } function is_waterborder($n) { if($n >= 52 && $n <= 64) // watter and sand return true; return false; } function make_in_borders(&$map) { make_water_borders(&$map); make_sand_borders(&$map); } function make_water_borders(&$map) { global $mtypes; $t=1; for($i=1;$i < 99;$i++) { for($j=1;$j < 99;$j++) { // Water and sand border if(is_waterborder($map[$i][$j]) != true) continue; $n=is_waterborder($map[$i][$j-1]); $s=is_waterborder($map[$i][$j+1]); $e=is_waterborder($map[$i+1][$j]); $w=is_waterborder($map[$i-1][$j]); $ne=is_waterborder($map[$i+1][$j-1]); $nw=is_waterborder($map[$i-1][$j-1]); $sw=is_waterborder($map[$i-1][$j+1]); $se=is_waterborder($map[$i+1][$j+1]); if($n && $s && $w && $e && $ne && $nw && $sw && $se) continue; if(!$n && $s && $w && $e) $map[$i][$j]=$mtypes[$t][4]; else if($n && !$s && $w && $e) $map[$i][$j]=$mtypes[$t][1]; else if($n && $s && !$w && $e) $map[$i][$j]=$mtypes[$t][2]; else if($n && $s && $w && !$e) $map[$i][$j]=$mtypes[$t][3]; else if(!$n && $s && !$w && $e) $map[$i][$j]=$mtypes[$t][5]; else if(!$n && $s && $w && !$e) $map[$i][$j]=$mtypes[$t][6]; else if($n && !$s && $w && !$e) $map[$i][$j]=$mtypes[$t][7]; else if($n && !$s && !$w && $e) $map[$i][$j]=$mtypes[$t][8]; else if(!$ne) $map[$i][$j]=$mtypes[$t][9]; else if(!$nw) $map[$i][$j]=$mtypes[$t][10]; else if(!$se) $map[$i][$j]=$mtypes[$t][11]; else if(!$sw) $map[$i][$j]=$mtypes[$t][12]; } } } function make_sand_borders(&$map) { global $mtypes; $t=0; for($i=1;$i < 99;$i++) { for($j=1;$j < 99;$j++) { // Sand and grass border if(cell_type($map[$i][$j]) != 0) continue; $n=is_sandborder($map[$i][$j-1]); $s=is_sandborder($map[$i][$j+1]); $e=is_sandborder($map[$i+1][$j]); $w=is_sandborder($map[$i-1][$j]); $ne=is_sandborder($map[$i+1][$j-1]); $nw=is_sandborder($map[$i-1][$j-1]); $se=is_sandborder($map[$i+1][$j+1]); $sw=is_sandborder($map[$i-1][$j+1]); if($n && $s && $w && $e && $ne && $nw && $sw && $se) continue; if(!$n && !$s && $w && $e) $map[$i][$j]=25; else if($n && $s && !$w && !$e) $map[$i][$j]=25; else if(!$n && $s && $w && $e) $map[$i][$j]=$mtypes[$t][4]; else if($n && !$s && $w && $e) $map[$i][$j]=$mtypes[$t][1]; else if($n && $s && !$w && $e) $map[$i][$j]=$mtypes[$t][2]; else if($n && $s && $w && !$e) $map[$i][$j]=$mtypes[$t][3]; else if(!$n && $s && !$w && $e) $map[$i][$j]=$mtypes[$t][5]; else if(!$n && $s && $w && !$e) $map[$i][$j]=$mtypes[$t][6]; else if($n && !$s && $w && !$e) $map[$i][$j]=$mtypes[$t][7]; else if($n && !$s && !$w && $e) $map[$i][$j]=$mtypes[$t][8]; else if(!$ne) $map[$i][$j]=$mtypes[$t][9]; else if(!$nw) $map[$i][$j]=$mtypes[$t][10]; else if(!$se) $map[$i][$j]=$mtypes[$t][11]; else if(!$sw) $map[$i][$j]=$mtypes[$t][12]; } } } function drawline(&$map,$x1,$y1,$x2,$y2,$c) { $dX = abs($x2-$x1); // store the change in X and Y of the line endpoints $dY = abs($y2-$y1); //------------------------------------------------------------------------ // DETERMINE "DIRECTIONS" TO INCREMENT X AND Y (REGARDLESS OF DECISION) //------------------------------------------------------------------------ if ($x1 > $x2) { $Xincr=-1; } else { $Xincr=1; } // which direction in X? if ($y1 > $y2) { $Yincr=-1; } else { $Yincr=1; } // which direction in Y? //------------------------------------------------------------------------ // DETERMINE INDEPENDENT VARIABLE (ONE THAT ALWAYS INCREMENTS y2 1 (OR -1) ) // AND INITIATE APPROPRIATE LINE DRAWING ROUTINE (BASED ON FIRST OCTANT // ALWAYS). THE X AND Y'S MAY BE FLIPPED IF Y IS THE INDEPENDENT VARIABLE. //------------------------------------------------------------------------ if ($dX >= $dY) // if X is the independent variable { $dPr = $dY<<1; // amount to increment decision if right is chosen (always) $dPru = $dPr - ($dX<<1); // amount to increment decision if up is chosen $P = $dPr - $dX; // decision variable start value for (; $dX>=0; $dX--) // process each point in the line one at a time (just use dX) { if($x1 >= 0 && $y1 >= 0 && $x1 < 100 && $y1 < 100) { $map[$x1][$y1]=$c; } if ($P > 0) // is the pixel going right AND up? { $x1+=$Xincr; // increment independent variable $y1+=$Yincr; // increment dependent variable $P+=$dPru; // increment decision (for up) } else // is the pixel just going right? { $x1+=$Xincr; // increment independent variable $P+=$dPr; // increment decision (for right) } } } else // if Y is the independent variable { $dPr = $dX<<1; // amount to increment decision if right is chosen (always) $dPru = $dPr - ($dY<<1); // amount to increment decision if up is chosen $P = $dPr - $dY; // decision variable start value for (; $dY>=0; $dY--) // process each point in the line one at a time (just use dY) { if($x1 >= 0 && $y1 >= 0 && $x1 < 100 && $y1 < 100) { $map[$x1][$y1]=$c; } //drawRGBPixel(r,g,b,x1, y1); // plot the pixel if ($P > 0) // is the pixel going up AND right? { $x1+=$Xincr; // increment dependent variable $y1+=$Yincr; // increment independent variable $P+=$dPru; // increment decision (for up) } else // is the pixel just going up? { $y1+=$Yincr; // increment independent variable $P+=$dPr; // increment decision (for right) } } } } function borders_water($map,$x,$y) { if($map[$x][$y-1] == 52 || $map[$x][$y+1] == 52 || $map[$x-1][$y] == 52 || $map[$x+1][$y] == 52) return true; return false; } function borders_ground($map,$x,$y) { if($map[$x][$y-1] == 0 || $map[$x][$y+1] == 0 || $map[$x-1][$y] == 0 || $map[$x+1][$y] == 0) return true; if($map[$x][$y-1] == 23 || $map[$x][$y+1] == 23 || $map[$x-1][$y] == 23 || $map[$x+1][$y] == 23) return true; } function make_island(&$map,&$obj) { // Init the arrays for($i=0;$i < 100;$i++) for($j=0;$j < 100;$j++) $map[$i][$j]=52; for($i=0;$i < 100;$i++) for($j=0;$j < 100;$j++) $obj[$i][$j]=0; // Create the base islands for($n=0;$n < mt_rand(1,10);$n++) { $w=mt_rand(3,50); $h=mt_rand(5,20); $mx=mt_rand(-30,30); $my=mt_rand(-30,30); for($i=0;$i < $h;$i++) { $wc=round($w*(($h-$i)/$h)); drawline($map,50-round($wc/2)+$mx,$my+49-$i,$mx+50+round($wc/2),$my+49-$i,0); drawline($map,50-round($wc/2)+$mx,$my+49+$i,$mx+50+round($wc/2),$my+49+$i,0); $w+=mt_rand(-4,4); if($w <= 1) break; if($w > 90) $w=90; } } for($i=0;$i < 100;$i++) for($j=0;$j < 100;$j++) $dmap[$i][$j]=52; $u=mt_rand(3,8); $v=mt_rand(3,8); $d=mt_rand(6,20); $ang=mt_rand(0,360)/180*M_PI; // Rotate and deform for($i=0;$i < 100;$i++) { for($j=0;$j < 100;$j++) { $a=sin(($i+$j+$u)/$d)*3+$i; $b=cos(($i+$j+$v)/$d)*3+$j; $a=50-$a; $b=50-$b; $x = $a * cos($ang) - $b * sin($ang); $y = $b * cos($ang) + $a * sin($ang); $x=50-$x; $y=50-$y; if($x < 0) $x=0; if($x > 99) $x=99; if($y < 0) $y=0; if($y > 99) $y=99; $dmap[$i][$j]=$map[$x][$y]; } } // Cleanup the borders drawline($dmap,0,0,99,0,52); drawline($dmap,0,1,99,1,52); drawline($dmap,0,2,99,2,52); drawline($dmap,0,99,99,99,52); drawline($dmap,0,98,99,98,52); drawline($dmap,0,97,99,97,52); drawline($dmap,0,0,0,99,52); drawline($dmap,1,0,1,99,52); drawline($dmap,2,0,2,99,52); drawline($dmap,99,0,99,99,52); drawline($dmap,98,0,98,99,52); drawline($dmap,97,0,97,99,52); $map=$dmap; // Remove 2 corrners for($i=1;$i < 99;$i++) for($j=1;$j < 99;$j++) { if($map[$i+1][$j+1] == 0 && $map[$i-1][$j-1] == 0) $map[$i][$j]=0; if($map[$i-1][$j+1] == 0 && $map[$i+1][$j-1] == 0) $map[$i][$j]=0; } // Remove water noise for($i=1;$i < 99;$i++) for($j=1;$j < 99;$j++) { if($map[$i][$j] == 52 && $map[$i][$j+1] == 0 && $map[$i][$j-1] == 0) $map[$i][$j]=0; if($map[$i][$j] == 52 && $map[$i+1][$j] == 0 && $map[$i-1][$j] == 0) $map[$i][$j]=0; if($map[$i][$j] == 52 && $map[$i][$j+1] == 0 && $map[$i][$j-1] == 0) $map[$i][$j]=0; } // Remove land noise for($i=1;$i < 99;$i++) for($j=1;$j < 99;$j++) { if($map[$i][$j] == 0 && $map[$i][$j+1] == 52 && $map[$i][$j-1] == 52) $map[$i][$j]=52; if($map[$i][$j] == 0 && $map[$i+1][$j] == 52 && $map[$i-1][$j] == 52) $map[$i][$j]=52; } // Randomize the grass for($i=0;$i < 100;$i++) for($j=0;$j < 100;$j++) { if($map[$i][$j] == 0 && mt_rand(0,6) == 0) $map[$i][$j]=mt_rand(3,7); else if($map[$i][$j] == 0) $map[$i][$j]=mt_rand(0,2); } // Add trees on the grass $trees=array(5,57,58,62,63,59,133); for($i=0;$i < 100;$i++) for($j=0;$j < 100;$j++) if($map[$i][$j] < 8 && mt_rand(0,30) == 0) $obj[$i][$j]=$trees[mt_rand(0,count($trees)-1)]; } ?>

Wyszukiwarka

Podobne podstrony:
make island
make island
make island
6 make a point
Wyspa tajemnic Shutter Island (2010) b
How to Make your Own Tracer Ammunition
Woodworking Plans Island, Kitchen Island 2
HOW TO MAKE AN MESSENGE BOX
Make Money With YouTube
make, do, have, get
Nazwiska islandzkie
130611150731?c tews8 don t make me laugh
Britney Spears?n t make you love me
Make Adjectives from these words
[dcpp][Bidemare][Crociera Guide][Pacifico][Eng] Cruising the Galapagos Islands
Ares Islanderbuch, ASB 1 1892
Garbage?n´t Seem To Make You Mine
how to make a triangle weave circle

więcej podobnych podstron