Although time cannot be used to say how long a character does an action, time CAN be used to say how long a Boolean attribute is true for a character. So while you CANNOT say "The fox chases the rabbit for 5 seconds," you CAN say "When the fox touches a rock, the fox becomes empowered for 5 seconds." Then you can add, "When the fox is empowered, the fox chases the rabbit." You are basically saying the fox chases the rabbit for 5 seconds, but you specify when the 5 seconds of chasing happen.
The following game plan example will show you step by step how to make something explode 2 seconds after being shot. Since we cannot set a time for a Boolean attribute (death) to be false, we have to use a compound condition (more than one condition):
To illustrate this better, we can use color to help us as well.
When an alien is shot, it turns white for 2 seconds. | Just like the earlier example with the foxes, we give shot aliens a Boolean attribute (white) to be true for a certain amount of time '2 seconds'. |
When an alien is shot, it turns white for 2 seconds. When an alien is shot, it becomes ready_to_explode. |
The problem is, when those 2 seconds are up and the shot aliens return back to normal, there is nothing to tell them apart from the other aliens. So, we give the shot aliens a new attribute: 'ready_to_explode'. |
When an alien is shot, it turns white for 2 seconds. When an alien is shot, it becomes ready_to_explode. When an alien is ready_to_explode and the alien is not white, it explodes. |
The third sentence states the compound condition, which can only be met two seconds after being shot. The alien explodes when the attribute 'ready_to_explode' is true AND when the color attribute 'white' is false. After 2 seconds of being shot, the alien will satisfy the compound condition in the third sentence above. Do you see it? |
Note that compound conditions joined by 'or' (such as "When the fox touches a rock or the fox touches a brick, ...") should be broken into two separate sentences:
Would the following work? Try it and see:
Complete Sample Games for Explode after 2 seconds
// Game #1. Star Explosion.
// Game #2. Pearl Explosion.
// Game #3. Kill the Cobra Boss -- wrap around through the top border.