Game Development Reference
The backpack feature gives you easy access to oten-used sprites and scripts. Over ime, you
will probably collect a standard set of objects to place in your backpack and carry with you at
all imes. Think of standard movements and keyboard control scripts; for example, if you build
a series of games or animaions, you might also reuse the same character sprites oten.
Now that we have a cannon and some ammo, we can start doing something about those
enemies running free. In this game, we will place cannons on the stage with a mouse click.
The cannons will aim towards the cursor point. So contrary to most Tower Defense games,
you will have to aim at the enemies manually by poining the mouse at them. The cannons
will ire cannonballs automaically.
Like with the targets in the Arillery Game and the enemies in this one, we will script
a base object that spawns clones to muliply the cannons and cannonballs as shown in
the following steps:
1. Click on the cannon sprite in the Sprites view and open the Script tab.
2. Throw away the script from the previous game by right-clicking and choosing delete ,
or drag-and-drop the enire script back into the script block menu.
3. Start a new script with a when <green lag> clicked block.
4. Atach a forever loop.
5. Place a go to <mouse-pointer> block inside. This will cause the cannon sprite to
always be where the mouse cursor is poining. If your cannon seems to be ofset
from the mouse pointer, check whether its center point is aligned properly.
6. Start another script with a when this sprite clicked block.
7. Atach a create clone of <myself> block.
8. That's all you need to start placing cannons on the stage.
9. Start a third script with a when I start as a clone block to script the created clones.
10. Atach a go to front block to make sure the cannons are placed on top of the
11. Add a forever loop.