Created
March 5, 2014 16:06
-
-
Save ortonomy/9370186 to your computer and use it in GitHub Desktop.
FLMobiGame Week 2 Complete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void actionOnTouch(float x, float y) { | |
mLastX = x; | |
mLastY = y; | |
//Increase/decrease the speed of the ball making the ball move towards the touch | |
mBallSpeedX = ( x - mBallX ) * 2; // will double the speed of the ball | |
mBallSpeedY = ( y - mBallY ) * 2; | |
} | |
//This is run just before the game "scenario" is printed on the screen | |
@Override | |
protected void updateGame(float secondsElapsed) { | |
// will make the ball stop under a tap | |
/*if ( ( mBallSpeedX < 0 && ( mBallX + secondsElapsed * mBallSpeedX ) < mLastX ) || ( mBallSpeedX > 0 && ( mBallX + secondsElapsed * mBallSpeedX ) > mLastX ) ) | |
{ | |
mBallSpeedX = 0; | |
mBallSpeedY = 0; | |
}*/ | |
// will make the ball "bounce" of the "walls" , or in other words, the screen edges! | |
if ( mBallSpeedX < 0 && ( ( mBallX + secondsElapsed * mBallSpeedX ) < 0 ) ) { | |
mBallSpeedX = -mBallSpeedX; | |
} | |
else if ( mBallSpeedY < 0 && ( ( mBallY + secondsElapsed * mBallSpeedY ) < 0 ) ) { | |
mBallSpeedY = -mBallSpeedY; | |
} | |
else if ( mBallSpeedY > 0 && ( ( mBallY + secondsElapsed * mBallSpeedY ) > mCanvasHeight ) ) { | |
mBallSpeedY = -mBallSpeedY; | |
} | |
else if ( mBallSpeedX > 0 && ( ( mBallX + secondsElapsed * mBallSpeedX ) > mCanvasWidth ) ) { | |
mBallSpeedX = -mBallSpeedX; | |
} | |
//Move the ball's X and Y using the speed (pixel/sec) | |
mBallX = mBallX + secondsElapsed * mBallSpeedX; | |
mBallY = mBallY + secondsElapsed * mBallSpeedY; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment