home *** CD-ROM | disk | FTP | other *** search
/ Roboty / ROBOTS_CD.iso / CD / circuits.dxr / 00024_drag&drop.ls < prev    next >
Encoding:
Text File  |  2005-05-13  |  2.7 KB  |  131 lines

  1. property spriteNum, startLoc, topZ, myAction, myNextaction, Active, myActiveState, tagretSp, myName
  2. global dropZones, DropCount
  3.  
  4. on beginSprite me
  5.   DropCount = 0
  6.   Active = 1
  7.   startLoc = sprite(spriteNum).loc
  8.   sprite(spriteNum).moveableSprite = 0
  9.   myName = sprite(spriteNum).member.name
  10.   if myName = "lit_side" then
  11.     myName = "lit"
  12.   end if
  13.   myAction = "None"
  14.   topZ = 50
  15. end
  16.  
  17. on mouseDown me
  18.   if Active then
  19.     if the doubleClick then
  20.       cursor(0)
  21.       sprite(spriteNum).moveableSprite = 0
  22.     else
  23.       cursor(290)
  24.       sprite(spriteNum).locZ = topZ
  25.       sendAllSprites(#activeSwitch, "off", spriteNum)
  26.       sprite(spriteNum).moveableSprite = 1
  27.       myAction = "Dragging"
  28.     end if
  29.   end if
  30. end
  31.  
  32. on mouseUp me
  33.   if Active then
  34.     sprite(spriteNum).locZ = spriteNum
  35.     sendAllSprites(#activeSwitch, "on", spriteNum)
  36.     sprite(spriteNum).moveableSprite = 1
  37.     myAction = myNextaction
  38.   end if
  39. end
  40.  
  41. on testValidDrop me
  42.   tagretSp = 0
  43.   repeat with x = 1 to count(dropZones)
  44.     if sprite(spriteNum).intersects(dropZones[x]) then
  45.       tagretSp = dropZones[x]
  46.       exit repeat
  47.     end if
  48.   end repeat
  49.   return sprite(tagretSp).member.name = (myName & "_zone")
  50. end
  51.  
  52. on DropMe me
  53.   Active = 0
  54.   sendSprite(tagretSp, #myItem, myName)
  55.   sprite(spriteNum).loc = startLoc
  56.   sprite(spriteNum).blend = 50
  57.   sprite(spriteNum).moveableSprite = 0
  58.   DropCount = DropCount + 1
  59.   puppetSound(1, "click")
  60.   if DropCount = count(dropZones) then
  61.     sendAllSprites(#testCircuit)
  62.   end if
  63. end
  64.  
  65. on exitFrame me
  66.   case myAction of
  67.     "Dragging":
  68.       dropOK = me.testValidDrop()
  69.       if dropOK then
  70.         myNextaction = "Add"
  71.       else
  72.         myNextaction = "Return"
  73.       end if
  74.     "Add":
  75.       cursor(0)
  76.       myAction = "None"
  77.       me.DropMe()
  78.     "Return":
  79.       incx = (sprite(spriteNum).loc[1] - startLoc[1]) / 2
  80.       incy = (sprite(spriteNum).loc[2] - startLoc[2]) / 2
  81.       sprite(spriteNum).loc = startLoc + point(incx, incy)
  82.       if me.distanceCheck(startLoc, sprite(spriteNum).loc) < 3 then
  83.         sprite(spriteNum).loc = startLoc
  84.         myAction = "None"
  85.       end if
  86.       cursor(0)
  87.     "None":
  88.   end case
  89. end
  90.  
  91. on distanceCheck me, obj1, obj2
  92.   return sqrt(power(obj1[1] - obj2[1], 2) + power(obj1[2] - obj2[2], 2))
  93. end
  94.  
  95. on Hide me
  96.   Active = 1
  97. end
  98.  
  99. on show me
  100.   Active = 0
  101. end
  102.  
  103. on activeSwitch me, val, spNum
  104.   if spNum <> spriteNum then
  105.     if val = "off" then
  106.       myActiveState = Active
  107.       Active = 0
  108.     else
  109.       Active = myActiveState
  110.     end if
  111.   end if
  112. end
  113.  
  114. on mouseWithin me
  115.   if Active and (myAction <> "Dragging") then
  116.     cursor(260)
  117.   end if
  118. end
  119.  
  120. on mouseEnter me
  121.   if Active and (myAction <> "Dragging") then
  122.     cursor(260)
  123.   end if
  124. end
  125.  
  126. on mouseLeave me
  127.   if Active and (myAction <> "Dragging") then
  128.     cursor(0)
  129.   end if
  130. end
  131.