Cob tutorial five - Fireworks

Introduction
In this cob tutorial we will make a new toy for the Norns - a set of fireworks I plan to release later on this year. In this tutorial you’ll learn the secret of animation! :) A very useful thing to know because objects that move and have animations tend to be be particularly cool and you can do practically anything in a cob with an animation.

Installation Script
inst new: simp hfwk 21 0 3500 0 setv cls2 2 13 31516 setv attr 4 bhvr 1 1 mvto 6390 515 sys: camt slim endm

inst new: simp hfwk 21 0 3500 0 setv cls2 2 13 31516 setv attr 6 The attributes in this object are 6 meaning it can be activated by the hand or the Norn. These fireworks are not able to be carried (they must be detonated from the spot they are injected) and thus do not suffer gravity or colide with things.

bhvr 1 1 mvto 6390 515 This command tells Creatures that we do not want the object injected on the hand as with the edit command, but moved to a specific spot. MVTO stands for move to. The other numbers after the MVTO command are the coordinated in Albia you want it moved to. In this case the fireworks are moved to the left dock of the light blue sea where they can be launged without interferance.

sys: camt A very handy command which moves the camera to the object that owns this script (the fireworks in this case). Sys: means that this is one of the nifty system commands (I’ve no idea really why they are called system, but many of the coolest ones are in the system group) camt means focus camera on target.

slim endm

Activate 1
scrp 2 13 31516 1 stim writ from 0 255 0 0 45 150 0 0 0 0 0 0 base 0 anim[0123456789] over pose 9 setv vely -12 reps 15 rndv var0 7 9 pose var0 repe setv vely 0 base 11 anim[0123456789] over kill targ endm

scrp 2 13 31516 1 stim writ from 0 255 0 0 45 150 0 0 0 0 0 0 base 0 This tells Creatures that the first picture for the animation that follows will be picture 0. Because of the way an animation command is structured, only the first 10 frames can be shown. This is because the animation command uses a string of numbers with no dividers between them to specify the frames. If you told Creatures to use picture 11 in the animation it would play picture number 1 twice instead. If you wanted to play frame 11 (as we will want to later in this script) you first must set the base to 10 (base 10). (see animation command below for more details). :)

anim[0123456789] The body of the animation! :) Anim is a shortening of animation. You must put the frames you want played in the square brackets behind the anim command. The numbers specify how many places after the base the picture you want to show lies. Using base 0 anim[0123456789] will show the picture at position 0 (the base picture itself), the picture one spot after that in the sprite file, the picture 2 spots after the base in the sprite file, the picture three spots after the base in the sprite file, etc.., until it gets to the picture nine spots after the base in the sprite file.

over Tells creatures that it must wait for the animation to be over before going any further. This is very useful because it aviods confusion where there are two anim commands one after each other. If you miss out the over command, creatures will start on the second anim command before the first is over so the last frames of the first command will be skipped.

pose 9 setv vely -12 reps 15 rndv var0 7 9 pose var0 repe setv vely 0 base 11 Here we set the base to the 11th picture in the sprite file. This is so we can use the anim command to view the pictures after that like I mentioned above.

anim[0123456789] over kill targ endm

Drop Script
scrp 2 13 31516 6 snde drop endm

Removal Script
inst enum 2 13 31516 kill targ next scrx 2 13 31516 1 scrx 2 13 31516 6 endm

Conclusion
Well here’s your first animated toy! :) The effects in this of course can be used in any type of cob and the animation commands are extremely useful no matter what sort of cob you make.

Acknowledgements
Sprites by Sam, owner of the Creatures Corral http://web.ukonline.co.uk/cfm/sam/creatures/ ).

Thanks everyone who’s given me such great feedback about these tutorials! :)