Game Development Reference
In-Depth Information
Figure 7-4. Iteration 5's regions depicted with different shaded areas
As Figure 7-4 shows, since we only have 15 vertical tiles (an odd number), we had to make the
top region eight tiles high and the bottom seven tiles high. We could have done it a different way,
but we chose this for ease of use. The horizontal length (ten tiles each) of the left and right
regions is identical because we have 20 tiles, an even number.
Now, let's take a look at two functions that are needed for the regions. The first, setRegions , is
used to create and populate the regions array. The second, setCurrentRegion , calculates the
current region for an object. Type these into your GameDemoIteratio5. as file just as they are.
//** added in iteration #5
private function setRegions():void {
regions = [];
//top left region
var tempRegion:Object = { col1:0, row1:0, col2:9, row2:7 };
regions.push(tempRegion);
//top right region region
tempRegion = { col1:10, row1:0, col2:19, row2:7 };
regions.push(tempRegion);
//bottom left region region
tempRegion = { col1:0, row1:8, col2:9, row2:14 };
regions.push(tempRegion);
//bot right region region
tempRegion = { col1:10, row1:8, col2:19, row2:14 };
Search WWH ::




Custom Search