Skip to 0 minutes and 4 seconds[CHIME]

Skip to 0 minutes and 9 seconds[CHIME]

Skip 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.

Skip 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’ll 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.

See if you can change the code to do the following:

  • Have the ball appear where you press (click) the screen and it stops moving
  • Double the ball’s speed

Here are some tips and points to consider 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, which operator will be of use here?
  • What’s the speed of the ball if it’s stationary?
  • When the screen is touched the code block ‘actionOnTouch’ (in TheGame.java) is executed. 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 you wanted to make the ball appear at a location say (10.00, 20.00), you 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)?

Let us know how you get on in the discussion area below.

Share this video:

This video is from the free online course:

Begin Programming: Build Your First Mobile Game

University of Reading