Game Development Reference
In-Depth Information
if (testRect.intersects(enemyRect)) {
var enemyPoint:Point = getGridPosition
(enemy);
var gridReference:GridReference =
_collisionGrid.getGridReference
(enemyPoint.x, enemyPoint.y);
gridReference.removeEnemy(enemy);
_enemies.splice(_enemies.indexOf(enemy),1);
removeChild(enemy as DisplayObject);
var pe:PlatformerEvent = new Platformer
Event(PlatformerEvent.PLAYER_DIE,
enemy.name);
dispatchEvent(pe);
}
}
}
The checkEnemies method is very similar to the item check,
except that a different outcome occurs in the form of a PLAYER_
DIE event. The enemy is also removed from all lists.
protected function checkPortals():void {
var testPoint:Point = getGridPosition(_player);
var testReference:GridReference = _collisionGrid.
getGridReference(testPoint.x, testPoint.y);
if (testReference.portals.length) {
var portal:IPortal = testReference.portals[0];
var portalRect:Rectangle = portal.hitArea.getRect
(this);
if (_player.hitArea.getRect(this).intersects
(portalRect)) {
var metRequirements:Boolean = true;
for each (var requirement:PortalRequirement
in portal.requirements) {
if (requirement.type ==
PortalRequirement.INVENTORY) {
if (!checkInventory(requirement.name)) {
metRequirements = false;
break;
}
}
}
if (metRequirements) {
var pe:PlatformerEvent = new
PlatformerEvent(PlatformerEvent.
ENTER_PORTAL, portal.destination);
dispatchEvent(pe);
Search Nedrilad ::




Custom Search