|
File "arkas.dir"
contains the basic pieces (taken
from a drawing by Greek cartoonist Arkas) for making a 4x4 puzzle: on mouseUp put sprite(_mouse.clickOn).locH put sprite(_mouse.clickOn).locV end
File "arkas1.dir"
has
the programming of the puzzle complete.
on mouseUp
finH = 267 -- inserted manually
finV = 147 -- inserted manually
currH = sprite(_mouse.clickOn).locH
currV = sprite(_mouse.clickOn).locV
if (abs(currH - finH) < 20) and (abs(currV - finV) < 20) then
sprite(_mouse.clickOn).locH = finH
sprite(_mouse.clickOn).locV = finV
beep
end if
end
File "arkas2.dir" is a little prettier in terms of interface and less cumbersome to replicate using the moveAndCheck() function: on mouseUp finH = 267 -- needs to be inserted manually finV = 147 -- needs to be inserted manually moveAndCheck(finH, finV) end
on startMovie
global success
success = 0 -- counts correctly placed pieces
member("banner").text = "Assemble the puzzle"
end
on checkIfDone
global success
if success = 4 then
member("banner").text = "Success!"
-- here you should play a sound and/or go to another frame
-- to celebrate success!
end if
end
File "arkas3.dir" Note that there are a couple problems with the game presentation: First, if you accidentally move a piece out of its position, the counter of successes will not decrease. So, you can "cheat" by moving a single piece in and out of position 4 times. It would be better to have a piece "stick" to its final place once it has moved there. You can do that by setting the moveableSprite property of a sprite to false. Next, when a piece moves on top of another, you cannot see the one below. That makes it difficult to move sprites on top of a congested stage. To avoid that you can move the sprite you are currently clicking on at the top channel available to your application. You can do that by setting the locZ property of a sprite to the highest channel available. locZ works like locH and locV, but it has only a temporary effect. After the end of the event handler it is in, it will go back to its original position. on mouseDown -- move sprite to top channel temporarily global gHighestSprite sprite(_mouse.clickOn).locZ = gHighestSprite + 1 gHighestSprite = gHighestSprite + 1 updateStage end The file at the header of this section implements both of these improvements. File "arkasSwap.dir. Finally, in this version, you are moving and swapping sprites based on whether they overlap or not. This is useful when you are doing a puzzle with in-situ pieces.
|
|
|
Maintained By: Takis Metaxas
|
|