0% found this document useful (0 votes)
12 views28 pages

Rocket Launch

The guide outlines a beginner curriculum for coding a rocket launch game, teaching fundamental programming concepts such as motion in 3D space, keyboard events, variables, and loops. Students will learn to control a rocket's movement using keyboard inputs, implement speed adjustments with variables, and add visual effects like flames using a particle system. The project culminates in a playable game that can be published and shared online.

Uploaded by

M K Khaing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views28 pages

Rocket Launch

The guide outlines a beginner curriculum for coding a rocket launch game, teaching fundamental programming concepts such as motion in 3D space, keyboard events, variables, and loops. Students will learn to control a rocket's movement using keyboard inputs, implement speed adjustments with variables, and add visual effects like flames using a particle system. The project culminates in a playable game that can be published and shared online.

Uploaded by

M K Khaing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Guide For

Hatch Kid’s Blocks-Based

Beginner Curriculum

Project 2:

Rocket Launch
Project 2:

Rocket Launch

Objective

In this guide we are going to learn about the fundamentals of programming, while coding a

rocket launch in a space environment, and learn to control the movement of a an object using

keyboard buttons.

You will code a game where you are able to make a rocket fly up and down by pressing the up,

and down arrow keys and stop by pressing the space key.

Concepts covered:

Motion in 3D Space

Understanding keyboard events

introduction to variables

Learn about loops in coding

Final Output Link:

https://kids.hatchxr.com/@XR4schools/G25-FC-S2

Student Template Link:

https://kids.hatchxr.com/@XR4schools/G25-FC-S2-template

28
How it works?

Let’s first understand what we are going to be building in this session.

Open the completed project link:

https://kids.hatchxr.com/@XR4schools/G25-FC-S2

You will a screen as shown below:

Click on the green play button to play the project

The moment you click on the “Green Play Button”, you will notice


1. The rocket starts flying up in the sky

2. The rocket stops moving when you press the space key on the keyboard

3. Pressing the up and down arrow keys makes the rocket move up and down

4. When the rocket is moving, flames are blowing from the bottom of the rocket, and when
the rocket stops, the flames stop as well.

Let’s get started.

89
Objective No. 1: Understanding the template

Step 1: We will start by opening the template link of the project mentioned here.

Student Template Link: https: //kids.hatchxr.com/@XR4schools/G25-FC-S2-template

Step 2: The link above will open up an empty project with no code in the hatch workspace,

that looks as shown here. Let’s understand the scene.

On the left panel There is an object by the name 3D object by the name

you will see the list “ParticleSystem” that is not visible “Rocketship”, for which

of objects added in initially, but this will help us add you will code motion

the game flames at the end of the rocket with keyboard controls

As you can see, the code window of the hatch workspace opens up, and this is where you can

use blocks to define how your game would work.

30
Objective No. 2: Making the rocket fly up

Let’s start by making the rocketship move up, when the green play button is clicked, just like

we made the play move forward in the previous project.

Step 1: Click on name “Rocketship” in the left panel. You will see a list of blocks appear, that

shows all the activity you can perform on the rocketship object


Step 2: There is a block named “Rocketship move forward for 5 meters”. Click on the block

and drag it outside into the coding workspace.



31
We know that the rocket will not move up on its own, it will need an event block, for the
computer to know when to move the rocket up. 



Step 3. Click on the Events section in the top section of the left panel on your screen.

Step 4: You will see a list of yellow colored event blocks appear. Lets click and drag out the very
first block that says, “When green play button clicked”

32
Sep 5: Drag the “move forward” block and attach it inside the “when green play button
clicked” block.

Click on the green play button, and you will see the rocketship move in its forward direction.
We want to make the rocket move in the upward direction.

First, click on the reload button to reset the scene and bring the rocket back to the moon

Step 6: You will notice that in the “move forward” block, there is a drop down menu option
with the text “move forward”. Click on it, and a menu appears that lets you select different
directions in which you can make the rocket move.

33
Step 7: Select the “move up” option from the drop down menu. The code in your workspace
would now be as shown here.

Click on the green play button, and now you will see the rocket fly up for some distance and
then stop.

Tidbit #1 : Try selecting each of the option for different movement direction (forward,
backward, left. right, up and down) and run the code for each case to see how they affect the
motion of the rocket.

