Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
MediaMacros
All_In_One Button Hue Shift
Number of CD Tracks - MCI
Video Status bar
List Inspector 1.1 with Tree View
Bounce That Sprite
NJC - Space Invaders
Sharp Image Export Xtra
Export to Pocket PC Xtra
DirSaver
 

 

 

Behavior Puzzler - Puzzle Maker

Added on 8/7/1999

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

Rating:

Author: MediaMacros (website)

Refer to the learning arcade for an example of this script in action.

property spriteNum, origonalLoc, group, lockSpritesList, baseMove, initialized
global topZ, allPieces, tollerance, amDone
on beginSprite me
  if amDone = void then amDone = false
  if tollerance = void then tollerance = 5
  if allPieces = void then allPieces = 0
  allPieces = allPieces + 1
  topZ = sprite(spriteNum).locZ
  origonalLoc = sprite(spriteNum).loc
  group = spriteNum  
  baseMove = sprite(spriteNum).loc  
  initialized = false
end
on mouseDown me
  if amDone = false then
    topZ = topZ + 1
    sendAllSprites(#pullUp, group)  
    startClick = the mouseLoc
    sendAllSprites(#getBase)
    repeat while the stilldown
      sendAllSprites(#moveMe, group, (the mouseLoc - startClick))
      updateStage  
    end repeat
    --see if it "locked" with another bordering sprite
    searchList = []
    --get a searchList
    sendAllSprites(#checkGroup, group, searchList)
    returnList = []
    --check the locking location of all touching sprites
    repeat with x = 1 to searchList.count
      sendSprite(searchList[x], #checkLock, group, origonalLoc - sprite(spriteNum).loc, returnList)
      if returnList <> [] then
        sendAllSprites(#lockGroup, group, returnList[1][1], returnList[1][2])
        exit repeat
      end if
    end repeat
    updateStage
    winList = []
    sendAllSprites(#checkWin, winList, group)
    if winList.count = 0 then
      --all true, winner
      amDone = true
      go "win"
    end if
  end if  
end
on exitFrame me
  if initialized = false then
    lockList = []
    sendAllSPrites(#getConnected, spriteNum, lockList)
    lockSpritesList = lockList
    initialized = true
  end if
end
on getConnected me, whatSprite, lockList
  if sprite(spriteNum).intersects(whatSprite) and whatSprite <> spriteNum then
    lockList.add(spritenum)
  end if
end
on shuffle me  
  okW = the stageRight - the stageLeft - sprite(spriteNum).width
  okH = the stageBottom - the stageTop - sprite(spriteNum).height  
  randomH = random(okW)
  randomV = random(okH)
  sprite(spriteNum).rect = rect(randomH, randomV, randomH + sprite(spriteNum).width, randomV + sprite(spriteNum).height)
end
on pullUp me, whatGroup
  if whatGroup = group then
    sprite(spriteNum).locZ = topZ
  end if
end
on getBase me
  baseMove = sprite(spriteNum).loc
end
on checkGroup me, theGroup, searchList
   if theGroup = group then
    if lockSpritesList.count > 0 then
      repeat with x = 1 to lockSpritesList.count
        if searchList.getOne(lockSpritesList[x]) = 0 then searchList.add(lockSpritesList[x])
      end repeat
    end if
  end if
end
on lockGroup me, whatGroup, newGroup, newOffset  
  if group = whatGroup then
    group = newGroup    
    sprite(spriteNum).loc = origonalLoc - newOffset
  end if
end
on moveMe me, whatGroup, whereMove
  if group = whatGroup then
    sprite(spriteNum).loc = sprite(spriteNum).baseMove + whereMove
  end if
end
on dropDown me, howMany
  sprite(spriteNum).locZ = sprite(SpriteNum).locZ - howMany
end
on checkLock me, whatGroup, whatOffset, returnList
  --if already linked no reason to run
  if whatGroup <> group then
    myOffset = origonalLoc - sprite(spriteNum).loc
    compareOffset = (myOffset - whatOffset)    
    if abs(compareOffset.locH) <= tollerance and abs(compareOffset.locV) <= tollerance then
      --it is "snapable"
      returnList.add([group, myOffset])
    end if
  end if
end
on checkWin me, winList, whatGroup
  if group <> whatGroup then
    winList.add(spriteNum)
  end if
end

on getBehaviorDescription me
  return "Drop this behavior on all your puzzle pieces with background transparent ink.  Use the command sendAllSprites(#shuffle) to re-arange the pieces.  More detailed explinations can be found at www.mediamacros.com/howto.shtml under the article called Puzzling"
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail