Game Development Reference
In-Depth Information
private function moveBall(deltaTime:Number):void
{
var maxDelta:Number = MAX_BALL_SPEED * deltaTime;
_ball.vx += _ax * deltaTime * ACCELERATION_MULTIPLIER;
if (_ball.vx > maxDelta)
{
_ball.vx = maxDelta;
}
else if (_ball.vx < -maxDelta)
{
_ball.vx = -maxDelta;
}
_ball.vy += _ay * deltaTime * ACCELERATION_MULTIPLIER;
if (_ball.vy
>
maxDelta)
{
_ball.vy = maxDelta;
}
else if (_ball.vy
<
-maxDelta)
{
_ball.vy = -maxDelta;
}
_ball.x += _ball.vx;
_ball.y += _ball.vy;
}
s current velocity is incremen-
ted based on the current acceleration from the Accelerometer and
the time that has elapsed. If the ball
When moveBall is called, the ball
'
s velocity exceeds the set max-
imum value, it is clamped to prevent an infinite increase. This
resultant velocity is then applied to the ball
'
'
s position. You may
notice that I
m multiplying the acceleration by a static value, in this
case 80. The reason for doing this was something I learned through
playtesting. When using the raw values from the accelerometer,
they were so small that you had to tilt very dramatically the iPhone
to get enough response to move the ball. This doesn
'
very fun experience as I had to move the phone in a very unnatural
fashion to get the ball to respond. By multiplying it by a much lar-
ger number, you get a fairly sensitive response time from much
smaller movements of the device. After testing a few different
values, I settled on this one for having the best feel .
'
private function checkCollisions():void
{
for each (var wall:IWall in _currentLevel.walls)
{