Our next step is to make the rocket move up continuously, as long as we want without the
rocket stopping.

34
Objective No. 3: Using loops for repeated motion

We were able to make the rocket move up for a some distance. Let’s now try to make the

rocket move up without stopping. One way to do it would be to add multiple move up blocks

one below the other as shown:

Try this, you will notice there are two main issues with this way of coding:


1. The rocket will eventually stop moving after all the move up blocks have been executed

2. Coding is all about efficiency, about performing activities in a simple way, and this is clearly

not efficient.

So how can we make the rocket move up continuously on its own.



Well our idea of running the move up block again and again is correct, but the way of

implementing the code above is not right. 



To make the rocket move up on its own, we are telling the computer, to move it up for 5

meters, and then move it up for 5 meters again and again.

So whenever we want to perform a same set of activity multiple times, we make use of loops

in coding. Let’s see how it works.

35
Step 0: Let’s first delete all the extra move up blocks that we have added except for one. To
delete any block, you can right click on the block, and a list of options will appear. There will be
an option called “Delete”, just click on it and your selected block will be removed from the
workspace.

Alternatively, you can click on a block and press the delete key on the keyboard to delete a
block as well.

Delete all the extra move up block leaving one, so that in your code window the following
blocks remain.

36
Step 1: In the top half of the left panel, you will notice “Loops & Timers” mentioned just below

“Events”. Click on “Loops & Timers”, you will see a list of new blocks appear.

In the loops section, you will notice a block titled, “repeat 10 times”. Click and drag it into the

code workspace.

Loops tell your computer to perform a set of activities multiple number of times.

37
Step 2: Inside the “repeat 10 times” block, you need to define the activity that you want to
repeat through your code. That would be the rocket move up action.

Click and drag the “rocket move up” block, inside the “repeat 10 times” block as shown here.

Step 3: You can now drag the “repeat 10 times” block and attach it inside the “when green
play button clicked” block.

38
Let’s run this code and see what happens. Click on the green play button.

You will notice, that the rocket, instead of just moving 5 meters up, keeps on moving up for

sometime. In fact the rocket ends up moving 50 meters up above the moon. That’s because,

the repeat block is going to run the activity of moving the rocket five meters up 10 times.

But this still has an issue, we want the rocket to keep on moving up and not stop at all. Here

the rocket stops eventually. Let’s fix that.

Step 4: Click on the “Loops & Timers” on the left panel, and there is a block called “forever”.

39
Step 5: Click an drag the “forever” block into the workspace.

Step 6: Drag the “move up” block and place it inside the “forever” block.

40
Step 7: Delete the “repeat” block from the workspace. and drag and attach the “forever”
block inside the “green play button” clicked block.

Now when you click on the green play button to run the code, you will see that the rocket
keeps on moving up forever and does not stop.

Forever block is used to run a set of activity again and again indefinitely.

Click on the “reload” button to stop the rocket from moving and to bring it back to the moon.

41
Objective No. 4: Adjust the speed of the rocket with a variable

In the code that you have implemented, it says “Rocket move up for 5 meters”. 



Try changing the number 5 to different values and you will see that if you reduce the value, the

rocket moves slowly, and if you increase the value then the rocket starts moving faster.

So the numerical value inside the move up block is controlling the speed of the rocket.

We can use a variable to change the value of speed of the rocket while playing the game.

Step 1: Click on the “variables” option in the top half of the left panel on your screen.

Step 2: Click on the “create a variable” button

42
A window will appear on your screen and it will ask you to give a name to the variable you
want to create. 



Since the variable we want to create is going to control the speed of the rocket, so we can
name the variable “speed”.

Step 3: Type the word “speed” in the box and click on the “create” button.

The moment you click on create, the following blocks appear:

Step 4: Click and drag the “set variable speed to” block in the workspace

43
We need to give a value to the variable speed.

Step 5: On the left panel, click on the category “Math”, and a list of math blocks will appear. At

the top of the list, you will find a number block, that just says “0”. Click and drag the “0” block

and place it inside the “set variable speed to” block.

44
Step 6: Change the value “0” to “5” inside the set variable speed block. Now that we have

created a variable and given it an initial value, we need to use the variable to move the rocket.

Step 7: Delete the number 5 block in the “Rocketship move up for 5 meters”.

Step 8: Click on the variables option in the left panel and select the “speed” block.

Step 9: Attach the “speed” block inside the “Rocketship move up” block.

45
Click on the green play button and you will notice that the rocket keeps on moving up. 



Now, try changing the value of the speed variable in the “set variable speed to 5” block.

And upon running the code you will see, changing the value of the speed variable changes

how the rocket moves in the game.

Objective No. 5: Implementing keyboard controls

With the motion of rocketship implemented, lets now learn to control the motion of the

rocketship using the keyboard buttons.

Just like clicking on the green play button is considered as an event in the code, similarly, any

other activity that a user can perform is also considered as an event. 



So pressing any keyboard button, is also considered as an event by your computer.

Step 1: Click on the “Events” section in the left panel of your screen.

Scroll down in the list of blocks that appear, and you will see a block that says:


”When space key pressed”

Step 2: Click and drag the “When space key pressed” block in the workspace.

You will notice, the shape of “when space key pressed” block is the same as “when green

play button clicked” block. You can define a set of actions inside the when space key block,

and those actions will only happen in the game when you press the space key on your

keyboard.

46
We need to define what needs to happen in the game when the space key is pressed.

Let’s make the rocket stop moving when you press the space key.

How do we make an object stop moving? We can control the speed of the rocket, and if an

object is not moving then its speed is “0”.

47
So, if we want the rocket to stop when you press the space, key,we need to tell the computer to

set the value of the speed of the rocket to “0” when the space key is pressed.

Step 3: Right click on the “set variable speed to 5” block. A drop down menu will appear,

select the option “duplicate”.

Step 4: You will see another “set variable speed to 5” block appear in the workspace. Drag that

block and attach it inside the “when space key pressed” block.

The block would now say, “when space key pressed, set variable speed to 5”.

Because we want the rocket to stop when space key is pressed. its speed should become

“0”. So change the number “5” to “0”

48
Click on the green play button, and you will see the rocket fly up. Press the space key and you
will see the rocket stop moving.

Let’s make the rocket move up again when we press the up arrow key on the keyboard.

Step 5: Right click on the when space key pressed block in the workspace and select
“duplicate”. 



A new “when space key pressed” block will appear in the workspace.

49
Step 6: Click on the word “space” in one of the “when space key pressed” block, and you will
see a drop down with the list of all the keyboard buttons. Select the “up arrow” option. 



Your block would now say “when up arrow key pressed, set variable speed to 0”.

Change the number “0” to “5”.

50
Click on the reload button to restart your game and then click on the green play button to run

the new code that you have in your workspace. You will see the rocket fly up. 



Press the space key and you will see the rocket stop moving.


Now if you press the up arrow key, the rocket starts moving up again.

You can duplicate the “when space key pressed” block again, this time changing the “space”

key to “down arrow” key and change the number “0” to “-5”.

Now when you reload your scene and run the run the code, you will be able to move the rocket

up and down with up arrow an down arrow key on your keyboard.

We are almost done with this project, lets just add some special effect of flames blowing out of

the bottom of the rocket as it moves up or down, and then you can publish and share this

project with your friends.

51
Objective No. 6: Add fire using particle system

In the bottom half of the left panel you will see there is an object named, “ParticleSystem”. 



We will explore particle system in detail in future projects, for now we are just going to use the

particle system to generate fire from the rocket. 



Step 1: Click on the name “ParticleSystem”. A list of blocks will appear. Scroll down and you

will see a block called, “ParticleSystem turn emitter on”.

Step 2: Drag the “turn emitter on” block and attach it above the “forever” block inside the

“when green play button clicked” block.

52
Step 2: Bring our another“turn emitter on” block and attach it in the “when up arrow key
pressed” block. And another one inside the “when down arrow key pressed” block.

Step 3: Bring out on last “turn emitter on” block and attach it in the “when space key
pressed” block. Click on the drop down menu option, and select the “turn emitter off” option
in this.

53
This is what the final code of your project should look like.

With the turn emitter on / off blocks we are telling our computer to add the flame when rocket
flies up, and when it moves down, and then saying that when rocket stops moving, turn off the
flames.

Click on the green play button and you will be able to control the motion of your rocket using
your keyboard button. 



Your project is ready. Login to your account, give your project a name and publish it by
clicking on the “REMIX” button at the top left corner of the screen and then you will be able
to share it with your friends.

END OF GUIDE

54

You might also like