Game Development Reference
In-Depth Information
ObjectPool before placing a spawn point only where there are no other game objects
around in, say, 150 pixel radius:
class Map
# ...
def find_spawn_point
while true
x = rand ( 0. . MAP_WIDTH * TILE_SIZE )
y = rand ( 0. . MAP_HEIGHT * TILE_SIZE )
if can_move_to?(x, y) &&
@object_pool . nearby_point(x, y, 150 ) . empty?
return [ x, y ]
end
end
end
# ...
end
How about powerups? They can also spawn in the middle of a forest, and while tanks
are not seeking them yet, we will be implementing this behavior, and leading tanks into
wilderness of trees is not the best idea ever. Let's fix it too:
class Map
# ...
def generate_powerups
pups = 0
target_pups = rand ( 20. . 30 )
while pups < target_pups do
x = rand ( 0. . MAP_WIDTH * TILE_SIZE )
y = rand ( 0. . MAP_HEIGHT * TILE_SIZE )
if tile_at(x, y) != @water &&
@object_pool . nearby_point(x, y, 150 ) . empty?
random_powerup . new( @object_pool , x, y)
pups += 1
end
end
end
# ...
end
We could also reduce tree count, but that would make the map look worse, so we are going
to keep this in our pocket as a mean of last resort.
Search WWH ::




Custom Search