Friday 24 April 2015

Meerk Toy



***create the Meerk Toy
*Make the rest of the instructions run in one tick
*(happens automatically for injection scripts with the CAOS Tool though,
*this is just a good habit to get into).
*Commands that stop the script running all in one tick include: slow, over, wait and endm
inst
*create one under the Norn garden
*Create a simple object with a classifier of family=2, genus=21 and species=1000.
*Family 2, Genus=21 shows that this is a toy object.
*The sprite file to use is called 'meerk', and you should use all the images starting at 0.
*Put the finished creation at image plane 5000.
new: simp 2 21 1000 "Meerk" 0 0 5000
*Give it attributes of 199 - (gravity, boundaries, activateable, pickupable)
attr 199
*hand can click on it - activate 1
*When the hand clicks on it that will launch an activate 1 event
clac 0
*can be picked up, hit, activate1 (push) and 2 (pull)
bhvr 43
*Acceleration due to gravity = 3
accg 3
*Not very elastic ... when it hits the floor 0 percent of its velocity remains
elas 0
*High friction ... will not slide down slopes.
fric 100
*Use image number 59
pose 59
*Define a point on the object where it will be picked up from (pickup handle).
*If you look in the sprite file you'll see that each frame is 72x56 pixels.
*Therefore the point (40,30) is slightly right and down of the centre of this sprite.
puhl -1 40 30
*if a test move to the norn terrarium is safe, move the toy to the norn terrarium.
doif tmvt 1850 950 eq 1
mvto 1850 950
*if not, move it safely to a random spot in the bottom of the DS norn meso.
*(rand chooses an X position of between 748 and 1550, but the height is fixed at 9547).
else mvsf rand 748 1550 9547
*ends the doif statement
endi
*make the camera move to show you where the toy is.
cmrt 0


**activate 1 (push) event
*This marks this chunk as being an activate 1 event script for
*any object that has the classifier 2 21 1000. This will be stored in the scriptorium.
scrp 2 21 1000 1
*Next time the hand clicks on this object it will launch an activate 2 event.
clac 1
*Give a stimulus to whatever activated (this will be ignored if the FROM object isn't a creature).
*Giving a stimulus lets the creature learn lessons from this.
*Stim 97 is the number you need to use for a toy, as it will reduce boredom in most cases.
stim writ from 97 1
*animate! Use the frames specified, in order.
*The 255 at the end means 'loop this sequence forever'.
anim [94 95 96 97 98 98 97 96 95 94 255]
*Play a sounds effect from the object - Mb_2 happens to be a sound effect from the music box
*but you can use any sound file you like!
sndc "mb_2"
*wait for a while (around 6-7 seconds). This allows the music to finish playing
*before the toy changes pose (in the next line)
wait 130
*Go back to the sitting down pose
pose 59
*End of the activate 1 event script.
endm

**activate 2 (pull) event
*This marks this chunk as being an activate 2 event script for any object that has the classifier
*2 21 1000. This will be stored in the scriptorium.
scrp 2 21 1000 2
*Same stimulus as the activate 1 event
stim writ from 97 1
*different animation than before, the last number in the anim is the 'sit' pose.
anim [22 23 24 25 26 27 28 29 30 31 32 33 59]
*Give the object some velocity in an upward direction.
setv vely -15
*Play a sound effect
sndc "ct_1"
*Next time the hand clicks on this object it will trigger an activate 1 event
clac 0
*End of the activate 2 event script
endm

**hit event
*This marks this chunk as being a hit event script for any object that has the classifier 2 21 1000.
*This will be stored in the scriptorium.
scrp 2 21 1000 3
*Same stim as before
stim writ from 97 1
*Play a sound effect, a metallic-sounding hit effect.
sndc "hit_"
*Animate
anim [70 71 72 73 74 75 76 77 78]
*Do not carry on with the rest of this script until the animation has finished playing.
*In this case when the object reaches pose 78 the script can carry on.
over
*Wait a little while (about half a second)
wait 10
*Change pose back to sitting on the floor
pose 59
*End of the hit script
endm

**pickup event
*This marks this chunk as being a pickup event script for any object
*that has the classifier 2 21 1000. This will be stored in the scriptorium.
scrp 2 21 1000 4
*'I have gotten' stimulus
stim writ from 18 1
*Change pose
pose 0
*End of the pickup script
endm

**drop event
*This marks this chunk as being a drop event script for any object
*that has the classifier 2 21 1000. This will be stored in the scriptorium.
scrp 2 21 1000 5
*'I have dropped' stimulus
stim writ from 19 1
*Change pose
pose 59
*End of the drop script
endm

*A remove script part is a very good habit to get into.
*It allows you to easily remove all objects and their scripts with the press of a button.
****REMOVAL
*This is a special command that is only used by the CAOS Tool.
*It marks the area below as being the remove script.
*This section will only be injected by selecting the 'inject remove script' from the CAOS Tool.
rscr
*Enumerate across all the objects that have a classifier of 2 21 1000
*(in case you've forgotten this is the Meerk toy we've just been making!)
enum 2 21 1000
*Kill it
kill targ
*Chose the next meerk toy
next
*Remove the activate 1 script for object 2 21 1000
scrx 2 21 1000 1
*Remove the activate 2 script
scrx 2 21 1000 2
*Remove the hit script
scrx 2 21 1000 3
*Remove the pickup script
scrx 2 21 1000 4
*Remove the drop script
scrx 2 21 1000 5

No comments:

Post a Comment