home *** CD-ROM | disk | FTP | other *** search
/ Singles (French) / Singles-FrenchVersion-Win95.iso / data1.cab / Statemachine / mimic.lua < prev    next >
Text File  |  2004-03-05  |  7KB  |  276 lines

  1. -- mimic state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onEnter(function(msg)
  6.         -- print("mimic enter");
  7.         setState("neutral1");
  8.     end )
  9.  
  10. --    onReturn(function(msg)
  11. --        nextAction();
  12. --    end )
  13.     
  14. --    onMsg("queue", function(msg)
  15. --        nextAction();
  16. --    end )
  17.     
  18.     -- general mimic control
  19.     
  20.     onMsg("stop", function(msg)
  21.         print("stop mimic" .. getParent().getCharacterName());
  22.         setState("stop");
  23.     end )        
  24.         
  25.     onMsg("neutral", function(msg)
  26.         local stateName = "neutral" .. random(1,3);
  27.         print(getParent().getCharacterName() .. " neutral with " .. stateName);
  28.         setState(stateName);
  29.     end )        
  30.         
  31.     onMsg("smile", function(msg)
  32.         local stateName = "smile" .. random(1,5);
  33.         print(getParent().getCharacterName() .. "smile with " .. stateName);
  34.         setState(stateName);
  35.     end )
  36.     
  37.     onMsg("talk", function(msg)
  38.         local stateName = "talk" .. random(1,2);
  39.         setState(stateName);
  40.     end )
  41.     
  42.     onMsg("angry", function(msg)
  43.         local stateName = "angry" .. random(1,2);
  44.         print(getParent().getCharacterName() .. "angry with " .. stateName);
  45.         setState(stateName);
  46.     end )
  47.             
  48.     onMsg("sad", function(msg)
  49.         local stateName = "sad" .. random(1,2);
  50.         print(getParent().getCharacterName() .. "sad with " .. stateName);
  51.         setState(stateName);
  52.     end )
  53.     
  54.     onMsg("eyeClose", function(msg)
  55.         -- print("eyeClose");
  56.         setState("eyeClose");
  57.     end )
  58.     
  59.     -- eye blink    
  60.     onMsg("eyeBlink", function(msg)
  61.     -- print("eyeBlink");
  62.     
  63.         if (getState() ~= "stop") and (getState() ~= "eyeClose") then 
  64.             addAnimation("mimicEyeBlink");
  65.         end;
  66.         sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  67.     end )
  68.     
  69.     
  70.     --onMsg("dlgPose", function(msg)
  71.     --    print("mimic dlgPose:" .. msg.data);
  72.     --    storeData("poseType", msg.data);
  73.     --    setState("dlgPose");        
  74.     --end )
  75.     
  76.     onDefault( function(msg)
  77.         if (strfind(msg.name, "mimic") == 1) then
  78.             storeData("animName", msg.name);
  79.             if (getState() == "pose") then
  80.                 sendMsgThis("poseChanged");
  81.             else
  82.                 setState("pose");
  83.             end
  84.             --setState("stop");
  85.             --setDelayedState("pose", 300);
  86.         end
  87.     end )
  88.     
  89.     
  90.     ----------------------------------------------------------------------------------
  91.     -- STATES ------------------------------------------------------------------------
  92.     ----------------------------------------------------------------------------------
  93.     
  94.     -- neutral
  95.     state("stop")
  96.         onEnter(function(msg)
  97.         -- print("stop");
  98.             stopPose();
  99.         end )
  100.         
  101.         
  102.     state("neutral1")
  103.         onEnter(function(msg)
  104.         -- print("neutral1");
  105.             setPose("mimicNeutral1");
  106.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  107.             setDelayedState("neutral2", random(3000, 8000));
  108.         end )
  109.  
  110.         
  111.     state("neutral2")
  112.         onEnter(function(msg)
  113.         -- print("neutral2");
  114.             setPose("mimicNeutral2");
  115.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  116.             setDelayedState("neutral3", random(3000, 8000));
  117.         end )
  118.  
  119.             
  120.     state("neutral3")
  121.         onEnter(function(msg)
  122.         -- print("neutral3");
  123.             setPose("mimicNeutral3");
  124.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  125.             setDelayedState("neutral1", random(3000, 8000));
  126.         end )
  127.  
  128.     
  129.     -- eyeClose
  130.     state("eyeClose")
  131.         onEnter(function(msg)
  132.         print("eyeClose");
  133.             setPose("mimicEyeClose");
  134.         end )
  135.  
  136.  
  137.     -- smile1
  138.     state("smile1")
  139.         onEnter(function(msg)
  140.         print("smile1");
  141.             setPose("mimicSmile1");
  142.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  143.             sendDelayedMsgThis("neutral", random(3000, 8000));
  144.         end )
  145.  
  146.  
  147.     -- smile2
  148.     state("smile2")
  149.         onEnter(function(msg)
  150.         print("smile2");
  151.             setPose("mimicSmile2");
  152.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  153.             sendDelayedMsgThis("neutral", random(3000, 8000));
  154.         end )
  155.         
  156.     -- smile3
  157.     state("smile3")
  158.         onEnter(function(msg)
  159.         print("smile3");
  160.             setPose("mimicSmile3");
  161.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  162.             sendDelayedMsgThis("neutral", random(3000, 8000));
  163.         end )
  164.         
  165.     -- smile4
  166.     state("smile4")
  167.         onEnter(function(msg)
  168.         -- print("smile4");
  169.             setPose("mimicSmile4");
  170.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  171.             sendDelayedMsgThis("neutral", random(3000, 8000));
  172.         end )
  173.         
  174.     -- smile5
  175.     state("smile5")
  176.         onEnter(function(msg)
  177.         -- print("smile5");
  178.             setPose("mimicSmile5");
  179.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  180.             sendDelayedMsgThis("neutral", random(3000, 8000));
  181.         end )
  182.         
  183.     
  184.     -- angry1
  185.     state("angry1")
  186.         onEnter(function(msg)
  187.         print("angry1");
  188.             setPose("mimicAngry1");
  189.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  190.             sendDelayedMsgThis("neutral", random(3000, 8000));
  191.         end )    
  192.         
  193.     -- angry1
  194.     state("angry2")
  195.         onEnter(function(msg)
  196.         print("angry2");
  197.             setPose("mimicAngry2");
  198.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  199.             sendDelayedMsgThis("neutral", random(3000, 8000));
  200.         end )
  201.     
  202.     
  203.     -- sad1
  204.     state("sad1")
  205.         onEnter(function(msg)
  206.         print("sad2");
  207.             setPose("mimicSad1");
  208.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  209.             sendDelayedMsgThis("neutral", random(3000, 8000));
  210.         end )
  211.     
  212.     -- sad1
  213.     state("sad2")
  214.         onEnter(function(msg)
  215.         print("sad2");
  216.             setPose("mimicSad2");
  217.             sendDelayedMsgThis("eyeBlink", random(2000, 7000));
  218.             sendDelayedMsgThis("neutral", random(3000, 8000));
  219.         end )
  220.     
  221.     -- talk1
  222.     state("talk1")
  223.         onEnter(function(msg)
  224.             print("talk1");
  225.             local character = getParent();
  226.             
  227.             if (character.isMale() == true) then
  228.                 setPose("mimicTalkMike1");
  229.             else
  230.                 setPose("mimicTalkElaine1");
  231.             end
  232.             
  233.             character.playSound(genderizeReal(character, "mimicTalk") .. "1", 1.0, SPEECH);
  234.             getParent().setEmoticon(EMOTICON_SMALLTALK , EMOTICON_DELAY);
  235.         end )
  236.         
  237.         onMsg("end", function(msg)
  238.             sendMsgThis("neutral");            
  239.         end )    
  240.         
  241.     state("talk2")
  242.         onEnter(function(msg)
  243.             print("talk2");
  244.             local character = getParent();
  245.             
  246.             if (character.isMale() == true) then
  247.                 setPose("mimicTalkMike2");
  248.             else
  249.                 setPose("mimicTalkElaine2");
  250.             end
  251.             
  252.             character.playSound(genderizePink(character, "mimicTalk") .. "2", 1.0, SPEECH);
  253.             getParent().setEmoticon(EMOTICON_SMALLTALK, EMOTICON_DELAY);
  254.         end )
  255.         
  256.         onMsg("end", function(msg)
  257.             sendMsgThis("neutral");            
  258.         end )
  259.         
  260.         
  261.     state("pose")
  262.         onEnter(function(msg)
  263.             local animName = retrieveData("animName");
  264.             print("pose onEnter (" .. animName ..  ")");
  265.             setPose(animName);                
  266.         end )
  267.         
  268.         onMsg("poseChanged", function(msg)
  269.             local animName = retrieveData("animName");
  270.             print(" pose onMsg poseChanged (" .. animName ..  ")");
  271.             setPose(animName);                
  272.         end )
  273.                         
  274.  
  275. endStateMachine()
  276.