# Jungle Juggling

Редактировал(а) FirstaAnta 2022/06/26 01:22

Here you will learn how to program a first game. You have to help the little cheetah to avoid the water!

# 1. A new project

First, download Pocket Code in the Android Play-Store and install it. Now you'll have to create a new project:

You can start your program (your scene!) anytime with the little triangle in the bottom right:

# 2. New objects

Objects are like your actors in a play. Get your images form the media library:

Go and get also the little cheetah from the media library:

It should now look like this:

# 3. A first script

Scripts are the screenplay for your actors. Scripts are built with bricks and always start with a rounded brick. That's how you add new bricks to your script:

Create this script in water:

Attention: Be careful with the values and settings of the single bricks. Change the value in the "size" and "change"-brick if the water doesn't seem to fit on your device (tap the start triangle to have a look!). You will get more information on the bricks here.

# 4. How can I move and delete a brick?

That's how it works:

Attention: If you tap the starting-brick (the rounded one) and select "Delete script", you will delete the whole script with all the bricks.

Switch to the cheetah's scripts and create this script:

Attention: Again, be careful with the value. To spawn the object to a random horizontal position, we set the x-value to a random number between -400 and 400. You will find the random value funtion within the functions category (do not write the function with "Abc" yourself!!!). Set the lower border to -400 and the upper border to 400.

Set the motion type of the cheetah to "moving and bouncing under gravity". Now the cheetah will act like a physical object and will be torn down by the gravity (hete with the strength -50).

Start your scene to see what has changed!

# 6. Juggle the cheetah

We will now expand the cheetah's functions step by step. Add this script within the cheetah (all scripts will be executed simultaneously):

Whenever we tap the object, we will set the object's velocity to y: 800 (the vertical direction). This will catapult the cheetah upwards. The gravity we set earlier, will then tear the cheetah towards the bottom. Just like a real object!

We set x to "x velocity", which you can find in the properties category. (Do not type it yourself with "Abc"!!!)

Now have a look again! If you think it's too boring, just try to set a higher y-value!

# 7. Let the object bounce

As you may have noticed, the object leaves your screen easily. Here is how you can avoid this:

To let the object bounce forever (and not only at the beginning of the scene), add a loop. Loops let you repeat bricks. The "forever loop" will repeat endlessly, at least so long you don't close the program

Start your project and try it!

# 8. Game Over

Maybe you have noticed, that our game runs forever? Nothing happens if you touch the water. Let us change this:

If you bounce off the water, the program will terminate.

If it still didn't work, check if you set the motion type in water to "not moving under gravity".

DONE! You just used only 16 bricks to build a basic game. If it's still not working, just check your bricks once again. Maybe a bug (a programming error) has appeared.

But we are not done here quite yet. Expand your game however you like it! Or be inspired with the following cool functions 😀

# Background

Here you will learn how to add a background. The background is also programmable, e.g. with a "set size"-brick.

# Background music

That's how you add background music:

Attention: Take care to select the brick with "and wait", otherwhise weird things will occur, try it!

You can choose sounds from various sources: the media library, record them yourself or get it from your device as audio file.

# Animations

Add all 3 different looks to the cheetah. They act like different costums for an actor.

After you did that, you can add this script to the cheetah:

# Obstacles

Add a new object as obstacle.

Add this script to it, and enable it to move it's position randomly every 3 seconds:

It doesn't work? Check whether you set the motion type to "not moving under gravity".

# Points & Highscore

You want points? Add this script to the cheetah:

Attention: Create a new variable by tapping "new" and choose a meaningful name. Take care that in both bricks the new variable is selected. You can adjust the appearance with different parameters.

You want also want to add a consistent highscore? To do this, extend this script in the cheetah:

Create a new variable named "highscore". Set the variable highscore to the variable points. You will will points in the data category.

The "if-brick" is called a conditional statementIt acitivates the red bricks only if a condition (abvoe you see a gap) is met, otherwhise they will be skipped. Our condition is: If points are higher than highscore, then... Try to build the condition yourself. You will find all you need in the data and the logic category. (Do not type in the condition with "Abc"!!!)

To display the highscore, add this function (select the correct variable!):

# Home screen

To add a home screen, we need to create a new scene:

New scenes are like subroutines of your game. They have independent objects and backgrounds. You can connect scenes with the "Continue scene" and "Start scene" bricks.

Add a new object to the new scene. Something like this play button:

Add this script to the button to start the game by tapping it:

Now you can configure the background and maybe include the game name and short instructions! If you want to, navigate to the looks of the background and experiment a bit.

# Effects

To add sound effects, you can use the "Start sound" brick. One good place might be right after the "When tapped" in the cheetah.

You can also add rumble effects:

Here's how to change the color of the objects:

Just try different bricks and see yourself 😃

# More cheetahs!?

Here you go:

By copying objects, every script of the object and all the looks will be copied along. But if you change single bricks after copying, they won't by synchronised. If you just want to adjust the look of an object, navigate to the looks of it, add a new one and delete the old one.