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

  1. -- easel character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local easel = getStateObjectFromID(msg.sender);
  6.         storeStateObject("easel", easel);
  7.         
  8.         if (easel) then
  9.             -- easel does exist
  10.             
  11.             if exitIfWrongPosition(getParent(), easel, retrieveData("actionPointName")) then return end;    
  12.             
  13.             
  14.             if (getParent().isOneActionPointLocked(easel)) then
  15.                 -- action point is locked
  16.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  17.                 sendMsg("emoThink", getParent().walkSO);
  18.                 exitStateMachine();
  19.             else
  20.                 getParent().lockActionPoints(easel);
  21.             end
  22.         else
  23.             -- easel does not exist anymore
  24.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  25.             sendMsg("emoThink", getParent().walkSO);
  26.             exitStateMachine();
  27.         end
  28.         
  29.         freeHands(getParent());
  30.                 
  31.     end )
  32.     
  33.     onExit(function(msg)
  34. --        local easel = retrieveStateObject("easel");
  35. --        getParent().unlockActionPoints(easel);
  36. --        getParent().stopAllActivities(easel);
  37. --        removeStateObject("easel");
  38.         
  39.         unlockAll("easel");
  40.         
  41.         getParent().stopAllActivities();        
  42.     end )
  43.     
  44.     state("paint")
  45.     
  46.         onEnter(function(msg)
  47.         
  48.             local brush = getParent().loadGameObject("StandardGO","paintbrush");
  49.             storeStateObject("brush", brush);
  50.             getParent().attachRightObjectHolder(brush);        
  51.         
  52.             local palette = getParent().loadGameObject("StandardGO","palette");
  53.             storeStateObject("palette", palette);
  54.             getParent().attachLeftObjectHolder(palette);        
  55.         
  56.             local easel = retrieveStateObject("easel");
  57.         
  58.             startAnimation("paint");
  59.             
  60.             local paintActivity = getParent().startActivity("paint", easel);
  61.             local length, scale = getActivityLength(paintActivity);
  62.  
  63. --            this.actionComplete();
  64.             sendDelayedMsgThis("stopPainting", length);
  65.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  66.             
  67.         end )
  68.     
  69.         onMsg("stopPainting", function(msg)
  70.  
  71.             getParent().detachRightObjectHolder();    
  72.             local brush = retrieveStateObject("brush");
  73.             if (brush) then brush.deleteGameObject(); end
  74.  
  75.             getParent().detachLeftObjectHolder();    
  76.             local palette = retrieveStateObject("palette");
  77.             if (palette) then palette.deleteGameObject(); end
  78.  
  79.             local easel = retrieveStateObject("easel");
  80.             getParent().stopActivity("paint", easel);
  81.             
  82.             exitStateMachine();
  83.         end )    
  84.         
  85. --        onMsg("queue", function(msg)
  86. --            sendMsgThis("stopPainting");
  87. --        end )
  88.         
  89.         onMsg("testCancel", function(msg)
  90.             if testCancel() and (not this.getParent().getCurrentActivityGain()) then
  91.                 sendMsgThis("stopPainting");
  92.             else
  93.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  94.             end
  95.         end )
  96.         
  97.  
  98.         onMsg("end", function(msg)
  99.             if testCancel() then
  100.                 sendMsgThis("stopPainting");
  101.             else
  102.                 startAnimation("paint");
  103.             end
  104.         end )    
  105.         
  106.  
  107.                 
  108. endStateMachine()
  109.