Game Development Reference
In-Depth Information
if (intersection.height) _player.
netForce.y = 0;
}
//ADJUST VALUES TO MATCH NEW RECT
_player.tempX = _player.x + (testRect.x - oldRect.x);
_player.tempY = _player.y + (testRect.y - oldRect.y);
}
}
The wall collision check is the most involved, as it requires the
most calculation and action on the engine
'
s part. If the player
is overlapping into a wall, then the player
spositionmustbe
corrected relative to the wall. If no overlap occurs, the full check
and adjustment is skipped to minimize calculations.
'
protected function checkItems(testReference:GridReference):
void {
var testRect:Rectangle = _player.hitArea.getRect(this);
for each (var item:IItem in testReference.items) {
var itemRect:Rectangle = item.hitArea.getRect(this);
if (testRect.intersects(itemRect)) {
var itemPoint:Point = getGridPosition(item);
var gridReference:GridReference =
_collisionGrid.getGridReference
(itemPoint.x, itemPoint.y);
gridReference.removeItem(item);
_inventory.push(item);
_items.splice(_items.indexOf(item),1);
removeChild(item as DisplayObject);
var pe:PlatformerEvent = new Platformer
Event(PlatformerEvent.INVENTORY_
UPDATE,item.name);
dispatchEvent(pe);
}
}
}
The next type of Sprite to check against is items. A similar rectangle
intersection test is performed, but no position adjustments are needed.
If the player collides with an item, it should simply be removed from
the screen and all collision lists, and added to the player
'
sinventory.
protected function checkEnemies(testReference:GridReference):void {
var testRect:Rectangle = _player.hitArea.getRect(this);
for each (var enemy:IEnemy in testReference.enemies) {
var enemyRect:Rectangle = enemy.hitArea.getRect
(this);
Search Nedrilad ::




Custom Search