0:16Skip to 0 minutes and 16 secondsSo now, I have an app where we can move a ball around on the screen. That's all pretty good. Of course, in the next coming weeks, we will create a game out of this. So we'll get something that's a little bit more exciting. But what I want you to look at now is if you can actually make some changes to it already. See if you can get the ball, for instance, to move double speed. It would only require some very small changes to make it do that. Try to see if you could do that.

0:54Skip to 0 minutes and 54 secondsThe next step I want you to try is to see if you can get the ball to jump directly to where you clicked. So instead of moving as it does now, I just want it to show up, jump directly to where you clicked. So that'll mean, instead of changing the speed of the ball, you would have to change the position of the ball directly. Have a go at that and see if you can do it.

Making changes to the game

In this video we’ll show you how to put your new found knowledge of variables and operators into practice.

You will open up the game code in the IDE and start making some changes, which will affect the behaviour of the balls. We’ll also introduce other changes you can make, so you can start to make your game really unique!

Can you change the code so that the ball appears where you press (click) the screen and stops moving? the ball’s speed is doubled?

Here are some tips to help you:

Ball’s speed is given by mBallSpeedX and mBallSpeedY.

Ball’s location is given by mBallX and mBallY.

If you want to double the speed of the ball what should you do? What operator we learnt earlier this week will be of use here?

What is the speed of the ball if it is stationary?

When the screen is touched the code block ‘actionOnTouch’ (in TheGame.java) is executed.So if you want the ball to respond to click or screen touch, your changes to the code should be made to this part of the code.

If we wanted to make the ball appear at a location say (10.00, 20.00) we would have to assign appropriate values to the variables mBallX and mBallY.

In the ‘actionOnTouch’ the location touched is given by (x,y). Can you try creating the statements to make the ball appear at location (x,y)?