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

  1. -- boxing character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local bag = getStateObjectFromID(msg.sender);
  6.         storeStateObject("bag", bag);
  7.         
  8.         if (bag) then
  9.             -- bag does exist
  10.             local actionPointName = retrieveData("actionPointName");
  11.             local actionPoint = getParent().getFreeActionPoint(bag, actionPointName);
  12.  
  13.             if exitIfWrongPosition(getParent(), bag, retrieveData("actionPointName")) then return end;    
  14.             
  15.             if (not actionPoint) then
  16.                 -- action points is locked
  17.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  18.                 sendMsg("emoThink", getParent().walkSO);
  19.                 exitStateMachine();
  20.             else
  21.                 getParent().lockActionPoint(bag, actionPointName);
  22.             end
  23.         else
  24.             -- sink does not exist anymore
  25.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  26.             sendMsg("emoThink", getParent().walkSO);
  27.             exitStateMachine();
  28.         end
  29.         
  30.         freeHands(getParent());
  31.                 
  32.     end )
  33.     
  34.     onExit(function(msg)
  35. --        local bag = retrieveStateObject("bag");
  36. --        if (bag) then
  37. --            getParent().stopAllActivities(bag);
  38. --            getParent().unlockActionPoints(bag);
  39. --            removeStateObject("bag");
  40. --        end
  41.         
  42.         unlockAll("bag"); 
  43.         
  44.         getParent().stopAllActivities();
  45.     end )
  46.     
  47.     
  48.     
  49.     state("boxStart")
  50.     
  51.         onEnter(function(msg)
  52.             startAnimation("boxingStart");
  53.         end )
  54.         
  55.         onMsg("end", function(msg)
  56.             
  57.             if testCancel() then
  58.                 setState("boxStop")
  59.             else
  60.                 setState("box")
  61.             end
  62.         end )    
  63.     
  64.     
  65.     state("box")
  66.     
  67.         onEnter(function(msg)
  68.             
  69.             local bag = retrieveStateObject("bag");
  70.             local box = getParent().startActivity("box", bag);
  71.             length, scale = getActivityLength(box);
  72.             storeData("scale", scale);
  73.  
  74.             sendDelayedMsgThis("stopBoxing", length);
  75.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  76.             
  77.             sendMsgThis("startLoop");
  78.             
  79.             local others = getOtherUsers(getParent(), bag, "box");
  80.             if (not others[1]) then
  81.                 bag.loopSound("boxingBag");
  82.             end;
  83.             
  84.         end )
  85.         
  86.         onExit(function(msg)
  87.             local bag = retrieveStateObject("bag");
  88.             bag.stopSound("boxingBag");
  89.         end )
  90.             
  91.         onMsg("startLoop", function(msg)
  92.             startAnimation("boxing", false, retrieveData("scale", 1.0));
  93.             sendDelayedMsgThis("punch", 2800);
  94.             sendDelayedMsgThis("punch", 3100);
  95.             sendDelayedMsgThis("punch", 3400);
  96.             sendDelayedMsgThis("punch", 4850);
  97.             sendDelayedMsgThis("punch", 5450);
  98.             sendDelayedMsgThis("punch", 6200);
  99.             sendDelayedMsgThis("punch", 6770);
  100.             sendDelayedMsgThis("punch", 7150);
  101.             sendDelayedMsgThis("punch", 7860);
  102.         end )
  103.             
  104.         onMsg("punch", function(msg)
  105.             getParent().playSound("punch" .. random(1,2));
  106.         end )    
  107.         
  108.         onMsg("stopBoxing", function(msg)
  109.             setState("boxStop")
  110.         end )
  111.         
  112.         
  113.         onMsg("testCancel", function(msg)
  114.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  115.                 setState("boxStop")
  116.             else
  117.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  118.             end
  119.         end )
  120.         
  121.         onMsg("end", function(msg)
  122.             
  123.             if testCancel() then
  124.                 setState("boxStop")
  125.             else
  126.                 sendMsgThis("startLoop");
  127.             end
  128.         end )
  129.             
  130.     state("boxStop")
  131.     
  132.         onEnter(function(msg)
  133.             startAnimation("boxingStart", false, -1.0);
  134.         end )
  135.         
  136.         onMsg("end", function(msg)
  137.             exitAndGoAway();
  138.         end )    
  139.             
  140.         
  141. endStateMachine()
  142.