behavior for playing movies depending on user selected level of difficulty.
--global level keep tracks
--easy: level=1
--medium: level=2
--hard: level=3
--if level is 1 then game is taken from "games1" folder
--if level is 2 then game is taken from "games2" folder etc.
--games should have equal names in different folders.
--Folders should have indexes 1, 2 and 3 in their names.
--anyFolderName1
--anyFolderName2
--anyFolderName3
--here is a listing of root folder
--mainMovie.dir
-- -- -- --So principle is simple:
--make one game (for example memory1.dir) with level=1 difficulty and put in games1 folder
--make same but little harder game with same name and put in games2 folder
--make same but hardest game with same name and put in games3 folder
--call the game from mainMovie.dir
--depends on global "level" behavior will play movie from those three folders
--(if "level=1" from "games1" folder etc.)
--******************************
--ATTENTION
--when you create buttons in mainMovie you should always select movie only from
--first folder
--******************************
--ACTION
--Apply this behavior to button and select game from first folder.
--make all buttons with all games from first folder
--during runtime when user select level of difficulty, behavior will play movie
--according to value of "level"
property mydistantMovie
--global LEVEL previously selected by user. Always on start of the whole game.
global level
on mouseUp
set rep=string(level)
--replaces index of folder with index from Level global
mydistantMovie=searchAndReplace(mydistantMovie, "1", rep)
--playing movie
play movie mydistantMovie
end
--handler to replace index with level value
on searchAndReplace input, oldStr, newStr
-- searches the input (string) for oldStr and replaces it with newStr
set output = ""
set posn = offset(oldStr, input)-1
if posn > 0 then put char 1 to posn of input after output
put newStr after output
delete char 1 to (posn + length(oldStr)) of input
put input after output
return output
end
--part for selecting movie from Jump to movie behavior from director library
on getPropertyDescriptionList me
if not the currentSpriteNum then exit
-- Choose a movie with FileIO Xtra or allow
-- user to Cancel and maintain current choice
theSprite = sprite(the currentSpriteNum)
theScriptList = theSprite.scriptList
behaviorCount = theScriptList.count
if theScriptList.count() then
-- Check if behavior has already been initialized
currentMovie = GetCurrentMovie (me, theScriptList, behaviorCount)
-- Use fileIO to find the movie to jump to
fileIOChild = new (xtra "fileIO")
setFilterMask (fileIOChild, "Director movies,*.d*r")
chosenMovie = displayOpen (fileIOChild)
if chosenMovie = EMPTY then
if not stringP (currentMovie) then
return ErrorAlert (me, #getPDL_NoMovie)
else
movieList = [currentMovie]
end if
else
movieList = [GetRelativePathTo (me, chosenMovie)]
end if
else
movieList = [#noMovieChosen]
end if
return ¬
[ ¬
#myDistantMovie : ¬
[ ¬
#comment :"On mouseUp, go to movie", ¬
#format :#movie, ¬
#range :movieList, ¬
#default :movieList[1] ¬
]]
end getPropertyDescriptionList
on GetCurrentMovie me, theScriptList, behaviorCount
-- Reads the scriptList for the current sprite to determine if a movie has
-- previously been selected returns the current value of #myDistantMovie
-- theScriptList = sprite(the currentSpriteNum).scriptList
-- behaviorCount = theScriptList.count
thisScript = string (me)
put "member ("into thisScript.word[1]
thisScript = value (thisScript)
repeat while behaviorCount
if theScriptList[behaviorCount][1] = thisScript then
behaviorInitializers = value (theScriptList[behaviorCount][2])
if behaviorInitializers.findPos(#myDistantMovie) then
return behaviorInitializers.getProp(#myDistantMovie)
end if
end if
behaviorCount = behaviorCount - 1
end repeat
end GetCurrentMovie
on GetRelativePathTo me, distantMovie
-- Calculates the relative path to the target movie, by comparing its
-- full path name with that of the current movie.
thatMoviePath = distantMovie
thisMoviePath = the moviePath
saveItemDelimiter = the itemDelimiter
if the machineType = 256 then
newItemDelimiter = "\"
else
newItemDelimiter = ""
end if
the itemDelimiter = newItemDelimiter
repeat while TRUE
thisFile = thisMoviePath.item[1]
thatFile = thatMoviePath.item[1]
if thisFile <> thatFile then exit repeat
delete thisMoviePath.item[1]
delete thatMoviePath.item[1]
end repeat
if thatMoviePath = distantMovie then
relativePath = distantMovie
else
relativePath = "@"
thisDeep = thisMoviePath.item.count
repeat while thisDeep
relativePath = relativePath&newItemDelimiter
thisDeep = thisDeep - 1
end repeat
relativePath = relativePath&thatMoviePath
end if
the itemDelimiter = saveItemDelimiter
return relativePath
end GetRelativePathTo
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA