--por legibilidad... NUM_PAIRS = 6 -- Theese need to be restarted every time game begins holes_touched = {} how_many_out = 0 holes = {} --textures characters = {"cerdo.pvr", "mono.pvr", "rana.pvr", "gallina.pvr", "raton.pvr", "fantasma.pvr"} closed_textures_uv = {{0,0}, {0.62, 0}, {0.31, 0}, {0,0.19}, {0.31, 0.19}, {0.64, 0.19} } --hole states CLOSED_HOLE = 0 CLEARED_HOLE = -1 --difficulty NUM_PAIRS_LOCKED = 0 --setup de las variables segun la dificultad function random_and_setup_game2() g_difficulty_game2 = getDifficulty(E_LEVEL_GAME2) if g_difficulty_game2 == E_LEVEL_EASY then NUM_PAIRS_LOCKED = 4 elseif g_difficulty_game2 == E_LEVEL_NORMAL then NUM_PAIRS_LOCKED = 2 elseif g_difficulty_game2 == E_LEVEL_HARD then NUM_PAIRS_LOCKED = 0 end holes_touched = {} how_many_out = 0 holes = {} --agujeros con parejas --for i = 1, NUM_PAIRS - NUM_PAIRS_LOCKED, 1 do -- holes[ #holes + 1 ] = math.random( #characters ) -- holes[ #holes + 1 ] = holes[ #holes ] --end local random_list = random_sequence(false, NUM_PAIRS - NUM_PAIRS_LOCKED, 1, #characters) for i = 1, #random_list, 1 do holes[ #holes + 1 ] = random_list[i] holes[ #holes + 1 ] = random_list[i] end --agujeros cerrados for i = 1, NUM_PAIRS_LOCKED, 1 do holes[ #holes + 1 ] = CLOSED_HOLE holes[ #holes + 1 ] = CLOSED_HOLE end --barajo la lista... scramble_list() end function scramble_list() log("INPUT LIST: (#holes " .. #holes .. ")") for i = 1, #holes, 1 do log("hole #" .. i .. " = " .. holes[i]) end for i = 1, NUM_PAIRS * 2, 1 do local random_ndx1 = math.random( #holes ) local random_ndx2 = math.random( #holes ) local value_aux = holes[random_ndx1] holes[random_ndx1] = holes[random_ndx2] holes[random_ndx2] = value_aux end log("OUTPUT LIST: ") for i = 1, #holes, 1 do log("hole #" .. i .. " = " .. holes[i]) end end function getHoleActor(_ndx) if holes[_ndx] ~= CLOSED_HOLE then return { name = "topo" .. _ndx, model = "gameParejas/topo.mesh", touchable = false, materials = { topo_material = { g_diffuseTexture = characters[holes[_ndx]], g_diffuseColor = { paramType = E_PARAM_COLOR, paramValue = {1, 1, 1, 1} }, }, } } end end function getLockedActor(_ndx) local uv_offsets_ndx = math.random(#closed_textures_uv) log("<<<....>>>><<<<....>>>><<<.....>>>closed actor: " .. _ndx .. " u: " .. closed_textures_uv[uv_offsets_ndx][1] .. " v: " .. closed_textures_uv[uv_offsets_ndx][2]) if holes[_ndx] == CLOSED_HOLE then return { name = "closed" .. _ndx, model = "gameParejas/tablas.mesh", touchable = false, materials = { tablas = { g_channel1OffsetU = { paramType = E_PARAM_FLOAT, paramValue = closed_textures_uv[uv_offsets_ndx][1] }, g_channel1OffsetV = { paramType = E_PARAM_FLOAT, paramValue = closed_textures_uv[uv_offsets_ndx][2] }, }, } } end end function getSignalActor(_ndx) return { name = "hand".._ndx , model = "gameParejas/hand.mesh", touchable = false} end function isTwoOutAndEqual() return how_many_out == 2 and holes_touched[#holes_touched] ~= holes_touched[#holes_touched - 1] and holes[holes_touched[#holes_touched]] == holes[holes_touched[#holes_touched - 1]] end function isGame2Ended() -- hay dos fuera y son iguales para empezar if(isTwoOutAndEqual()) then -- todos los agujeros o ya han sido completaods, o estan cerrados o son alguno de los dos ultimos for i = 1, #holes, 1 do if( holes[i] == CLEARED_HOLE or holes[i] == CLOSED_HOLE or (holes_touched[#holes_touched] == i or holes_touched[#holes_touched - 1] == i ) ) then --nuthin log("OK for hole " .. i) else return false end end return true else return false end end -------------------------------------- -- Pantalla de instrucciones del juego -------------------------------------- TGame2TutorialHandsIn = TState:new{ m_name = "TGame2TutorialHandsIn", hole1 = 0, hole2 = 0, events = { onBegin = function(_self) local aux = {} local holes_not_closed = {} for i = 1, #holes, 1 do if (holes[i] ~= CLOSED_HOLE) then holes_not_closed[#holes_not_closed + 1] = i end end --aqui estan todos los agujeros que no estan cerrados... elijo uno al azar... _self.hole1 = holes_not_closed[math.random(#holes_not_closed)] _self.hole2 = _self.hole1 --mientras no consiga sacar otro que sea distinto... while(_self.hole1 == _self.hole2) do log("infinito?") _self.hole2 = holes_not_closed[math.random(#holes_not_closed)] end ActivateActor("hand" .. _self.hole1) ActivateActor("hand" .. _self.hole2) --ya tengo los dos, ahora meto las anims return { setAnims = { { actorName = "hand" .. _self.hole1, properties = { anim = "gameParejas/handCicle.anm", loop = false, } }, { actorName = "hand" .. _self.hole2, properties = { anim = "gameParejas/handCicle.anm", loop = false, } }, } } end, onAnimEnded = { default = function(_self) --estado del juego, en espera... DeactivateActor("hand" .. _self.hole1) DeactivateActor("hand" .. _self.hole2) _self.superState.superState:setNextState(TGame2LoopState:new()) end, }, } } TGame2InstructionsOut = TState:new{ m_name = "TGame2InstructionsOut", events = { onBegin = function(_self) return { setAnims = { { actorName = "Instructions", properties = { anim = "gameParejas/tutorialOut.anm", loop = false, } }, } } end, onAnimEnded = { Instructions = function(_self) --estado del juego, en espera... _self.superState.superState:setNextState(TGame2TutorialHandsIn:new()) end, }, onFinish = function(_self) end, } } TGame2InstructionsWait = TState:new{ m_name = "TGame2InstructionsWait", events = { onBegin = function(_self) return { setAnims = { { actorName = "Instructions", properties = { anim = "gameParejas/tutorialCicle.anm", loop = true, } }, } } end, onClick = { button = function(_self) _self.superState:setNextState(TGame2InstructionsOut:new()) end, }, onFinish = function(_self) end, } } TGame2InstructionsIn = TState:new{ m_name = "TGame2InstructionsIn", events = { onBegin = function(_self) log("AGH creo el panel de instruciones") Sound.PlaySound(g_Sound.fx.game2.tutorial) return { actors = { { actorType = "ActorGeom", properties = { name = "Instructions", model = "gameParejas/tutorial.mesh", touchable = true, camera = "game2", layer = LF_PANELS }, }, }, setAnims = { { actorName = "Instructions", properties = { anim = "gameParejas/tutorialIn.anm", loop = false, } }, } } end, onAnimEnded = { Instructions = function(_self) _self:setNextState(TGame2InstructionsWait:new()) end, }, onFinish = function(_self) end, } } --------------------------------------------------- --------------------------------------------------- TGame2CongratulationsState = TState:new{ m_name = "TGame2CongratulationsState", events = { onBegin = function(_self) DeactivateActor("pause") IncrementPointsAndSave(E_LEVEL_GAME2) Sound.PlaySound(g_Sound.fx.game2.congratulations) return { actors = { { actorType = "ActorGeom", properties = { name = "Win", model = "efectos/congratulationcicle.mesh", touchable = false, layer = LF_PANELS+1 }, }, { actorType = "ActorGeom", properties = { name = "CubePart", model = g_cubePartMeshes[2], touchable = false, layer = LF_PANELS + 2, camera = "game1" }, }, }, setAnims = { { actorName = "Win", properties = { anim = "efectos/congratulationcicle.anm", loop = false, } }, { actorName = "CubePart", properties = { anim = g_cubePartAnms[2], loop = false, } }, } } end, onAnimEnded = { Win = function(_self) --local auxState = _self:findParent("TRootState") _self.superState:setNextState(TGame2FadeOutState:new()) end, } } } TGame2GreatState = TState:new{ m_name = "TGame2GreatState", events = { onBegin = function(_self) SaveGameProgress() Sound.PlaySound(g_Sound.fx.game2.great) ActivateActor("hand" .. holes_touched[#holes_touched]) ActivateActor("hand" .. holes_touched[#holes_touched - 1]) return { setAnims = { { actorName = "hand" .. holes_touched[#holes_touched], properties = { anim = "gameParejas/mensajeInGreat.anm", loop = false, } }, { actorName = "hand" .. holes_touched[#holes_touched - 1], properties = { anim = "gameParejas/mensajeInGreat.anm", loop = false, } }, } } end, onAnimEnded = { default = function(_self) DeactivateActor("hand" .. holes_touched[#holes_touched]) DeactivateActor("hand" .. holes_touched[#holes_touched - 1]) local auxState = _self:findParent("TGame2LoopState") auxState:setNextState(auxState) end, } } } TGame2FailState = TState:new{ m_name = "TGame2FailState", events = { onBegin = function(_self) log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FAIL!!!") Sound.PlaySound(g_Sound.fx.game2.wrong) ActivateActor("hand" .. holes_touched[#holes_touched]) ActivateActor("hand" .. holes_touched[#holes_touched - 1]) return { setAnims = { { actorName = "hand" .. holes_touched[#holes_touched], properties = { anim = "gameParejas/mensajeInWrong.anm", loop = false, } }, { actorName = "hand" .. holes_touched[#holes_touched - 1], properties = { anim = "gameParejas/mensajeInWrong.anm", loop = false, } }, } } end, onAnimEnded = { default = function(_self) log("meto todos") DeactivateActor("hand" .. holes_touched[#holes_touched]) DeactivateActor("hand" .. holes_touched[#holes_touched - 1]) _self.superState:setNextState(TGame2TopoIn:new{ m_hole_ndxs = { holes_touched[#holes_touched], holes_touched[#holes_touched - 1], } }:new()) end }, } } ---------------------------------------------------------------------------------------------------- -- Estados de los topos ---------------------------------------------------------------------------------------------------- --evaluo el estado del juego solo si se ha sacado un animalillo del agujero -- dependiendo del estado del juego voy a --no hacer nada si how_many_out no es dos --terminar el juego si ya están todas las parejas --si las dos ultimas elecciones no forman pareja, voy a meter los dos actores TGame2EvalGameState = TState:new{ m_name = "TGame2EvalGameState", events = { onBegin = function(_self) if isGame2Ended() then log("GAME 2 ENDED SUCCESSFULLY!! CONGRATULATIONS") _self:setNextState(TGame2CongratulationsState:new()) elseif (how_many_out < 2) then log("how_many_out < 2") -- me quedo en el estado local auxState = _self:findParent("TGame2LoopState") auxState:setNextState(auxState) elseif (how_many_out == 2) then log("how_many_out == 2") if (isTwoOutAndEqual()) then log("isTwoOutAndEqual()") -- los dos ultimos agujeros tenian el mismo contenido -- estado de great! y sigo holes[ holes_touched[#holes_touched]] = CLEARED_HOLE holes[ holes_touched[#holes_touched - 1]] = CLEARED_HOLE _self:setNextState(TGame2GreatState:new()) --reseteo la cuenta de los que estan fuera how_many_out = 0 else -- los dos ultimos agujeros no tenian el mismo contenido, abajo con todos _self:setNextState(TGame2FailState:new()) end else log("WTF??!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") assert(false) end end, } } -- ciclo TGame2TopoCycle = TState:new{ m_name = "TGame2TopoCycle", m_hole_ndx = 0, events = { onBegin = function(_self) --comprobar si el juego ha terminado _self.superState:setNextState(TGame2EvalGameState:new()) return { setAnims = { { actorName = "topo" .. _self.m_hole_ndx, properties = {anim = "gameParejas/topoCicle.anm", loop = true} } }, } end, }, changeAfterBeginning = true } -- sale fuera TGame2TopoOut = TState:new{ m_name = "TGame2TopoOut", m_hole_ndx = 0, events = { onBegin = function(_self) log("#holes_touched: " .. #holes_touched) if(#holes_touched > 1) then log ("how_many_out: " .. how_many_out .. "holes_touched[ #holes_touched - 1 ]: " .. holes_touched[ #holes_touched - 1 ] .. " ~= _self.m_hole_ndx: " .. _self.m_hole_ndx); end Sound.PlaySound(g_Sound.fx.game2["character" .. holes[_self.m_hole_ndx] .. "Out"]) --no puedo hacer salir dos veces el mismo if #holes_touched == 1 or (#holes_touched > 1 and (how_many_out == 0 or (how_many_out == 1 and holes_touched[ #holes_touched - 1 ] ~= _self.m_hole_ndx ))) then --incremento la cuenta de los que estan fuera how_many_out = how_many_out + 1 --add anim log("setting anim to topo" .. _self.m_hole_ndx) log("topo" .. _self.m_hole_ndx .. " is a " .. holes[_self.m_hole_ndx ]) ActivateActor("topo" .. _self.m_hole_ndx) return { setAnims = { { actorName = "topo" .. _self.m_hole_ndx, properties = {anim = "gameParejas/topoIn.anm", loop = false} }, } } end end, onAnimEnded = { default = function(_self, _nodeName) log("_nodeName: " .. _nodeName .. " == \"topo".._self.m_hole_ndx .. "\"") if (_nodeName == "topo".._self.m_hole_ndx) then _self.superState:setNextState(TGame2TopoCycle:new{m_hole_ndx = _self.m_hole_ndx}:new()) end end, } }, } -- se mete en el agujero TGame2TopoIn = TState:new{ m_name = "TGame2TopoIn", m_hole_ndxs = {}, events = { onBegin = function(_self) --quiero que siga el juego despues de esto... local aux = {} for i = 1, #_self.m_hole_ndxs, 1 do --decremento la cuenta de los que estan fuera... Sound.PlaySound(g_Sound.fx.game2["character" .. holes[_self.m_hole_ndxs[i]] .. "In"]) how_many_out = how_many_out - 1 ClearActorAnims("topo" .. _self.m_hole_ndxs[i], true, true) aux[#aux + 1] = { actorName = "topo" .. _self.m_hole_ndxs[i], properties = {anim = "gameParejas/topoOut.anm", loop = false}} end return { setAnims = aux } end, onAnimEnded = { default = function(_self) local auxState = _self:findParent("TGame2LoopState") auxState:setNextState(auxState) end } }, } ------------------------------------------------ -- bucle del juego ------------------------------------------------ TGame2LoopState = TState:new{ m_name = "TGame2LoopState", proccessTouch = function(_self,_ndx) log(" !!!!TOPO OUT") log("_ndx: " .. _ndx) log("how_many_out: " .. how_many_out) if ( ( how_many_out == 0 or (how_many_out == 1 and holes_touched[#holes_touched] ~= _ndx) ) and holes[_ndx] ~= CLOSED_HOLE and holes[_ndx] ~= CLEARED_HOLE) then log(" !!!!TOPO OUT") --si no esta cerrado ni forma parte de una pareja resuelta... holes_touched[#holes_touched + 1] = _ndx _self:setNextState(TGame2TopoOut:new{ m_hole_ndx = _ndx }:new()) else log(" !!!!NO HAGO NADAAAAAA") --no hago nada _self:setNextState(_self) end end, events = { onBegin = function(_self) _self:setNextState(_self) if IsMrHatLite then return {} else return { actors = {{ actorType = "ActorGeom", properties = { name = "pause", model = "menuPause/pauseButton.mesh", touchable = true, camera = "game1", layer = LF_PANELS+3 }, },} } end end, onClick = { button1 = function(_self) _self:proccessTouch(1) end, button2 = function(_self) _self:proccessTouch(2) end, button3 = function(_self) _self:proccessTouch(3) end, button4 = function(_self) _self:proccessTouch(4) end, button5 = function(_self) _self:proccessTouch(5) end, button6 = function(_self) _self:proccessTouch(6) end, button7 = function(_self) _self:proccessTouch(7) end, button8 = function(_self) _self:proccessTouch(8) end, button9 = function(_self) _self:proccessTouch(9) end, button10 = function(_self) _self:proccessTouch(10) end, button11 = function(_self) _self:proccessTouch(11) end, button12 = function(_self) _self:proccessTouch(12) end, ['currentMenuScreen:back()'] = function(_self) pause() end, } } } TGame2InitialSetup = TState:new{ m_name = "TGame2InitialSetup", events = { onBegin = function(_self) for i = 1, NUM_PAIRS*2, 1 do DeactivateActor("hand" .. i) end _self:setNextState(TGame2InstructionsIn:new()) end } } TGame2FadeInState = TState:new{ m_name = "TGame2FadeInState", m_bLoad = false, events = { onBegin = function(_self) Game2Started() loadFxsGame2() Sound.PlayMusic(g_Sound.music.game2Theme) g_currentGame = E_LEVEL_GAME2 random_and_setup_game2() _self:setNextState(TGame2InitialSetup:new()) local aux = { { actorName = "Fade", properties = { anim = "fadeblackout.anm", loop = false},} } for i = 1, NUM_PAIRS * 2, 1 do aux[#aux + 1] = { actorName = "topo" .. i, properties = { anim = "gameParejas/topoHide.anm", loop = false, } } end SaveGameProgress() return { actors = { { actorType = "ActorGeom", properties = { name = "Scene1", model = "gameParejas/pareja1.mesh", touchable = true}, }, { actorType = "ActorGeom", properties = { name = "Scene2", model = "gameParejas/pareja2.mesh", touchable = true}, }, { actorType = "ActorGeom", properties = { name = "Scene3", model = "gameParejas/pareja3.mesh", touchable = true}, }, { actorType = "ActorGeom", properties = { name = "Scene4", model = "gameParejas/pareja4.mesh", touchable = true}, }, { actorType = "ActorGeom", properties = { name = "Scene5", model = "gameParejas/pareja5.mesh", touchable = true}, }, { actorType = "ActorGeom", properties = { name = "Scene6", model = "gameParejas/pareja6.mesh", touchable = true}, }, { actorType = "ActorGeom", properties = { name = "Scene7", model = "gameParejas/pareja7.mesh", touchable = true}, }, { actorType = "ActorGeom", properties = { name = "Scene8", model = "gameParejas/pareja8.mesh", touchable = false}, }, { actorType = "ActorGeom", properties = { name = "Scene9", model = "gameParejas/pareja9.mesh", touchable = false}, }, { actorType = "ActorGeom", properties = { name = "Fade", model = "fadeblack.mesh", touchable = false, layer = LF_PANELS+4}, }, }, setAnims = aux, } end, onFinish = function() Sound.StopMusic(g_Sound.music.game2Theme) releaseFxSoundResources(g_Sound.fx.game2) end }, changeAfterBeginning = true } TGame2IntroState = TState:new{ m_name = "TGame2IntroState", events = { onBegin = function(_self) ChangeCamera("game2") OpenVideoURL(g_Video.game2.intro, "g_currentState:finish()") _self:setNextState(_self) end, onFinish = function(_self) local auxState = _self:findParent("TRootState") auxState:setNextState(TGame2FadeInState:new()) end } } TGame2EndingState = TState:new{ m_name = "TGame2EndingState", events = { onBegin = function(_self) if(not IsMrHatLite) then OpenVideoURL(g_Video.game2.ending, "g_currentState:finish()") _self:setNextState(_self) end end, onFinish = function(_self) local auxState = _self:findParent("TRootState") if(not IsMrHatLite) then auxState:setNextState(TMainMenuFadeIn:new{ m_givePrizeOnGame = E_LEVEL_GAME2 }:new()) else auxState:setNextState(TBuyFullVersionState:new()) end end } } TGame2FadeOutState = TState:new{ m_name = "TGame2FadeOutState", 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(TGame2EndingState:new()) end, }, } }