csCharacterName = nil csBioText = nil csSuperTitle = nil csSuperText = nil csJumpTitle = nil csSpeedTitle = nil csStrengthTitle = nil csStartingLevelTitle = nil csPortrait = nil csCharacterAnimL = nil csCharacterAnimR = nil csLeftArrow = nil csRightArrow = nil csLeftArrowSmall = nil csRightArrowSmall = nil csBurgerGfx = nil csTotalCharacters = 0 csCurrentCharacter = 0 csChosenLevelText = nil csLevelChoosing = false csChosenLevel = 0 csLevelChoosingAnimL = nil csLevelChoosingAnimR = nil csJumpBurgers = { } csSpeedBurgers = { } csStrengthBurgers = { } CS_CHARACTER_LIST = { "DAD", "SON", "DAUGHTER", "MOM", } function getCharacterAtIndex( index ) local i = 0 local hitIndex = false for k, v in pairs(CS_CHARACTER_LIST) do if CHARACTER_LIST[v]["ENABLED"] == true then if i == index then return CHARACTER_LIST[v] end i = i + 1 end end print("not found " .. tostring(index)) return nil end function countCharacters(table) local n = 0 for k, v in pairs(table) do if CHARACTER_LIST[v]["ENABLED"] == true then n = n + 1 end end return n end function showCharacterPortrait(character) local characterLocked = isCharacterLocked( character ) if not characterLocked then if character["PORTRAIT"] ~= nil then if MOAIEnvironment.osBrand == "PSM" then layer:removeProp(csPortrait) end local characterPortraitGfx = MOAIGfxQuad2D.new() characterPortraitGfx:setTexture( character["PORTRAIT"] ) characterPortraitGfx:setRect( 0, 0, 219, 192 ) characterPortraitGfx:setUVRect ( 0, 0, 1, 1 ) csPortrait:setDeck( characterPortraitGfx ) layer:insertProp(csPortrait) else layer:removeProp(csPortrait) end csBioText:setString( character['BIO'] ) else if character["LOCKED_PORTRAIT"] ~= nil then local characterPortraitGfx = MOAIGfxQuad2D.new() characterPortraitGfx:setTexture( character["LOCKED_PORTRAIT"] ) characterPortraitGfx:setRect( 0, 0, 219, 192 ) characterPortraitGfx:setUVRect ( 0, 0, 1, 1 ) csPortrait:setDeck( characterPortraitGfx ) layer:insertProp(csPortrait) else layer:removeProp(csPortrait) end csBioText:setString( character['UNLOCK_TEXT'] ) end csSuperText:setString( character['SUPER_TEXT'] ) for k, v in pairs(csJumpBurgers) do layer:removeProp(v) end for k, v in pairs(csSpeedBurgers) do layer:removeProp(v) end for k, v in pairs(csStrengthBurgers) do layer:removeProp(v) end for i = 1, character['JUMP_RATING'] do layer:insertProp( csJumpBurgers[i] ) end for i = 1, character['SPEED_RATING'] do layer:insertProp( csSpeedBurgers[i] ) end for i = 1, character['STRENGTH_RATING'] do layer:insertProp( csStrengthBurgers[i] ) end end function characterSelectSetInactive( widget1, widget2 ) widget1:setColor( 0.5, 0.5, 0.5, 1.0 ) widget2:setColor( 0.5, 0.5, 0.5, 1.0 ) end function csCreateText( font, x, y, width, height, alignment, text ) local textObj = MOAITextBox.new () textObj:setFont( font ) textObj:setRect( 0, 0, width, height ) textObj:setLoc( x, y ) textObj:setAlignment ( alignment ) textObj:setString( text ) textObj:setColor( 0.3, 0.3, 0.3, 1 ) layer:insertProp( textObj, 2 ) return textObj end function csCreateBurgerAt( x, y ) local burger = MOAIProp2D.new() burger:setDeck( csBurgerGfx ) burger:setPriority( 2 ) burger:setLoc( x, y ) return burger end function characterSelectSetup() csBurgerGfx = MOAIGfxQuad2D.new () csBurgerGfx:setTexture( BBQ_BURGER ) csBurgerGfx:setRect( 0, 0, 30, 26 ) csBurgerGfx:setUVRect ( 0, 0, 1, 1 ) csCharacterName = csCreateText( font, 330, 77, 300, 40, MOAITextBox.CENTER_JUSTIFY, "DAD" ) csBioText = csCreateText( smallFont, 237.5, 130, 150, 200, MOAITextBox.LEFT_JUSTIFY, "Bio:" ) csSuperTitle = csCreateText( smallFont, 70, 250, 300, 40, MOAITextBox.RIGHT_JUSTIFY, "SUPER" ) csSuperTitle:setColor( 0.05, 0.0, 1.0, 1.0 ) csSuperText = csCreateText( smallFont, 225, 270, 150, 200, MOAITextBox.RIGHT_JUSTIFY, "Super:" ) csJumpTitle = csCreateText( smallFont, 596, 149, 300, 40, MOAITextBox.LEFT_JUSTIFY, "JUMP:" ) csSpeedTitle = csCreateText( smallFont, 596, 199, 300, 40, MOAITextBox.LEFT_JUSTIFY, "SPEED:" ) csStrengthTitle = csCreateText( smallFont, 596, 252, 300, 40, MOAITextBox.LEFT_JUSTIFY, "STRENGTH:" ) csStartingLevelTitle = csCreateText( smallFont, 330, 340, 300, 40, MOAITextBox.CENTER_JUSTIFY, "STARTING LEVEL" ) local csBackgroundGfx = MOAIGfxQuad2D.new() csBackgroundGfx:setTexture( CHARACTER_SELECT_BACKGROUND_IMAGE ) csBackgroundGfx:setRect( 0, 0, 580, 544 ) csBackgroundGfx:setUVRect ( 0, 0, 1, 1 ) local csBackground = MOAIProp2D.new() csBackground:setDeck( csBackgroundGfx ) csBackground:setPriority( 1 ) csBackground:setLoc( 190, 0 ) csPortrait = MOAIProp2D.new() csPortrait:setLoc( 377, 128 ) csPortrait:setPriority( 2 ) local csLeftArrowGfx = MOAIGfxQuad2D.new() csLeftArrowGfx:setTexture( UI_CS_LEFT_ARROW ) csLeftArrowGfx:setRect( 0, 0, 33, 66 ) csLeftArrowGfx:setUVRect ( 0, 0, 1, 1 ) csLeftArrow = MOAIProp2D.new() csLeftArrow:setDeck( csLeftArrowGfx ) csLeftArrow:setLoc( 265, 70 ) csLeftArrow:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) csLeftArrow:setColor( 0.5, 0.5, 0.5, 0.5 ) csLeftArrow:setPriority( 2 ) local csRightArrowGfx = MOAIGfxQuad2D.new() csRightArrowGfx:setTexture( UI_CS_RIGHT_ARROW ) csRightArrowGfx:setRect( 0, 0, 33, 66 ) csRightArrowGfx:setUVRect ( 0, 0, 1, 1 ) csRightArrow = MOAIProp2D.new() csRightArrow:setDeck( csRightArrowGfx ) csRightArrow:setLoc( 667, 70 ) csRightArrow:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) csRightArrow:setColor( 0.5, 0.5, 0.5, 0.5 ) csRightArrow:setPriority( 2 ) local csLeftArrowSmallGfx = MOAIGfxQuad2D.new() csLeftArrowSmallGfx:setTexture( UI_CS_LEFT_ARROW_SMALL ) csLeftArrowSmallGfx:setRect( 0, 0, 24, 46 ) csLeftArrowSmallGfx:setUVRect ( 0, 0, 1, 1 ) csLeftArrowSmall = MOAIProp2D.new() csLeftArrowSmall:setDeck( csLeftArrowSmallGfx ) csLeftArrowSmall:setLoc( 322, 367 ) csLeftArrowSmall:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) csLeftArrowSmall:setColor( 0.5, 0.5, 0.5, 0.5 ) csLeftArrowSmall:setPriority( 2 ) local csRightArrowSmallGfx = MOAIGfxQuad2D.new() csRightArrowSmallGfx:setTexture( UI_CS_RIGHT_ARROW_SMALL ) csRightArrowSmallGfx:setRect( 0, 0, 24, 46 ) csRightArrowSmallGfx:setUVRect ( 0, 0, 1, 1 ) csRightArrowSmall = MOAIProp2D.new() csRightArrowSmall:setDeck( csRightArrowSmallGfx ) csRightArrowSmall:setLoc( 614, 367 ) csRightArrowSmall:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) csRightArrowSmall:setColor( 0.5, 0.5, 0.5, 0.5 ) csRightArrowSmall:setPriority( 2 ) for i = 1, 4 do csJumpBurgers[i] = csCreateBurgerAt( 596 + 34 * (i - 1), 171 ) csSpeedBurgers[i] = csCreateBurgerAt( 596 + 34 * (i - 1), 223 ) csStrengthBurgers[i] = csCreateBurgerAt( 596 + 34 * (i - 1), 274 ) end layer:insertProp( csBackground ) layer:insertProp( csLeftArrow ) layer:insertProp( csRightArrow ) layer:insertProp( csLeftArrowSmall ) layer:insertProp( csRightArrowSmall ) setupScreenWithTitle( "CHARACTER SELECT" ) inputCallback = characterSelectOnInput csTotalCharacters = countCharacters( CS_CHARACTER_LIST ) -- if MOAIEnvironment.osBrand == "PSM" then -- csCurrentCharacter = csTotalCharacters-1 -- end showCharacterPortrait( getCharacterAtIndex(csCurrentCharacter) ) csCharacterName:setString( getCharacterAtIndex(csCurrentCharacter)["NAME"] ) csLevelChoosing = false csChosenLevel = 0 csChosenLevelText = csCreateText( bigFont, 330, 360, 300, 40, MOAITextBox.CENTER_JUSTIFY, "1" ) csChosenLevelText:setColor( 0.3, 1, 0.03 ) MOAIPSM.setTextBoxShadow( csChosenLevelText.textBoxID ) characterFadeOut() characterSelectSetInactive( csLeftArrowSmall, csRightArrowSmall ) -- initialize values -- allocate resources -- spin up threads end function characterSelectTeardown() layer:clear() -- spin down threads -- clean up resources end function levelFadeOut() if csLevelChoosing then csLevelChoosingAnimL = csLeftArrowSmall:seekColor(1, 1, 1, 0.25, 0.5, MOAIEaseType.LINEAR) csLevelChoosingAnimR = csRightArrowSmall:seekColor(1, 1, 1, 0.25, 0.5, MOAIEaseType.LINEAR) csLevelChoosingAnimL:setListener( MOAIAction.EVENT_STOP, levelFadeIn ) end end function levelFadeIn() if csLevelChoosing then csLevelChoosingAnimL = csLeftArrowSmall:seekColor(1, 1, 1, 1, 0.5, MOAIEaseType.LINEAR) csLevelChoosingAnimR = csRightArrowSmall:seekColor(1, 1, 1, 1, 0.5, MOAIEaseType.LINEAR) csLevelChoosingAnimL:setListener( MOAIAction.EVENT_STOP, levelFadeOut ) end end function characterFadeOut() if not csLevelChoosing then csCharacterAnimL = csLeftArrow:seekColor(1, 1, 1, 0.25, 0.5, MOAIEaseType.LINEAR) csCharacterAnimR = csRightArrow:seekColor(1, 1, 1, 0.25, 0.5, MOAIEaseType.LINEAR) csCharacterAnimL:setListener( MOAIAction.EVENT_STOP, characterFadeIn ) end end function characterFadeIn() if not csLevelChoosing then csCharacterAnimL = csLeftArrow:seekColor(1, 1, 1, 1, 0.5, MOAIEaseType.LINEAR) csCharacterAnimR = csRightArrow:seekColor(1, 1, 1, 1, 0.5, MOAIEaseType.LINEAR) csCharacterAnimL:setListener( MOAIAction.EVENT_STOP, characterFadeOut ) end end function characterSelectOnInput( key, isDown ) if (key == KEY_CONFIRM) and not isDown then SFX["MENU_SELECT"]:play() if not isCharacterLocked( getCharacterAtIndex(csCurrentCharacter) ) then if not csLevelChoosing then CURRENT_CHARACTER = getCharacterAtIndex(csCurrentCharacter) csLevelChoosing = true levelFadeOut() csCharacterAnimL:stop() csCharacterAnimL = nil csCharacterAnimR:stop() csCharacterAnimR = nil characterSelectSetInactive( csLeftArrow, csRightArrow ) else CURRENT_LEVEL = csChosenLevel changeGameState(GAME_STATE_GAME) end end elseif key == KEY_CANCEL and not isDown then -- z SFX["MENU_BACK"]:play() if not csLevelChoosing then changeGameState(GAME_STATE_MENU) else csLevelChoosing = false csLevelChoosingAnimL:stop() csLevelChoosingAnimL = nil csLevelChoosingAnimR:stop() csLevelChoosingAnimR = nil characterSelectSetInactive( csLeftArrowSmall, csRightArrowSmall ) characterFadeOut() end elseif key == KEY_RIGHT and not isDown then SFX["MENU_MOVE_R"]:play() if not csLevelChoosing then csCurrentCharacter = csCurrentCharacter + 1 if csCurrentCharacter >= csTotalCharacters then csCurrentCharacter = 0 end local activeCharacter = getCharacterAtIndex(csCurrentCharacter) csCharacterName:setString( activeCharacter["NAME"] ) showCharacterPortrait( activeCharacter ) else csChosenLevel = math.min( MAX_CHOOSABLE_LEVEL, csChosenLevel + 1 ) csChosenLevelText:setString( tostring( csChosenLevel + 1 ) ) end elseif key == KEY_LEFT and not isDown then SFX["MENU_MOVE_L"]:play() if not csLevelChoosing then csCurrentCharacter = csCurrentCharacter - 1 if csCurrentCharacter < 0 then csCurrentCharacter = csTotalCharacters-1 end local activeCharacter = getCharacterAtIndex(csCurrentCharacter) csCharacterName:setString( activeCharacter["NAME"] ) showCharacterPortrait( activeCharacter ) else csChosenLevel = math.max( 0, csChosenLevel - 1 ) csChosenLevelText:setString( tostring( csChosenLevel + 1 ) ) end end end