Game Development Reference
In-Depth Information
12. Inside the loop, place a point towards <mouse-pointer> block to aim the clones
at the mouse cursor posiion at all imes. That inishes our cannon scripts for now.
You can now place as many cannons as you want all over the stage. We will refine these
scripts later to improve the game challenge. But let's script the cannonballs first so we
can actually shoot enemies instead of just poining at them menacingly.
We want to fire all the cannons we place. So the clones of the cannonball have to be placed at
all cannon posiions repeatedly. How do we turn one cannonball into many? And how do we
keep track of what all of them will do? This might seem like a challenging problem, but actually
it isn't too diicult. Moving the clones will be very similar to the Arillery Game example, minus
the gravity. The challenge here is to start all clones at the right spot, this being the posiion of
all the cannons. Because the number of cannons will increase as we place more on the stage,
the number of posiions to remember is variable. So the obvious conclusion is to use a variable
to store the posiions. But a regular variable won't suice because that can only store one
thing at a ime. We will have an increasing list of things to store, so instead of using a regular
variable, we will use a list to store the cannon coordinates.
We will create two lists for ease of use. One will store all the x coordinates in order. The
other will store all the y coordinates. We will use these lists as a combined pair. Keep that
in mind and be careful that you don't switch around the soring order of either of them,
because that will make a mess of your stored data and cause unpredictable results. The
following are the steps required to create the lists:
1.
Select the Data category in the Scripts tab.
2.
Use Make a List and call it cannon-x .
 
Search WWH ::




Custom Search