Game Development Reference
In-Depth Information
The checkPlayerCollisions method actually consists of several
methods that test against individual kinds of Sprites. The tests for each
are very similar, but the results are handled differently in each case.
protected function checkWalls(testReference:GridReference):
void {
var testRect:Rectangle = _player.hitArea.getRect(this);
var oldRect:Rectangle = testRect.clone();
testRect.x += _player.tempX - _player.x;
testRect.y += _player.tempY - _player.y;
for each (var wall:IWall in testReference.walls) {
var wallRect:Rectangle = wall.getRect(this);
var intersection:Rectangle = wallRect.
intersection(testRect);
if (!intersection.width || !intersection.height)
continue;
if (wallRect.top > = oldRect.bottom) { //WALL IS
BELOW
testRect.y -= intersection.height;
//OFFSET BY INTERSECTION HEIGHT
_player.netForce.y = 0;
}
intersection = wallRect.intersection(testRect);
if (wallRect.right
<
= oldRect.left) { //WALL IS TO
THE LEFT
testRect.x += intersection.width;
if (intersection.width) _player.netForce.
x=0;
}
intersection = wallRect.intersection(testRect);
if (wallRect.left > = oldRect.right) { //WALL IS TO
THE RIGHT
testRect.x -= intersection.width;
if (intersection.width) _player.netForce.
x=0;
}
intersection = wallRect.intersection(testRect);
if (wallRect.bottom < = oldRect.top) { //WALL IS
ABOVE
testRect.y += intersection.height;
//OFFSET BY INTERSECTION HEIGHT
Search Nedrilad ::




Custom Search