starling-handbook-preview

ggschelling

private static const BIRD_RADIUS:Number = 18; 1

public function advanceTime(passedTime:Number):void

{

/* ... */

}

checkForCollisions(); 2

private function checkForCollisions():void

{

var bottom:Number = _ground.y - BIRD_RADIUS; 3

}

if (_bird.y > bottom) 4

{

_bird.y = bottom;

_birdVelocity = 0;

}

1 Add a new constant at the very top: the radius of the bird’s body circle (in points).

2 Collision detection is handled in a separate method, called every frame.

3 The bottom, that’s where the grass starts. The bird’s fall will stop a little further upwards.

(Remember: we moved the bird’s pivot point to the center of its body.)

4 When we hit bottom, the bird’s velocity is set to zero immediately, and we make sure it doesn’t

move any further down.

That makes playing around with our prototype much easier! Granted: when we hit rock bottom, it

should actually mean "game over", but the bird just moves on. But that’s the topic of a later chapter.

For now, I think we have made great progress!

22

More magazines by this user
Similar magazines