Created
May 22, 2013 22:39
-
-
Save connors511/5631515 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createHouses() { | |
$tries = 0; | |
$max_tries = 3; | |
$timeout = 500; | |
$time_start = microtime(true); | |
$start = | |
$use = 'timeout'; | |
while($house_count > 0) { | |
if ($use == 'timeout') { | |
if (microtime(true) - $time_start > $timeout) { | |
break; | |
} | |
} else { | |
if ($tries == $max_tries) { | |
break; | |
} | |
} | |
for ($i=0; $i < $n; $i++) { | |
for ($j=0; $j < $n; $j++) { | |
if ($house_count == 0) { | |
break; | |
} | |
if ($this->grid[$i][$j] == Types::$TYPE_GRASS) | |
{ | |
// Higher chance near intersections? | |
if ($this->hasNearbyRoad($i,$j) && ($allow_nearby_house || !$this->hasNearbyHouse($i,$j))) { | |
// var isWall = Math.floor(Math.random()*(/wallFrequency)); | |
$chance = (rand(0,1000) / 1000) <= $house_pct; | |
if ($chance) { | |
$this->grid[$i][$j] = Types::$TYPE_HOUSE; | |
$this->houses[] = array('x' => $i, 'y' => $j); | |
$house_count--; | |
} | |
} | |
} | |
} | |
} | |
$tries++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment