Helicopter Game: Extras and Challenges

Planning
Step 1
Now that you have the skeleton of a game on your hands, it's time for the fun part- making it your own!

This is an example of what I did to make the game nicer looking and more interesting.

Planning
Step 2
We're going to make the smoke particle together and then the rest of the lessons are suggestions/challenges

Watch the smoke particles closely, what do you notice about them?..

  1. they are grey circles
  2. slightly transparent
  3. they move backwards
  4. what else can you see?
Step 3
First, like with all groups of objects, we make an array for our smoke particles

Next we'll start populating the array with smoke objects.

What properties do you think these particles should have?

Step 4
This time we'll make a create smoke function

The reasoning for this will become clear in a couple of steps...

Step 5
In this function we create a new object and push it into the smoke array

Now, whenever you call createSmoke() a new object is added to the smoke array.

Planning
Step 6
We don't want to call this function every frame or you'll get this

This actually looks pretty cool- but not like smoke. Try it if you want to see...

We need to create a system so that createSmoke() is called at fixed intervals (every 200 milliseconds is an example of a fixed interval).

Step 7
We have two ways of creating a fixed interval

You can either create a new smokeTimer variable which you have to tick down every frame and reset when it runs out...

..or you can use setInterval which calls a function once every set number of milliseconds

Step 8
Now we'll create a function which draws, moves, and deletes the smoke particles
Step 9
For each smoke particle "s" of the smoke array...

Remember that we have to handle each smoke particle one at a time.

Step 10
...draw a slightly transparent circle
Check Your Work
Step 11
Now each smoke particle will be drawn on the screen...
Step 12
Each smoke particle "s" will move to the left

Which now looks like this:

Step 13
...finally, each particle should increase it's size by 1

Remember: ++ means "add 1 to".

s.size++ means "add 1 to" s.size.

Step 14
It's important to remove all of the smoke particles that are off the screen from the array

This is a pretty complex line of code but try to read and understand this

Basically all of the smoke particles whose x is greater than 0 get to stay in the array.

Check Your Work
Step 15
It may be

It's hard to see this working but notice that the particles at the left side are being deleted:

Compare to before:

This might actually look a bit nicer, so we can change our filter to pass any smoke particles whose x is greater than -50:

Planning
Step 16
In this lesson we reviewed how to add a new effect to our game.

The next series of lessons will give you ideas and challenges for what you can add to your game.

You can complete each of the following lessons for points! (each challenge will tell you how many points it is worth)

Helicopter Game: Extras and Challenges Info

Account

MVCode

Created By

jamie

Course:

Helicopter Game

Access Level

public

For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach