The game is pretty cool with one obstacle,
but you copying, or cloning, the obstacle
will make it more challenging.
In this video, you will add more obstacles to your game.
When the user starts your game by clicking the flag,
the obstacle sprite should start cloning,
or making copies of itself.
From the control menu, drag a "create clone of myself" block
into the scripts area.
Click on it.
Nothing seems to happen, but when you move the sprite,
you'll see an exact copy underneath it.
Create the clone at the beginning of the game
by adding a "when flagged click" block from the events menu
on top of the "create clone of myself" block.
Next, tell the clone what to do.
It should move across the screen,
the same way you programmed the original obstacle to move,
in the previous video.
Use a new event to keep the clone code
separate from the original sprite's code.
From the control menu, place a "when I start as clone" block
on top of the code you wrote in the previous video.
Test your code by clicking the flag.
Great, every time you click the flag,
the obstacle sprite clones itself
and moves across the stage.
However, one obstacle is hardly enough
to make it an interesting game.
It needs to keep cloning itself throughout the entire game.
Add a "forever" block
around the "create clone of myself" block.
Test your code again.
Whoa, that's a lot of obstacles!
There's no way the racer can avoid these.
Fix this by adding a weight block to the "forever" loop,
then test your code.
Great, now there are fewer obstacles,
but the game is too predictable,
since obstacles appear at one-second intervals.
Spice up the game by adding a "pick random" block
to the weight block,
so the obstacles appear at random times.
This example will use .5 and two seconds in the blank,
but tinker with the values until you like the game.
Test your code.
Notice how the original obstacle sprite
is always displayed on the stage.
Modify your code so that
the original obstacle sprite is invisible.
To do this, add a "hide" block from the Looks menu,
right after when "when flagged clicked" block.
Then, add a "show" block immediately after
the "when I start as clone" block.
Test the code again.
You don't see the original sprite anymore.
Now, to solve another problem,
the obstacles move to the left side,
but they never disappear.
Add a "delete this clone" block from the Control menu
to the end of the block stack, to make the clones disappear
when they reach the left side of the stage.
Great, the obstacles appear and disappear as expected.
Lastly, change the obstacle's costume
to make the game more interesting.
From the Looks menu, add a "switch costume to" block
to the beginning of the "when I start as clone" stack.
Add a "pick random" block to that block.
Find out how many costumes the obstacle sprite has
by clicking on the costumes tab.
This sprite has three costumes,
so enter the numbers one to three
in the "pick random" block.
Test your code once more.
Now, different obstacles randomly move across the stage.
That's pretty sweet.
Alright, here's the game plan.
Randomly clone the obstacle sprite using "forever,"
"wait," "pick random" and the clone blocks.
Hide the original obstacle sprite,
show the clones when they appear,
and delete them when they reach the left edge.
Lastly, make random obstacles appear,
using the "switch costume to" and "pick random" blocks.
You can play your game now,
but nothing happens when the racer hits an obstacle.
In the next video, you'll program the losing condition.
Sign in to save your project and track your progress.