-------------------------------------- --Datos -------------------------------------- NUM_WORDS = 3 --resetear a estos valores cada vez que se carga la escena de entrada de las letras... (meter en el begin del estado, no?) words_drawed = {} words_drawed_ndx = {} single_letters = {nil,nil,nil} g_dic_complete ={ {"dog", "pig", "hat", "pen", "cow", "bag", "fox", "cup",}, {"bed", "sheep", "owl", "bell", "tent", "ball", "tree", "frog", "crab", "fish", "flag",}, {"mouse", "apple", "plane", "sheep", "zebra", "shell", "cake", "plate", "snake",}, } g_dic_sounds ={ { g_Sound.fx.words.easy.dog, g_Sound.fx.words.easy.pig, g_Sound.fx.words.easy.hat, g_Sound.fx.words.easy.pen, g_Sound.fx.words.normal.cow, g_Sound.fx.words.easy.bag, g_Sound.fx.words.easy.fox, g_Sound.fx.words.easy.cup,}, { g_Sound.fx.words.easy.bed, g_Sound.fx.words.normal.sheep, g_Sound.fx.words.normal.owl, g_Sound.fx.words.normal.bell, g_Sound.fx.words.normal.tent, g_Sound.fx.words.normal.ball, g_Sound.fx.words.normal.tree, g_Sound.fx.words.normal.frog, g_Sound.fx.words.normal.crab, g_Sound.fx.words.normal.fish, g_Sound.fx.words.normal.flag,}, { g_Sound.fx.words.hard.mouse, g_Sound.fx.words.hard.apple, g_Sound.fx.words.hard.plane, g_Sound.fx.words.hard.sheep, g_Sound.fx.words.hard.zebra, g_Sound.fx.words.hard.shell, g_Sound.fx.words.hard.cake, g_Sound.fx.words.hard.plate, g_Sound.fx.words.hard.snake,}, } g_dic_textures ={ {"perro.pvr", "cerdo.pvr", "sombrero.pvr", "boligrafo.pvr", "vaca.pvr", "bolso.pvr", "zorro.pvr", "vaso.pvr",}, {"cama.pvr", "oveja.pvr", "buho.pvr", "campana.pvr", "tienda.pvr", "pelota.pvr", "arbol.pvr", "rana.pvr", "cangrejo.pvr", "pez.pvr", "bandera.pvr",}, {"raton.pvr", "manzana.pvr", "avion.pvr", "oveja.pvr", "cebra.pvr", "concha.pvr", "tarta.pvr", "plato.pvr", "serpiente.pvr",}, } g_dic ={ {"d g", "p g", "h t", "p n", "c w", "b g", "f x", "c p"}, {"b d", "sh p", " wl", "b ll", "t nt", "b ll", "tr ", "fr g", "cr b", "f sh", "fl g"}, {"m s ", " ppl ", "pl n ", "sh p", "z br ", "sh ll", "c k ", "pl t ", "sn k "}, } g_timesCompleted = 0 g_lastButtonClicked = nil basic_colours = { {{0.755, 0.0, 0.0, 1.0},{0.2, 0.2, 0.2, 1.0}}, {{0.0, 0.824, 0.102, 1.0},{0.2, 0.2, 0.2, 1.0}}, {{0.0, 0.0, 0.82, 1.0},{0.2, 0.2, 0.2, 1.0}}, {{0.986, 0.971, 0.0, 1.0},{0.2, 0.2, 0.2, 1.0}}, {{0.0, 0.971, 0.986, 1.0},{0.2, 0.2, 0.2, 1.0}}, } basic_colours2 = { {{0.755, 0.0, 0.0, 1.0},{0.2, 0.2, 0.2, 1.0}}, {{0.0, 0.824, 0.102, 1.0},{0.2, 0.2, 0.2, 1.0}}, {{0.0, 0.0, 0.82, 1.0},{0.2, 0.2, 0.2, 1.0}}, {{0.986, 0.971, 0.0, 1.0},{0.2, 0.2, 0.2, 1.0}}, {{0.0, 0.971, 0.986, 1.0},{0.2, 0.2, 0.2, 1.0}}, } function sortSingleLetterColours() --colores asignados local assigned = {false,false,false,false,false} local word = g_dic_complete[g_difficulty_game1][g_word_ndx] log("sortSingleLetterColours, word:" .. word) basic_colours2 = {nil,nil,nil} log("buscando colores para las letras") for i = 1, #single_letters, 1 do local letra = single_letters[i] log("sortSingleLetterColours, letra: " .. letra) --local found = false for j = 1, string.len(word), 1 do log("comprobando letra:" .. string.sub(word, j, j)) if(letra == string.sub(word, j, j)) then local color_ndx = math.mod(g_word_ndx+j,#basic_colours) + 1 basic_colours2[i] = basic_colours[color_ndx] assigned[color_ndx] = true log("#######Assigned " .. color_ndx) --found = true --log("salgo") break end end --if(found) then break end end local letra = 1 log("buscando colores para el resto de letras") for letra = 1, 3, 1 do log("letra " .. letra) if(basic_colours2[letra] == nil) then log("falta la letra " .. letra) --a esta letra no le ha sido asignado un color for i = 1, #basic_colours, 1 do if( assigned[i] == false ) then basic_colours2[letra] = basic_colours[i] assigned[i] = true break end end end end end function generateWord() --inicialmente local repeated used_colours = {} repeat g_word_ndx = math.random(#g_dic_complete[g_difficulty_game1]) g_currentWord = g_dic[g_difficulty_game1][g_word_ndx] repeated = false log("\\\\\\\\\\\\\\\\\GENERADA la palabra " .. g_dic_complete[g_difficulty_game1][g_word_ndx]) log( "Extraidas " .. #words_drawed) --compruebo si esta repetida la palabra... for i = 1, #words_drawed, 1 do log(g_dic_complete[g_difficulty_game1][g_word_ndx] .. " es distinta de " .. words_drawed[i] .. "??") if(words_drawed[i] == g_dic_complete[g_difficulty_game1][g_word_ndx]) then repeated = true log("REPETIDA!!!!!!!!!!!!!!!!!!! ") break end end until (not repeated) --la guardo words_drawed[#words_drawed + 1] = g_dic_complete[g_difficulty_game1][g_word_ndx] words_drawed_ndx[#words_drawed_ndx + 1] = g_word_ndx end function drawGoodLetterOptions() drawLetterOptions() while not isOkForLetters() do drawLetterOptions() end end function drawLetterOptions() local possible = "aeiou" log("!!!!!!!!!!!!!!!!!!!!me quedan: " .. possible) for i = 1, 3, 1 do local random_n = math.random(string.len(possible)) log("random_n: " .. random_n) local letter = string.sub(possible, random_n, random_n) log("letter: " .. letter) local aux = "" --actualizo la cadena con las letras que quedan if(random_n > 1) then aux = string.sub(possible, 1, random_n - 1) log("remaining head: " .. aux) end if(random_n < string.len(possible)) then aux = aux .. string.sub(possible, random_n + 1, string.len(possible)) log("remaining complete: " .. aux) end possible = aux log("me quedan: " .. possible) single_letters[i] = letter end end function wordLetters( _ndx ) local word = g_dic_complete[g_difficulty_game1][g_word_ndx] local color_ndx = math.mod(g_word_ndx+_ndx,#basic_colours) + 1 log("\n\nwordLetters( " .. _ndx .. " ) letra:" .. string.sub(word,_ndx,_ndx) .. " color_ndx: " .. color_ndx) return { name = "word" .. _ndx, model = "gameletras/" .. string.sub(word,_ndx,_ndx) .. ".mesh", touchable = false, layer = LF_PANELS, camera = "game1palabra", materials = { numeros = { g_matDiffuse = { paramType = E_PARAM_COLOR, paramValue = basic_colours[color_ndx][1] }, g_ambientColor = { paramType = E_PARAM_COLOR, paramValue = basic_colours[color_ndx][2] }, g_matSpecular = { paramType = E_PARAM_COLOR, paramValue = {0.0,0.0,0.0,1.0} }, }, } } end function hideLetters() --log hiddingleteters for i=1, string.len(g_currentWord),1 do if string.sub(g_dic[g_difficulty_game1][g_word_ndx], i, i) == " " then DeactivateActor("word" .. i) end end end function singleLetters( _ndx ) --Todo que siempre haya --find single letter in word to get the same colour log("\n\nsingleLetters( " .. _ndx .. " ), color_ndx = " .. _ndx) -- have a random then, get a e i o u deppending on this... log("\n\nsingleLetters[" .. _ndx .. "] = " .. single_letters[_ndx]) return { name = "single" .. _ndx, model = "gameletras/" .. single_letters[_ndx] .. ".mesh", touchable = true, camera = "game1letras", materials = { numeros = { g_matDiffuse = { paramType = E_PARAM_COLOR, paramValue = basic_colours2[_ndx][1] }, g_ambientColor = { paramType = E_PARAM_COLOR, paramValue = basic_colours2[_ndx][2] }, g_matSpecular = { paramType = E_PARAM_COLOR, paramValue = {0.0,0.0,0.0,1.0} }, }, } } --return { name = "single" .. _ndx, model = "gameletras/a.mesh", touchable = true, camera = "game1" } end function isOkForLetters() log("asking isOkForLetters()?") for i = 1, #single_letters, 1 do log ("find " .. single_letters[i] .." in " .. g_dic_complete[g_difficulty_game1][g_word_ndx]) local aux = string.find(g_dic_complete[g_difficulty_game1][g_word_ndx], single_letters[i], 1, true) if ( aux ~= nil) then log("" .. aux .. " ~= nil") log("g_currentWord: " .. g_currentWord) aux = string.find(g_currentWord, single_letters[i], 1, true) if (aux == nil) then log("nil == nil") log("FOUND!") return true end end end log("NOT FOUND!") return false end function isGame1Ended () return g_timesCompleted >= NUM_WORDS end function isWordCompleted() log( " isWordCompleted()" .. g_currentWord .. " == " .. g_dic_complete[g_difficulty_game1][g_word_ndx]) return g_currentWord == g_dic_complete[g_difficulty_game1][g_word_ndx] end function substChar(str, _ndx, char) log("SUBSTCHAR") log("substChar(" .. str .. "," .. _ndx .. "," .. char .. ")") local aux = str local res = "" if(_ndx - 1 >= 1) then res = string.sub(aux, 1, _ndx - 1) end res = res .. char if(_ndx + 1 <= string.len(aux)) then res = res .. string.sub(aux, _ndx + 1, string.len(aux)) end log("res: " .. res) return res end function checkLetters( _ndx) local letra = single_letters[_ndx] log("checking clicked on: " .. letra) local letras = {} for i=1, string.len(g_currentWord), 1 do log("checking letter #" .. i .. " - " .. string.sub(g_currentWord,i,i)) log("string.sub(" .. g_currentWord .. "," .. i .. "," .. i ..") == \" \" ") log("checking " ..string.sub(g_dic_complete[g_difficulty_game1][g_word_ndx], i, i) .. " == " .. letra .. " ?") if(string.sub(g_currentWord,i,i) == " " and string.sub(g_dic_complete[g_difficulty_game1][g_word_ndx], i, i) == letra) then log("yes! adding " .. i .. " to letters") g_currentWord = substChar(g_currentWord, i, letra) letras[#letras + 1] = i else log("no!") end end -- devuelvo los indices de las letras que he ido poniendo... para poner una animacion y hacerlas visibles en otro estado más tarde... return letras end -------------------------------------- --Estados -------------------------------------- TGame1IntroState = TState:new{ m_name = "TGame1IntroState", events = { onBegin = function(_self) ChangeCamera("game1") OpenVideoURL(g_Video.game1.intro, "g_currentState:finish()") _self:setNextState(_self) end, onFinish = function(_self) local auxState = _self:findParent("TRootState") auxState:setNextState(TGame1FadeInState:new()) end } } TGame1EndingState = TState:new{ m_name = "TGame1EndingState", events = { onBegin = function(_self) if(not IsMrHatLite) then OpenVideoURL(g_Video.game1.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_GAME1 }:new()) else auxState:setNextState(TBuyFullVersionState:new()) end end } } -------------------------------------- -- Pantalla de instrucciones del juego -------------------------------------- TGame1InstructionsOut = TState:new{ m_name = "TGame1InstructionsOut", events = { onBegin = function(_self) return { setAnims = { { actorName = "Instructions", properties = { anim = "gameletras/tutorialOut.anm", loop = false, } }, } } end, onAnimEnded = { Instructions = function(_self) --estado del juego, en espera... _self.superState.superState:setNextState(TGame1LoadObject:new()) end, }, onFinish = function(_self) end, } } TGame1InstructionsWait = TState:new{ m_name = "TGame1InstructionsWait", events = { onBegin = function(_self) return { setAnims = { { actorName = "Instructions", properties = { anim = "gameletras/tutorialCicle.anm", loop = true, } }, } } end, onClick = { button = function(_self) _self.superState:setNextState(TGame1InstructionsOut:new()) end, }, onFinish = function(_self) end, } } TGame1InstructionsIn = TState:new{ m_name = "TGame1InstructionsIn", events = { onBegin = function(_self) log("AGH creo el panel de instruciones") Sound.PlaySound(g_Sound.fx.game1.tutorial) return { actors = { { actorType = "ActorGeom", properties = { name = "Instructions", model = "gameletras/tutorial.mesh", touchable = true, camera = "game1", layer = LF_PANELS }, }, }, setAnims = { { actorName = "Instructions", properties = { anim = "gameletras/tutorialIn.anm", loop = false, } }, } } end, onAnimEnded = { Instructions = function(_self) _self:setNextState(TGame1InstructionsWait:new()) end, }, onFinish = function(_self) end, } } -------------------------------------- -- Objeto representando a la palabra que sea... -------------------------------------- TGame1LoadObject = TState:new{ m_name = "TGame1LoadObject", events = { onBegin = function(_self) generateWord() log("comienza el juego con la palabra '" .. g_currentWord .. "' que hay que rellenar hasta " .. g_dic_complete[g_difficulty_game1][g_word_ndx] ) SetEffectParamFloat("Huecos", "MenuTriangulo", "g_channel1OffsetV", uvoffset[string.len(g_dic_complete[g_difficulty_game1][g_word_ndx]) - 2][2]) _self:setNextState(TGame1LoadObjectTextureAndAnim:new()) return { actors = { { actorType = "ActorGeom", properties = { name = "Word_object", model = "gameletras/objeto.mesh", touchable = true, layer = LF_PANELS }, } }, setAnims = {}, } end, }, changeAfterBeginning = true } TGame1LoadObjectTextureAndAnim = TState:new{ m_name = "TGame1LoadObjectTextureAndAnim", events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game1.objectIn) SetEffectParamTexture("Word_object", "objeto", "g_diffuseTexture", g_dic_textures[g_difficulty_game1][g_word_ndx]) return { setAnims = { { actorName = "Word_object", properties = { anim = "gameletras/objetoIn.anm", loop = false, } } } } end, onAnimEnded = { default = function(_self) _self:setNextState(TGame1ObjectCycle:new()) end } }, } TGame1ObjectCycle = TState:new{ m_name = "TGame1ObjectCycle", events = { onBegin = function(_self) if g_SoundAux ~= nil then Sound.ReleaseSound(g_SoundAux) end g_SoundAux = Sound.LoadSound(g_dic_sounds[g_difficulty_game1][g_word_ndx]) Sound.PlaySound(g_SoundAux) return { actors = { --{ actorType = "ActorGeom", -- properties = { name = "Button", model = "gameletras/button.mesh", touchable = true, layer = LF_PANELS }, --} }, setAnims = { { actorName = "Word_object", properties = { anim = "gameletras/objetoCicle.anm", loop = true, } }, } } end, onClick = { button = function(_self) --DeactivateActor("Button") _self:setNextState(TGame1ObjectOut:new()) end } }, } TGame1ObjectOut = TState:new{ m_name = "TGame1ObjectOut", events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game1.objectOut) ClearActorAnims("Word_object", true, true) return { setAnims = { { actorName = "Word_object", properties = { anim = "gameletras/objetoout.anm", loop = false, } }, } } end, onAnimEnded = { default = function(_self) _self:setNextState(TGame1LoopStartState:new()) end } }, } -------------------------------------- -- Win and fail anim... -------------------------------------- TGame1FailState = TState:new{ m_name = "TGame1FailState", events = { onBegin = function(_self) --DeactivateActor("Background") --DeactivateActor("Scene") log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FAIL!!!") return { actors = { { actorType = "ActorGeom", properties = { name = "Fail", model = "efectos/wrong.mesh", touchable = false, layer = LF_PANELS+1 }, }, }, setAnims = { { actorName = "Fail", properties = { anim = "efectos/wrongIn.anm", loop = false, } }, } } end, onAnimEnded = { Fail = function(_self) _self.superState:setNextState(_self.superState) end }, } } TGame1WinState = TState:new{ m_name = "TGame1WinState", events = { onBegin = function(_self) DeactivateActor("pause") if isGame1Ended() then IncrementPointsAndSave(E_LEVEL_GAME1) Sound.PlaySound(g_Sound.fx.game1.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[1], touchable = false, layer = LF_PANELS+2, camera = "game1" }, }, }, setAnims = { { actorName = "Win", properties = { anim = "efectos/congratulationcicle.anm", loop = false, } }, { actorName = "CubePart", properties = { anim = g_cubePartAnms[1], loop = false, } }, } } else SaveGameProgress() Sound.PlaySound(g_Sound.fx.game1.great) return { actors = { { actorType = "ActorGeom", properties = { name = "Win", model = "efectos/great.mesh", touchable = false, layer = LF_PANELS+1 }, }, }, setAnims = { { actorName = "Win", properties = { anim = "efectos/greatCicle.anm", loop = false, } }, } } end end, onAnimEnded = { Win = function(_self) if isGame1Ended() then --congratulations... log("GAME ENDED! YOU WIN!") _self:setNextState(TGame1FadeOutState:new()) else log("GAME Continues! GREAT!") --vuelvo al principio del juego...!TGame1LoopStartState local aux = _self:findParent("TGame1LoadObject") aux.superState:setNextState(TGame1LoadObject:new()) --_self.superState:setNextState(TGame1LettersOut:new()) end end }, } } TGame1WinLetterDisappearState = TState:new{ m_name = "TGame1WinLetterDisappearState", m_indexes = {}, events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game1.letterDisappear) return { setAnims = { { actorName = "single" .. g_lastButtonClicked, properties = { anim = "gameletras/explosionIn.anm", loop = false, } }, } } end, onAnimEnded = { default = function(_self) _self.superState:setNextState(TGame1WinLetterAppearState:new{ m_indexes = _self.m_indexes }:new()) end }, } } TGame1WinLetterAppearState = TState:new{ m_name = "TGame1WinLetterAppearState", m_indexes = {}, events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game1.letterAppear) local aux = {} --local color_ndx = math.mod(g_word_ndx+g_lastButtonClicked,#basic_colours) + 1 for i = 1, #_self.m_indexes, 1 do ActivateActor("word" .. _self.m_indexes[i]) --SetEffectParamColor("word" .. _self.m_indexes[i], "numeros", "g_matDiffuse", basic_colours[color_ndx][1]) --SetEffectParamColor("word" .. _self.m_indexes[i], "numeros", "g_ambientColor", basic_colours[color_ndx][2] ) aux[#aux + 1] = { actorName = "word" .. _self.m_indexes[i], properties = { anim = "gameletras/explosionOut.anm", loop = false, } } end return { setAnims = aux } end, onAnimEnded = { default = function(_self) if(isWordCompleted()) then g_timesCompleted = g_timesCompleted + 1 _self.superState.superState:setNextState(TGame1WinState:new()) else local auxState =_self:findParent("TGame1LettersIn") log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FIND PARENT!!") auxState:setNextState(TGame1LettersOut:new()) end end }, } } -------------------------------------------------------------- -- Ciclo principal -------------------------------------------------------------- TGame1LoopState = TState:new{ m_name = "TGame1LoopState", events = { onBegin = function(_self) _self:setNextState(_self) g_currentState:findParent("TRootState") return { setAnims = { { actorName = "Letters", properties = { anim = "gameletras/posseLetracicle.anm", loop = true, } }, { actorName = "Word", properties = { anim = "gameletras/palabracicle.anm", loop = true, } }, } } end, onClick = { button1 = function(_self, _nodeName) g_lastButtonClicked = 1 local aux = checkLetters(1) if #aux == 0 then -- estado fail!! Sound.PlaySound(g_Sound.fx.game1.wrong) _self:setNextState(TGame1FailState:new()) else _self:setNextState(TGame1WinLetterDisappearState:new{ m_indexes = aux }:new()) -- estado great!! --al salir de great recordar ver si el juego a terminado y salir... end end, button2 = function(_self, _nodeName) g_lastButtonClicked = 2 local aux = checkLetters(2) if #aux == 0 then -- estado fail!! Sound.PlaySound(g_Sound.fx.game1.wrong) _self:setNextState(TGame1FailState:new()) else _self:setNextState(TGame1WinLetterDisappearState:new{ m_indexes = aux }:new()) -- estado great!! --al salir de great recordar ver si el juego a terminado y salir... end end, button3 = function(_self, _nodeName) g_lastButtonClicked = 3 local aux = checkLetters(3) if #aux == 0 then -- estado fail!! Sound.PlaySound(g_Sound.fx.game1.wrong) _self:setNextState(TGame1FailState:new()) else _self:setNextState(TGame1WinLetterDisappearState:new{ m_indexes = aux }:new()) -- estado great!! --al salir de great recordar ver si el juego a terminado y salir... end end, ['currentMenuScreen:back()'] = function(_self) pause() end, } }, } TGame1LoopCreateWordActor = TState:new{ m_name = "TGame1LoopStartState", events = { onBegin = function(_self) --DeactivateActor("Background") --DeactivateActor("Scene") return { actors = { { actorType = "ActorGeom", properties = { name = "Word", model = "gameletras/palabra.mesh", touchable = false, layer = LF_WORLD+1 }, }, } } end, }, } TGame1LoopStartState = TState:new{ m_name = "TGame1LoopStartState", events = { onBegin = function(_self) --DeactivateActor("Background") --DeactivateActor("Scene") _self:setNextState(TGame1PrepareWordsState:new()) if(IsMrHatLite) then return { actors = { { actorType = "ActorGeom", properties = { name = "Word", model = "gameletras/palabra.mesh", touchable = false, layer = LF_WORLD+1 }, }, }, } else return { actors = { { actorType = "ActorGeom", properties = { name = "pause", model = "menuPause/pauseButton.mesh", touchable = true, camera = "game1", layer = LF_PANELS+3 }, }, { actorType = "ActorGeom", properties = { name = "Word", model = "gameletras/palabra.mesh", touchable = false, layer = LF_WORLD+1 }, }, }, } end end, }, changeAfterBeginning = true } TGame1PrepareWordsState = TState:new{ m_name = "TGame1PrepareWordsState", events = { onBegin = function(_self) --DeactivateActor("Background") --DeactivateActor("Scene") hideLetters() return { setAnims = { { actorName = "Word", properties = { anim = "gameletras/palabraIn.anm", loop = false, } }, } } end, onAnimEnded = { Word = function (_self) log("Siguiente estado: BUCLE PRINCIPAL!") _self:setNextState(TGame1LettersIn:new()) end }, }, } TGame1LettersIn = TState:new{ m_name = "TGame1LettersIn", events = { onBegin = function(_self) Sound.PlaySound(g_Sound.fx.game1.lettersIn) drawGoodLetterOptions() sortSingleLetterColours() return { actors = { { actorType = "ActorGeom", properties = { name = "Letters", model = "gameletras/posseletras.mesh", touchable = false, camera = "game1", layer = LF_WORLD+1 }, }, { actorType = "ActorGeom", properties = { name = "Luz", model = "gameletras/luz.mesh", touchable = true, camera = "game1", layer = LF_WORLD+1 }, }, { actorType = "ActorGeom", properties = { name = "Buttons", model = "gameletras/posseletrasbotones.mesh", touchable = true, camera = "game1", layer = LF_WORLD+1 }, }, }, setAnims = { { actorName = "Letters", properties = { anim = "gameletras/posseLetraIn.anm", loop = false, } }, { actorName = "Luz", properties = { anim = "gameletras/luzin.anm", loop = false, } }, } } end, onAnimEnded = { Letters = function (_self) --habría que volver a hacer el sorteo... log("Siguiente estado: BUCLE PRINCIPAL!") if isOkForLetters() then _self:setNextState(TGame1LoopState:new()) else _self:setNextState(TGame1LettersOut:new()) end end }, }, } TGame1LettersOut = TState:new{ m_name = "TGame1LettersOut", events = { onBegin = function(_self) return { setAnims = { { actorName = "Letters", properties = { anim = "gameletras/posseLetraOut.anm", loop = false, } }, } } end, onAnimEnded = { Letters = function (_self) _self.superState.superState:setNextState(TGame1LettersIn:new()) end }, }, } -------------------------------------- -- Entrada del fondo -------------------------------------- uvoffset = { {0.0,0.0}, {0.0,0.98}, {0.0,0.96}, } TGame1FadeInState = TState:new{ m_name = "TGame1FadeInState", m_bLoad = false, events = { onBegin = function(_self) Game1Started() loadFxsGame1() Sound.PlayMusic(g_Sound.music.game1Theme) --Sound.PlaySound(g_Sound.fx.game1.machinery, true) if not _self.m_bLoad then log("g_timesCompleted is ZERO!") g_timesCompleted = 0 end g_currentGame = E_LEVEL_GAME1 g_difficulty_game1 = getDifficulty(E_LEVEL_GAME1) words_drawed = {} words_drawed_ndx = {} log("AGH, Deberia cargar ahora las instrucciones") _self:setNextState(TGame1InstructionsIn:new()) SaveGameProgress() return { actors = { { actorType = "ActorGeom", properties = { name = "Background", model = "gameletras/gameletrasbg.mesh", touchable = false, camera = "game1", layer = LF_WORLD }, }, { actorType = "ActorGeom", properties = { name = "Scene", model = "gameletras/gameletrasbgmaquinaciclo.mesh", touchable = false, camera = "game1", layer= LF_WORLD+2 }, }, { actorType = "ActorGeom", properties = { name = "Fade", model = "fadeblack.mesh", touchable = false, camera = "game1", layer= LF_PANELS+4 }, }, { actorType = "ActorGeom", properties = { name = "Huecos", model = "gameletras/huecos.mesh", touchable = false, camera = "game1", layer= LF_WORLD+2, materials = { MenuTriangulo = { g_channel1OffsetV = { paramType = E_PARAM_FLOAT, paramValue = uvoffset[g_difficulty_game1][2]}, } }}, }, }, setAnims = { { actorName = "Scene", properties = { anim = "gameletras/cycle.anm", loop = true, } }, { actorName = "Fade", properties = { anim = "fadeblackout.anm", loop = false, } }, } } end, onFinish = function() Sound.StopMusic(g_Sound.music.game1Theme) --Sound.StopSound(g_Sound.fx.game1.machinery) releaseFxSoundResources(g_Sound.fx.game1) end }, changeAfterBeginning = true } TGame1FadeOutState = TState:new{ m_name = "TGame1FadeOutState", events = { onBegin = function() if g_SoundAux ~= nil then Sound.ReleaseSound(g_SoundAux) end 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(TGame1EndingState:new()) end, }, } } TGameGiveUpState = TState:new{ m_name = "TGameGiveUpState", events = { onBegin = function(_self) _self:setNextState(nil) log(debug.traceback()) return { actors = { { actorType = "ActorGeom", properties = { name = "Fade", model = "fadeblack.mesh", touchable = false, layer = LF_PANELS+4 }, }, }, setAnims = { { actorName = "Fade", properties = { anim = "fadeblackin.anm", loop = false, } }, } } end, onAnimEnded = { Fade = function(_self) log("GIVE UP!") local aux = _self:findParent("TRootState") aux:setNextState(TMainMenuFadeIn:new()) end, }, } } function SaveGameProgress() log("saving g_currentGame = " .. g_currentGame) SavePreference("g_currentGame", g_currentGame) log("saving g_timesCompleted = " .. g_timesCompleted) SavePreference("g_timesCompleted", g_timesCompleted) end function IncrementPointsAndSave(_game) SavePreference("g_currentGame", E_MENU_SCREEN) SavePreference("g_timesCompleted", 0) IncrementGamePoints(_game) end