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

  1. -- mat character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local mat = getStateObjectFromID(msg.sender);
  6.         storeStateObject("mat", mat);
  7.         
  8.         if (mat) then
  9.         
  10.             if exitIfWrongPosition(getParent(), mat, retrieveData("actionPointName")) then return end;            
  11.         
  12.             -- mat does exist
  13.             if (getParent().isOneActionPointLocked(mat)) 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(mat);
  20.             end
  21.         else
  22.             -- mat does not exist anymore
  23.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  24.             sendMsg("emoThink", getParent().walkSO);
  25.             exitStateMachine();
  26.         end
  27.         
  28.         freeHands(getParent());
  29.                 
  30.     end )
  31.     
  32.     onExit(function(msg)
  33. --        local mat = retrieveStateObject("mat");
  34. --        getParent().unlockActionPoints(mat);
  35. --        getParent().stopAllActivities(mat);
  36. --        removeStateObject("mat");
  37.         
  38.         unlockAll("mat");        
  39.         
  40.         getParent().stopAllActivities();
  41.     end )
  42.     
  43.     state("pushupStart")
  44.     
  45.         onEnter(function(msg)
  46.             startAnimation("pushupDown");
  47.         end )
  48.     
  49.  
  50.         onMsg("end", function(msg)
  51.             
  52.             if testCancel() then
  53.                 setState("pushupEnd");
  54.             else
  55.                 setState("pushupLoop");
  56.             end
  57.         end )    
  58.         
  59.     state("pushupLoop")
  60.     
  61.         onEnter(function(msg)
  62.             local mat = retrieveStateObject("mat");
  63.             local makePushups = getParent().startActivity("makePushups", mat);
  64.             local length, scale = getActivityLength(makePushups);
  65.             scale = scale * 0.5; --make push ups slower
  66.             storeData("scale", scale);
  67.             startAnimation("pushupLoop", false, scale);
  68.             sendDelayedMsgThis("stopPushups", length);
  69.             print("npa length:" .. length);
  70.         end )
  71.     
  72.         onMsg("stopPushups", function(msg)
  73.             local mat = retrieveStateObject("mat");
  74.             getParent().stopActivity("makePushups", mat);
  75.             setState("pushupEnd");
  76.         end )
  77.  
  78.         onMsg("breathe", function(msg)
  79.             getParent().playSound(genderizeReal(getParent(), "atem" .. random(1,2)));
  80.         end )
  81.  
  82.         onMsg("end", function(msg)
  83.             
  84.             if testCancel() or (not getParent().getCurrentActivityGain()) or (getParent().getCondition(NEED_TIREDNESS) < 0.1) then
  85.                 sendMsgThis("stopPushups");
  86.             else
  87.                 startAnimation("pushupLoop", false, retrieveData("scale", 1.0));
  88.                 if (random() < 0.5) then sendMsgThis("breathe"); end;
  89.             end
  90.         end )    
  91.  
  92.     state("pushupEnd")
  93.     
  94.         onEnter(function(msg)
  95.             startAnimation("pushupDown", false, -1);
  96.         end )
  97.     
  98.  
  99.         onMsg("end", function(msg)
  100.             exitAndGoAway();
  101.         end )    
  102.                 
  103. endStateMachine()
  104.