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

  1. -- sofa character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local sofa = retrieveStateObject("sofa");
  6. --        removeStateObject("seat");
  7. --        storeStateObject("sofa", sofa);
  8.         
  9.         if (not sofa) then
  10.             -- sofa does not exist anymore
  11.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  12.             sendMsg("emoThink", getParent().walkSO);
  13.             exitStateMachine();
  14.         else
  15.             local actionPointName = retrieveData("actionPointName");
  16.             if exitIfWrongPosition(getParent(), sofa, actionPointName) then return end;
  17.         end
  18.         
  19.         --freeHands(getParent());
  20.     end )
  21.     
  22.     onExit(function(msg)
  23.         local sofa = retrieveStateObject("sofa");
  24.         if (sofa) then
  25.             getParent().unlockActionPoints(sofa);
  26.             getParent().stopAllActivities(sofa);
  27.             removeStateObject("sofa");
  28.         end;
  29.         
  30. --        local guitarRack = retrieveStateObject("guitarRack");
  31. --        if (guitarRack) then
  32. --            getParent().unlockActionPoints(guitarRack);
  33. --            getParent().stopAllActivities(guitarRack);
  34. --            removeStateObject("guitarRack");
  35. --        end;
  36. --        
  37. --        --local guitar = retrieveStateObject("guitar");
  38. --        removeStateObject("guitar");
  39.         
  40.     end )
  41.     
  42.     -- sit down on sofa
  43.     state("sitDown")
  44.     
  45.         onEnter(function(msg)
  46.                 
  47.             local sofa = retrieveStateObject("sofa");
  48.             local actionPointName = retrieveData("actionPointName");
  49.             
  50.             if (getParent().isActionPointLocked(sofa, actionPointName)) then
  51.                 -- action point is locked
  52.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  53.                 sendMsg("emoThink", getParent().walkSO);
  54.                 freeHands(getParent());
  55.                 exitStateMachine();
  56.             else
  57.                 getParent().lockActionPoint(sofa, actionPointName);
  58.                 getParent().handSO.stopAnimation(0.0);
  59.                 startAnimation("playGuitarSitdown", false, 1.0, 0.0);
  60.                 sofa.playSound("Sofa setzen");
  61.             end
  62.             
  63.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  64.             
  65.         end )
  66.     
  67.         onMsg("end", function(msg)
  68.         
  69.             if testCancel() then
  70.                 setState("standUp");
  71.             else
  72.                 setState("playSitting");
  73.             end
  74.  
  75.         end )    
  76.     
  77.         onMsg("testCancel", function(msg)
  78.             if testCancel()  then
  79.                 setState("standUp");
  80.             else
  81.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  82.             end
  83.         end )
  84.         
  85.     state("playSitting")
  86.     
  87.         onEnter(function(msg)
  88.         
  89.             local guitarRack = retrieveStateObject("guitarRack");
  90.             local play = getParent().startActivity("playGuitar", guitarRack);
  91.             local length, scale = getActivityLength(play);
  92.             storeData("scale", scale);
  93.         
  94.             startAnimation("playGuitarLoop");
  95.             sendDelayedMsgThis("stopPlaying", length);
  96.             --this.actionComplete();
  97.             
  98.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  99.             
  100.             getParent().loopSound("guitar");
  101.         end )    
  102.         
  103.         
  104.         onExit(function(msg)
  105.             getParent().stopSound("guitar");
  106.         end )    
  107.         
  108.         
  109.         
  110.         onMsg("testCancel", function(msg)
  111.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  112.                 sendMsgThis("stopPlaying");
  113.             else
  114.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  115.             end
  116.         end )
  117.         
  118.  
  119.         onMsg("end", function(msg)
  120.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  121.                 sendMsgThis("stopPlaying");
  122.             else
  123.                 startAnimation("playGuitarLoop");
  124.             end
  125.         end )
  126.  
  127.         onMsg("stopPlaying", function(msg)
  128.             local guitarRack = retrieveStateObject("guitarRack");
  129.             getParent().stopAllActivities(guitarRack);
  130.             setState("standUp");
  131.         end )
  132.         
  133.         onMsg("queue", function(msg)
  134.             sendMsgThis("stopPlaying");
  135.         end )
  136.         
  137.     -- stand up from sofa
  138.     state("standUp")
  139.     
  140.         onEnter(function(msg)
  141.             startAnimation("standupArmchair");
  142.             
  143.             getParent().detachLeftObjectHolder();
  144.                 
  145.             local guitar = retrieveStateObject("guitar");
  146.             if (guitar) then  guitar.deleteGameObject(); end
  147.             
  148.             local guitarRack = retrieveStateObject("guitarRack");
  149.             if (guitarRack) then  guitarRack.setChildEnable("guitar", true) end
  150.             
  151.         end )
  152.     
  153.         onMsg("end", function(msg)
  154.             flipPoseDirection();
  155.             exitStateMachine();
  156.         end )    
  157.     
  158.  
  159.     
  160. endStateMachine()
  161.