Game Development Reference
In-Depth Information
These loops will make sure both lists are empied when we start a new game. Now we are
ready to fill the lists with new coordinates. We will store the cannon coordinates when a
clone is created. Then we will use these saved coordinates to place cannonball clones at all
the cannon locaions. To do this, follow the given steps:
1.
Click on the cannon in the Sprites view and look at its Scripts tab.
2.
In the clone script, before the forever loop, place two add thing to … blocks.
3.
Replace the word thing with the built-in x-posiion and y-posiion variables
of the cannon.
4.
Click on the small black arrows and change the selectors to <cannon-x> and
<cannon-y> respecively. Make sure you connect the variables to the correct list.
Switching them around will cause unpredictable results. The finished script should
look as follows:
If the lists are shown on your stage (remember to select the box in front of the variable
block), you can see how they are filled with coordinates as you place cannons on the stage.
Try this a few imes to get familiar with how lists are constructed and reset.
Now that we are properly saving the cannon coordinates, let's use them to create some
cannonballs as shown in the following steps:
1. Go to the Scripts tab of the cannonball sprite.
2. Start a script, as usual, with a when <green lag> clicked block.
3. First make sure you hide the original sprite so it won't be shown when
not needed.
4. Add a forever loop to place cannonballs for as long as the game is running.
5. Create a new variable named i . This is a temporary variable that we will use as
a counter to step through our lists. Using the leter i (and j, k, l, and so on for <>
temporary variables) is a programming standard.
6. Set <i> to 0 to start couning from 0.
 
Search WWH ::




Custom Search