Game Development Reference
In-Depth Information
portals = null;
}
}
}
Every type of object a grid reference can store has a vector cre-
ated just for it. Many of these vectors may stay empty, but they
consume very little memory by themselves, so it is a small price to
pay for such flexibility. Similar to an array, grid reference objects
have a concat method, which allows you to merge one grid refer-
ence with another. With this functionality, it is possible to combine
multiple grid references into one for easy checking.
There are also convenient methods for removing enemies and
items from a grid reference, and a custom toString method that
allows you to easily see what
s in a grid reference with a simple
trace statement. Finally, there is also a clear method that can be
called during engine cleanup.
'
The CollisionGrid Class
In order to store all the grid references in a cohesive structure, we
need a container. We could use a simple array or vector to keep
track of all of them, but in our case, it makes more sense to create a
custom data structure: enter the CollisionGrid. This class uses both
an array and multiple vectors to create a multidimensional grid.
package com.flashgamebook.engines.platformer {
import flash.geom.Point;
public class CollisionGrid {
private var _width:int;
private var _height:int;
private var _grid:Array;
public function CollisionGrid(width:int, height:int) {
_width = width;
_height = height;
_grid = new Array(_width, true);
for (var i:int = 0; i
_width; i++) {
_grid[i] = new Vector.
<
<
GridReference
>
(_height, true);
for(varj:int=0;j < _height; j++) {
_grid[i][j] = new GridReference();
}
}
}
Search Nedrilad ::




Custom Search