Making food objects for C3

Right, we've made a toy and dealt with making things animate and play sounds... making food can actually be easier than this! Usually you don't need any animation and can make a food object with just two images (or even just one).

Here's some example food - in the shape of cheese.

CodeExplanation
********Lets make some Food *This is a comment
instStart with an inst - makes the rest of this part of code run in an instant
*create some underneath the gardenThis is a comment
new: simp 2 11 1000 "infinite_cheese_machine" 2 44 5000Create a new object, with a classifier of 2 11 1000 (this family/genus combination marks the item as being a Food item). It will use the sprite file called 'infinite_cheese_machine' - BUT it will only use 2 images from this file starting at image number 44. Position the object at image plane 5000
attr 195Give it attributes that enable it to have gravity, boundaries and be picked up.
bhvr 48Behaviour for the creature: creatures can perform pickup and eat on this object
elas 30Slightly elastic - meaning it will bounce slightly when colliding with the floor
fric 50Some friction - when placed on a slope it will slide for a while
accg 3Moderate acceleration due to gravity
mvto 1950 950Move to a suitable position
cmrt 0Move the camera to point at it
  
*****eat scriptThis is a comment
scrp 2 11 1000 12Mark this script as being an eat script for all objects that have a classifier of 2 11 1000
lockLock the script - this means it cannot be interrupted by other scripts for this object, or by a creature trying to perform the same action in rapid succession
sndc "chwp"Play a sound effect
stim writ from 79 1Send a stim to whoever triggered this event. This stim is the stim for eating food - it generally produces fat and protein in the receiving creature.
pose 1Change pose
wait 20wait for a little while (around a second)
kill ownrKill the owning object - i.e. the piece of cheese that was eaten.
endmEnd of eat event script.
  
********REMOVALThis is a comment
rscrMarks this bit as a removal script
enum 2 11 1000Enumerate across all the objects that match the classifier given (which in this case is our cheese)
kill targKill the current targ (which will be our cheese)
nextChoose the next one that matches the classifier.

This code will inject a single piece of cheese into the world - it isn't the same cheese that comes out of the Cheese Machine though. This cheese can only have one bite taken out of it, and once eaten will show an eaten frame for a second before removing itself from the world.

The advantage of using the genetic stims of a creature (the STIM command) rather than directly injecting chemicals is that you don't need to worry about what chemicals to inject, and in what amount. In this way all food will teach consistent lessons and have consistent effects. Another advantage is that each creature has the potential to have a different response to the object - because the genetics that define the response to that stim can differ among different creatures!Some projects that can be worked on with this code:

(1) Make the cheese supply multiple bites (for example, 5 bites before disappearing)
(2) Use your own graphics
(3) As well as doing a STIM, why not try injecting some other chemicals directly? A touch of alcohol may add a comedy walk to all who eat the cheese :-)


Downloads:   COS File