Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override protected void updateGame(float secondsElapsed) {
- /*Detect if the ball is touching or has passed the edge of the screen.
- If it has, reverse the speed of the ball and slow it down slightly (making it appear
- to bounce back, losing 10% power)
- */
- if (mBallX >= mCanvasWidth) {
- mBallX = mCanvasWidth;
- mBallSpeedX = 0f - mBallSpeedX;
- }
- if (mBallX <= 0) {
- mBallX = 0;
- mBallSpeedX = 0f - mBallSpeedX;
- }
- if (mBallY >= mCanvasHeight) {
- mBallY = mCanvasHeight;
- mBallSpeedY = 0f - mBallSpeedY;
- }
- if (mBallY <= 0) {
- mBallY = 0;
- mBallSpeedY = 0f - mBallSpeedY;
- }
- //Move the ball's X and Y using the speed (pixel/sec)
- mBallX = mBallX + secondsElapsed * mBallSpeedX;
- mBallY = mBallY + secondsElapsed * mBallSpeedY;
- }
Add Comment
Please, Sign In to add comment