Game Development Reference
In-Depth Information
_timer->setVisible(true);
}
}
}
Note that we use a larger radius for the white ball in our logic (four times larger).
This is because we don't want the target area to be too small, since this game will
run on both iPhones and iPads. We want the player to comfortably hit the white
ball with his or her finger.
4. We store where in the ball the point lies. This way, the player can hit the ball at
different spots, causing it to move at different angles:
//make point lie within ball
if (diff > pow(BALL_RADIUS * 2, 2)) {
float angle = atan2(diffy, diffx);
_cueStartPoint = Vec2(
playerPos.x + BALL_RADIUS * 0.8f *
cos(angle),
playerPos.y + BALL_RADIUS * 0.8f *
sin(angle));
} else {
_cueStartPoint = playerPos;
}
Since we made the white ball a much larger target for our touch event, now we
must make sure the actual point picked by the player lies within the ball. So we
may have to make some adjustments here.
5. We pass the point to our LineContainer object and we prepare the cue body
to be used, as follows:
_lineContainer->setBallPoint(_cueStartPoint);
_cue->getBody()->SetLinearVelocity(b2Vec2(0,0));
_cue->getBody()->SetAngularVelocity(0.0);
_touch = touch;
We once again have a LineContainer node so we can draw a dashed line
between the cue and the spot on the ball where the cue will hit. This serves as a
visual aid for the player to prepare his or her shot. The visual aid effect is demon-
strated here:
Search WWH ::




Custom Search