Game Development Reference
In-Depth Information
What just happened?
When we instantiate a block in
initBlock
, we create a 5 x 4 building made out of wall
tiles and roof tiles, each a sprite. And when we need to turn this building into a 3 x 2 build-
ing, or a 4 x 4 building, or whatever, we simply turn the excess tiles invisible at the end of
setupBlock
.
The texture used for the roof is picked randomly, but the one picked for the walls is based
on building type (from our
patterns
array). It is also inside this
for
loop that all the
tiles positioned at a point greater than the new building's width and height are turned invis-
ible.