Game Development Reference
In-Depth Information
var xPos:int = Math.floor(centerX / Number(_currentLevel.
@gridSquareSize));
var centerY:Number = spriteRect.y + (spriteRect.height/2);
var yPos:int = Math.floor(centerY / Number(_currentLevel.
@gridSquareSize));
return new Point(xPos, yPos);
}
protected function updateGridReference(sprite:IEnemy):void {
var position:Point = getGridPosition(sprite);
var newGridReference = _collisionGrid.getGridReference
(position.x, position.y);
if (newGridReference == sprite.gridReference) return;
sprite.gridReference.removeEnemy(sprite);
sprite.gridReference = newGridReference;
newGridReference.enemies.push(sprite);
}
protected function getCollisionReference(sprite:ISprite):
GridReference {
var testPoint:Point = getGridPosition(sprite);
var testReference:GridReference = new GridReference();
//CHECK THE CURRENT GRID REFERENCE, AND THE EIGHT
SURROUNDING
testReference.concat(_collisionGrid.getGridReference
(testPoint.x-1, testPoint.y-1));
testReference.concat(_collisionGrid.getGridReference
(testPoint.x, testPoint.y-1));
testReference.concat(_collisionGrid.getGridReference
(testPoint.x+1, testPoint.y-1));
testReference.concat(_collisionGrid.getGridReference
(testPoint.x-1, testPoint.y));
testReference.concat(_collisionGrid.getGridReference
(testPoint.x, testPoint.y));
testReference.concat(_collisionGrid.getGridReference
(testPoint.x+1, testPoint.y));
testReference.concat(_collisionGrid.getGridReference
(testPoint.x-1, testPoint.y+1));
testReference.concat(_collisionGrid.getGridReference
(testPoint.x, testPoint.y+1));
testReference.concat(_collisionGrid.getGridReference
(testPoint.x+1, testPoint.y+1));
return testReference;
}
//END UTILITY
To make it easy to determine the grid space for any given Sprite
in the game, there is a single method, which returns a Point object.
Search Nedrilad ::




Custom Search