![]() ocotillo puzzle code snippet | show it | return | |
global gLocList, gMoveCounter
on startmovie
-- puppet the 20 pieces, stored in sprites 2 20 20
-- sprite 26 is an invisible quickdraw shape that
-- defines the area where pieces are constrained to
repeat with i = 2 to 21
puppetSprite i,1
set the constraint of sprite i = 26
end repeat
-- puppet the holder piece
puppetSprite 23,1
-- track the starting positions
set gLocList = getOriginalLocs( 2,21 )
-- shuffle the puzzle pieces
shufflePieces
go to frame "scramble"
-- reset the counter and display
set gMoveCounter = 0
put "0 moves so far" into field "counter"
end
on getOriginalLocs firstSprite, lastSprite
-- builds and returns a list of the locations of
-- sprites in the specified range (assumes they
-- are consecutively stored)
set pList = []
repeat with i = firstSprite to lastSprite
append pList, the loc of sprite i
end repeat
return pList
end
on shufflePieces
-- shuffle the pieces within the area of the sprite
-- that defines the boundary of the puzzle,
-- with some randomness thrown in
set spaceW = the width of sprite 25 - 80
set spaceH = the height of sprite 25 - 80
repeat with i = 2 to 21
set the loc of sprite i = point( 40 + random(spaceW), 40 + random(spaceH) )
end repeat
updateStage
end
on isAllCorrect
-- checks for sprites being in their proper location according
-- to the positions established in frame 1
repeat with i = 2 to 21
if the loc of sprite i <> getAt(gLocList, the memberNum of sprite i) then return 0
end repeat
return 1
end
|
| These are the initial scripts to set up the puzzle. When the movie starts, the puzzle is correctly assembled, and hidden behind a quickdraq sprite, so we can load the correct final positions before shuffling the pieces.
lingo era = v5.0 Quite a bit of this movie is hardwired for the number and sizes of pieces used. |