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

  1. -- treadmil character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local treadmill = getStateObjectFromID(msg.sender);
  6.         storeStateObject("treadmill", treadmill);
  7.         
  8.         if (treadmill) then
  9.             -- treadmill does still exist
  10.             local actionPointName = retrieveData("actionPointName");
  11.             if exitIfWrongPosition(getParent(), treadmill, actionPointName) then return end;
  12.  
  13.             if (getParent().isOneActionPointLocked(treadmill)) then
  14.                 -- action point is locked
  15.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  16.                 sendMsg("emoThink", getParent().walkSO);
  17.                 exitStateMachine();
  18.             else
  19.                 getParent().lockActionPoints(treadmill);
  20.             end
  21.         else
  22.             -- treadmill does not exist anymore
  23.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  24.             sendMsg("emoThink", getParent().walkSO);
  25.             exitStateMachine();
  26.         end
  27.     end )
  28.     
  29.     onExit(function(msg)
  30. --        local treadmill = retrieveStateObject("treadmill");
  31. --        getParent().stopAllActivities(treadmill);
  32. --        getParent().unlockActionPoints(treadmill);
  33. --        removeStateObject("treadmill");
  34.         
  35.         unlockAll("treadmill");    
  36.         
  37.         getParent().stopAllActivities();
  38.     end )
  39.     
  40.     -- enter the treadmil
  41.     state("enter")
  42.     
  43.         onEnter(function(msg)
  44.             startAnimation("treadmilStart");
  45.             sendDelayedMsgThis("startTreadmilSound", 3000);
  46.             
  47.         end )
  48.         
  49.         onMsg("startTreadmilSound", function(msg)
  50.             getParent().playSound("treadmilOn");
  51.             getParent().playSound("treadmilFadein");
  52.             sendDelayedMsg("startTreadmilLoopSound", this, 3430);
  53.         end )
  54.             
  55.         onMsg("startTreadmilLoopSound", function(msg)
  56.             getParent().loopSound("treadmilLoop");
  57.         end )    
  58.     
  59.         onMsg("end", function(msg)
  60.             if (testCancel()) then
  61.                 setState("exit");
  62.             else
  63.                 setState("run");
  64.             end
  65.         end )    
  66.     
  67.     -- run on treadmil
  68.     state("run")
  69.     
  70.         onEnter(function(msg)
  71.             local treadmill = retrieveStateObject("treadmill");
  72.             local run = getParent().startActivity("run", treadmill);
  73.             length, scale = getActivityLength(run);
  74.             storeData("scale", scale);
  75.             print("run scale:" .. scale);
  76.             startAnimation("treadmilLoop", false, scale);
  77.             sendDelayedMsgThis("stopRun", length);
  78.         end )
  79.         
  80.         onMsg("startTreadmilLoopSound", function(msg)
  81.             getParent().loopSound("treadmilLoop");
  82.         end )    
  83.         
  84.         onMsg("stopRun", function(msg)
  85.             print("stopRun timeout");
  86.             setState("exit");
  87.         end )    
  88.     
  89.         onMsg("end", function(msg)
  90.             if testCancel()  or (not this.getParent().getCurrentActivityGain())  then
  91.                 print("stopRun getCurrentActivityGain");
  92.                 setState("exit");
  93.             else                
  94.                 startAnimation("treadmilLoop", false, retrieveData("scale", 1.0));
  95.                 --doSomething();
  96.             end
  97.         end )    
  98.         
  99.     -- exit the treadmill
  100.     state("exit")
  101.     
  102.         onEnter(function(msg)
  103.             --print("exit the treadmill");
  104.             startAnimation("treadmilExit", false, retrieveData("scale", 1.0));
  105.             getParent().stopSound("treadmilLoop");
  106.             getParent().playSound("treadmilFadeout");
  107.             local treadmill = retrieveStateObject("treadmill");
  108.             getParent().stopAllActivities(treadmill);
  109.         end )
  110.     
  111.         onMsg("end", function(msg)
  112.             setCurrentPosition();
  113.             exitStateMachine();
  114.         end )    
  115.     
  116. endStateMachine()
  117.