Game Development Reference
In-Depth Information
Now that the score values are increasing as enemies are defeated, we can use those values
to increase the power of the spear. Each score value/color will have a different effect on the
spear. These effects are as follows:
F The scoreRed value will influence how quickly the player can shoot another spear
F The scoreBlue value will determine when the spear will be upgraded to a
new costume
F The scoreYellow value will increase the number of spears shot simultaneously
Let's start scriping the scoring system into the spear sprite. We will tackle the scoreRed
funcionality irst. As the scoreRed value increases, spears will be spawned at a faster rate.
We put a limit of 30 on the value to prevent the spawn rate from increasing to absurd levels.
1. We start this piece of script with an if () then () else () condiion block.
2. We use this block to check whether scoreRed is less than 30 by entering 30 in
the scoreRed < () block . We now allow the script to calculate the spawn rate.
If this is true, we calculate the spawn rate based on the scoreRed value as follows:
1. First, divide the scoreRed value by 30 .
2. Then, deduct the result from a base value of 1.5 .
3. We wrap this calculation in a wait () secs block to cause the delay
between spawns.
The order of the preceding calculaion operators is very important. The operator blocks
will be processed from the innermost block to the outer blocks. The result is the number
of seconds we have to wait for a new spear to appear.
Take the wait () secs block and place it inside the else bracket to create a minimum
spawn ime of 0.5 seconds when the scoreRed value exceeds 30.
Place this piece of script where the wait 0.5 secs block was, right underneath the
create clone of <myself> block.
Search WWH ::

Custom Search