Note: only the keyboard can be used to make the controlled player shoot. Mouse clicks cannot make the player character shoot. In the following examples, we assume the player controls the pointer:
What happens when a character is shot? We must describe that as well.
Note that "is shot" is preferred over "collides with" between a character and a bullet.
Now, let us consider about clarity of sentences. Consider the following
sentence
When the pointer shoots an alien, the alien blows up.
While this above sentence might seem clear to you, it is actually ambiguous.
Why so? Because when the pointer shoots, the bullet may or may not hit the
target. In other words, we can think of the sentence as saying:
When the pointer fires a bullet at the alien, the alien blows up.
Hence, it is essentially implying that whenever
the pointer is shooting at an alien, the alien will explode, irrespective of
how far the alien is from the pointer or whether the bullets touches the
alien. Do you get it?
So the proper way is to say
When an alien is shot, the alien blows up.
Example 1:
There are twenty carrots scattered near the top in the playing area.
There is one pointer placed near the bottom of the area.
The player controls the pointer with the keyboard.
When right arrow is pressed, the pointer moves right.
When left arrow is pressed, the pointer moves left.
When spacebar is pressed, the pointer shoots up.
When a carrot is shot, it explodes.
Example 2:
There is a spinstar at the bottom of the canvas.
The spinstar is controlled by the mouse.
When Z is pressed, the spinstar shoots up.
There are 13 aliens scattered around the top half.
The aliens move towards the spinstar.
When an alien is shot, the alien dies.
When an alien collides with the spinstar, the game is over.
Quiz: What will the following do?
When an alien is shot, it is empowered. When an alien is shot and it is empowered, it explodes.
Will the alien ever explode? Try it and see!
How would you rewrite the following sentence?
When a fox is super and collides with a rabbit, the rabbit dies.
Hint: the clause containing 'collide' must include 2 characters.
Complete Sample Games using Bullets and Power-Ups
// Game #1. Destroy the dino by moving all aliens to their corresponding gem.
// Game #2. Get to the top. Shoot the precious stones to freeze some characters.
// Game #3. Destroy the rocks and avoid the converted balls.