The aim of the game is to throw the Pokeball at the cat and catch it.
Setup the scene with the sprites show above.
The Pokeball will be controlled by the flick of the mouse (while the mouse button is pressed).
We will need to work out the speed of the flick of the mouse, this will determine the position of the pokeball.
Create the following variables:
Poke Cats Caught – The total number of cats we have caught
escaped – Random number to determine if the cat escapes
speed – the speed of the mouse flick.
Build a ‘My Block’ to animate the ball throwing. Using a My Block will allow us to use this animate in more of our code without re-writing it.
Step 1: Move the ball to the correct position:
Step 2: Use the mouse to work out the speed of the ball.
Let’s wait until the mouse is down and the sprite is touching the mouse before we start working out the speed.
Inside our forever block:
When the mouse has been released, point the sprite towards the mouse and then calculate the distance to where the mouse pointer is now (after the button has been released). Make this speed a small number, so we can use it on our backdrop which has a size of 240, 140.
Set the speed variable to this calculation.
Step 3: Animate the ball moving
We want to animate the ball moving, we need to make our ball slow down, to do this we will change it by -0.1 each time the loop runs. If we are higher than 80 pixels high (y position), then we need to move the ball back down on the screen to give a dropping effect.
Otherwise we will move the ball the number of steps that our speed variable currently has in it.
Once the ball has come to a stop, we broadcast the ‘ball thrown’ event, which we can use to animate the capture of the poke cat.
(Don’t forget these 3 steps go into a forever block).
Step 4: PokeCat – Determine if hit.
Use the event ‘ballthrown’ to test if the ball is touching the cat.
Step 5: Reset if we missed the cat
The cat will raise an event called ‘miss’ if we haven’t touched the cat with the pokeball. In this case, we can reset the game:
We can use the My Block in the Pokeball sprite for this.
Step 6: Animate the hit
First we need to switch to the flashing costume of the pokeball and make it get bigger over a small period of time.
We then switch back to the pokeball sprite and make it move backwards and forwards so that it looks like the cat is trying to escape.
Use a random block to determine if the cat escapes from the ball.