Game Development Reference
ball and the center of the collision is used to
determine the angle of the collision.
Once the angle of collision has been deter-
mined, it is rounded to the nearest 90 degrees.
This is so that the appropriate offset can be cal-
This offset is then applied to the x and y coordi-
nates of the ball since the walls in this example
not to move in response to being hit.
private function checkHazards():void
Figure 15.7 When the ball and wall intersect, the
angle of the intersection is determined using the
center points of the ball and the collision.
var ballRect:Rectangle = _ball.getRect
for each (var hazard:IHazard in _currentLevel.hazards)
private function resetBall():void
_ball.x = _currentLevel.startPoint.x;
_ball.y = _currentLevel.startPoint.y;
_ball.vx = 0;
_ball.vy = 0;
Once the wall collisions have been resolved, the engine iterates
through all of the hazards in a level and determines if they inter-
sect. If the ball collides with any hazard, it is reset to initial starting
point with its velocity dropped to zero.
private function checkWin():void
var testPoint:Point = new Point(_ball.x, _ball.y);
if (Point.distance(testPoint, _currentLevel.endPoint) <
The final method of the class, checkWin ,simplymeasuresthe
distance between the ball and the endpoint specified by the level.