NUM_PUZZLES = 3 --debug1 = 3 --debug2 = 4 g_puzzle_templates = { { "gameMalo/piezas/arbolTemplate.mesh", "gameMalo/piezas/ratonTemplate.mesh", "gameMalo/piezas/avionTemplate.mesh", "gameMalo/piezas/barcoTemplate.mesh", "gameMalo/piezas/boligrafoTemplate.mesh", "gameMalo/piezas/cuboTemplate.mesh",}, { "gameMalo/piezas/buhoTemplate.mesh", "gameMalo/piezas/cangrejoTemplate.mesh", "gameMalo/piezas/manzanaTemplate.mesh", "gameMalo/piezas/pezTemplate.mesh",}, { "gameMalo/piezas/bolsoTemplate.mesh", "gameMalo/piezas/pelotaTemplate.mesh", "gameMalo/piezas/ranaTemplate.mesh", "gameMalo/piezas/cerdoTemplate.mesh",}, } g_puzzles = { { {"gameMalo/piezas/arbolhole.mesh","gameMalo/piezas/arbol1.mesh","gameMalo/piezas/arbol2.mesh","gameMalo/piezas/arbol3.mesh"}, {"gameMalo/piezas/ratonhole.mesh","gameMalo/piezas/raton1.mesh","gameMalo/piezas/raton2.mesh","gameMalo/piezas/raton3.mesh"}, {"gameMalo/piezas/avionhole.mesh","gameMalo/piezas/avion1.mesh","gameMalo/piezas/avion2.mesh","gameMalo/piezas/avion3.mesh"}, {"gameMalo/piezas/barcohole.mesh","gameMalo/piezas/barco1.mesh","gameMalo/piezas/barco2.mesh","gameMalo/piezas/barco3.mesh"}, {"gameMalo/piezas/boligrafohole.mesh","gameMalo/piezas/boligrafo1.mesh","gameMalo/piezas/boligrafo2.mesh","gameMalo/piezas/boligrafo3.mesh"}, {"gameMalo/piezas/cubohole.mesh","gameMalo/piezas/cubo1.mesh","gameMalo/piezas/cubo2.mesh","gameMalo/piezas/cubo3.mesh"},}, { {"gameMalo/piezas/buhohole.mesh","gameMalo/piezas/buho1.mesh","gameMalo/piezas/buho2.mesh","gameMalo/piezas/buho3.mesh","gameMalo/piezas/buho4.mesh"}, {"gameMalo/piezas/cangrejohole.mesh","gameMalo/piezas/cangrejo1.mesh","gameMalo/piezas/cangrejo2.mesh","gameMalo/piezas/cangrejo3.mesh","gameMalo/piezas/cangrejo4.mesh"}, {"gameMalo/piezas/manzanahole.mesh","gameMalo/piezas/manzana1.mesh","gameMalo/piezas/manzana2.mesh","gameMalo/piezas/manzana3.mesh","gameMalo/piezas/manzana4.mesh"}, {"gameMalo/piezas/pezhole.mesh","gameMalo/piezas/pez1.mesh","gameMalo/piezas/pez2.mesh","gameMalo/piezas/pez3.mesh","gameMalo/piezas/pez4.mesh"},}, { {"gameMalo/piezas/bolsohole.mesh","gameMalo/piezas/bolso1.mesh","gameMalo/piezas/bolso2.mesh","gameMalo/piezas/bolso3.mesh","gameMalo/piezas/bolso4.mesh","gameMalo/piezas/bolso5.mesh"}, {"gameMalo/piezas/pelotahole.mesh","gameMalo/piezas/pelota1.mesh","gameMalo/piezas/pelota2.mesh","gameMalo/piezas/pelota3.mesh","gameMalo/piezas/pelota4.mesh","gameMalo/piezas/pelota5.mesh"}, {"gameMalo/piezas/ranahole.mesh","gameMalo/piezas/rana1.mesh","gameMalo/piezas/rana2.mesh","gameMalo/piezas/rana3.mesh","gameMalo/piezas/rana4.mesh","gameMalo/piezas/rana5.mesh"}, {"gameMalo/piezas/cerdohole.mesh","gameMalo/piezas/cerdo1.mesh","gameMalo/piezas/cerdo2.mesh","gameMalo/piezas/cerdo3.mesh","gameMalo/piezas/cerdo4.mesh","gameMalo/piezas/cerdo5.mesh"},}, } --g_timesCompleted = 0 g_puzzle_random = {} function puzzleCompleted() log("-----------------------------------puzzle completed " .. g_timesCompleted + 1 .. " times--------------------------") g_timesCompleted = g_timesCompleted + 1 SaveGameProgress() if isGame5Ended() then g_currentState:setNextState(TGame5CongratulationsState:new()) else g_currentState:setNextState(TGame5GreatState:new()) end FinishPuzzleGameState() end function getPiece(_ndx) log(g_difficulty_game5) --log(">>>>>>>>>creando pieza " .. g_puzzles[g_difficulty_game5][g_puzzle_random[g_timesCompleted + 1]][_ndx + 1]) return { name = "piece" .. _ndx, model = g_puzzles[g_difficulty_game5][g_puzzle_random[g_timesCompleted + 1]][_ndx + 1], touchable = true} --return { name = "piece" .. _ndx, model = g_puzzles[debug1][debug2][_ndx + 1], touchable = true} end function random_sequence(_repeating , _count, _m, _n) local solution = {} local drawed = {} while #solution < _count do log("" .. #solution .. " < " .. _count) local aux = math.random(_m,_n) log("aux = " .. aux) if(_repeating or (not list_contains(solution, aux))) then log("incluyo") solution[#solution + 1] = aux end end return solution end function random_and_setup_game5() g_puzzle_random = {} local count = #g_puzzles[g_difficulty_game5] g_puzzle_random = random_sequence(false,count,1,count) --g_puzzle_random[g_puzzle_number] me darķa las piezas del puzle actual. end function isGame5Ended () return not (g_timesCompleted < NUM_PUZZLES) end --------------------------------------------------- --Great, Congratulations and Fail --------------------------------------------------- TGame5CongratulationsState = TState:new{ m_name = "TGame5CongratulationsState", events = { onBegin = function(_self) --local auxState = _self:findParent("TRootState") --auxState:setNextState(TMainMenuFadeIn:new()) Sound.PlaySound(g_Sound.fx.game5.congratulations) DeactivateActor("pause") IncrementPointsAndSave(E_LEVEL_GAME5) return { actors = { { actorType = "ActorGeom", properties = { name = "Win", model = "efectos/congratulationcicle.mesh", touchable = false, layer = LF_PANELS+1, camera = "game1" }, }, { actorType = "ActorGeom", properties = { name = "CubePart", model = g_cubePartMeshes[5], touchable = false, layer = LF_PANELS + 2, camera = "game1"}, }, }, setAnims = { { actorName = "Win", properties = { anim = "efectos/congratulationcicle.anm", loop = false, } }, { actorName = "CubePart", properties = { anim = g_cubePartAnms[5], loop = false, } }, } } end, onAnimEnded = { All = function(_self) local auxState = _self:findParent("TPiecesInState") auxState:setNextState(nil) auxState = _self:findParent("TRootState") --auxState:setNextState(nil) auxState:setNextState(TGame5FadeOutState:new()) end, } } } TGame5GreatState = TState:new{ m_name = "TGame5GreatState", events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game5.great) DeactivateActor("pause") return { actors = { { actorType = "ActorGeom", properties = { name = "Win", model = "efectos/great.mesh", touchable = false, layer = LF_PANELS, camera = "game1" }, }, }, setAnims = { { actorName = "Win", properties = { anim = "efectos/greatCicle.anm", loop = false, } }, } } end, onAnimEnded = { Win = function(_self) local auxState = _self:findParent("TPiecesInState") auxState:setNextState(nil) auxState.superState:setNextState(TPiecesInState:new()) end, } } } TGame5FailState = TState:new{ m_name = "TGame5FailState", events = { onBegin = function(_self) log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FAIL!!!") return { actors = { { actorType = "ActorGeom", properties = { name = "Fail", model = "efectos/wrong.mesh", touchable = false, layer = LF_PANELS, camera = "game1"}, }, }, setAnims = { { actorName = "Fail", properties = { anim = "efectos/wrongIn.anm", loop = false, } }, } } end, onAnimEnded = { Fail = function(_self) _self:findParent("TRootState") local auxState = _self:findParent("TPiecesInState") auxState.superState:setNextState(TPiecesInState:new()) end }, } } -------------------------------------- -- Objeto representando a la palabra que sea... -------------------------------------- TPiecesInState = TState:new{ m_name = "TPiecesInState", events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game5.pieceSpawn) return { actors = { --{ actorType = "ActorGeom", -- properties = { name = "Reflejo", model = "gameMalo/reflejo.mesh" }, --}, { actorType = "ActorGeom", properties = { name = "Rayos", model = "gameMalo/rayos.mesh" }, }, { actorType = "ActorGeom", properties = { name = "Flash", model = "flashin.mesh" }, }, }, setAnims = { { actorName = "Flash", properties = { anim = "flashout.anm", loop = false, } }, { actorName = "Rayos", properties = { anim = "gameMalo/rayos.anm", loop = false, } }, --{ actorName = "Reflejo", -- properties = { anim = "gameMalo/reflejo.anm", loop = false, } --}, } } end, onAnimEnded = { All = function(_self) _self:setNextState(TPiecesIn2ndState:new()) DeactivateActor("Rayos") --DeactivateActor("Reflejo") end } }, } TPiecesIn2ndState = TState:new{ m_name = "TPiecesIn2ndState", events = { onBegin = function(_self) return { actors = { { actorType = "ActorGeom", properties = { name = "Reflejo", model = "gameMalo/reflejo.mesh" }, }, { actorType = "ActorGeom", properties = { name = "Rayos", model = "gameMalo/rayos.mesh" }, }, { actorType = "ActorGeom", properties = { name = "Flash", model = "flashin.mesh" }, }, }, setAnims = { { actorName = "Flash", properties = { anim = "flashin.anm", loop = false, } }, { actorName = "Rayos", properties = { anim = "gameMalo/rayos.anm", loop = false, } }, { actorName = "Reflejo", properties = { anim = "gameMalo/reflejo.anm", loop = false, } }, } } end, onAnimEnded = { All = function(_self) _self:setNextState(TPiecesIn3rdState:new()) DeactivateActor("Rayos") DeactivateActor("Reflejo") end } }, } TPiecesIn2ndState = TState:new{ m_name = "TPiecesIn2ndState", events = { onBegin = function(_self) ActivateActor("Flash") return { setAnims = { { actorName = "Flash", properties = { anim = "flashin.anm", loop = false, } }, } } end, onAnimEnded = { Flash = function(_self) log("Meto las piezas") DeactivateActor("Flash") _self:setNextState(TPiecesIn4thState:new()) end } }, } TPiecesIn4thState = TState:new{ m_name = "TPiecesIn4thState", events = { onBegin = function(_self) _self:setNextState(TGame5PiecesSetup:new()) log("dificultad: " .. g_difficulty_game5) log("puzle numero: " .. g_timesCompleted + 1) log("random: " .. g_puzzle_random[g_timesCompleted + 1]) return { actors = { { actorType = "ActorGeom", properties = { name = "PiecesHole", model = g_puzzles[g_difficulty_game5][g_puzzle_random[g_timesCompleted + 1]][1], touchable = false }, --properties = { name = "PiecesHole", model = g_puzzles[debug1][debug2][1], touchable = false }, }, { actorType = "ActorGeom", properties = { name = "Pieces", model = g_puzzle_templates[g_difficulty_game5][g_puzzle_random[g_timesCompleted + 1]] }, --properties = { name = "Pieces", model = g_puzzle_templates[debug1][debug2] }, }, }, setAnims = { { actorName = "Flash", properties = { anim = "flashin.anm", loop = false, } }, } } end, }, changeAfterBeginning = true } TGame5PiecesSetup = TState:new{ m_name = "TGame5PiecesSetup", events = { --seteffectparams.... onBegin = function(_self) _self:setNextState(TGame5LoopState:new()) end, }, changeAfterBeginning = true } -------------------------------------- -- Pantalla de instrucciones del juego -------------------------------------- TGame5InstructionsOut = TState:new{ m_name = "TGame5InstructionsOut", events = { onBegin = function(_self) return { setAnims = { { actorName = "Instructions", properties = { anim = "gameMalo/tutorialOut.anm", loop = false, } }, } } end, onAnimEnded = { Instructions = function(_self) --estado del juego, en espera... _self.superState.superState:setNextState(TPiecesInState:new()) end, }, onFinish = function(_self) end, } } TGame5InstructionsWait = TState:new{ m_name = "TGame5InstructionsWait", events = { onBegin = function(_self) return { setAnims = { { actorName = "Instructions", properties = { anim = "gameMalo/tutorialCicle.anm", loop = true, } }, } } end, onClick = { button = function(_self) _self.superState:setNextState(TGame5InstructionsOut:new()) end, }, onFinish = function(_self) end, } } TGame5InstructionsIn = TState:new{ m_name = "TGame5InstructionsIn", events = { onBegin = function(_self) log("AGH creo el panel de instruciones") Sound.PlaySound(g_Sound.fx.game5.tutorial) return { actors = { { actorType = "ActorGeom", properties = { name = "Instructions", model = "gameMalo/tutorialMalo.mesh", touchable = true, camera = "game3", layer = LF_PANELS }, }, }, setAnims = { { actorName = "Instructions", properties = { anim = "gameMalo/tutorialIn.anm", loop = false, } }, } } end, onAnimEnded = { Instructions = function(_self) _self:setNextState(TGame5InstructionsWait:new()) end, }, onFinish = function(_self) end, } } --------------------------------------------------- TGame5LoopState = TState:new{ m_name = "TGame5LoopState", events = { onBegin = function(_self) _self:setNextState(_self) log("") log("COMIENZO EL ESTADO DE JUEGO!") log("") local auxState = _self:findParent("TPiecesInState") auxState:setNextState(auxState) StartPuzzleGameState() return {actors = { { actorType = "ActorGeom", properties = { name = "pause", model = "menuPause/pauseButton.mesh", touchable = true, camera = "game1", layer = LF_PANELS+3 }, },}} end, onClick = { backButton = function(_self) pause() end, } } } TGame5InitialSetup = TState:new{ m_name = "TGame5InitialSetup", events = { onBegin = function(_self) random_and_setup_game5() _self:setNextState(TGame5InstructionsIn:new()) end } } TGame5CycleAfterFadeInState = TState:new{ m_name = "TGame5CycleAfterFadeInState", events = { onBegin = function(_self) _self:setNextState(TGame5InitialSetup:new()) return { setAnims = { { actorName = "Background", properties = { anim = "gameMalo/gameMalobg.anm", loop = true, } }, }, } end, }, changeAfterBeginning = true } TGame5FadeInState = TState:new{ m_name = "TGame5FadeInState", m_bLoad = false, events = { onBegin = function(_self) Game5Started() ChangeCamera("game5") loadFxsGame5() Sound.PlayMusic(g_Sound.music.game5Theme) if not _self.m_bLoad then g_timesCompleted = 0 end g_currentGame = E_LEVEL_GAME5; log("\n<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>\n") g_difficulty_game5 = getDifficulty(E_LEVEL_GAME5) _self:setNextState(TGame5CycleAfterFadeInState:new()) log("creando escena ".. ball_scenes[g_difficulty_game5]) SaveGameProgress() return { actors = { { actorType = "ActorGeom", properties = { name = "Background", model = "gameMalo/background.mesh", camera = "game5bg"}, }, { actorType = "ActorGeom", properties = { name = "Fade", model = "fadeblack.mesh", touchable = false, layer = LF_PANELS+4 }, }, }, setAnims = { { actorName = "Fade", properties = { anim = "fadeblackout.anm", loop = false, } }, } } end, onFinish = function() Sound.StopMusic(g_Sound.music.game5Theme) releaseFxSoundResources(g_Sound.fx.game5) end }, changeAfterBeginning = true } TGame5IntroState = TState:new{ m_name = "TGame5IntroState", events = { onBegin = function(_self) OpenVideoURL(g_Video.game5.intro, "g_currentState:finish()") _self:setNextState(_self) end, onFinish = function(_self) local auxState = _self:findParent("TRootState") auxState:setNextState(TGame5FadeInState:new()) end } } TGame5EndingState = TState:new{ m_name = "TGame5EndingState", events = { onBegin = function(_self) _self:setNextState(_self) OpenVideoURL(g_Video.game5.ending, "g_currentState:finish()") end, onFinish = function(_self) local auxState = _self:findParent("TRootState") if GetGamePoints(E_LEVEL_GAME5) >= g_PointsToCompleteAGame then auxState:setNextState(TMainMenuEndingState:new()) else auxState:setNextState(TMainMenuFadeIn:new{ m_givePrizeOnGame = E_LEVEL_GAME5 }:new()) end end } } --final absoluto del juegooo TMainMenuEndingState = TState:new{ m_name = "TMainMenuEndingState", events = { onBegin = function(_self) _self:setNextState(_self) EnqueueTimeExecuteScript([[OpenVideoURL(g_Video.ending, "g_currentState:finish()")]], 1.0) end, onFinish = function(_self) local auxState = _self:findParent("TRootState") auxState:setNextState(TMainMenuFadeIn:new{ m_givePrizeOnGame = E_LEVEL_GAME5 }:new()) end } } TGame5FadeOutState = TState:new{ m_name = "TGame5FadeOutState", events = { onBegin = function() log(debug.traceback()) return { actors = { { actorType = "ActorGeom", properties = { name = "Fade2", model = "fadeblack.mesh", touchable = false, layer = LF_PANELS+4 }, }, }, setAnims = { { actorName = "Fade2", properties = { anim = "fadeblackin.anm", loop = false, } }, } } end, onAnimEnded = { Fade2 = function(_self) log("Fade ended") log("BIEN!, onFinish de " .. _self.m_name) --_self.superState:setNextState(nil) local aux = _self:findParent("TRootState") aux:setNextState(TGame5EndingState:new()) end, }, } }