NUM_NUMBERS = 3 log_aux = "" number_intervals = {} number_intervals[E_LEVEL_EASY] = { from = 2, to = 6} number_intervals[E_LEVEL_NORMAL] = { from = 2, to = 9} number_intervals[E_LEVEL_HARD] = { from = 2, to = 9} solution_textures_ndx = {} game3_object_textures ={ "cerdo.pvr", "sombrero.pvr", "oveja.pvr", "pelota.pvr", "rana.pvr", "cangrejo.pvr", "manzana.pvr", "fantasma.pvr", "cubo.pvr", } basic_colours4 = { {{0.755, 0.0, 0.0, 1.0},{0.098, 0.106, 0.11, 1.0}}, {{0.0, 0.824, 0.102, 1.0},{0.098, 0.106, 0.11, 1.0}}, {{0.0, 0.0, 0.82, 1.0},{0.098, 0.106, 0.11, 1.0}}, {{0.986, 0.971, 0.0, 1.0},{0.098, 0.106, 0.11, 1.0}}, } function getObjectActor(_ndx) return { name = "countable" .. _ndx, model = "gameParejas/topo.mesh", touchable = false, materials = { topo_material = { g_diffuseTexture = game3_object_textures[object_instanced_tex[_ndx]], g_diffuseColor = { paramType = E_PARAM_COLOR, paramValue = {1, 1, 1, 1} }, }, } } end function number(_ndx) assert(numbers_drawed[_ndx] >= 2 and numbers_drawed[_ndx] <= 9 ) local color_ndx = math.mod(_ndx,#basic_colours4) + 1 --SetEffectParamColor("number" .. _ndx, "numeros","g_matDiffuse", hole_colours[i][1]) return { name = "number" .. _ndx, model = "gameNumeros/" .. numbers_drawed[_ndx] .. ".mesh", touchable = false, materials = { numeros = { g_matDiffuse = { paramType = E_PARAM_COLOR, paramValue = basic_colours4[color_ndx][1] }, g_ambientColor = { paramType = E_PARAM_COLOR, paramValue = basic_colours4[color_ndx][2] }, }, } } end function isGame3Ended () return g_timesCompleted >= NUM_NUMBERS end function list_contains( list, _item ) log("list_contains buscando " .. _item) for i = 1, #list, 1 do log("#" .. i .. ": " .. list[i] .. " == " .. _item) if list[i] == _item then return true end end return false end function random_sequence(_repeating , _count, _m, _n) local solution = {} local drawed = {} while #solution < _count do log("" .. #solution .. " < " .. _count) log("math.random(" .. _m .. "," .. _n .. ")") 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 --assert(false) end return solution end function random_and_setup_game3() g_difficulty_game3 = getDifficulty(E_LEVEL_GAME3) if number_intervals[ g_difficulty_game3 ] == nil then log("!!!!!!!!!!!!!!!!!!!number_intervals[ g_difficulty_game3 ] == nil") end local from = number_intervals[ g_difficulty_game3 ].from local to = number_intervals[ g_difficulty_game3 ].to --extraigo 3 numeros en los limites de la secuencia... log("extraigo 3 numeros en los limites de la secuencia... random_sequence(false,".. NUM_NUMBERS .. ", " .. from .. ", " .. to .. ")") numbers_drawed = random_sequence(false, NUM_NUMBERS, from, to) -- de esos tres este es el bueno: numbers_drawed_ndxs[solution_number] log("de esos tres este es el bueno: numbers_drawed_ndxs[solution_number]") solution_number = math.random(NUM_NUMBERS) if(solution_textures_ndx == nil) then solution_textures_ndx = random_sequence(false, #game3_object_textures, 1, #game3_object_textures) end --el tipo de objeto que voy a extraer como solucion... lo puedo asociar log("el tipo de objeto que voy a extraer como solucion... lo puedo asociar") --solution_texture = math.random(#game3_object_textures)--extraigo el tipo del objeto que voy a extraer... solution_texture = solution_textures_ndx[g_timesCompleted + 1] --objetos que hay que contar... -- si es facil o medio, todos los objetos son iguales. --si es dificil relleno hasta 9 siempre con objetos random que no sean object_instanced_tex = {} for i = 1, numbers_drawed[solution_number], 1 do object_instanced_tex[#object_instanced_tex + 1] = solution_texture end if g_difficulty_game3 == E_LEVEL_HARD then log_aux = "(" --entonces aņado los que me quedan en random, distintos de la textura de la solucion... for i = numbers_drawed[solution_number], 9, 1 do local aux = math.random(#game3_object_textures) while solution_texture == aux do aux = math.random(#game3_object_textures) end object_instanced_tex[#object_instanced_tex + 1] = aux log_aux = " " .. game3_object_textures[aux] .. "," end log_aux = log_aux .. ")" end end --------------------------------------------------- --Great, Congratulations and Fail --------------------------------------------------- TGame3CongratulationsState = TState:new{ m_name = "TGame3CongratulationsState", events = { onBegin = function(_self) DeactivateActor("pause") --local auxState = _self:findParent("TRootState") --auxState:setNextState(TMainMenuFadeIn:new()) IncrementPointsAndSave(E_LEVEL_GAME3) Sound.PlaySound(g_Sound.fx.game3.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[3], touchable = false, layer = LF_PANELS + 2, camera = "game1" }, }, }, setAnims = { { actorName = "Win", properties = { anim = "efectos/congratulationcicle.anm", loop = false, } }, { actorName = "CubePart", properties = { anim = g_cubePartAnms[3], loop = false, } }, } } end, onAnimEnded = { Win = function(_self) local auxState = _self:findParent("TRootState") auxState:setNextState(TGame3FadeOutState:new()) end, } } } TGame3GreatState = TState:new{ m_name = "TGame3GreatState", events = { onBegin = function(_self) DeactivateActor("pause") Sound.PlaySound(g_Sound.fx.game3.great) return { actors = { { actorType = "ActorGeom", properties = { name = "Win", model = "efectos/great.mesh", touchable = false, layer = LF_PANELS }, }, }, setAnims = { { actorName = "Win", properties = { anim = "efectos/greatCicle.anm", loop = false, } }, } } end, onAnimEnded = { Win = function(_self) local auxState = _self:findParent("TGame3LoadObject") auxState.superState:setNextState(TGame3LoadObject:new()) end, } } } TGame3FailState = TState:new{ m_name = "TGame3FailState", events = { onBegin = function(_self) log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FAIL!!!") Sound.PlaySound(g_Sound.fx.game3.wrong) DeactivateActor("pause") return { actors = { { actorType = "ActorGeom", properties = { name = "Fail", model = "efectos/wrong.mesh", touchable = false, layer = LF_PANELS }, }, }, setAnims = { { actorName = "Fail", properties = { anim = "efectos/wrongIn.anm", loop = false, } }, } } end, onAnimEnded = { Fail = function(_self) ActivateActor("pause") log("meto todos") local auxState = _self:findParent("TGame3LoopState") auxState:setNextState(auxState) end }, } } -------------------------------------------- --Entrada, ciclo, salida de los numeritos -------------------------------------------- TGame3AllInstancesFadeIn = TState:new{ m_name = "TGame3AllInstancesFadeIn", events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game3.objectToCountIn) local aux = 9 if (g_difficulty_game3 ~= E_LEVEL_HARD) then aux = numbers_drawed[solution_number] end return { actors = { { actorType = "ActorGeom", properties = { name = "ToCountInstances", model = "gameNumeros/objetos.mesh", touchable = false, layer = LF_WORLD + 1 }, }, { actorType = "ActorGeom", properties = { name = "NumberInstances", model = "gameNumeros/numeros.mesh", touchable = false, layer = LF_WORLD + 1 }, }, { actorType = "ActorGeom", properties = { name = "Buttons", model = "gameNumeros/numerostouch.mesh", touchable = true, }, }, }, setAnims = { { actorName = "ToCountInstances", properties = { anim = "gameNumeros/objetos" .. aux .. "In.anm", loop = false, } }, { actorName = "NumberInstances", properties = { anim = "gameNumeros/numerosIn.anm", loop = false, } }, }, } end, onAnimEnded = { ToCountInstances = function(_self) _self:setNextState(TGame3AllInstancesWait:new()) end } }, } TGame3AllInstancesWait = TState:new{ m_name = "TGame3AllInstancesWait", events = { onBegin = function(_self) local aux = 9 if (g_difficulty_game3 ~= E_LEVEL_HARD) then aux = numbers_drawed[solution_number] end _self:setNextState(TGame3LoopState:new()) return { setAnims = { { actorName = "ToCountInstances", properties = { anim = "gameNumeros/objetos" .. aux .. "Cicle.anm", loop = true, } }, { actorName = "NumberInstances", properties = { anim = "gameNumeros/numerosCicle.anm", loop = true, } }, }, } end, }, changeAfterBeginning = true, } TGame3AllInstancesFadeOut = TState:new{ m_name = "TGame3AllInstancesFadeOut", events = { onBegin = function(_self) local aux = 9 if (g_difficulty_game3 ~= E_LEVEL_HARD) then aux = numbers_drawed[solution_number] end return { setAnims = { { actorName = "ToCountInstances", properties = { anim = "gameNumeros/objetos" .. aux .. "Out.anm", loop = false, } }, { actorName = "NumberInstances", properties = { anim = "gameNumeros/numerosOut.anm", loop = false, } }, }, } end, onAnimEnded = { ToCountInstances = function(_self) --otra ronda! local aux = _self:findParent("TGame3LoadObject") aux.superState:setNextState(TGame3LoadObject:new()) end } }, } -------------------------------------- -- Objeto representando a la palabra que sea... -------------------------------------- TGame3LoadObject = TState:new{ m_name = "TGame3LoadObject", events = { onBegin = function(_self) random_and_setup_game3() log("!!-- Hay que contar hasta " .. numbers_drawed[solution_number] .. " (textura " .. game3_object_textures[solution_texture] .. ")") if g_difficulty_game3 == E_LEVEL_HARD then log("!!-- Objetos adicionales:" .. log_aux) end _self:setNextState(TGame3LoadObjectTextureAndAnim:new()) return { actors = { { actorType = "ActorGeom", properties = { name = "to_count_object", model = "gameNumeros/objeto.mesh", touchable = false, layer = LF_PANELS }, } }, setAnims = {}, } end, }, changeAfterBeginning = true } TGame3LoadObjectTextureAndAnim = TState:new{ m_name = "TGame3LoadObjectTextureAndAnim", events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game3.objectIn) SetEffectParamTexture("to_count_object", "objeto", "g_diffuseTexture", game3_object_textures[solution_texture]) return { setAnims = { { actorName = "to_count_object", properties = { anim = "gameNumeros/objetoIn.anm", loop = false, } } } } end, onAnimEnded = { default = function(_self) _self:setNextState(TGame3ObjectCycle:new()) end } }, } TGame3ObjectCycle = TState:new{ m_name = "TGame3ObjectCycle", events = { onBegin = function(_self) return { actors = { { actorType = "ActorGeom", properties = { name = "Button", model = "gameNumeros/button.mesh", touchable = true, layer = LF_PANELS }, } }, setAnims = { { actorName = "to_count_object", properties = { anim = "gameNumeros/objetoCicle.anm", loop = true, } }, } } end, onClick = { button = function(_self) _self:setNextState(TGame3ObjectOut:new()) end } }, } TGame3ObjectOut = TState:new{ m_name = "TGame3ObjectOut", events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game3.objectOut) DeactivateActor("Button") ClearActorAnims("to_count_object", true, true) return { setAnims = { { actorName = "to_count_object", properties = { anim = "gameNumeros/objetoout.anm", loop = false, } }, } } end, onAnimEnded = { default = function(_self) _self:setNextState(TGame3AllInstancesFadeIn:new()) end } }, } -------------------------------------- -- Pantalla de instrucciones del juego -------------------------------------- TGame3InstructionsOut = TState:new{ m_name = "TGame3InstructionsOut", events = { onBegin = function(_self) return { setAnims = { { actorName = "Instructions", properties = { anim = "gameNumeros/tutorialOut.anm", loop = false, } }, } } end, onAnimEnded = { Instructions = function(_self) --estado del juego, en espera... ActivateActor("pause") _self.superState.superState:setNextState(TGame3LoadObject:new()) end, }, onFinish = function(_self) end, } } TGame3InstructionsWait = TState:new{ m_name = "TGame3InstructionsWait", events = { onBegin = function(_self) return { setAnims = { { actorName = "Instructions", properties = { anim = "gameNumeros/tutorialCicle.anm", loop = true, } }, } } end, onClick = { button = function(_self) _self.superState:setNextState(TGame3InstructionsOut:new()) end, }, onFinish = function(_self) end, } } TGame3InstructionsIn = TState:new{ m_name = "TGame3InstructionsIn", events = { onBegin = function(_self) log("AGH creo el panel de instruciones") Sound.PlaySound(g_Sound.fx.game3.tutorial) return { actors = { { actorType = "ActorGeom", properties = { name = "Instructions", model = "gameNumeros/tutorial.mesh", touchable = true, camera = "game3", layer = LF_PANELS }, }, }, setAnims = { { actorName = "Instructions", properties = { anim = "gameNumeros/tutorialIn.anm", loop = false, } }, } } end, onAnimEnded = { Instructions = function(_self) _self:setNextState(TGame3InstructionsWait:new()) end, }, onFinish = function(_self) end, } } --------------------------------------------------- TGame3LoopState = TState:new{ m_name = "TGame3LoopState", proccessTouch = function(_self,_ndx) if _ndx == solution_number then Sound.PlaySound(g_Sound.fx.game3["number" .. numbers_drawed[_ndx]]) g_timesCompleted = g_timesCompleted + 1 if isGame3Ended() then _self:setNextState(TGame3CongratulationsState:new()) else _self:setNextState(TGame3GreatState:new()) end else --fail! _self:setNextState(TGame3FailState:new()) 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, ['currentMenuScreen:back()'] = function(_self) pause() end, } } } TGame3InitialSetup = TState:new{ m_name = "TGame3InitialSetup", events = { onBegin = function(_self) _self:setNextState(TGame3InstructionsIn:new()) end } } TGame3CycleAfterFadeInState = TState:new{ m_name = "TGame3CycleAfterFadeInState", events = { onBegin = function(_self) _self:setNextState(TGame3InitialSetup:new()) return { setAnims = { { actorName = "Background", properties = { anim = "gameNumeros/numerosBgCicle.anm", loop = true, } }, }, } end, }, changeAfterBeginning = true } TGame3FadeInState = TState:new{ m_name = "TGame3FadeInState", m_bLoad = false, events = { onBegin = function(_self) Game3Started() loadFxsGame3() Sound.PlayMusic(g_Sound.music.game3Theme) log("random start") if not _self.m_bLoad then g_timesCompleted = 0 end g_currentGame = E_LEVEL_GAME3 solution_textures_ndx = nil random_and_setup_game3() log("random ended") _self:setNextState(TGame3CycleAfterFadeInState:new()) SaveGameProgress() return { actors = { { actorType = "ActorGeom", properties = { name = "Background", model = "gameNumeros/numerosbg.mesh", touchable = true}, }, { actorType = "ActorGeom", properties = { name = "Fade", model = "fadeblack.mesh", touchable = true, layer = LF_PANELS + 4}, }, }, setAnims = { { actorName = "Fade", properties = { anim = "fadeblackout.anm", loop = false}, }, } } end, onFinish = function() Sound.StopMusic(g_Sound.music.game3Theme) releaseFxSoundResources(g_Sound.fx.game3) end }, changeAfterBeginning = true } TGame3IntroState = TState:new{ m_name = "TGame3IntroState", events = { onBegin = function(_self) ChangeCamera("game3") OpenVideoURL(g_Video.game3.intro, "g_currentState:finish()") _self:setNextState(_self) end, onFinish = function(_self) local auxState = _self:findParent("TRootState") auxState:setNextState(TGame3FadeInState:new()) end } } TGame3EndingState = TState:new{ m_name = "TGame3EndingState", events = { onBegin = function(_self) if(not IsMrHatLite) then OpenVideoURL(g_Video.game3.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_GAME3 }:new()) else auxState:setNextState(TBuyFullVersionState:new()) end end } } TGame3FadeOutState = TState:new{ m_name = "TGame3FadeOutState", 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(TGame3EndingState:new()) end, }, } }