characterProp = nil scoreText = nil levelText = nil burgersMatchedText = nil scoreUpdateText = {} scoreUpdateTextIdx = 0 scoreUpdateTextIdxs = {} scoreKickers = {} scoreKickerIdx = 0 scoreKickersIdxs = {} buffActiveText = nil messageText = nil messageTextBottom = nil characterIdleL = nil characterIdleR = nil characterJumpL = nil characterJumpR = nil characterFallL = nil characterFallR = nil characterWalkL = nil characterWalkR = nil characterSmackL = nil characterSmackR = nil characterDigAnim = nil characterDown = nil characterSheet = nil characterLocation = { GRID_OFFSET_X, GRID_OFFSET_Y } curPowerUpProp = nil hitsRemaining = 0 characterLockState = {} gameOverQueue = {} gameOverQueueComplete = false gameplayMusic = nil menuItem1Text = nil menuItem2Text = nil menuItem1TextAnim = nil menuItem2TextAnim = nil gameOverText = {} gameOverTextIdx = 0 gameOverProps = {} gameOverPropIdx = 1 sessionMaxLevel = 0 sessionMaxMatch = 0 sessionMaxPoints = 0 local CHARACTER_IDLE = "CHARACTER_IDLE" local CHARACTER_JUMPING = "CHARACTER_JUMPING" local CHARACTER_FALLING = "CHARACTER_FALLING" local CHARACTER_WALKING = "CHARACTER_WALKING" local CHARACTER_DEATH = "CHARACTER_DEATH" local CHARACTER_DOWN = "CHARACTER_DOWN" local CHARACTER_STATE = CHARACTER_IDLE GAMEPLAY_STATE = GAMEPLAY_STATE_ACTIVE CURRENT_CHARACTER = nil characterXVelocity = 0 characterYVelocity = 0 characterFacingRight = true characterHoldingDown = false characterFalling = true characterJumping = false starNextDropTime = 0 timeToRevive = 0 activeLevel = 0 burgersMatchCount = 0 local uiLayer = 13 local fxLayer = 11 local tractorBeamLayer = 12 buffMatchCounter = 0.0 RED_BUFF_ACTIVE = false GREEN_BUFF_ACTIVE = false BLUE_BUFF_ACTIVE = false local gameplayCurTime = MOAISim.getCurrentTime() beanieGfx = MOAITileDeck2D.new() beanieGfx:setTexture( BEANIE_IMAGE ) beanieGfx:setRect( 0, 0, 47, 47 ) beanieGfx:setSize( 2, 1 ) beanieGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) local beanieAnimCurve = MOAIAnimCurve.new() beanieAnimCurve:reserveKeys( 3 ) beanieAnimCurve:setKey( 1, 0.00, 1, MOAIEaseType.FLAT ) beanieAnimCurve:setKey( 2, 0.50, 2, MOAIEaseType.FLAT ) beanieAnimCurve:setKey( 3, 1.00, 1, MOAIEaseType.FLAT ) beanieProp = nil ufoGfx = MOAIGfxQuad2D.new() ufoGfx:setTexture( UFO_IMAGE ) ufoGfx:setRect( 0, 0, 580, 60 ) ufoGfx:setUVRect ( 0, 0, 1, 1 ) local tractorBeamAnimCurve = MOAIAnimCurve.new() tractorBeamAnimCurve:reserveKeys( 10 ) tractorBeamAnimCurve:setKey( 1, 0.0, 1, MOAIEaseType.FLAT ) tractorBeamAnimCurve:setKey( 2, 0.033, 2, MOAIEaseType.FLAT ) tractorBeamAnimCurve:setKey( 3, 0.066, 3, MOAIEaseType.FLAT ) tractorBeamAnimCurve:setKey( 4, 0.099, 4, MOAIEaseType.FLAT ) tractorBeamAnimCurve:setKey( 5, 0.132, 5, MOAIEaseType.FLAT ) tractorBeamAnimCurve:setKey( 6, 0.165, 6, MOAIEaseType.FLAT ) tractorBeamAnimCurve:setKey( 7, 0.198, 7, MOAIEaseType.FLAT ) tractorBeamAnimCurve:setKey( 8, 0.231, 8, MOAIEaseType.FLAT ) tractorBeamAnimCurve:setKey( 9, 0.264, 9, MOAIEaseType.FLAT ) tractorBeamAnimCurve:setKey( 10, 0.297, 9, MOAIEaseType.FLAT ) tractorBeamProp = nil tractorBeamActiveProp = nil tractorBeamActiveAnim = nil groundGfx = MOAIGfxQuad2D.new() groundGfx:setTexture( GROUND_IMAGE ) groundGfx:setRect( 0, 0, 565, 88 ) groundGfx:setUVRect ( 0, 0, 1, 1 ) bbqExplosionGfx = MOAITileDeck2D.new() bbqExplosionGfx:setTexture( BBQ_EXPLOSION ) bbqExplosionGfx:setRect( 0, 0, 60, 60 ) bbqExplosionGfx:setSize( 10, 1 ) bbqExplosionGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) local bbqExplosionAnimCurve = MOAIAnimCurve.new() bbqExplosionAnimCurve:reserveKeys( 11 ) bbqExplosionAnimCurve:setKey( 1, 0.00, 1, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 2, 0.10, 2, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 3, 0.20, 3, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 4, 0.30, 4, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 5, 0.40, 5, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 6, 0.50, 6, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 7, 0.60, 7, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 8, 0.70, 8, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 9, 0.80, 9, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 10, 0.90, 10, MOAIEaseType.FLAT ) bbqExplosionAnimCurve:setKey( 11, 1.00, 10, MOAIEaseType.FLAT ) function onBBQDeathOver( anim ) anim:stop() local prop = anim["prop"] layer:removeProp( prop ) spriteDestroy( prop ) end function createBBQDeathAnimation( x, y ) local bbqExplosionProp = MOAIProp2D.new() bbqExplosionProp:setDeck( bbqExplosionGfx ) bbqExplosionProp:setPriority( fxLayer ) bbqExplosionProp:setLoc( x, y ) layer:insertProp( bbqExplosionProp ) local bbqDeathAnim = MOAIAnim.new() bbqDeathAnim:reserveLinks( 1 ) bbqDeathAnim:setLink( 1, bbqExplosionAnimCurve, bbqExplosionProp, MOAIProp2D.ATTR_INDEX ) bbqDeathAnim:setMode( MOAITimer.NORMAL ) bbqDeathAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onBBQDeathOver ) bbqDeathAnim:start() bbqDeathAnim["prop"] = bbqExplosionProp end smokePuffGfx = MOAITileDeck2D.new() smokePuffGfx:setTexture( SMOKEPUFF ) smokePuffGfx:setRect( 0, 0, 60, 60 ) smokePuffGfx:setSize( 11, 1 ) smokePuffGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) local smokePuffAnimCurve = MOAIAnimCurve.new() smokePuffAnimCurve:reserveKeys( 12 ) smokePuffAnimCurve:setKey( 1, 0.00, 1, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 2, 0.10, 2, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 3, 0.20, 3, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 4, 0.30, 4, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 5, 0.40, 5, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 6, 0.50, 6, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 7, 0.60, 7, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 8, 0.70, 8, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 9, 0.80, 9, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 10, 0.90, 10, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 11, 1.00, 11, MOAIEaseType.FLAT ) smokePuffAnimCurve:setKey( 12, 1.10, 11, MOAIEaseType.FLAT ) function onSmokePuffOver( anim ) anim:stop() local prop = anim["prop"] layer:removeProp( prop ) spriteDestroy( prop ) end function createSmokePuffAnimation( x, y ) local smokePuffProp = MOAIProp2D.new() smokePuffProp:setDeck( smokePuffGfx ) smokePuffProp:setPriority( fxLayer ) smokePuffProp:setLoc( x, y ) layer:insertProp( smokePuffProp ) local smokePuffAnim = MOAIAnim.new() smokePuffAnim:reserveLinks( 1 ) smokePuffAnim:setLink( 1, smokePuffAnimCurve, smokePuffProp, MOAIProp2D.ATTR_INDEX ) smokePuffAnim:setMode( MOAITimer.NORMAL ) smokePuffAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onSmokePuffOver ) smokePuffAnim:start() smokePuffAnim["prop"] = smokePuffProp end cloudPuffGfx = MOAITileDeck2D.new() cloudPuffGfx:setTexture( CLOUD_ANIM ) cloudPuffGfx:setRect( 0, 0, 51, 51 ) cloudPuffGfx:setSize( 5, 5 ) cloudPuffGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) local cloudAnimCurve = MOAIAnimCurve.new() cloudAnimCurve:reserveKeys( 26 ) for i = 1, 25 do cloudAnimCurve:setKey( i, (i - 1) * 0.033, i, MOAIEaseType.FLAT ) end cloudAnimCurve:setKey( 26, 25 * 0.033, 25, MOAIEaseType.FLAT ) function onCloudPuffOver( anim ) anim:stop() local prop = anim["prop"] layer:removeProp( prop ) spriteDestroy( prop ) end function createCloudPuffAnimation( x, y, moveX ) local cloudPuffProp = MOAIProp2D.new() cloudPuffProp:setDeck( cloudPuffGfx ) cloudPuffProp:setPriority( fxLayer ) if moveX > 0 then cloudPuffProp:setScl( -1, 1 ) end cloudPuffProp:setLoc( x, y ) layer:insertProp( cloudPuffProp ) local cloudPuffAnim = MOAIAnim.new() cloudPuffAnim:reserveLinks( 1 ) cloudPuffAnim:setLink( 1, cloudAnimCurve, cloudPuffProp, MOAIProp2D.ATTR_INDEX ) cloudPuffAnim:setMode( MOAITimer.NORMAL ) cloudPuffAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onCloudPuffOver ) cloudPuffAnim:start() cloudPuffAnim["prop"] = cloudPuffProp cloudPuffProp:moveLoc( moveX, 0, 0.6, MOAIEaseType.LINEAR ) end starGfx = MOAIGfxQuad2D.new() starGfx:setTexture( STAR ) starGfx:setRect( 0, 0, 15, 15 ) starGfx:setUVRect( 0, 0, 1, 1 ) function onStarFinished( anim ) anim:stop() local prop = anim["prop"] layer:removeProp( prop ) spriteDestroy( prop ) end function createStarAnimation( x, y, moveX, moveY ) local starProp = MOAIProp2D.new() starProp:setDeck( starGfx ) starProp:setPriority( fxLayer ) starProp:setLoc( x, y ) layer:insertProp( starProp ) local starAnim = starProp:moveLoc( moveX, moveY, 0.3, MOAIEaseType.EASE_IN ) starAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onStarFinished ) starAnim["prop"] = starProp end shootingStarGfx = MOAITileDeck2D.new() shootingStarGfx:setTexture( SHOOTING_STAR ) shootingStarGfx:setRect( 0, 0, 128, 128 ) shootingStarGfx:setSize( 4, 4 ) shootingStarGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) local shootingStarAnimCurve = MOAIAnimCurve.new() shootingStarAnimCurve:reserveKeys( 17 ) for i = 1, 16 do shootingStarAnimCurve:setKey( i, (i - 1) * 0.0416, i, MOAIEaseType.FLAT ) end shootingStarAnimCurve:setKey( 17, 16 * 0.0416, 16, MOAIEaseType.FLAT ) function onShootingStarOver( anim ) anim:stop() local prop = anim["prop"] layer:removeProp( prop ) spriteDestroy( prop ) end function createShootingStarAnimation( x, y ) local shootingStarProp = MOAIProp2D.new() shootingStarProp:setDeck( shootingStarGfx ) shootingStarProp:setPriority( 1 ) shootingStarProp:setLoc( x, y ) shootingStarProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE ) layer:insertProp( shootingStarProp ) local shootingStarAnim = MOAIAnim.new() shootingStarAnim:reserveLinks( 1 ) shootingStarAnim:setLink( 1, shootingStarAnimCurve, shootingStarProp, MOAIProp2D.ATTR_INDEX ) shootingStarAnim:setMode( MOAITimer.NORMAL ) shootingStarAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onShootingStarOver ) shootingStarAnim:start() shootingStarAnim["prop"] = shootingStarProp end powerUpGfx = MOAITileDeck2D.new() powerUpGfx:setTexture( POWERUP_ANIM ) powerUpGfx:setRect( 0, 0, 128, 128 ) powerUpGfx:setSize( 5, 5 ) powerUpGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) local powerUpAnimCurve = MOAIAnimCurve.new() powerUpAnimCurve:reserveKeys( 26 ) for i = 1, 25 do powerUpAnimCurve:setKey( i, (i - 1) * 0.0416, i, MOAIEaseType.FLAT ) end powerUpAnimCurve:setKey( 26, 25 * 0.0416, 25, MOAIEaseType.FLAT ) function onPowerUpOver( anim ) anim:stop() local prop = anim["prop"] layer:removeProp( prop ) spriteDestroy( prop ) curPowerUpProp = nil end function createPowerUpAnimation( x, y ) local powerUpProp = MOAIProp2D.new() powerUpProp:setDeck( powerUpGfx ) powerUpProp:setPriority( fxLayer ) powerUpProp:setLoc( x + POWERUP_X_OFFSET, y + POWERUP_Y_OFFSET ) powerUpProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE ) layer:insertProp( powerUpProp ) local powerUpAnim = MOAIAnim.new() powerUpAnim:reserveLinks( 1 ) powerUpAnim:setLink( 1, powerUpAnimCurve, powerUpProp, MOAIProp2D.ATTR_INDEX ) powerUpAnim:setMode( MOAITimer.NORMAL ) powerUpAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onPowerUpOver ) powerUpAnim:start() powerUpAnim["prop"] = powerUpProp return powerUpProp end matchActivateGfx = MOAITileDeck2D.new() matchActivateGfx:setTexture( MATCH_ACTIVATE_ANIM ) matchActivateGfx:setRect( 0, 0, TILE_SIZE, TILE_SIZE ) matchActivateGfx:setSize( 3, 3 ) matchActivateGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) local matchActivateAnimCurve = MOAIAnimCurve.new() matchActivateAnimCurve:reserveKeys( 10 ) for i = 1, 9 do matchActivateAnimCurve:setKey( i, (i - 1) * 0.033, i, MOAIEaseType.FLAT ) end matchActivateAnimCurve:setKey( 10, 9 * 0.033, 9, MOAIEaseType.FLAT ) function createMatchActivateAnimation( x, y ) local matchActivateProp = MOAIProp2D.new() matchActivateProp:setDeck( matchActivateGfx ) matchActivateProp:setPriority( fxLayer ) matchActivateProp:setLoc( x, y ) matchActivateProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE ) matchActivateProp:setColor( 1, 1, 1, 0.0 ) layer:insertProp( matchActivateProp ) local matchActivateAnim = MOAIAnim.new() matchActivateAnim:reserveLinks( 1 ) matchActivateAnim:setLink( 1, matchActivateAnimCurve, matchActivateProp, MOAIProp2D.ATTR_INDEX ) matchActivateAnim:setMode( MOAITimer.LOOP ) matchActivateAnim:start() return matchActivateProp end matchExpireGfx = MOAITileDeck2D.new() matchExpireGfx:setTexture( MATCH_ACTIVATE_EXPIRE ) matchExpireGfx:setRect( 0, 0, TILE_SIZE, TILE_SIZE ) matchExpireGfx:setSize( 3, 3 ) matchExpireGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) local matchExpireAnimCurve = MOAIAnimCurve.new() matchExpireAnimCurve:reserveKeys( 10 ) for i = 1, 9 do matchExpireAnimCurve:setKey( i, (i - 1) * 0.033, i, MOAIEaseType.FLAT ) end matchExpireAnimCurve:setKey( 10, 9 * 0.033, 9, MOAIEaseType.FLAT ) function createMatchExpireAnimation( x, y ) local matchExpireProp = MOAIProp2D.new() matchExpireProp:setDeck( matchExpireGfx ) matchExpireProp:setPriority( fxLayer ) matchExpireProp:setLoc( x, y ) matchExpireProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE ) matchExpireProp:setColor( 1, 1, 1, 0.0 ) layer:insertProp( matchExpireProp ) local matchExpireAnim = MOAIAnim.new() matchExpireAnim:reserveLinks( 1 ) matchExpireAnim:setLink( 1, matchExpireAnimCurve, matchExpireProp, MOAIProp2D.ATTR_INDEX ) matchExpireAnim:setMode( MOAITimer.LOOP ) matchExpireAnim:start() return matchExpireProp end gameOverGfx = MOAIGfxQuad2D.new() gameOverGfx:setTexture( GAME_OVER_IMAGE ) gameOverGfx:setRect( 0, 0, 580, 300 ) gameOverBack = nil uiLeft = MOAIGfxQuad2D.new() uiLeft:setTexture( GAMEPLAY_UI_LEFT ) uiLeft:setRect( 0, 0, 182, 544 ) uiLeft:setUVRect( 0, 0, 1, 1 ) uiRight = MOAIGfxQuad2D.new() uiRight:setTexture( GAMEPLAY_UI_RIGHT ) uiRight:setRect( 0, 0, 182, 544 ) uiRight:setUVRect( 0, 0, 1, 1 ) hudLeft = MOAIGfxQuad2D.new() hudLeft:setTexture( GAMEPLAY_HUD_LEFT ) hudLeft:setRect( 0, 0, 190, 544 ) hudLeft:setUVRect( 0, 0, 1, 1 ) hudRight = MOAIGfxQuad2D.new() hudRight:setTexture( GAMEPLAY_HUD_RIGHT ) hudRight:setRect( 0, 0, 195, 544 ) hudRight:setUVRect( 0, 0, 1, 1 ) bgGradient = MOAIGfxQuad2D.new() bgGradient:setTexture( GAMEPLAY_BG_GRADIENT ) bgGradient:setRect( 0, 0, 580, 1638 ) bgGradient:setUVRect( 0, 0, 1, 1 ) bgTrees1 = MOAIGfxQuad2D.new() bgTrees1:setTexture( GAMEPLAY_BG_TREES1 ) bgTrees1:setRect( 0, 0, 580, 370 ) bgTrees1:setUVRect( 0, 0, 1, 1 ) bgTrees2 = MOAIGfxQuad2D.new() bgTrees2:setTexture( GAMEPLAY_BG_TREES2 ) bgTrees2:setRect( 0, 0, 580, 391 ) bgTrees2:setUVRect( 0, 0, 1, 1 ) gameplayBGStarsProp = nil bgStarsTex = MOAITexture.new() bgStarsTex:load( GAMEPLAY_BG_STARS ) bgStarsTex:setWrap(true) bgStars = MOAIGfxQuad2D.new() bgStars:setTexture( bgStarsTex ) bgStars:setRect( 0, 0, 577, 524 ) bgStars:setUVRect( 0, 0, 1, 1 ) function loadBlockAsset( assetFilename ) local gfxObj = MOAIGfxQuad2D.new () gfxObj:setTexture( assetFilename ) gfxObj:setRect( 0, 0, TILE_SIZE, TILE_SIZE ) gfxObj:setUVRect ( 0, 0, 1, 1 ) return gfxObj end function loadBlockAssetNew( assetFilename ) local gfxTex = MOAITexture.new() gfxTex:setFilter( MOAITexture.GL_NEAREST ) gfxTex:load( assetFilename ) local gfxObj = MOAITileDeck2D.new() gfxObj:setTexture( gfxTex ) gfxObj:setRect( 0, 0, TILE_SIZE, TILE_SIZE ) gfxObj:setSize( 6, 3 ) gfxObj:setUVRect( -0.5, 0.5, 0.5, -0.5 ) return gfxObj end local blockDeathAnimCurve = MOAIAnimCurve.new() blockDeathAnimCurve:reserveKeys( 9 ) blockDeathAnimCurve:setKey( 1, 0.05, 1, MOAIEaseType.FLAT ) blockDeathAnimCurve:setKey( 2, 0.1, 2, MOAIEaseType.FLAT ) blockDeathAnimCurve:setKey( 3, 0.15, 3, MOAIEaseType.FLAT ) blockDeathAnimCurve:setKey( 4, 0.20, 4, MOAIEaseType.FLAT ) blockDeathAnimCurve:setKey( 5, 0.25, 5, MOAIEaseType.FLAT ) blockDeathAnimCurve:setKey( 6, 0.30, 6, MOAIEaseType.FLAT ) blockDeathAnimCurve:setKey( 7, 0.35, 7, MOAIEaseType.FLAT ) blockDeathAnimCurve:setKey( 8, 0.4, 8, MOAIEaseType.FLAT ) blockDeathAnimCurve:setKey( 9, 0.45, 8, MOAIEaseType.FLAT ) function loadBlockDeathAsset( assetFilename ) local gfxObj = MOAITileDeck2D.new () gfxObj:setTexture( assetFilename ) gfxObj:setSize( 8, 1 ) gfxObj:setRect( 0, 0, TILE_SIZE, TILE_SIZE ) gfxObj:setUVRect( -0.5, 0.5, 0.5, -0.5 ) return gfxObj end function onBlockDeathOver( anim ) anim:stop() local prop = anim["prop"] layer:removeProp( prop ) spriteDestroy( prop ) end function createBlockDeathAnimation( propGfx, x, y ) local blockExplosionProp = MOAIProp2D.new() blockExplosionProp:setDeck( propGfx ) blockExplosionProp:setPriority( fxLayer ) blockExplosionProp:setLoc( x, y ) layer:insertProp( blockExplosionProp ) local blockDeathAnim = MOAIAnim.new() blockDeathAnim:reserveLinks( 1 ) blockDeathAnim:setLink( 1, blockDeathAnimCurve, blockExplosionProp, MOAIProp2D.ATTR_INDEX ) blockDeathAnim:setMode( MOAITimer.NORMAL ) blockDeathAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onBlockDeathOver ) blockDeathAnim:start() blockDeathAnim["prop"] = blockExplosionProp end gameplayCurTime = MOAISim.getCurrentTime() earthBlocks = {} earthBlocks[BLOCK_EARTH_RED] = loadBlockAssetNew( BLOCK_EARTH_RED ) earthBlocks[BLOCK_EARTH_GREEN] = loadBlockAssetNew( BLOCK_EARTH_GREEN ) earthBlocks[BLOCK_EARTH_BLUE] = loadBlockAssetNew( BLOCK_EARTH_BLUE ) earthBlocks[BLOCK_EARTH_YELLOW] = loadBlockAssetNew( BLOCK_EARTH_YELLOW ) earthBlockDeaths = {} earthBlockDeaths[earthBlocks[BLOCK_EARTH_RED]] = loadBlockDeathAsset( BLOCK_EARTH_RED_DEATH ) earthBlockDeaths[earthBlocks[BLOCK_EARTH_GREEN]] = loadBlockDeathAsset( BLOCK_EARTH_GREEN_DEATH ) earthBlockDeaths[earthBlocks[BLOCK_EARTH_BLUE]] = loadBlockDeathAsset( BLOCK_EARTH_BLUE_DEATH ) earthBlockDeaths[earthBlocks[BLOCK_EARTH_YELLOW]] = loadBlockDeathAsset( BLOCK_EARTH_YELLOW_DEATH ) gemBlocks = {} gemBlocks[BLOCK_GEM_RED] = loadBlockAsset( BLOCK_GEM_RED ) gemBlocks[BLOCK_GEM_GREEN] = loadBlockAsset( BLOCK_GEM_GREEN ) gemBlocks[BLOCK_GEM_BLUE] = loadBlockAsset( BLOCK_GEM_BLUE ) stoneBlockGfx = loadBlockAsset( BLOCK_STONE ) bbqBlockGfx = loadBlockAsset( BLOCK_BBQ ) bbqSmokeGfx = MOAITileDeck2D.new() bbqSmokeGfx:setTexture( BBQ_SMOKE ) bbqSmokeGfx:setRect( 0, 0, 60, 60 ) bbqSmokeGfx:setSize( 4, 4 ) bbqSmokeGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) local bbqSmokeAnimCurve = MOAIAnimCurve.new() bbqSmokeAnimCurve:reserveKeys( 17 ) for i = 1, 16 do bbqSmokeAnimCurve:setKey( i, (i - 1) * 0.033, i, MOAIEaseType.FLAT ) end bbqSmokeAnimCurve:setKey( 17, 16 * 0.033, 16, MOAIEaseType.FLAT ) -- TODO: Move BBQ function -- Destroy BBQ function function createBBQSmokeProp( x, y ) local bbqSmokeProp = MOAIProp2D.new() bbqSmokeProp:setDeck( bbqSmokeGfx ) bbqSmokeProp:setPriority( fxLayer ) bbqSmokeProp:setLoc( x, y ) layer:insertProp( bbqSmokeProp ) local bbqSmokeAnim = MOAIAnim.new() bbqSmokeAnim:reserveLinks( 1 ) bbqSmokeAnim:setLink( 1, bbqSmokeAnimCurve, bbqSmokeProp, MOAIProp2D.ATTR_INDEX ) bbqSmokeAnim:setMode( MOAITimer.LOOP ) bbqSmokeAnim:start() bbqSmokeProp["anim"] = bbqSmokeAnim return bbqSmokeProp end function onBlockShrinkOver( anim ) anim:stop() local prop = anim["prop"] layer:removeProp( prop ) spriteDestroy( prop ) end function createWhiteShrinkAnimation( x, y ) local whiteBlock = MOAIProp2D.new() whiteBlock:setDeck( glomOverGfx ) whiteBlock:setPriority( fxLayer ) whiteBlock:setLoc( x + (TILE_SIZE * 0.5), y + (TILE_SIZE * 0.5) ) layer:insertProp( whiteBlock ) local shrinkAnim = whiteBlock:moveScl( -1, -1, 0.15, MOAIEaseType.LINEAR ) shrinkAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onBlockShrinkOver ) shrinkAnim["prop"] = whiteBlock end burgerBlockGfx = loadBlockAsset( BLOCK_BURGER ) gemIndexMapper = {} gemIndexMapper[gemBlocks[BLOCK_GEM_RED]] = 1 gemIndexMapper[gemBlocks[BLOCK_GEM_GREEN]] = 2 gemIndexMapper[gemBlocks[BLOCK_GEM_BLUE]] = 3 bbqBlockInPlay = false gemToEarthBlockMapper = {} gemToEarthBlockMapper[gemBlocks[BLOCK_GEM_RED]] = earthBlocks[BLOCK_EARTH_RED] gemToEarthBlockMapper[gemBlocks[BLOCK_GEM_GREEN]] = earthBlocks[BLOCK_EARTH_GREEN] gemToEarthBlockMapper[gemBlocks[BLOCK_GEM_BLUE]] = earthBlocks[BLOCK_EARTH_BLUE] glomOverGfx = loadBlockAsset( GLOM_OVER_IMAGE ) glomOverGfx:setRect( -TILE_SIZE * 0.5, -TILE_SIZE * 0.5, TILE_SIZE * 0.5, TILE_SIZE * 0.5 ) barShineGfx = MOAIGfxQuad2D.new() barShineGfx:setTexture( BUFF_BAR_SHINE ) barShineGfx:setRect( 0, 0, 11, 132 ) barShineProp = nil barGoopTopGfx = MOAIGfxQuad2D.new() barGoopTopGfx:setTexture( BUFF_BAR_GOOP_TOP ) barGoopTopGfx:setRect( 0, 0, 62, 10 ) barGoopTopProp = nil barGreenGfx = MOAIGfxQuad2D.new() barGreenGfx:setTexture( BUFF_BAR_GREEN ) barGreenGfx:setRect( 0, 0, 4, 4 ) barGreenProp = nil barGlowGfx = MOAIGfxQuad2D.new() barGlowGfx:setTexture( BUFF_BAR_GLOW ) barGlowGfx:setRect( 0, 0, 63, 151 ) barGlowProp = nil barGlowAnim = nil function updateMatchUI( percent ) barGreenGfx:setRect( 0, 0, 61, -percent * 158 ) barShineGfx:setRect( 0, 0, 11, -percent * 132 ) barGlowGfx:setRect( 0, 0, 63, -percent * 158 ) if barGoopTopProp ~= nil then barGoopTopProp:setLoc( 794, 185 - (percent * 158) ) end if MOAIEnvironment.osBrand == "PSM" then -- weird UV height needs to be inverted here if barGreenProp ~= nil then barGreenProp:updateUVs() barShineProp:updateUVs() barGlowProp:updateUVs() end end end updateMatchUI( 0 ) buffBlockCounter = {} buffBlockCounter[gemBlocks[BLOCK_GEM_RED]] = 0 buffBlockCounter[gemBlocks[BLOCK_GEM_GREEN]] = 0 buffBlockCounter[gemBlocks[BLOCK_GEM_BLUE]] = 0 -- Helper stuff if MOAIEnvironment.osBrand == "PSM" then function spriteDestroy(sprite) -- print( "Destroying: " .. tostring(#sprite.timers) .. " timers" ) for i,v in ipairs(sprite.timers) do v:stop() end MOAIAnim:stopAnimWithProp(sprite) MOAIPSM.destroySprite(sprite.spriteID, sprite.spriteUniqueID) end else function spriteDestroy(sprite) end end function createPortraitGfx( filename ) local characterPortraitGfx = MOAIGfxQuad2D.new() characterPortraitGfx:setTexture( filename ) characterPortraitGfx:setRect( 0, 0, 219, 192 ) characterPortraitGfx:setUVRect ( 0, 0, 1, 1 ) return characterPortraitGfx end function isGem( blockGfx ) return gemToEarthBlockMapper[blockGfx] ~= nil end dofile("helpers.lua") function unshake( block ) MOAISim.wobbleBlock( block[1].spriteID, block[1].spriteUniqueID, 0 ) end function removeBlock( x, y, shouldExplode ) if shouldExplode == nil then shouldExplode = true end local currentBlock = currentBlocks[y][x] if currentBlock[2] == bbqBlockGfx then bbqBlockInPlay = false end currentBlocks[y][x] = nil local locX, locY = currentBlock[1]:getLoc() local earthBlockDeathGfx = earthBlockDeaths[currentBlock[2]] if earthBlockDeathGfx ~= nil then createBlockDeathAnimation( earthBlockDeathGfx, locX, locY ) elseif currentBlock[2] == bbqBlockGfx and shouldExplode then createBBQDeathAnimation( locX, locY ) elseif currentBlock[2] == stoneBlockGfx then createSmokePuffAnimation( locX, locY ) elseif shouldExplode then createWhiteShrinkAnimation( locX, locY ) end if currentBlock[2] == bbqBlockGfx and currentBlock["smoke"] then currentBlock["smoke"]["anim"]:stop() layer:removeProp( currentBlock["smoke"] ) spriteDestroy( currentBlock["smoke"] ) end unshake( currentBlock ) layer:removeProp( currentBlock[1] ) spriteDestroy( currentBlock[1] ) destroyGlomOver( currentBlock ) end function blockIsFalling( block ) return block['falling'] == 1 or block['xVel'] ~= nil end function setCharacterLoc( x, y ) if GAMEPLAY_STATE ~= GAMEPLAY_STATE_DYING then characterLocation[1] = x characterLocation[2] = y characterProp:setLoc( x + CHARACTER_X_OFFSET, y + CURRENT_CHARACTER["CHARACTER_Y_OFFSET"] ) if curPowerUpProp ~= nil then curPowerUpProp:setLoc( x + POWERUP_X_OFFSET, y + POWERUP_Y_OFFSET ) end end end function addCharacterLoc( x, y ) setCharacterLoc( characterLocation[1] + x, characterLocation[2] + y ) end local COLLECT_DIR_LEFT = 0 local COLLECT_DIR_UP = 1 local COLLECT_DIR_RIGHT = 2 local COLLECT_DIR_DOWN = 3 local COLLECT_DIR_ALL = -1 function collectConnectedBlocks( collection, allBlocks, blockType, x, y, dir ) if x < 0 or x >= BLOCKS_GRID_WIDTH or y < 0 or y >= BLOCKS_GRID_HEIGHT then return end local currentBlock = allBlocks[y][x] if currentBlock ~= nil and collection[currentBlock] == nil then local currentBlockType = currentBlock[2] if currentBlockType == blockType then collection[currentBlock] = {x, y, currentBlock}; if dir == COLLECT_DIR_LEFT then -- came from the left, so look left, up, and down collectConnectedBlocks( collection, allBlocks, blockType, x-1, y, COLLECT_DIR_LEFT ) collectConnectedBlocks( collection, allBlocks, blockType, x, y-1, COLLECT_DIR_UP ) collectConnectedBlocks( collection, allBlocks, blockType, x, y+1, COLLECT_DIR_DOWN ) elseif dir == COLLECT_DIR_UP then collectConnectedBlocks( collection, allBlocks, blockType, x-1, y, COLLECT_DIR_LEFT ) collectConnectedBlocks( collection, allBlocks, blockType, x+1, y, COLLECT_DIR_RIGHT ) collectConnectedBlocks( collection, allBlocks, blockType, x, y-1, COLLECT_DIR_UP ) elseif dir == COLLECT_DIR_RIGHT then collectConnectedBlocks( collection, allBlocks, blockType, x+1, y, COLLECT_DIR_RIGHT ) collectConnectedBlocks( collection, allBlocks, blockType, x, y-1, COLLECT_DIR_UP ) collectConnectedBlocks( collection, allBlocks, blockType, x, y+1, COLLECT_DIR_DOWN ) elseif dir == COLLECT_DIR_DOWN then collectConnectedBlocks( collection, allBlocks, blockType, x-1, y, COLLECT_DIR_LEFT ) collectConnectedBlocks( collection, allBlocks, blockType, x+1, y, COLLECT_DIR_RIGHT ) collectConnectedBlocks( collection, allBlocks, blockType, x, y+1, COLLECT_DIR_DOWN ) else collectConnectedBlocks( collection, allBlocks, blockType, x-1, y, COLLECT_DIR_LEFT ) collectConnectedBlocks( collection, allBlocks, blockType, x+1, y, COLLECT_DIR_RIGHT ) collectConnectedBlocks( collection, allBlocks, blockType, x, y+1, COLLECT_DIR_DOWN ) collectConnectedBlocks( collection, allBlocks, blockType, x, y-1, COLLECT_DIR_UP ) end end end end function canDigBlock( blockGfx ) return not isGem(blockGfx) and (blockGfx ~= stoneBlockGfx or GREEN_BUFF_ACTIVE) end function spawnBurger( locX, locY, currentBlocksL ) local burgerProp = MOAIProp2D.new() burgerProp:setDeck( burgerBlockGfx ) burgerProp:setLoc( (GRID_OFFSET_X + (locX * TILE_SIZE)), (GRID_OFFSET_Y + (locY * TILE_SIZE)) ) burgerProp:setPriority( 10 ) layer:insertProp( burgerProp ) currentBlocksL[locY][locX] = { burgerProp, burgerBlockGfx } createSmokePuffAnimation( (GRID_OFFSET_X + (locX * TILE_SIZE)), (GRID_OFFSET_Y + (locY * TILE_SIZE)) ) end function performDigDown() local x, y = characterLocation[1], characterLocation[2] -- This sucks :( local blockBelow1 = getBlock( x, y + 1, -0.5 ) local blockBelow2 = getBlock( x, y + 1, -0.11 ) local blockBelow3 = getBlock( x, y + 1, -0.89 ) local blockBelow = blockBelow1 or blockBelow2 or blockBelow3 if blockBelow ~= nil and (blockBelow[2] ~= stoneBlockGfx or GREEN_BUFF_ACTIVE) then local offset = -0.5 if blockBelow == blockBelow2 then offset = -0.11 elseif blockBelow == blockBelow3 then offset = -0.89 end local blockLocX, blockLocY = worldSpaceToBlockSpace( x, y + 1, offset ) if canDigBlock( blockBelow[2] ) and blockBelow[2] ~= bbqBlockGfx then -- find all connecting blocks of the same type collection = {} collectConnectedBlocks( collection, currentBlocks, blockBelow[2], blockLocX, blockLocY, COLLECT_DIR_DOWN ) SFX["EARTH_DESTROY"]:play() local numBlocks = 0 for key, blockData in pairs(collection) do removeBlock( blockData[1], blockData[2] ) if blockData[3][2] == stoneBlockGfx then spawnBurger( blockData[1], blockData[2], currentBlocks ) end numBlocks = numBlocks + 1 end displayPointsAward( numBlocks * EARTH_BLOCK_SCORE_MODIFIER, false ) elseif blockBelow["timeToRemove"] == nil then local resultY = 0 for searchY = 0, blockLocY - 1 do local actualSearchY = blockLocY - 1 - searchY local searchBlock = currentBlocks[actualSearchY][blockLocX] if searchBlock ~= nil or searchY >= CURRENT_CHARACTER["BLOCK_FLIP_MAX_HEIGHT"] then resultY = actualSearchY+1 break end end if resultY >= 0 and blockLocY ~= resultY then SFX["SCOOP"]:play() -- swap setCharacterLoc( GRID_OFFSET_X + (blockLocX * TILE_SIZE), GRID_OFFSET_Y + (blockLocY * TILE_SIZE) ) currentBlocks[resultY][blockLocX] = blockBelow currentBlocks[blockLocY][blockLocX] = nil blockBelow['yVel'] = -10 end end end if blockBelow ~= nil and blockBelow[2] == stoneBlockGfx then SFX["NO_MOVE"]:play() elseif blockBelow == nil then SFX["SPATULA_AIRTIME"][math.random( 1, #SFX["SPATULA_AIRTIME"] )]:play() -- magic Karl code end end function createSmackStars( locX, locY ) local xOffset = TILE_SIZE if characterFacingRight then xOffset = -TILE_SIZE end locY = locY + (TILE_SIZE * 0.35) createStarAnimation( locX - xOffset, locY, xOffset, TILE_SIZE * 0.5 ) createStarAnimation( locX - xOffset, locY, xOffset, 0 ) createStarAnimation( locX - xOffset, locY, xOffset, -TILE_SIZE * 0.5 ) end function performDig() local x, y = characterLocation[1], characterLocation[2] local xBlockOffset = 0 local yBlockOffset = 0.5 if characterFacingRight then -- print( "Digging to the right!" ) xBlockOffset = 0.5 else -- print( "Digging to the left!" ) xBlockOffset = -1.5 end local searchTable = { { 0, 0 }, { -SMACK_WIDTH, -SMACK_HEIGHT }, { 0, -SMACK_HEIGHT }, { SMACK_WIDTH, -SMACK_HEIGHT }, { -SMACK_WIDTH, 0 }, { SMACK_WIDTH, 0 }, { -SMACK_WIDTH, SMACK_HEIGHT }, { 0, SMACK_HEIGHT }, { SMACK_WIDTH, SMACK_HEIGHT } } local xOffset = 0 local yOffset = 0 local blockBeside = nil for k, v in pairs(searchTable) do xOffset = v[1] yOffset = v[2] blockBeside = getBlock( x, y, xBlockOffset + xOffset, yOffset - yBlockOffset ) if blockBeside ~= nil then break end end if blockBeside ~= nil and blockBeside[2] ~= burgerBlockGfx then if blockBeside[2] == bbqBlockGfx then blockBeside['willExplode'] = nil end local blockLocX, blockLocY = worldSpaceToBlockSpace( x, y, xBlockOffset + xOffset, yOffset - yBlockOffset ) -- print( "Matching X offset: " .. tostring(xOffset) .. " Y offset: " .. tostring(yOffset) .. " xBlockOffset: " .. tostring(xBlockOffset) ) local collectDirection = COLLECT_DIR_LEFT if xBlockOffset > 0 then collectDirection = COLLECT_DIR_RIGHT end if isGem(blockBeside[2]) or blockBeside[2] == bbqBlockGfx then -- easy way to test if it is a gem SFX["SMACK"]:play() if blockBeside["timeToRemove"] ~= nil or (blockBeside['xVel'] ~= nil and blockBeside['xVel'] ~= 0) then return end -- smack to the other side instead of destroying local charLocX, charLocY = worldSpaceToBlockSpace( x, y, 0 ) if characterFacingRight then if blockLocX < BLOCKS_GRID_WIDTH-1 and currentBlocks[blockLocY][blockLocX+1] == nil then unshake( blockBeside ) blockBeside['xVel'] = BLOCK_HORIZONTAL_ACCELERATION createSmackStars( x, y ) elseif blockLocX == BLOCKS_GRID_WIDTH-1 or currentBlocks[blockLocY][blockLocX+1] ~= nil and (not characterFalling and not (blockBeside['yVel'] ~= nil and blockBeside['yVel'] ~= 0 ) or currentBlocks[blockLocY][blockLocX+1][2] == bbqBlockGfx ) then if currentBlocks[blockLocY][blockLocX+1] ~= nil and currentBlocks[blockLocY][blockLocX+1][2] == bbqBlockGfx then createSmackStars( x, y ) bbqBlockConsume(blockLocX, blockLocY, blockLocX+1, blockLocY, blockBeside, currentBlocks[blockLocY][blockLocX+1]) elseif currentBlocks[blockLocY][blockLocX-1] == nil and not (blockLocX == BLOCKS_GRID_WIDTH-1 and characterFalling) then currentBlocks[blockLocY][blockLocX-1] = blockBeside currentBlocks[blockLocY][blockLocX] = nil unshake( blockBeside ) blockBeside[1]:moveLoc( -TILE_SIZE, 0 ) moveGlomOver( blockBeside, -TILE_SIZE, 0 ) if blockBeside["smoke"] ~= nil then blockBeside["smoke"]:moveLoc( -TILE_SIZE, 0 ) end setCharacterLoc( GRID_OFFSET_X + blockLocX*TILE_SIZE, GRID_OFFSET_Y + blockLocY*TILE_SIZE ) end end else if blockLocX > 0 and currentBlocks[blockLocY][blockLocX-1] == nil then unshake( blockBeside ) blockBeside['xVel'] = -BLOCK_HORIZONTAL_ACCELERATION createSmackStars( x, y ) elseif blockLocX == 0 or currentBlocks[blockLocY][blockLocX-1] ~= nil and (not characterFalling and not (blockBeside['yVel'] ~= nil and blockBeside['yVel'] ~= 0 ) or currentBlocks[blockLocY][blockLocX-1][2] == bbqBlockGfx ) then if currentBlocks[blockLocY][blockLocX-1] ~= nil and currentBlocks[blockLocY][blockLocX-1][2] == bbqBlockGfx then createSmackStars( x, y ) bbqBlockConsume(blockLocX, blockLocY, blockLocX-1, blockLocY, blockBeside, currentBlocks[blockLocY][blockLocX-1]) elseif currentBlocks[blockLocY][blockLocX+1] == nil and not (blockLocX == 0 and characterFalling) then currentBlocks[blockLocY][blockLocX+1] = blockBeside currentBlocks[blockLocY][blockLocX] = nil unshake( blockBeside ) blockBeside[1]:moveLoc( TILE_SIZE, 0 ) moveGlomOver( blockBeside, TILE_SIZE, 0 ) if blockBeside["smoke"] ~= nil then blockBeside["smoke"]:moveLoc( TILE_SIZE, 0 ) end setCharacterLoc( GRID_OFFSET_X + blockLocX*TILE_SIZE, GRID_OFFSET_Y + blockLocY*TILE_SIZE ) end end end elseif blockBeside[2] ~= stoneBlockGfx or GREEN_BUFF_ACTIVE then -- find all connecting blocks of the same type collection = {} collectConnectedBlocks( collection, currentBlocks, blockBeside[2], blockLocX, blockLocY, collectDirection ) SFX["EARTH_DESTROY"]:play() local numBlocks = 0 for key, blockData in pairs(collection) do removeBlock( blockData[1], blockData[2] ) if blockData[3][2] == stoneBlockGfx then spawnBurger( blockData[1], blockData[2], currentBlocks ) end numBlocks = numBlocks + 1 end displayPointsAward( numBlocks * EARTH_BLOCK_SCORE_MODIFIER, false ) end end if blockBeside ~= nil and blockBeside[2] == stoneBlockGfx and not GREEN_BUFF_ACTIVE then SFX["NO_MOVE"]:play() elseif blockBeside == nil then SFX["SPATULA_AIRTIME"][math.random( 1, #SFX["SPATULA_AIRTIME"] )]:play() -- magic Karl code end end function generateRandomBlock() local blockGfx = nil local randomNum = math.random( 0, 100 ) if randomNum < 1 and not bbqBlockInPlay and activeLevel >= MIN_BBQ_LEVEL then blockGfx = bbqBlockGfx bbqBlockInPlay = true elseif randomNum < 39 then blockGfx = nil elseif randomNum < 49 then blockGfx = earthBlocks[BLOCK_EARTH_RED] elseif randomNum < 60 then blockGfx = earthBlocks[BLOCK_EARTH_GREEN] elseif randomNum < 70 then blockGfx = earthBlocks[BLOCK_EARTH_BLUE] elseif randomNum < 80 then blockGfx = earthBlocks[BLOCK_EARTH_YELLOW] elseif randomNum < 86 then blockGfx = gemBlocks[BLOCK_GEM_RED] elseif randomNum < 91 then blockGfx = gemBlocks[BLOCK_GEM_GREEN] elseif randomNum < 96 then blockGfx = gemBlocks[BLOCK_GEM_BLUE] else blockGfx = stoneBlockGfx end return blockGfx end function fillRowOfBlocks( rowToFill, rowNum, yOffset ) local rowWidthL = BLOCKS_GRID_WIDTH-1 local GRID_OFFSET_X_L = GRID_OFFSET_X local TILE_SIZE_L = TILE_SIZE local GRID_OFFSET_Y_L = GRID_OFFSET_Y for x = 0, rowWidthL do local blockGfx = generateRandomBlock() if x > 0 and isGem(blockGfx) then while isGem(blockGfx) and rowToFill[x-1] ~= nil and isGem(rowToFill[x-1][2]) do blockGfx = generateRandomBlock() end end if blockGfx ~= nil then propObj = MOAIProp2D.new () propObj:setDeck ( blockGfx ) propObj:setLoc ( (GRID_OFFSET_X_L + x * TILE_SIZE_L) , yOffset + GRID_OFFSET_Y_L + (rowNum * TILE_SIZE_L) ) propObj:setPriority( 10 ) layer:insertProp ( propObj ) if earthBlockDeaths[blockGfx] ~= nil then propObj:setIndex( 8 ) end local blockToAdd = { propObj, blockGfx, debugText } rowToFill[x] = blockToAdd blockToAdd['yVel'] = 0 if blockGfx == bbqBlockGfx then blockToAdd["blocksEaten"] = { 0, 0, 0 } end else rowToFill[x] = nil end end local currentBlocksL = currentBlocks local rowWidthH = BLOCKS_GRID_HEIGHT-1 for x = 0, rowWidthL do if rowToFill[x] ~= nil then glomGfxUpdate( currentBlocksL, rowWidthL, rowWidthH, x, rowNum, rowToFill[x], true ) end end end function destroyColumn( x ) for y = 0, BLOCKS_GRID_HEIGHT-1 do local currentBlock = currentBlocks[y][x] if currentBlock ~= nil then removeBlock( x, y ) end end end function createCharacterAnim( animTimes, index, isLeft, loopType ) local animTimesLen = #animTimes local animCurve = MOAIAnimCurve.new() animCurve:reserveKeys( animTimesLen + 1 ) local actualIndex = index if isLeft then actualIndex = actualIndex + animTimesLen end -- Due to the way things work in Moai, -- the first frame should start at 0.0, then -- subsequent frames are off by the previous -- then the last frame is duplicated local firstFrame = animTimes[1] animCurve:setKey( 1, 0.0, actualIndex ) local currentTime = 0.0 --print( "animCurve:setKey( 1, 0.0, " .. tostring(actualIndex) .. ")" ) for i, v in ipairs( animTimes ) do if i > 0 and i < animTimesLen then animCurve:setKey( i+1, v + currentTime, i+actualIndex-1 ) --print( "animCurve:setKey( " .. tostring(i+1) .. ", " .. tostring(v + currentTime) .. ", " .. tostring(i+actualIndex) .. ")" ) currentTime = currentTime + v end end local lastTime = animTimes[animTimesLen] animCurve:setKey( animTimesLen + 1, currentTime + lastTime, actualIndex + animTimesLen - 1 ) --print( "animCurve:setKey( " .. tostring(animTimesLen + 1) .. ", " .. tostring(currentTime + firstFrame) .. ", " .. tostring(actualIndex + animTimesLen - 1) .. ")" ) local characterAnimToReturn = MOAIAnim.new() characterAnimToReturn:reserveLinks( 1 ) characterAnimToReturn:setLink( 1, animCurve, characterProp, MOAIProp2D.ATTR_INDEX ) characterAnimToReturn:setMode( loopType ) return characterAnimToReturn end function onDigEnd() characterSmackL:stop() characterSmackR:stop() characterDigAnim:stop() setCharacterState( CHARACTER_STATE ) end function initialize() -- for i = 3, 20 do -- print( awardPointsForBlocks( i ) ) -- end -- levelingUnitTests() characterLockState = {} for k, v in pairs( CHARACTER_LIST ) do characterLockState[k] = isCharacterLocked( v ) end sessionMaxMatch = CURRENT_MAX_MATCH local maxStartHeight = BLOCKS_GRID_HEIGHT - INITIAL_NUM_ROWS bbqBlockInPlay = false buffMatchCounter = 0.0 buffBlockCounter[gemBlocks[BLOCK_GEM_RED]] = 0 buffBlockCounter[gemBlocks[BLOCK_GEM_GREEN]] = 0 buffBlockCounter[gemBlocks[BLOCK_GEM_BLUE]] = 0 characterSheet = MOAITileDeck2D.new() characterSheet:setTexture( CURRENT_CHARACTER["IMAGE"] ) characterSheet:setSize( CURRENT_CHARACTER["SPRITESHEET_WIDTH"], CURRENT_CHARACTER["SPRITESHEET_HEIGHT"] ) if MOAIEnvironment.osBrand == "PSM" then characterSheet:setRect( 0, 0, CHARACTER_SIZE, CHARACTER_SIZE ) else characterSheet:setRect( 0, CHARACTER_SIZE, CHARACTER_SIZE, 0 ) end hitsRemaining = CURRENT_CHARACTER["MAX_HITS"] activeLevel = CURRENT_LEVEL burgersMatchCount = 0 GAMEPLAY_STATE = GAMEPLAY_STATE_ACTIVE characterProp = nil characterXVelocity = 0 characterYVelocity = 0 characterFacingRight = true characterHoldingDown = false characterFalling = true characterProp = MOAIProp2D.new() characterProp:setDeck( characterSheet ) setCharacterLoc( GRID_OFFSET_X, GRID_OFFSET_Y ) characterProp:setPriority( 11 ) layer:insertProp( characterProp ) local characterAnims = CURRENT_CHARACTER["ANIMS"] local animIdle = characterAnims["IDLE"] characterIdleR = createCharacterAnim( animIdle["TIMES"], animIdle["INDEX"], false, MOAITimer.LOOP ) characterIdleL = createCharacterAnim( animIdle["TIMES"], animIdle["INDEX"], true, MOAITimer.LOOP ) local animJump = characterAnims["JUMP"] characterJumpR = createCharacterAnim( animJump["TIMES"], animJump["INDEX"], false, MOAITimer.NORMAL ) characterJumpL = createCharacterAnim( animJump["TIMES"], animJump["INDEX"], true, MOAITimer.NORMAL ) local animFall = characterAnims["FALL"] characterFallR = createCharacterAnim( animFall["TIMES"], animFall["INDEX"], false, MOAITimer.NORMAL ) characterFallL = createCharacterAnim( animFall["TIMES"], animFall["INDEX"], true, MOAITimer.NORMAL ) local animWalk = characterAnims["WALK"] characterWalkR = createCharacterAnim( animWalk["TIMES"], animWalk["INDEX"], false, MOAITimer.LOOP ) characterWalkL = createCharacterAnim( animWalk["TIMES"], animWalk["INDEX"], true, MOAITimer.LOOP ) local animSmack = characterAnims["SMACK"] characterSmackR = createCharacterAnim( animSmack["TIMES"], animSmack["INDEX"], false, MOAITimer.NORMAL ) characterSmackL = createCharacterAnim( animSmack["TIMES"], animSmack["INDEX"], true, MOAITimer.NORMAL ) local animDeath = characterAnims["DEATH"] characterDeathR = createCharacterAnim( animDeath["TIMES"], animDeath["INDEX"], false, MOAITimer.NORMAL ) characterDeathL = createCharacterAnim( animDeath["TIMES"], animDeath["INDEX"], true, MOAITimer.NORMAL ) local animDig = characterAnims["DIG"] characterDigAnim = createCharacterAnim( animDig["TIMES"], animDig["INDEX"], false, MOAITimer.NORMAL ) local downAnimCurve = MOAIAnimCurve.new() downAnimCurve:reserveKeys( 2 ) downAnimCurve:setKey( 1, 0.0, CURRENT_CHARACTER["DOWN_FRAME"] ) downAnimCurve:setKey( 2, 0.1, CURRENT_CHARACTER["DOWN_FRAME"] ) characterDown = MOAIAnim.new() characterDown:reserveLinks( 1 ) characterDown:setLink( 1, downAnimCurve, characterProp, MOAIProp2D.ATTR_INDEX ) characterDown:setMode( MOAITimer.LOOP ) characterSmackL:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onDigEnd ) characterSmackR:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onDigEnd ) characterDigAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onDigEnd ) characterDeathL:setListener( MOAITimer.EVENT_TIMER_END_SPAN, showGameOver ) characterDeathR:setListener( MOAITimer.EVENT_TIMER_END_SPAN, showGameOver ) scoreText = MOAITextBox.new () scoreText:setFont ( font ) scoreText:setRect ( 0, 0, 240, 40 ) scoreText:setLoc ( 40 - 120, 70 ) scoreText:setAlignment ( MOAITextBox.RIGHT_JUSTIFY ) layer:insertProp ( scoreText ) scoreText:setColor ( 1, 1, 1, 1 ) scoreText:setPriority( uiLayer ) levelText = MOAITextBox.new () levelText:setFont ( font ) levelText:setRect ( 0, 0, 240, 40 ) levelText:setLoc( 40 - 120, 170 ) levelText:setAlignment ( MOAITextBox.RIGHT_JUSTIFY ) layer:insertProp ( levelText ) levelText:setColor ( 1, 1, 1, 1 ) levelText:setPriority( uiLayer ) levelText:setString( tostring(activeLevel+1) ) burgersMatchedText = MOAITextBox.new () burgersMatchedText:setFont ( font ) burgersMatchedText:setRect ( 0, 0, 240, 40 ) burgersMatchedText:setLoc( 40 - 120, 300 ) burgersMatchedText:setAlignment ( MOAITextBox.RIGHT_JUSTIFY ) layer:insertProp ( burgersMatchedText ) burgersMatchedText:setColor ( 1, 1, 1, 1 ) burgersMatchedText:setPriority( uiLayer ) burgersMatchedText:setString( "0" ) scoreUpdateText = {} for i = 1, MAX_SCORE_UPDATES do local curScoreUpdateText = MOAITextBox.new () curScoreUpdateText:setFont ( font ) curScoreUpdateText:setRect ( 0, 0, 240, 40 ) curScoreUpdateText:setLoc( 190, 60 + (i-1)*35 ) curScoreUpdateText:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) curScoreUpdateText:setColor ( 1, 1, 1, 1 ) curScoreUpdateText:setPriority( uiLayer ) MOAIPSM.setTextBoxShadow( curScoreUpdateText.textBoxID ) scoreUpdateText[i] = curScoreUpdateText end scoreUpdateTextIdx = 0 scoreUpdateTextIdxs = {} scoreKickers = {} for i = 1, MAX_SCORE_UPDATES do local curScoreKickerText = MOAITextBox.new () curScoreKickerText:setFont ( font ) curScoreKickerText:setRect ( 0, 0, 240, 40 ) curScoreKickerText:setLoc( 0, 0 ) curScoreKickerText:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) curScoreKickerText:setColor ( 0.91, 0.96, 0.96, 1 ) curScoreKickerText:setPriority( uiLayer ) scoreKickers[i] = curScoreKickerText end scoreKickerIdx = 0 scoreKickersIdxs = {} gameOverText = {} for i = 1, 2 do local curGameOverText = MOAITextBox.new () curGameOverText:setFont ( font ) curGameOverText:setRect ( 0, 0, 240, 40 ) curGameOverText:setLoc( 0, 0 ) curGameOverText:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) curGameOverText:setColor ( 0.41, 0.95, 0.07, 1 ) curGameOverText:setPriority( uiLayer+1 ) gameOverText[i] = curGameOverText end gameOverTextIdx = 0 gameOverProps = {} for i = 1, 2 do local curGameOverProp = MOAIProp2D.new () curGameOverProp:setLoc( 0, 0 ) curGameOverProp:setPriority( uiLayer ) curGameOverProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) gameOverProps[i] = curGameOverProp end gameOverPropIdx = 1 buffActiveText = MOAITextBox.new () buffActiveText:setFont ( font ) buffActiveText:setRect ( 0, 0, 300, 40 ) buffActiveText:setLoc( 190, 100 ) buffActiveText:setAlignment ( MOAITextBox.LEFT_JUSTIFY ) buffActiveText:setColor ( 1, 1, 1, 1 ) buffActiveText:setPriority( uiLayer ) MOAIPSM.setTextBoxShadow( buffActiveText.textBoxID ) messageText = MOAITextBox.new () messageText:setFont ( font ) messageText:setRect ( 0, 0, 450, 160 ) messageText:setLoc ( 255, 150 ) messageText:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) layer:insertProp( messageText ) messageText:setColor ( 0.4, 0.51, 0.98, 1 ) messageText:setPriority( 10000 ) messageTextBottom = MOAITextBox.new () messageTextBottom:setFont ( font ) messageTextBottom:setRect ( 0, 0, 450, 80 ) messageTextBottom:setLoc ( 255, 330 ) messageTextBottom:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) messageTextBottom:setColor ( 1, 1, 1, 1 ) messageTextBottom:setPriority( 10000 ) menuItem1Text = MOAITextBox.new () menuItem1Text:setFont ( font ) menuItem1Text:setRect ( 0, 0, 450, 40 ) menuItem1Text:setLoc ( 255, 250 ) menuItem1Text:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) menuItem1Text:setColor ( 1, 1, 1, 1 ) menuItem1Text:setPriority( 10000 ) menuItem1Text:setString("Resume") menuItem2Text = MOAITextBox.new () menuItem2Text:setFont ( font ) menuItem2Text:setRect ( 0, 0, 450, 40 ) menuItem2Text:setLoc ( 255, 290 ) menuItem2Text:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) menuItem2Text:setColor ( 1, 1, 1, 1 ) menuItem2Text:setPriority( 10000 ) menuItem2Text:setString("Quit to main menu") gameOverBack = MOAIProp2D.new() gameOverBack:setDeck( gameOverGfx ) gameOverBack:setLoc( 190, 122 ) gameOverBack:setPriority( uiLayer ) gameOverBack:setColor( 1, 1, 1, 0.75 ) gameOverBack:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) layer:removeProp( gameOverBack ) -- TODO: remove this, vita needs this because setting the blend mode apparently will add the prop currentBlocks = {} for blockIdx = 0, BLOCKS_GRID_HEIGHT-1 do currentBlocks[blockIdx] = {} end previewBlocks = {} local numRowsL = BLOCKS_GRID_HEIGHT-1 for y = maxStartHeight, numRowsL do local currentRow = currentBlocks[y] fillRowOfBlocks( currentRow, y, 0 ) end fillRowOfBlocks( previewBlocks, BLOCKS_GRID_HEIGHT, PREVIEW_ROW_OFFSET ) scoreText:setString( tostring(SCORE) ) starNextDropTime = 0 barGreenProp = MOAIProp2D.new () barGreenProp:setDeck( barGreenGfx ) barGreenProp:setPriority( uiLayer-2 ) barGreenProp:setLoc( 793, 190 ) layer:insertProp( barGreenProp ) barShineProp = MOAIProp2D.new () barShineProp:setDeck( barShineGfx ) barShineProp:setPriority( uiLayer-2 ) barShineProp:setLoc( 793, 190 ) layer:insertProp( barShineProp ) barGlowProp = MOAIProp2D.new() barGlowProp:setDeck( barGlowGfx ) barGlowProp:setPriority( uiLayer-2 ) barGlowProp:setLoc( 793, 190 ) barGlowProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) barGoopTopProp = MOAIProp2D.new () barGoopTopProp:setDeck( barGoopTopGfx ) barGoopTopProp:setPriority( uiLayer-1 ) barGoopTopProp:setLoc( 793, 190 ) updateMatchUI( 0.0 ) layer:insertProp( barGoopTopProp ) SFX["SESSION_START"]:play() end function setCharacterState( newState ) --print( "Current state: " .. CHARACTER_STATE .. " new state: " .. newState ) if CHARACTER_STATE == CHARACTER_IDLE then characterIdleL:stop() characterIdleR:stop() elseif CHARACTER_STATE == CHARACTER_JUMPING then characterJumpL:stop() characterJumpR:stop() elseif CHARACTER_STATE == CHARACTER_FALLING then characterFallL:stop() characterFallR:stop() elseif CHARACTER_STATE == CHARACTER_WALKING then characterWalkL:stop() characterWalkR:stop() elseif CHARACTER_STATE == CHARACTER_DEATH then characterDeathL:stop() characterDeathR:stop() elseif CHARACTER_STATE == CHARACTER_DOWN then characterDown:stop() end local oldCharacterState = CHARACTER_STATE CHARACTER_STATE = newState if characterDigAnim:isActive() then characterDigAnim:stop() end if (characterSmackL:isActive() or characterSmackR:isActive() ) and newState ~= CHARACTER_DEATH then return end if CHARACTER_STATE == CHARACTER_IDLE then if characterFacingRight then characterIdleR:start() else characterIdleL:start() end elseif CHARACTER_STATE == CHARACTER_JUMPING then if characterFacingRight then characterJumpR:start() else characterJumpL:start() end elseif CHARACTER_STATE == CHARACTER_FALLING then if characterFacingRight then characterFallR:start() else characterFallL:start() end elseif CHARACTER_STATE == CHARACTER_WALKING then if characterFacingRight then characterWalkR:start() else characterWalkL:start() end elseif CHARACTER_STATE == CHARACTER_DEATH then if characterFacingRight then characterDeathR:start() else characterDeathL:start() end elseif CHARACTER_STATE == CHARACTER_DOWN then characterDown:start() end end function playerSquished() if hitsRemaining == 0 then SFX["GAME_OVER"]:play() setCharacterState( CHARACTER_DEATH ) GAMEPLAY_STATE = GAMEPLAY_STATE_DYING else -- swap spritesheet -- launch beanie beanieProp = MOAIProp2D.new() beanieProp:setDeck( beanieGfx ) beanieProp:setLoc( characterLocation[1] + BEANIE_SPAWN_X_OFFSET, characterLocation[2] + BEANIE_SPAWN_Y_OFFSET ) beanieProp:setPriority( characterProp:getPriority() + 1 ) local beanieAnim = MOAIAnim.new() beanieAnim:reserveLinks( 1 ) beanieAnim:setLink( 1, beanieAnimCurve, beanieProp, MOAIProp2D.ATTR_INDEX ) beanieAnim:setMode( MOAITimer.LOOP ) beanieAnim:start() layer:insertProp( beanieProp ) beanieProp:moveLoc( 0, -500, 2 ) characterSheet:setTexture( CURRENT_CHARACTER["HIT_IMAGE"] ) if MOAIEnvironment.osBrand == "PSM" then characterProp:textureUpdate() end hitsRemaining = hitsRemaining - 1 SFX["BEANIE"]:play() -- Todo: force blocks update here? or make ned invulnerable for half a second? beanieUpdate( currentBlocks ) end end function getScoringLevel() return math.min( LEVEL_CAP_SCORING, activeLevel + 1 ) end function playerUpdate() while true do if characterHoldingDown and CHARACTER_STATE == CHARACTER_IDLE then setCharacterState( CHARACTER_DOWN ) end local currentX, currentY = characterLocation[1], characterLocation[2] local resultX = currentX + characterXVelocity local burgerBlockLocX = -1 local burgerBlockLocY = -1 local burgerBlock = nil if resultX > GRID_OFFSET_X - (1.0+PLAYER_WIDTH_PADDING_L)*TILE_SIZE and resultX < (GRID_OFFSET_X + (BLOCKS_GRID_WIDTH * TILE_SIZE) - (0.5*TILE_SIZE)) then local nearbyBlock1 = getBlock( resultX, currentY, PLAYER_WIDTH_PADDING_L ) local nearbyBlock2 = getBlock( resultX, currentY, PLAYER_WIDTH_PADDING_R ) --local nearbyBlock3 = getBlock( resultX, currentY - (TILE_SIZE * 0.75) + 1.0, PLAYER_WIDTH_PADDING_L ) --local nearbyBlock4 = getBlock( resultX, currentY - (TILE_SIZE * 0.75) + 1.0, PLAYER_WIDTH_PADDING_R ) local anyBlock = nearbyBlock1 or nearbyBlock2 or nearbyBlock3 or nearbyBlock4 if anyBlock ~= nil and anyBlock[2] == burgerBlockGfx then -- below sucks, need to refactor if anyBlock == nearbyBlock1 then burgerBlock = anyBlock burgerBlockLocX, burgerBlockLocY = worldSpaceToBlockSpace( resultX, currentY, PLAYER_WIDTH_PADDING_L ) currentX = resultX setCharacterLoc( currentX, currentY ) elseif anyBlock == nearbyBlock2 then burgerBlock = anyBlock burgerBlockLocX, burgerBlockLocY = worldSpaceToBlockSpace( resultX, currentY, PLAYER_WIDTH_PADDING_R ) currentX = resultX setCharacterLoc( currentX, currentY ) -- elseif anyBlock == nearbyBlock3 then -- burgerBlockLocX, burgerBlockLocY = worldSpaceToBlockSpace( resultX, currentY - (TILE_SIZE * 0.75) + 1.0, PLAYER_WIDTH_PADDING_L ) -- elseif anyBlock == nearbyBlock4 then -- burgerBlockLocX, burgerBlockLocY = worldSpaceToBlockSpace( resultX, currentY - (TILE_SIZE * 0.75) + 1.0, PLAYER_WIDTH_PADDING_R ) -- else -- print("ERROR: anyBlock did not match any:" .. anyBlock) end elseif anyBlock == nil then currentX = resultX setCharacterLoc( currentX, currentY ) elseif nearbyBlock1 and nearbyBlock2 == nil and characterFacingRight then currentX = resultX setCharacterLoc( currentX, currentY ) elseif nearbyBlock1 == nil and nearbyBlock2 and not characterFacingRight then currentX = resultX setCharacterLoc( currentX, currentY ) end end if characterFalling then characterYVelocity = characterYVelocity + GRAVITY end local resultY = currentY + characterYVelocity if characterYVelocity >= TILE_SIZE*0.5 then if getBlock( currentX, currentY + (TILE_SIZE * 0.9), PLAYER_WIDTH_PADDING_L ) ~= nil and getBlock( currentX, currentY + (TILE_SIZE * 0.9), PLAYER_WIDTH_PADDING_R ) ~= nil then resultY = currentY + (TILE_SIZE * 0.9) end end local handledYResult = false local hitBlockBelow = false local startBlockX, startBlockY = worldSpaceToBlockSpace( currentX, resultY ) if characterYVelocity > 0.0 then for i = 0, BLOCKS_GRID_HEIGHT-1 - startBlockY do local hitBlock1 = getBlock( currentX, resultY, PLAYER_WIDTH_PADDING_L, i ) local hitBlock2 = getBlock( currentX, resultY, PLAYER_WIDTH_PADDING_R, i ) -- if you are 'on top' of a block local hitBlock = hitBlock1 or hitBlock2 if hitBlock ~= nil and hitBlock[2] ~= burgerBlockGfx then local hitBlockX, hitBlockY = hitBlock[1]:getLoc() if ( hitBlockY - TILE_SIZE ) < resultY then setCharacterLoc( currentX, hitBlockY - TILE_SIZE ) handledYResult = true hitBlockBelow = true end break end end elseif characterYVelocity < 0.0 then for i = 0, BLOCKS_GRID_HEIGHT - startBlockY do local hitBlock1 = getBlock( currentX, resultY, PLAYER_WIDTH_PADDING_L, -i ) local hitBlock2 = getBlock( currentX, resultY, PLAYER_WIDTH_PADDING_R, -i ) -- if you are 'below a block but jumping' local hitBlock = hitBlock1 or hitBlock2 if hitBlock ~= nil and hitBlock[2] ~= burgerBlockGfx then local hitBlockX, hitBlockY = hitBlock[1]:getLoc() if hitBlockY + TILE_SIZE > resultY then setCharacterLoc( currentX, hitBlockY + TILE_SIZE - 1 ) characterYVelocity = 0 handledYResult = true end break end end end if not handledYResult and resultY < TILE_SIZE then setCharacterLoc( currentX, TILE_SIZE ) characterYVelocity = 0 handledYResult = true end if not handledYResult then setCharacterLoc( currentX, math.min( resultY, GRID_BOTTOM ) ) end if burgerBlock ~= nil then -- award points and remove burger -- TODO: Animate the burger graphic away displayPointsAward( BURGER_SCORE_AWARD * getScoringLevel(), false, true ) removeBlock(burgerBlockLocX, burgerBlockLocY, false) SFX["BURGER_COLLECT"]:play() end local updatedX, updatedY = characterLocation[1], characterLocation[2] local wasFalling = characterFalling characterFalling = updatedY ~= currentY and not hitBlockBelow characterJumping = updatedY < currentY wasFalling = wasFalling ~= characterFalling and not characterFalling if CHARACTER_STATE == CHARACTER_JUMPING and not characterJumping then setCharacterState( CHARACTER_FALLING ) elseif CHARACTER_STATE == CHARACTER_FALLING and characterJumping then setCharacterState( CHARACTER_JUMPING ) end if CHARACTER_STATE == CHARACTER_FALLING and not characterFalling then if characterXVelocity == 0 then setCharacterState( CHARACTER_IDLE ) else setCharacterState( CHARACTER_WALKING ) end end if wasFalling then local puffOffsetX = updatedX local puffOffsetY = updatedY + TILE_SIZE - 20 createCloudPuffAnimation( puffOffsetX + 50, puffOffsetY, 20 ) createCloudPuffAnimation( puffOffsetX + 60, puffOffsetY - 5, 20 ) createCloudPuffAnimation( puffOffsetX - 20, puffOffsetY - 4, -20 ) createCloudPuffAnimation( puffOffsetX - 10, puffOffsetY, -20 ) end if GAMEPLAY_STATE ~= GAMEPLAY_STATE_DEAD and GAMEPLAY_STATE ~= GAMEPLAY_STATE_DYING then local insideBlock1 = getBlock( updatedX, updatedY, PLAYER_WIDTH_PADDING_L ) local insideBlock2 = getBlock( updatedX, updatedY, PLAYER_WIDTH_PADDING_R ) if insideBlock1 ~= nil and insideBlock1[2] ~= burgerBlockGfx and insideBlock2 ~= nil and insideBlock2[2] ~= burgerBlockGfx then local insideBlockX, insideBlockY = insideBlock1[1]:getLoc() print("test1 " .. tostring(insideBlockX) ) if insideBlockY - TILE_SIZE < updatedY and insideBlockY + (TILE_SIZE * 0.25) > updatedY then playerSquished() end end if GAMEPLAY_STATE ~= GAMEPLAY_STATE_DYING and updatedY > GRID_BOTTOM then playerSquished() end end -- if buff is active -- decrement buff counter at tunable rate -- if hit zero, buff is deactivated if RED_BUFF_ACTIVE then buffMatchCounter = buffMatchCounter - BUFF_DRAIN if buffMatchCounter <= 0.0 then buffMatchCounter = 0.0 RED_BUFF_ACTIVE = false -- award the accumulated points local totalBlocks = buffBlockCounter[gemBlocks[BLOCK_GEM_RED]] + buffBlockCounter[gemBlocks[BLOCK_GEM_GREEN]] + buffBlockCounter[gemBlocks[BLOCK_GEM_BLUE]] local scoreIncrease = awardPointsForBlocks( totalBlocks ) print( "Total blocks in virtual glom: " .. tostring( totalBlocks ) ) print( "Total points for virtual glom: " .. tostring( scoreIncrease ) ) displayPointsAward( scoreIncrease ) updateCounterUI( totalBlocks ) buffBlockCounter[gemBlocks[BLOCK_GEM_RED]] = 0 buffBlockCounter[gemBlocks[BLOCK_GEM_GREEN]] = 0 buffBlockCounter[gemBlocks[BLOCK_GEM_BLUE]] = 0 removeBuffActiveText() end updateMatchUI( buffMatchCounter ) end if GREEN_BUFF_ACTIVE then buffMatchCounter = buffMatchCounter - BUFF_DRAIN if buffMatchCounter <= 0.0 then buffMatchCounter = 0.0 GREEN_BUFF_ACTIVE = false removeBuffActiveText() end updateMatchUI( buffMatchCounter ) end if BLUE_BUFF_ACTIVE then buffMatchCounter = buffMatchCounter - BUFF_DRAIN if buffMatchCounter <= 0.0 then buffMatchCounter = 0.0 BLUE_BUFF_ACTIVE = false removeBuffActiveText() end updateMatchUI( buffMatchCounter ) end coroutine.yield () end end function getSurroundingBlocks( surroundingBlocks, x, y ) if x > 0 then local leftBlock = currentBlocks[y][x-1] if leftBlock ~= nil then surroundingBlocks[leftBlock] = { x-1, y, leftBlock } end end if y > 0 then local aboveBlock = currentBlocks[y-1][x] if aboveBlock ~= nil then surroundingBlocks[aboveBlock] = { x, y-1, aboveBlock } end end if x < BLOCKS_GRID_WIDTH-1 then local rightBlock = currentBlocks[y][x+1] if rightBlock ~= nil then surroundingBlocks[rightBlock] = { x+1, y, rightBlock } end end if y < BLOCKS_GRID_HEIGHT-1 then local bottomBlock = currentBlocks[y+1][x] if bottomBlock ~= nil then surroundingBlocks[bottomBlock] = { x, y+1, bottomBlock } end end end function anyBlocksFalling( bunchOfBlocks ) for key, blockData in pairs(bunchOfBlocks) do if blockIsFalling( blockData[3] ) then return true end end return false end function removeScoreUpdateText() if #scoreUpdateTextIdxs > 0 then layer:removeProp( scoreUpdateText[scoreUpdateTextIdxs[1]] ) table.remove( scoreUpdateTextIdxs, 1 ) end end function removeScoreKickerText() if #scoreKickersIdxs > 0 then layer:removeProp( scoreKickers[scoreKickersIdxs[1]] ) table.remove( scoreKickersIdxs, 1 ) end end function removeBuffActiveText() layer:removeProp( buffActiveText ) barGlowAnim:stop() layer:removeProp( barGlowProp ) end function resetBlockGlomState( currentBlock ) currentBlock["timeToRemove"] = nil destroyGlomOver( currentBlock ) end function awardPointsForBlocks( numBlocks ) -- ROUND(25* POW(3,(A3 - 3) * 0.79) * (1/5)) * 5 return (math.floor(math.ceil(25 * math.pow(3,(numBlocks-3) * 0.79)) * (1/5)) * 5) * getScoringLevel() end function displayPointsAward( scoreIncrease, withUI, withKicker ) if withUI == nil then withUI = true end if withKicker == nil then withKicker = false end if scoreIncrease > 0 then SCORE = SCORE + scoreIncrease if withUI then local updateTextCount = #scoreUpdateTextIdxs if updateTextCount >= 1 then for k, v in pairs( scoreUpdateTextIdxs ) do scoreUpdateText[v]:moveLoc( 0, 35, 0.5 ) end end scoreUpdateTextIdx = scoreUpdateTextIdx + 1 if scoreUpdateTextIdx > MAX_SCORE_UPDATES then scoreUpdateTextIdx = 1 end local isIdxActive = false for i, v in ipairs( scoreUpdateTextIdxs ) do if scoreUpdateTextIdx == v then table.remove( scoreUpdateTextIdxs, i ) layer:removeProp( scoreUpdateText[v] ) break end end -- solution: circular index for next free item -- if in list: -- remove -- remove from scene -- each time: -- add to scene -- add to end of list -- increment next item index local curScoreUpdateText = scoreUpdateText[scoreUpdateTextIdx] curScoreUpdateText:setLoc( 190, 60 ) -- TODO: handle more than 5 queued curScoreUpdateText:setString( "+" .. tostring(scoreIncrease) .. " points!" ) layer:insertProp( curScoreUpdateText ) table.insert( scoreUpdateTextIdxs, scoreUpdateTextIdx ) performWithDelay( SCORE_UPDATE_TIMEOUT, removeScoreUpdateText ) elseif withKicker then scoreKickerIdx = scoreKickerIdx + 1 if scoreKickerIdx > MAX_SCORE_UPDATES then scoreKickerIdx = 1 end local isIdxActive = false for i, v in ipairs( scoreKickersIdxs ) do if scoreKickerIdx == v then table.remove( scoreKickersIdxs, i ) layer:removeProp( scoreKickers[v] ) break end end -- solution: circular index for next free item -- if in list: -- remove -- remove from scene -- each time: -- add to scene -- add to end of list -- increment next item index local curScoreKickerText = scoreKickers[scoreKickerIdx] curScoreKickerText:setLoc( characterLocation[1] - 100, characterLocation[2] ) -- TODO: handle more than 5 queued curScoreKickerText:setString( "+" .. tostring(scoreIncrease) ) curScoreKickerText:setColor ( 0.91, 0.96, 0.96, 1 ) layer:insertProp( curScoreKickerText ) table.insert( scoreKickersIdxs, scoreKickerIdx ) curScoreKickerText:moveLoc( 0, -70, 0, SCORE_UPDATE_TIMEOUT / 1000, MOAIEaseType.LINEAR ) curScoreKickerText:moveColor( 0, 0, 0, -1, SCORE_UPDATE_TIMEOUT / 1000, MOAIEaseType.LINEAR ) performWithDelay( SCORE_UPDATE_TIMEOUT, removeScoreKickerText ) end end end function updateCounterUI( numBlocks ) buffMatchCounter = buffMatchCounter + (numBlocks * CURRENT_CHARACTER["BUFF_UPDATE_AMT"]) updateMatchUI( buffMatchCounter ) if buffMatchCounter >= 1.0 then buffMatchCounter = 1.0 end if math.ceil(buffMatchCounter * 10) * 0.1 == 1.0 then -- this is dumb local buffAbility = CURRENT_CHARACTER["BUFF_ABILITY"] if buffAbility == 'time' then BLUE_BUFF_ACTIVE = true buffActiveText:setString( BLUE_BUFF_TEXT ) elseif buffAbility == 'supersize' then RED_BUFF_ACTIVE = true -- supersize buffActiveText:setString( RED_BUFF_TEXT ) elseif buffAbility == 'superstrength' then GREEN_BUFF_ACTIVE = true -- super strength buffActiveText:setString( GREEN_BUFF_TEXT ) else print("UNRECOGNIZED BUFF ABIITY FOR " .. tostring(CURRENT_CHARACTER["NAME"]) .. ": " .. buffAbility ) end SFX["BUFF_ACTIVATE"]:play() curPowerUpProp = createPowerUpAnimation( characterLocation[1], characterLocation[2] ) layer:insertProp( buffActiveText ) -- start animating the glow in layer:insertProp( barGlowProp ) barGlowProp:setColor( 1, 1, 1, 0 ) barGlowAnim = barGlowProp:moveColor( 0, 0, 0, 1, 1, MOAIEaseType.LINEAR ) barGlowAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onBarFadeIn ) end end function onBarFadeIn( anim ) barGlowAnim = barGlowProp:moveColor( 0, 0, 0, -1, 1, MOAIEaseType.LINEAR ) barGlowAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onBarFadeOut ) end function onBarFadeOut( anim ) barGlowAnim = barGlowProp:moveColor( 0, 0, 0, 1, 1, MOAIEaseType.LINEAR ) barGlowAnim:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onBarFadeIn ) end function activeLevelCalc() local calcLevel = 0 local burgerCounter = burgersMatchCount for i, v in ipairs(LEVEL_THRESHOLDS) do if i > CURRENT_LEVEL then burgerCounter = burgerCounter - v if burgerCounter < 0 then calcLevel = i-1 break end end end if burgerCounter >= 0 then calcLevel = 9 end local additionalLevelCount = 0 while burgerCounter >= 0 do burgerCounter = burgerCounter - LEVEL_THRESHOLD_LAST additionalLevelCount = additionalLevelCount + 1 end return calcLevel + additionalLevelCount end function blockGlomUpdate( currentBlock, connectedBlocks, currentTime ) local glomBlockCount = countTableSize( connectedBlocks ) if glomBlockCount > 2 then if not anyBlocksFalling( connectedBlocks ) then -- Desire: once a match 3 is found, wait some time before removing the blocks -- and rewarding points -- If during the countdown a block is added or removed from the glom, then reset the counter -- Match 3 is made - mark all blocks with time to re-evaluate -- If time has expired then remove -- If block has no glom, then reset any time local newGlom = false local timeToRemove = nil for key, blockData in pairs(connectedBlocks) do local curTimeToRemove = blockData[3]["timeToRemove"] if curTimeToRemove == nil then newGlom = true break elseif timeToRemove == nil then timeToRemove = curTimeToRemove elseif timeToRemove ~= curTimeToRemove then newGlom = true break end end if newGlom then if glomBlockCount == 3 then SFX["MATCH_BEGIN"]:play() -- print("match begin") else SFX["MATCH_ADD"]:play() -- print("match add") end for key, blockData in pairs(connectedBlocks) do resetBlockGlomState( blockData[3] ) blockData[3]["timeToRemove"] = currentTime + GLOM_TIMEOUT local blockLocX, blockLocY = blockData[3][1]:getLoc() createGlomOver( blockData[3] ) end end local numBlocks = 0 for key, blockData in pairs(connectedBlocks) do if blockData[3]["timeToRemove"] ~= nil and currentTime > blockData[3]["timeToRemove"] then removeBlock( blockData[1], blockData[2] ) removedGlom = true numBlocks = numBlocks + 1 end end if numBlocks > 0 then processGlomComplete( numBlocks, currentBlock[2] ) end end else for key, blockData in pairs(connectedBlocks) do resetBlockGlomState( blockData[3] ) end end end function processGlomComplete( numBlocks, currentBlockType ) SFX["MATCH_FINISH"]:play() if RED_BUFF_ACTIVE then buffBlockCounter[currentBlockType] = buffBlockCounter[currentBlockType] + numBlocks else local scoreIncrease = awardPointsForBlocks( numBlocks ) displayPointsAward( scoreIncrease ) updateCounterUI( numBlocks ) burgersMatchCount = burgersMatchCount + numBlocks burgersMatchedText:setString( tostring(burgersMatchCount) ) local oldLevel = activeLevel activeLevel = activeLevelCalc() if activeLevel > oldLevel then playStinger( SFX["LEVEL_UP"] ) end levelText:setString( tostring(activeLevel+1) ) end if sessionMaxMatch < numBlocks then sessionMaxMatch = numBlocks end end function getBlockSafe( currentBlocksL, blockLocX, blockLocY, oobNotify ) if blockLocX >= 0 and blockLocX < BLOCKS_GRID_WIDTH and blockLocY >= 0 and blockLocY < BLOCKS_GRID_HEIGHT then return currentBlocksL[blockLocY][blockLocX] else print( "OOB: " .. tostring(blockLocX) .. ", " .. tostring(blockLocY) ) if oobNotify then return "OOB" else return nil end end end function bbqBlockConsume(x, y, resultLocX, resultLocY, currentBlock, bbqBlock) local gemCounter = bbqBlock["blocksEaten"] gemCounter[gemIndexMapper[currentBlock[2]]] = gemCounter[gemIndexMapper[currentBlock[2]]] + 1 removeBlock(x,y, false) -- bbq easy debug code -- gemCounter[1] = 1 -- gemCounter[2] = 1 if bbqBlock["smoke"] == nil then bbqBlock["smoke"] = createBBQSmokeProp( (GRID_OFFSET_X + (resultLocX * TILE_SIZE)), (GRID_OFFSET_Y + (resultLocY * TILE_SIZE)) + BBQ_SMOKE_Y_OFFSET ) end local currentBlocksL = currentBlocks if gemCounter[1] > 0 and gemCounter[2] > 0 and gemCounter[3] > 0 then SFX["BBQ_SMOKE"]:play() removeBlock(resultLocX, resultLocY, false) createSmokePuffAnimation( (GRID_OFFSET_X + (resultLocX * TILE_SIZE)), (GRID_OFFSET_Y + (resultLocY * TILE_SIZE)) ) local numBurgers = math.random( BBQ_BURGER_SPAWN_MIN, BBQ_BURGER_SPAWN_MAX ) print("Burger rewards! (" .. tostring(numBurgers) .. " burgers)") local searchRange = BLOCKS_GRID_WIDTH * 0.5 for i = 0, numBurgers-1 do -- find a free spot to spawn a burger around the bbq destruction point local foundSpotX = -1 local foundSpotY = -1 for searchIdx = 1, searchRange+1 do -- print( "Looking from " .. tostring(-searchIdx) .. " to " .. tostring(searchIdx) .. " in steps of: " .. tostring(searchIdx*2) ) for yOffset = -searchIdx, searchIdx+1, searchIdx do for xOffset = -searchIdx, searchIdx+1, searchIdx do -- print( "Checking x:" .. tostring(xOffset) .. " y:" .. tostring(yOffset) ) local potentialSpot = getBlockSafe(currentBlocksL, resultLocX+xOffset, resultLocY+yOffset, true) if potentialSpot == nil then -- print( potentialSpot ) foundSpotX = resultLocX+xOffset foundSpotY = resultLocY+yOffset -- print("Found a spot: " .. tostring(foundSpotX) .. ", " .. tostring(foundSpotY) ) break end end if foundSpotX ~= -1 then break end end if foundSpotX ~= -1 then break end end if foundSpotX == -1 then print("Couldn't find a place for the burger!") else local burgerProp = MOAIProp2D.new() burgerProp:setDeck( burgerBlockGfx ) burgerProp:setLoc( (GRID_OFFSET_X + (resultLocX * TILE_SIZE)), (GRID_OFFSET_Y + (resultLocY * TILE_SIZE)) ) local moveAnim = burgerProp:moveLoc( (foundSpotX - resultLocX) * TILE_SIZE, (foundSpotY - resultLocY) * TILE_SIZE, 0.5, MOAIEaseType.EASE_IN ) moveAnim:setListener( MOAIAction.EVENT_STOP, burgerDoneMoving ) burgerProp:setPriority( 10 ) layer:insertProp( burgerProp ) local burgerObj = { burgerProp, burgerBlockGfx } currentBlocksL[foundSpotY][foundSpotX] = burgerObj moveAnim["burgerObj"] = burgerObj end end else SFX["BBQ_CONSUME"]:play() end end function burgerDoneMoving(anim) local currentTime = MOAISim.getDeviceTime() local burgerObj = anim["burgerObj"] burgerObj["falling"] = nil burgerObj["fallAt"] = currentTime + BLOCK_FALL_DELAY MOAISim.wobbleBlock( burgerObj[1].spriteID, burgerObj[1].spriteUniqueID, 1 ) end function glomGfxUpdate( currentBlocksL, GRIDLIMITW, GRIDLIMITH, glomX, glomY, currentGlomBlock, propogate ) local surroundingBlocksCode = 0 local counter = 0 for y = glomY-1, glomY+1 do for x = glomX-1, glomX+1 do if not(x == glomX and y == glomY) and ((y-glomY) == 0 or (x-glomX) == 0 ) then --print( x - glomX, y - glomY ) --print( x, y ) if y >= 0 and y <= GRIDLIMITH and x >= 0 and x <= GRIDLIMITW then --print( "in bounds: " .. tostring(x - glomX) .. tostring( y - glomY ) ) local glomGfxBlock = currentBlocksL[y][x] if glomGfxBlock ~= nil and glomGfxBlock[2] == currentGlomBlock[2] then --print( "inside: " .. tostring( x - glomX ) .. ',' .. tostring(y - glomY ) ) --print( currentGlomBlock[2] ) --print( glomGfxBlock == currentGlomBlock ) if propogate then glomGfxUpdate( currentBlocksL, GRIDLIMITW, GRIDLIMITH, x, y, glomGfxBlock, false ) end surroundingBlocksCode = surroundingBlocksCode + (10 ^ counter) end end counter = counter + 1 end end end local frameMapper = { [0000] = 8, [0001] = 6, [0010] = 5, [0011] = 15, [0100] = 10, [0101] = 13, [0110] = 2, [0111] = 17, [1000] = 4, [1001] = 9, [1010] = 3, [1011] = 16, [1100] = 1, [1101] = 18, [1110] = 12, [1111] = 11, } local selectedFrame = frameMapper[surroundingBlocksCode] --print( "Frame: " .. tostring(selectedFrame) ) if selectedFrame == nil then print("MAJOR PROBLEM HERE: " .. tostring(surroundingBlocksCode) ) end currentGlomBlock[1]:setIndex(selectedFrame) end function killAt( currentBlocksL, x, y ) if x >= 0 and x < BLOCKS_GRID_WIDTH and y >= 0 and y < BLOCKS_GRID_HEIGHT then if currentBlocksL[y][x] ~= nil then removeBlock( x, y, false ) createBBQDeathAnimation( GRID_OFFSET_X + (x * TILE_SIZE), GRID_OFFSET_Y + (y * TILE_SIZE) ) else local x2, y2 = worldSpaceToBlockSpace( characterLocation[1], characterLocation[2], PLAYER_WIDTH_PADDING_L ) local x3, y3 = worldSpaceToBlockSpace( characterLocation[1], characterLocation[2], PLAYER_WIDTH_PADDING_R ) if x == x2 and y == y2 and x == x3 and y == y3 then playerSquished() end createBBQDeathAnimation( GRID_OFFSET_X + (x * TILE_SIZE), GRID_OFFSET_Y + (y * TILE_SIZE) ) end end end function beanieUpdate(currentBlocksL) if beanieProp ~= nil then local beanieX, beanieY = beanieProp:getLoc() if beanieY < 0 then layer:removeProp( beanieProp ) spriteDestroy( beanieProp ) beanieProp = nil else local beanieBlockX, beanieBlockY = worldSpaceToBlockSpace( beanieX, beanieY, -0.5 ) if beanieBlockY >= 0 and beanieBlockY < BLOCKS_GRID_HEIGHT and currentBlocksL[beanieBlockY][beanieBlockX] ~= nil then removeBlock( beanieBlockX, beanieBlockY ) end end end end -- TODO: Do this properly local starsUV = 1.0 function blocksUpdate() local fallingKey = "falling" local fallAtKey = "fallAt" local stoneBlockGfxL = stoneBlockGfx local COLLECT_DIR_ALLKey = COLLECT_DIR_ALL local xVelKey = 'xVel' local timeToRemoveKey = "timeToRemove" local burgerBlockGfxL = burgerBlockGfx local earthBlocksL = earthBlocks local currentBlocksL = currentBlocks local GRIDLIMITH = BLOCKS_GRID_HEIGHT-1 local GRIDLIMITW = BLOCKS_GRID_WIDTH-1 local TILE_SIZE_L = TILE_SIZE local GRID_OFFSET_Y_L = GRID_OFFSET_Y local smokeKey = "smoke" local yVelKey = "yVel" local BLOCK_FALL_SPEED_L = BLOCK_FALL_SPEED local earthBlockDeathsL = earthBlockDeaths while true do bgStars:setUVRect( 0, starsUV, 1, 1 + starsUV ) starsUV = starsUV + 0.0001 if starsUV < 0.0 then starsUV = 1.0 end if MOAIEnvironment.osBrand == "PSM" then gameplayBGStarsProp:updateUVs() end local currentTime = MOAISim.getDeviceTime() if currentTime > starNextDropTime then if math.random( 0, SHOOTING_STAR_CHANCE_RANGE ) < SHOOTING_STAR_CHANCE then createShootingStarAnimation( ((math.random( 0, 100 ) * 0.01) * 500) + 190, ((math.random( 0, 100 ) * 0.01) * 313) + 77 ) end end -- idea: go over and mark all blocks that can move down -- then go again each glom, if all bottom blocks can move down, -- move glom down? then mark glom as moved, so don't move it anymore for that pass? -- repeat until no more movement this frame? -- glomming still isn't perfect... -- we should probably modify this to the do: -- go through every block, finding all connected parts -- if 'the group' can move down, move them all down (be careful to go from bottom to top) -- then mark them all as moved -- continue iterating on all the rest that haven't been moved -- in theory this should preserve glomming shapes... -- Clear the previous frame's canMove flags beanieUpdate(currentBlocksL) -- current algorithm: -- while blocks are falling, -- figure out if a glom can fall -- (logically) move the block down if it can -- start the visual move -- then go through all the blocks -- if they haven't reached their logical destination -- visually animate them towards there -- new algorithm should be: -- while blocks are falling -- figure out if a glom can fall, if it isn't already -- start the visual move -- then go through all the blocks -- if they have visually reached the next logical destination -- update their logical destination --local glomFrame = MOAISim.getDeviceTime() --local collectionTime = 0.0 --print( tostring( (MOAISim.getDeviceTime() - glomFrame) * 1000.0 ) .. ' collection time: ' .. tostring(collectionTime * 1000.0) ) for y = 0, GRIDLIMITH do local currentRow = currentBlocksL[y] local destinationY = ((y * TILE_SIZE_L) + GRID_OFFSET_Y_L) for x = 0, GRIDLIMITW do local currentBlock = currentRow[x] if currentBlock ~= nil then if currentBlock[xVelKey] ~= nil then local xVelocity = currentBlock[xVelKey] if xVelocity > 0 then -- going right -- check if there are any blocks to move to -- check if the resulting position block is empty (if not, nil out xVel, clamp position) -- if it is, then animate, set logical position to resulting position local wsX, wsY = currentBlock[1]:getLoc() local resultLocX, resultLocY = worldSpaceToBlockSpace( wsX + xVelocity, wsY, 0 ) local blockAtDest = nil if resultLocX ~= BLOCKS_GRID_WIDTH then blockAtDest = currentBlocks[y][resultLocX] end if resultLocX == BLOCKS_GRID_WIDTH or blockAtDest ~= nil and x ~= resultLocX and blockAtDest[2] ~= bbqBlockGfx then currentBlock[xVelKey] = nil currentBlock[1]:setLoc( (GRID_OFFSET_X + x * TILE_SIZE) , GRID_OFFSET_Y + (y * TILE_SIZE) ) setGlomOverLoc( currentBlock, (GRID_OFFSET_X + x * TILE_SIZE) , GRID_OFFSET_Y + (y * TILE_SIZE) ) else if resultLocX > x and blockAtDest ~= nil and blockAtDest[2] == bbqBlockGfx then bbqBlockConsume( x, y, resultLocX, y, currentBlock, blockAtDest ) else if resultLocX > x then currentBlocks[y][resultLocX] = currentBlock currentBlocks[y][x] = nil end currentBlock[1]:addLoc( xVelocity, 0 ) moveGlomOver( currentBlock, xVelocity, 0 ) if currentBlock["smoke"] ~= nil then currentBlock["smoke"]:addLoc( xVelocity, 0 ) end currentBlock[xVelKey] = xVelocity + BLOCK_HORIZONTAL_ACCELERATION end end else -- going left local wsX, wsY = currentBlock[1]:getLoc() local resultLocX, resultLocY = worldSpaceToBlockSpace( wsX + xVelocity, wsY, -1 ) local blockAtDest = nil if resultLocX >= 0 then blockAtDest = currentBlocks[y][resultLocX] end if resultLocX < 0 or blockAtDest ~= nil and x ~= resultLocX and blockAtDest[2] ~= bbqBlockGfx then currentBlock[xVelKey] = nil currentBlock[1]:setLoc( (GRID_OFFSET_X + x * TILE_SIZE) , GRID_OFFSET_Y + (y * TILE_SIZE) ) setGlomOverLoc( currentBlock, (GRID_OFFSET_X + x * TILE_SIZE) , GRID_OFFSET_Y + (y * TILE_SIZE) ) else if resultLocX < x and blockAtDest ~= nil and blockAtDest[2] == bbqBlockGfx then bbqBlockConsume( x, y, resultLocX, y, currentBlock, blockAtDest ) else if resultLocX < x then currentBlocks[y][resultLocX] = currentBlock currentBlocks[y][x] = nil end currentBlock[1]:addLoc( xVelocity, 0 ) moveGlomOver( currentBlock, xVelocity, 0 ) if currentBlock["smoke"] ~= nil then currentBlock["smoke"]:addLoc( xVelocity, 0 ) end currentBlock[xVelKey] = xVelocity - BLOCK_HORIZONTAL_ACCELERATION end end end end local exactX, exactY = currentBlock[1]:getLoc() local currentBlockSpeed = currentBlock[yVelKey] if currentBlockSpeed ~= nil and currentBlockSpeed < 0 then currentBlock[1]:addLoc( 0, currentBlockSpeed ) if (exactY + currentBlockSpeed) <= destinationY then currentBlock["falling"] = nil currentBlock[yVelKey] = 0 currentBlock[fallAtKey] = currentTime + BLOCK_FALL_DELAY MOAISim.wobbleBlock( currentBlock[1].spriteID, currentBlock[1].spriteUniqueID, 1 ) else currentBlock[yVelKey] = currentBlock[yVelKey] - 0.1 end elseif exactY < destinationY then currentBlock[yVelKey] = BLOCK_FALL_SPEED_L currentBlockSpeed = currentBlock[yVelKey] currentBlock[1]:addLoc( 0, currentBlockSpeed ) moveGlomOver( currentBlock, 0, currentBlockSpeed ) local smokeProp = currentBlock[smokeKey] if smokeProp ~= nil then smokeProp:addLoc( 0, currentBlockSpeed ) end currentBlock[fallingKey] = 1 if currentBlock[2] == bbqBlockGfx then local belowBlock = getBlockSafe( currentBlocksL, x, y+1 ) if belowBlock == nil or belowBlock[fallingKey] == nil or belowBlock[fallingKey] == 0 then if currentBlock["willExplode"] == nil then currentBlock["willExplode"] = 1 else currentBlock["willExplode"] = currentBlock["willExplode"] + 1 --hackhackhack end end end elseif exactY ~= destinationY then currentBlock[1]:setLoc( exactX, destinationY ) setGlomOverLoc( currentBlock, exactX, destinationY ) local smokeProp = currentBlock[smokeKey] if smokeProp ~= nil then smokeProp:setLoc( exactX, destinationY + BBQ_SMOKE_Y_OFFSET ) end if earthBlockDeathsL[currentBlock[2]] ~= nil then glomGfxUpdate( currentBlocksL, GRIDLIMITW, GRIDLIMITH, x, y, currentBlock, true ) end currentBlock[fallingKey] = 0 currentBlock[yVelKey] = 0 -- if currentBlock[2] == bbqBlockGfx then -- print("Arriving.") -- end else if currentBlock[2] == bbqBlockGfx then if currentBlock["stopped"] == nil then if currentBlock[fallAtKey] == nil and currentBlock["willExplode"] ~= nil and currentBlock["willExplode"] > 3 then -- print("Arrived.") currentBlock["stopped"] = 1 end elseif currentBlock["willExplode"] ~= nil and currentBlock["stopped"] == 1 then removeBlock( x, y ) killAt( currentBlocksL, x, y-1 ) killAt( currentBlocksL, x, y+1 ) killAt( currentBlocksL, x-1, y ) killAt( currentBlocksL, x+1, y ) SFX["BBQ_EXPLODE"]:play() end end end end end end scoreText:setString( tostring(SCORE) ) --print( 'Total frame: ' .. tostring( (MOAISim.getDeviceTime() - currentTime) * 1000.0 ) ) --for i = 1, 2 do coroutine.yield() --end end end function blockThink() local GRIDLIMITH = BLOCKS_GRID_HEIGHT-1 local GRIDLIMITW = BLOCKS_GRID_WIDTH-1 local glomIDKey = 'glomID' local currentBlocksL = currentBlocks local fallingKey = "falling" local fallAtKey = "fallAt" local stoneBlockGfxL = stoneBlockGfx local COLLECT_DIR_ALLKey = COLLECT_DIR_ALL local xVelKey = 'xVel' local timeToRemoveKey = "timeToRemove" local burgerBlockGfxL = burgerBlockGfx local earthBlocksL = earthBlocks while true do local currentTime = MOAISim.getDeviceTime() for y = 0, GRIDLIMITH do local currentRow = currentBlocksL[y] for x = 0, GRIDLIMITW do local currentBlock = currentRow[x] if currentBlock ~= nil then currentBlock[glomIDKey] = -1 end end end local currentGlomID = -1 --local glomFrame = MOAISim.getDeviceTime() --local collectionTime = 0.0 -- first pass idea: -- go through all active blocks, call C# function to set state -- do C# logic update -- go through all cells, ask for block info? coroutine.yield() for y = 0, GRIDLIMITH do local actualY = GRIDLIMITH - y local currentRow = currentBlocksL[actualY] for x = 0, GRIDLIMITW do local currentBlock = currentRow[x] if currentBlock ~= nil and currentBlock[glomIDKey] == -1 and currentBlock[2] ~= stoneBlockGfxL then local currentBlockType = currentBlock[2] local connectedBlocks = {} --local collectionTimeStart = MOAISim.getDeviceTime() if currentBlockType ~= burgerBlockGfxL then collectConnectedBlocks( connectedBlocks, currentBlocksL, currentBlockType, x, actualY, COLLECT_DIR_ALLKey ) end --collectionTime = collectionTime + (MOAISim.getDeviceTime() - collectionTimeStart) connectedBlocks[currentBlock] = {x, actualY, currentBlock}; -- make sure we have at least ourselves, in case we are frozen -- how could I cache this stuff? -- is there some way all this logic can take place in C#, then somehow lua is informed what to do? if isGem(currentBlockType) then blockGlomUpdate( currentBlock, connectedBlocks, currentTime ) -- TODO: try running this less frequently end currentGlomID = currentGlomID + 1 local canFall = true -- Hack to prevent burgers from thinking they are part of a glom if currentBlockType == burgerBlockGfx then currentBlockType = nil end for key, blockData in pairs(connectedBlocks) do local currentGlomBlock = blockData[3] currentGlomBlock[glomIDKey] = currentGlomID if canFall then local glomX = blockData[1] local glomY = blockData[2] if glomY < GRIDLIMITH and currentGlomBlock[2] ~= stoneBlockGfxL and currentGlomBlock[xVelKey] == nil then local belowBlock = currentBlocksL[glomY+1][glomX] if belowBlock ~= nil and (belowBlock[2] ~= currentBlockType and belowBlock[fallAtKey] == nil) and not (isGem(currentBlockType) and belowBlock[2] == bbqBlockGfx and currentGlomBlock[timeToRemoveKey] == nil) and not (currentBlockType == bbqBlockGfx and isGem(belowBlock[2]) and belowBlock[timeToRemoveKey] == nil) then canFall = false -- don't break here since we still need to mark all the blocks with their glomID end else canFall = false end end end if canFall then local allDone = false while not allDone do allDone = true for key, blockData in pairs(connectedBlocks) do local glomX = blockData[1] local glomY = blockData[2] local currentGlomBlock = blockData[3] local fallTime = currentGlomBlock[fallAtKey] if fallTime ~= nil then if currentTime > fallTime and (currentGlomBlock[fallingKey] == nil or currentGlomBlock[fallingKey] == 0) then if currentBlocksL[glomY+1][glomX] == nil then currentBlocksL[glomY+1][glomX] = currentGlomBlock currentBlocksL[glomY][glomX] = nil currentGlomBlock[fallingKey] = 1 allDone = false elseif currentBlocksL[glomY+1][glomX][2] == bbqBlockGfx and isGem(currentBlockType) then bbqBlockConsume(glomX, glomY, glomX, glomY+1, currentGlomBlock, currentBlocksL[glomY+1][glomX]) allDone = false connectedBlocks[key] = nil elseif isGem(currentBlocksL[glomY+1][glomX][2]) and currentBlockType == bbqBlockGfx then bbqBlockConsume(glomX, glomY+1, glomX, glomY, currentBlocksL[glomY+1][glomX], currentGlomBlock) allDone = false connectedBlocks[key] = nil end end else currentGlomBlock["falling"] = nil currentGlomBlock[fallAtKey] = currentTime + BLOCK_FALL_DELAY MOAISim.wobbleBlock( currentGlomBlock[1].spriteID, currentGlomBlock[1].spriteUniqueID, 1 ) end end end else for key, blockData in pairs(connectedBlocks) do local currentGlomBlock = blockData[3] currentGlomBlock[fallAtKey] = nil MOAISim.wobbleBlock( currentGlomBlock[1].spriteID, currentGlomBlock[1].spriteUniqueID, 0 ) end end end end coroutine.yield() end --for i = 1, 6 do coroutine.yield() --end end end function onBlockGone( anim ) anim:stop() local propObj = anim["prop"] layer:removeProp( propObj ) spriteDestroy( propObj ) end function addInRow() SFX["ROW_UPDATE_PERFORM"]:play() performWithDelay( 500, tractorBeamAnimOver ) local currentBlocksL = currentBlocks if characterLocation[2] < GRID_OFFSET_Y then local mover = characterProp:moveLoc( 0, -TILE_SIZE, 2.01, MOAIEaseType.EASE_IN ) characterProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) characterProp:moveColor( 0, 0, 0, -1, 2, MOAIEaseType.EASE_IN ) mover:setListener( MOAITimer.EVENT_TIMER_END_SPAN, showGameOver ) SFX["GAME_OVER"]:play() GAMEPLAY_STATE = GAMEPLAY_STATE_DYING end for y = 0, BLOCKS_GRID_HEIGHT-2 do for x = 0, BLOCKS_GRID_WIDTH-1 do if y == 0 then local currentBlock = currentBlocksL[y][x] if currentBlock ~= nil then if currentBlock[2] == bbqBlockGfx then bbqBlockInPlay = false end unshake(currentBlock) currentBlock[1]:moveLoc( 0, -TILE_SIZE ) currentBlock[1]:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) local mover = currentBlock[1]:moveLoc( 0, -TILE_SIZE, 2.01, MOAIEaseType.EASE_IN ) currentBlock[1]:moveColor( 0, 0, 0, -1, 2, MOAIEaseType.EASE_IN ) mover["prop"] = currentBlock[1] mover:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onBlockGone ) fadeOutGlomOver( currentBlock ) if currentBlock["smoke"] ~= nil then currentBlock["smoke"]:moveLoc( 0, -TILE_SIZE ) local smokeMover = currentBlock["smoke"]:moveLoc( 0, -TILE_SIZE, 2.01, MOAIEaseType.EASE_IN ) currentBlock["smoke"]:moveColor( 0, 0, 0, -1, 2, MOAIEaseType.EASE_IN ) smokeMover["prop"] = currentBlock["smoke"] smokeMover:setListener( MOAITimer.EVENT_TIMER_END_SPAN, onBlockGone ) end end end local belowBlock = currentBlocksL[y+1][x] currentBlocksL[y][x] = belowBlock if belowBlock ~= nil then belowBlock[1]:moveLoc( 0, -TILE_SIZE ) moveGlomOver( belowBlock, 0, -TILE_SIZE ) if belowBlock["smoke"] ~= nil then belowBlock["smoke"]:moveLoc( 0, -TILE_SIZE ) end end end end for x = 0, BLOCKS_GRID_WIDTH-1 do local previewBlock = previewBlocks[x] currentBlocksL[BLOCKS_GRID_HEIGHT-1][x] = previewBlock previewBlocks[x] = nil if previewBlock ~= nil then previewBlock[1]:moveLoc( 0, -(TILE_SIZE + PREVIEW_ROW_OFFSET) ) moveGlomOver( previewBlock, 0, -(TILE_SIZE + PREVIEW_ROW_OFFSET ) ) end end for x = 0, BLOCKS_GRID_WIDTH-1 do local currentBlock = currentBlocksL[BLOCKS_GRID_HEIGHT-1][x] if currentBlock ~= nil then glomGfxUpdate( currentBlocksL, BLOCKS_GRID_WIDTH-1, BLOCKS_GRID_HEIGHT-1, x, BLOCKS_GRID_HEIGHT-1, currentBlock, true ) end end fillRowOfBlocks( previewBlocks, BLOCKS_GRID_HEIGHT, PREVIEW_ROW_OFFSET ) addCharacterLoc( 0, -TILE_SIZE ) end function rowDelayCalc() local rowDelay = math.max( LEVEL_UPDATE_CAP, ROW_UPDATE_DELAY + (activeLevel * LEVEL_ROW_TIME_MODIFIER)) if BLUE_BUFF_ACTIVE then rowDelay = math.ceil(rowDelay * ROW_TIMEOUT_BUFF_MODIFIER * 1/500) * 500 end return rowDelay end function rowUpdateSchedule() --MOAISim.stopProfiling() --MOAISim.startProfiling() addInRow() print( "Next line in: " .. tostring(rowDelayCalc()) ) if ROW_UPDATE_TIMER ~= nil then ROW_UPDATE_TIMER:stop() end if ROW_TELL_TIMER ~= nil then ROW_TELL_TIMER:stop() end local rowDelayTime = rowDelayCalc() ROW_UPDATE_TIMER = performWithDelay(rowDelayTime, rowUpdateSchedule ) ROW_TELL_TIMER = performWithDelay(rowDelayTime - ROW_TELL_TIME_MODIFIER, showRowUpdateTell ) end function showRowUpdateTell() if GAMEPLAY_STATE ~= GAMEPLAY_STATE_DEAD then SFX["ROW_UPDATE_BEGIN"]:play() else SFX["UFO_GAMEOVER"]:play() end layer:removeProp( tractorBeamProp ) layer:insertProp( tractorBeamActiveProp ) tractorBeamActiveAnim:start() end -- Hack below ROW_UPDATE_TIMER = nil ROW_TELL_TIMER = nil TRACTOR_BEAM_AMBIENT = nil function startGameLoop() GAME_STATE = GAME_STATE_GAME playerUpdateThread = MOAIThread.new() playerUpdateThread:run( playerUpdate ) blocksUpdateThread = MOAIThread.new() blocksUpdateThread:run( blocksUpdate ) blockThinkThread = MOAIThread.new() blockThinkThread:run( blockThink ) print("startGameLoop") local rowDelayTime = rowDelayCalc() showRowUpdateTell() performWithDelay( 1500, playMatchBeginAudio ) TRACTOR_BEAM_AMBIENT = performWithDelay( 2000, tractorBeamAnimOver ) ROW_UPDATE_TIMER = performWithDelay(rowDelayTime, rowUpdateSchedule ) ROW_TELL_TIMER = performWithDelay(rowDelayTime - ROW_TELL_TIME_MODIFIER, showRowUpdateTell ) --MOAISim.startProfiling() end function playMatchBeginAudio() SFX["TRACTOR_BEAM"]:play() end function togglePause( showMenu ) if showMenu == nil then showMenu = true end if GAMEPLAY_STATE == GAMEPLAY_STATE_DEAD or GAMEPLAY_STATE == GAMEPLAY_STATE_DYING then return end if GAMEPLAY_STATE == GAMEPLAY_STATE_ACTIVE then GAMEPLAY_STATE = GAMEPLAY_STATE_PAUSE if showMenu then messageText:setString("PAUSED") SFX["MENU_SELECT"]:play() layer:insertProp( gameOverBack ) menuItem1Text:setColor( 1, 1, 1, 1 ) layer:insertProp( menuItem1Text ) menuItem2Text:setColor( 0.5, 0.5, 0.5, 0.5 ) layer:insertProp( menuItem2Text ) --menuItem1FadeOut() menuItem1TextAnim = 1 local GRIDLIMITH = BLOCKS_GRID_HEIGHT-1 local GRIDLIMITW = BLOCKS_GRID_WIDTH-1 local currentBlocksL = currentBlocks local currentTime = MOAISim.getDeviceTime() for y = 0, GRIDLIMITH do local currentRow = currentBlocksL[y] for x = 0, GRIDLIMITW do local currentBlock = currentRow[x] if currentBlock ~= nil then layer:removeProp( currentBlock[1] ) pauseGlomOver( currentBlock, currentTime ) end end end for x = 0, GRIDLIMITW do local currentBlock = previewBlocks[x] if currentBlock ~= nil then layer:removeProp( currentBlock[1] ) end end layer:removeProp( characterProp ) end characterXVelocity = 0 playerUpdateThread:pause() blocksUpdateThread:pause() blockThinkThread:pause() ROW_UPDATE_TIMER:stop() ROW_TELL_TIMER:stop() MOAISim.togglePause( 1 ) else GAMEPLAY_STATE = GAMEPLAY_STATE_ACTIVE messageText:setString("") SFX["MENU_BACK"]:play() layer:removeProp( gameOverBack ) layer:removeProp( menuItem1Text ) layer:removeProp( menuItem2Text ) local GRIDLIMITH = BLOCKS_GRID_HEIGHT-1 local GRIDLIMITW = BLOCKS_GRID_WIDTH-1 local currentBlocksL = currentBlocks local currentTime = MOAISim.getDeviceTime() for y = 0, GRIDLIMITH do local currentRow = currentBlocksL[y] for x = 0, GRIDLIMITW do local currentBlock = currentRow[x] if currentBlock ~= nil then layer:insertProp( currentBlock[1] ) resumeGlomOver( currentBlock, currentTime ) end end end for x = 0, GRIDLIMITW do local currentBlock = previewBlocks[x] if currentBlock ~= nil then layer:insertProp( currentBlock[1] ) end end layer:insertProp( characterProp ) playerUpdateThread:pause(false) blocksUpdateThread:pause(false) blockThinkThread:pause(false) local rowDelayTime = rowDelayCalc() ROW_UPDATE_TIMER = performWithDelay(rowDelayTime, rowUpdateSchedule ) ROW_TELL_TIMER = performWithDelay(rowDelayTime - ROW_TELL_TIME_MODIFIER, showRowUpdateTell ) MOAISim.togglePause( 0 ) print("Unpause") end end function gameplaySetup() -- initialize values -- allocate resources -- spin up threads local bgGradientProp = MOAIProp2D.new() bgGradientProp:setDeck( bgGradient ) bgGradientProp:setLoc( 190, -1092 ) bgGradientProp:setPriority( 1 ) -- bgGradientProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) layer:insertProp( bgGradientProp ) bgGradientProp:moveLoc( 0, 1638, 120, MOAIEaseType.LINEAR ) local bgTreesProp2 = MOAIProp2D.new() bgTreesProp2:setDeck( bgTrees2 ) bgTreesProp2:setLoc( 190, 220 ) bgTreesProp2:setPriority( 2 ) layer:insertProp( bgTreesProp2 ) bgTreesProp2:moveLoc( 0, 370, 30, MOAIEaseType.LINEAR ) local bgTreesProp1 = MOAIProp2D.new() bgTreesProp1:setDeck( bgTrees1 ) bgTreesProp1:setLoc( 190, 220 ) bgTreesProp1:setPriority( 2 ) layer:insertProp( bgTreesProp1 ) bgTreesProp1:moveLoc( 0, 370, 25, MOAIEaseType.LINEAR ) gameplayBGStarsProp = MOAIProp2D.new() gameplayBGStarsProp:setDeck( bgStars ) -- gameplayBGStarsProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) gameplayBGStarsProp:setLoc( 190, 0 ) gameplayBGStarsProp:setPriority( 1 ) layer:insertProp( gameplayBGStarsProp ) local groundImage = MOAIProp2D.new() groundImage:setDeck( groundGfx ) groundImage:setLoc( 197.5, GRID_OFFSET_Y + (BLOCKS_GRID_HEIGHT * TILE_SIZE) - 18 ) groundImage:setPriority( 3 ) layer:insertProp( groundImage ) -- Deferred tractor beam asset loading to here gameplayCurTime = MOAISim.getCurrentTime() tractorBeamGfx = MOAITileDeck2D.new() tractorBeamGfx:setTexture( TRACTOR_BEAM ) tractorBeamGfx:setRect( 0, 0, 512, 512 ) tractorBeamGfx:setSize( 3, 3 ) tractorBeamGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) tractorBeamActiveGfx = MOAITileDeck2D.new() tractorBeamActiveGfx:setTexture( TRACTOR_BEAM_ACTIVE ) tractorBeamActiveGfx:setRect( 0, 0, 512, 512 ) tractorBeamActiveGfx:setSize( 3, 3 ) tractorBeamActiveGfx:setUVRect( -0.5, 0.5, 0.5, -0.5 ) tractorBeamProp = MOAIProp2D.new() tractorBeamProp:setDeck( tractorBeamGfx ) tractorBeamProp:setLoc( 190 + 34, -120 ) tractorBeamProp:setPriority( tractorBeamLayer ) -- tractorBeamProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) local tractorBeamAnim = MOAIAnim.new() tractorBeamAnim:reserveLinks( 1 ) tractorBeamAnim:setLink( 1, tractorBeamAnimCurve, tractorBeamProp, MOAIProp2D.ATTR_INDEX ) tractorBeamAnim:setMode( MOAITimer.LOOP ) tractorBeamAnim:start() layer:insertProp( tractorBeamProp ) tractorBeamActiveProp = MOAIProp2D.new() tractorBeamActiveProp:setDeck( tractorBeamActiveGfx ) tractorBeamActiveProp:setLoc( 190 + 34, -120 ) tractorBeamActiveProp:setPriority( tractorBeamLayer ) -- tractorBeamActiveProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) tractorBeamActiveAnim = MOAIAnim.new() tractorBeamActiveAnim:reserveLinks( 1 ) tractorBeamActiveAnim:setLink( 1, tractorBeamAnimCurve, tractorBeamActiveProp, MOAIProp2D.ATTR_INDEX ) tractorBeamActiveAnim:setMode( MOAITimer.LOOP ) local ufoProp = MOAIProp2D.new() ufoProp:setDeck( ufoGfx ) ufoProp:setLoc( 190, UFO_Y_POS ) ufoProp:setPriority( 13 ) ufoProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) layer:insertProp( ufoProp ) local uiLeftProp = MOAIProp2D.new() uiLeftProp:setDeck( uiLeft ) uiLeftProp:setLoc( 0, 0 ) uiLeftProp:setPriority( 2 ) layer:insertProp( uiLeftProp ) local uiRightProp = MOAIProp2D.new() uiRightProp:setDeck( uiRight ) uiRightProp:setLoc( SCREEN_WIDTH - 182, 0 ) uiRightProp:setPriority( 2 ) layer:insertProp( uiRightProp ) local hudLeftProp = MOAIProp2D.new() hudLeftProp:setDeck( hudLeft ) hudLeftProp:setLoc( 0, 0 ) hudLeftProp:setPriority( uiLayer ) layer:insertProp( hudLeftProp ) local hudRightProp = MOAIProp2D.new() hudRightProp:setDeck( hudRight ) hudRightProp:setLoc( 765, 0 ) hudRightProp:setPriority( uiLayer ) layer:insertProp( hudRightProp ) -- Final initialization initialize() startGameLoop() inputCallback = gameplayOnInput starNextDropTime = MOAISim.getDeviceTime() + SHOOTING_STAR_INITIAL_DELAY setCharacterState( CHARACTER_FALLING ) backgroundMusic:stop() if CURRENT_MUSIC_ON then gameplayMusic = MOAIUntzSound.new() if MOAIEnvironment.osBrand == "PSM" then gameplayMusic:setBackground( true ) end gameplayMusic:load("audio/mus_gameplay.mp3") gameplayMusic:setLooping( true ) gameplayMusic:setVolume( MUSIC_VOLUME ) gameplayMusic:play() end end function tractorBeamAnimOver() if tractorBeamActiveAnim:isActive() then tractorBeamActiveAnim:stop() layer:removeProp( tractorBeamActiveProp ) layer:insertProp( tractorBeamProp ) end end function gameplayTeardown() -- spin down threads -- clean up resources if gameplayMusic ~= nil then gameplayMusic:stop() end backgroundMusic:play() -- go through all blocks and run destroyGlomOver local GRIDLIMITH = BLOCKS_GRID_HEIGHT-1 local GRIDLIMITW = BLOCKS_GRID_WIDTH-1 local currentBlocksL = currentBlocks for y = 0, GRIDLIMITH do local currentRow = currentBlocksL[y] for x = 0, GRIDLIMITW do local currentBlock = currentRow[x] if currentBlock ~= nil then destroyGlomOver( currentBlock ) end end end for x = 0, GRIDLIMITW do local currentBlock = previewBlocks[x] if currentBlock ~= nil then destroyGlomOver( currentBlock ) end end playerUpdateThread:stop() blocksUpdateThread:stop() blockThinkThread:stop() ROW_UPDATE_TIMER:stop() ROW_TELL_TIMER:stop() if TRACTOR_BEAM_AMBIENT ~= nil then TRACTOR_BEAM_AMBIENT:stop() end layer:clear() if MOAIEnvironment.osBrand == "PSM" then MOAIPSM.destroyAnimCurve( characterIdleL.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterIdleR.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterJumpL.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterJumpR.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterFallL.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterFallR.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterWalkL.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterWalkR.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterSmackL.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterSmackR.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterDigAnim.curve.animCurveID ) MOAIPSM.destroyAnimCurve( characterDown.curve.animCurveID ) MOAIPSM.destroyTextBox( scoreText.textBoxID ) MOAIPSM.destroyTextBox( levelText.textBoxID ) for i, v in ipairs( scoreUpdateText ) do MOAIPSM.destroyTextBox( v.textBoxID ) end MOAIPSM.destroyTextBox( buffActiveText.textBoxID ) MOAIPSM.destroyTextBox( messageText.textBoxID ) MOAIPSM.destroyTextBox( messageTextBottom.textBoxID ) MOAIPSM.destroyTextBox( menuItem1Text.textBoxID ) MOAIPSM.destroyTextBox( menuItem2Text.textBoxID ) local characterSheetToUnload = MOAITileDeck2D.new() characterSheetToUnload:setTexture( CURRENT_CHARACTER["IMAGE"] ) -- unload character textures here: MOAIPSM.unloadTexture( characterSheetToUnload.textureID ) MOAIPSM.unloadTexture( characterSheet.textureID ) -- TODO: Add more to this! Or just fix other screens to create/purge and kill everything end end function showGameOver() performWithDelay( 1000, showGameOverActual ) end function showGameOverActual() if GAMEPLAY_STATE ~= GAMEPLAY_STATE_DYING then print("Trying to enter showGameOver when GAMEPLAY_STATE is: " .. GAMEPLAY_STATE ) return end GAMEPLAY_STATE = GAMEPLAY_STATE_DEAD playerUpdateThread:pause() blocksUpdateThread:pause() blockThinkThread:pause() ROW_UPDATE_TIMER:stop() ROW_TELL_TIMER:stop() local lbEntryDone = false local newHighScore = false if activeLevel > CURRENT_MAX_LEVEL then CURRENT_MAX_LEVEL = activeLevel end if SCORE > CURRENT_MAX_POINTS then CURRENT_MAX_POINTS = SCORE end CURRENT_MAX_MATCH = sessionMaxMatch writeSettings() -- save score to leaderboard for i, v in ipairs(CURRENT_LEADERBOARD_DATA) do if tonumber(v[1]) < SCORE then table.insert( CURRENT_LEADERBOARD_DATA, i, { SCORE, activeLevel+1 } ) lbEntryDone = true newHighScore = i == 1 break end end local lbSize = countTableSize( CURRENT_LEADERBOARD_DATA ) if not lbEntryDone and lbSize < 10 then table.insert( CURRENT_LEADERBOARD_DATA, { SCORE, activeLevel+1 } ) lbEntryDone = true end if lbSize > 10 then table.remove( CURRENT_LEADERBOARD_DATA, 10 ) end if lbEntryDone then -- save leaderboard to disk local leaderboardFile = io.open( LEADERBOARD_FILEPATH, 'w' ) if leaderboardFile ~= nil then for k, v in pairs(CURRENT_LEADERBOARD_DATA) do io.write( leaderboardFile, (tostring(v[1]) .. ',' .. tostring(v[2]) .. '\n' ) ) end io.close( leaderboardFile ) end end layer:insertProp( gameOverBack ) if newHighScore or lbSize == 0 then gameOverQueue[1] = { text = "New High Score!", sfx=SFX["HIGH_SCORE"] } end local highscore = CURRENT_LEADERBOARD_DATA[1][1] messageText:setString( "GAME OVER\n Score: " .. tostring(SCORE) .. " Points\nBest: " .. tostring(highscore) .. " Points" ) -- TODO: Unlock character check here -- add characters unlocked to game over queue -- game over queue: -- populated in this function -- emptied on teardown -- each entry needs: audio, text -- play audio, animate text from left to center -- wait at center for 2 seconds -- animate away, start next entry -- if last entry, once animated away, show -- press any button text -- do not allow skipping -- if gameOverQueue is empty, process input -- fill queue in here -- start executing based on the queue -- display the text once the queue is done showRowUpdateTell() performWithDelay( 500, suckBlocksAndPlayerUp ) timeToRevive = MOAISim.getDeviceTime() + DEAD_TIMEOUT -- go through characters for k, v in pairs( CHARACTER_LIST ) do -- if they were locked, but aren't now, then we just unlocked them. if characterLockState[k] == true and not isCharacterLocked( v ) then table.insert( gameOverQueue, { text = "Unlocked " .. tostring(v["NAME"]), sfx=SFX["UNLOCK"], gfx=createPortraitGfx(v["PORTRAIT"]) } ) end end gameOverQueueComplete = false performWithDelay( 2250, processGameOverQueue ) end function suckBlocksAndPlayerUp() -- all blocks move up local GRIDLIMITH = BLOCKS_GRID_HEIGHT-1 local GRIDLIMITW = BLOCKS_GRID_WIDTH-1 local currentBlocksL = currentBlocks for y = 0, GRIDLIMITH do local currentRow = currentBlocksL[y] for x = 0, GRIDLIMITW do local currentBlock = currentRow[x] if currentBlock ~= nil then currentBlock[1]:moveLoc( 0, -600, 1.0 + math.random( 0, 100 ) * 0.01, MOAIEaseType.EASE_OUT ) -- TODO: animate away the glom stuff? fadeOutGlomOver( currentBlock ) end end end for x = 0, GRIDLIMITW do local currentBlock = previewBlocks[x] if currentBlock ~= nil then currentBlock[1]:moveLoc( 0, -600, 1.0 + math.random( 0, 100 ) * 0.01, MOAIEaseType.EASE_OUT ) end end characterProp:moveLoc( 0, -600, 1.0 + math.random(0,100) * 0.01, MOAIEaseType.EASE_OUT ) TRACTOR_BEAM_AMBIENT = performWithDelay( 1750, tractorBeamAnimOver ) end function processGameOverQueue() if #gameOverQueue == 0 then layer:insertProp( messageTextBottom ) messageTextBottom:setString( "Press any button to play again" ) gameOverQueueComplete = true else local currentMessage = gameOverQueue[1] playStinger( currentMessage["sfx"] ) gameOverTextIdx = gameOverTextIdx + 1 if gameOverTextIdx > 2 then gameOverTextIdx = 1 end local curGameOverText = gameOverText[gameOverTextIdx] if currentMessage["gfx"] then curGameOverText:setLoc( 0, 230 ) else curGameOverText:setLoc( 0, 270 ) end curGameOverText:setString( currentMessage["text"] ) layer:insertProp( curGameOverText ) curGameOverText:setColor( 0.41, 0.95, 0.07, 0 ) curGameOverText:moveColor( 0, 0, 0, 1, 0.5 ) local anim = curGameOverText:moveLoc( 360, 0, 0, 0.5 ) anim:setListener( MOAIAction.EVENT_STOP, gameOverQueueOnCenter ) -- game over queue textbox - show text (which ever textbox is free, there will be 2) -- set location to left -- set up animation to center (over 0.5 seconds ) -- set callback to on center if currentMessage["gfx"] then gameOverPropIdx = gameOverPropIdx + 1 if gameOverPropIdx > 2 then gameOverPropIdx = 1 end local curGameOverProp = gameOverProps[gameOverPropIdx] curGameOverProp:setDeck(currentMessage["gfx"]) curGameOverProp:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) curGameOverProp:setColor( 1, 1, 1, 0 ) curGameOverProp:setLoc( 0, 270 ) curGameOverProp:moveLoc( 360, 0, 0.5 ) curGameOverProp:moveColor( 0, 0, 0, 1, 0.5 ) layer:insertProp( curGameOverProp ) curGameOverProp["active"] = true end end end function gameOverQueueOnCenter() performWithDelay( 2000, gameOverQueueMoveNext ) end function gameOverQueueMoveNext() local curGameOverText = gameOverText[gameOverTextIdx] curGameOverText:moveColor( 0, 0, 0, -1, 0.5 ) local anim = curGameOverText:moveLoc( 360, 0, 0, 0.5 ) anim["prop"] = curGameOverText anim:setListener( MOAIAction.EVENT_STOP, gameOverTextDone ) local curGameOverProp = gameOverProps[gameOverPropIdx] if curGameOverProp["active"] then curGameOverProp:moveColor( 0, 0, 0, -1, 0.5 ) local propAnim = curGameOverProp:moveLoc( 360, 0, 0.5 ) propAnim["prop"] = curGameOverProp propAnim:setListener( MOAIAction.EVENT_STOP, gameOverTextDone ) curGameOverProp["active"] = nil end -- game over queue textbox move to right for 0.5 seconds table.remove( gameOverQueue, 1 ) processGameOverQueue() end function gameOverTextDone(anim) layer:removeProp( anim["prop"] ) end function getJumpKey() if CURRENT_CONTROL_CFG == 0 then return KEY_JUMP else return KEY_ENTER end end function getSmackKey() if CURRENT_CONTROL_CFG == 0 then return KEY_DIG else return KEY_JUMP end end local pauseMenuCanFade = true function menuItem1FadeOut() if pauseMenuCanFade then menuItem1TextAnim = menuItem1Text:moveColor(0, 0, 0, -0.75, 0.5, MOAIEaseType.LINEAR) menuItem1TextAnim:setListener( MOAIAction.EVENT_STOP, menuItem1FadeIn ) end end function menuItem1FadeIn() if pauseMenuCanFade then menuItem1TextAnim = menuItem1Text:moveColor(0, 0, 0, 0.75, 0.5, MOAIEaseType.LINEAR) menuItem1TextAnim:setListener( MOAIAction.EVENT_STOP, menuItem1FadeOut ) end end function menuItem2FadeOut() if pauseMenuCanFade then menuItem2TextAnim = menuItem2Text:moveColor(0, 0, 0, -0.75, 0.5, MOAIEaseType.LINEAR) menuItem2TextAnim:setListener( MOAIAction.EVENT_STOP, menuItem2FadeIn ) end end function menuItem2FadeIn() if pauseMenuCanFade then menuItem2TextAnim = menuItem2Text:moveColor(0, 0, 0, 0.75, 0.5, MOAIEaseType.LINEAR) menuItem2TextAnim:setListener( MOAIAction.EVENT_STOP, menuItem2FadeOut ) end end function gameplayOnInput( key, isDown ) if key == KEY_DOWN then characterHoldingDown = isDown end if GAMEPLAY_STATE == GAMEPLAY_STATE_DEAD and (not isDown) and (MOAISim.getDeviceTime() > timeToRevive) and gameOverQueueComplete then SCORE = 0 gameplayTeardown() gameplaySetup() return elseif GAMEPLAY_STATE == GAMEPLAY_STATE_DEAD or GAMEPLAY_STATE == GAMEPLAY_STATE_DYING then return end if GAMEPLAY_STATE == GAMEPLAY_STATE_PAUSE then if not isDown then if key == KEY_UP or key == KEY_DOWN then if key == KEY_UP then SFX["MENU_MOVE_R"]:play() else SFX["MENU_MOVE_L"]:play() end if menuItem1TextAnim ~= nil then pauseMenuCanFade = false --menuItem1TextAnim:stop() pauseMenuCanFade = true menuItem1TextAnim = nil menuItem2Text:setColor( 1, 1, 1, 1 ) --menuItem2FadeOut() menuItem1Text:setColor( 0.5, 0.5, 0.5, 0.5 ) else if menuItem2TextAnim ~= nil then pauseMenuCanFade = false menuItem2TextAnim:stop() pauseMenuCanFade = true menuItem2TextAnim = nil end menuItem1Text:setColor( 1, 1, 1, 1 ) --menuItem1FadeOut() menuItem2Text:setColor( 0.5, 0.5, 0.5, 0.5 ) menuItem1TextAnim = 1 end elseif key == KEY_CONFIRM or key == KEY_SPACEBAR or key == KEY_PAUSE then if menuItem1TextAnim ~= nil then togglePause() else SCORE = 0 SFX["MENU_SELECT"]:play() changeGameState(GAME_STATE_MENU) MOAISim.togglePause( 0 ) end pauseMenuCanFade = false if menuItem1TextAnim ~= nil then --menuItem1TextAnim:stop() menuItem1TextAnim = nil end if menuItem2TextAnim ~= nil then --menuItem2TextAnim:stop() menuItem2TextAnim = nil end pauseMenuCanFade = true elseif key == KEY_SCREENSHOT then togglePause() end end return else if not isDown and (key == KEY_PAUSE) then togglePause() end if not isDown and (key == KEY_SCREENSHOT) then togglePause(false) end end if isDown and key == KEY_LEFT then characterXVelocity = -CURRENT_CHARACTER["SPEED"] characterFacingRight = false if not characterFalling then if characterSmackR:isActive() then local animTime = characterSmackR:getTime() characterSmackR:stop() characterSmackL:start() characterSmackL:setTime( animTime ) else setCharacterState( CHARACTER_WALKING ) end else setCharacterState( CHARACTER_FALLING ) end elseif isDown and key == KEY_RIGHT then characterXVelocity = CURRENT_CHARACTER["SPEED"] characterFacingRight = true if not characterFalling then if characterSmackL:isActive() then local animTime = characterSmackL:getTime() characterSmackL:stop() characterSmackR:start() characterSmackR:setTime( animTime ) else setCharacterState( CHARACTER_WALKING ) end else setCharacterState( CHARACTER_FALLING ) end elseif not isDown then if (key == KEY_LEFT and characterXVelocity == -CURRENT_CHARACTER["SPEED"]) or (key == KEY_RIGHT and characterXVelocity == CURRENT_CHARACTER["SPEED"]) then characterXVelocity = 0 if characterJumping then setCharacterState( CHARACTER_JUMPING ) elseif characterFalling then setCharacterState( CHARACTER_FALLING ) else setCharacterState( CHARACTER_IDLE ) end end end if isDown and key == getJumpKey() and not characterFalling then SFX["JUMP"]:play() characterYVelocity = -CURRENT_CHARACTER["JUMP_FORCE"] characterFalling = true setCharacterState( CHARACTER_JUMPING ) end if not isDown and key == getJumpKey() then characterYVelocity = math.max( characterYVelocity, JUMP_MIN_FORCE ) end if key == KEY_DOWN then if not isDown and CHARACTER_STATE == CHARACTER_DOWN then setCharacterState( CHARACTER_IDLE ) end end if key == KEY_FORCEROW and not isDown then print("Manual force") rowUpdateSchedule() end if key == 49 and not isDown then updateCounterUI( 3 ) end if key == getSmackKey() and isDown then if characterHoldingDown then if not characterFalling and not characterDigAnim:isActive() then characterDigAnim:start() performDigDown() end elseif not characterSmackL:isActive() and not characterSmackR:isActive() then if characterFacingRight then characterSmackR:start() else characterSmackL:start() end performDig() end end if key == KEY_FORCEBURGERS and not isDown then processGlomComplete( 3 ) end if key == KEY_MEMDUMP and not isDown then MOAISim.triggerMemDump() end end function onStingOver() if CURRENT_MUSIC_ON then gameplayMusic:setVolume( MUSIC_VOLUME ) end end function playStinger( asset ) if CURRENT_MUSIC_ON then gameplayMusic:setVolume( MUSIC_VOLUME * 0.6 ) end asset:play() performWithDelay( 3000, onStingOver ) end local glomOverKey = "glomOver" local glomUpKey = "glomUp" local glomEndKey = "gomHotKey" function moveGlomOver( block, x, y ) local glomOver = block[glomOverKey] if glomOver ~= nil then glomOver:moveLoc( x, y ) end local glomUp = block[glomUpKey] if glomUp ~= nil then glomUp:moveLoc( x, y ) end local glomEnd = block[glomEndKey] if glomEnd ~= nil then glomEnd:moveLoc( x, y ) end end function setGlomOverLoc( block, x, y ) local glomOver = block[glomOverKey] if glomOver ~= nil then glomOver:setLoc( x + (TILE_SIZE * 0.5), y + (TILE_SIZE * 0.5) ) end local glomUp = block[glomUpKey] if glomUp ~= nil then glomUp:setLoc( x, y ) end local glomEnd = block[glomEndKey] if glomEnd ~= nil then glomEnd:setLoc( x, y ) end end function createGlomOver( block ) if block[glomOverKey] ~= nil then print("PROBLEM: Trying to add another glomOver where there is one") end local locX, locY = block[1]:getLoc() local glomOver = MOAIProp2D.new() glomOver:setDeck( glomOverGfx ) glomOver:setLoc( locX + (TILE_SIZE * 0.5), locY + (TILE_SIZE * 0.5) ) glomOver:setPriority( fxLayer ) glomOver:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) glomOver:setColor( 1, 1, 1, 1 ) layer:insertProp( glomOver ) block[glomOverKey] = glomOver block["glomFader"] = glomOver:moveColor( 0, 0, 0, -1.0, 0.1, MOAIEaseType.LINEAR ) local glomUp = createMatchActivateAnimation( locX, locY ) block[glomUpKey] = glomUp block["glomUpFader"] = glomUp:moveColor( 0, 0, 0, 1.0, GLOM_TIMEOUT, MOAIEaseType.LINEAR ) block["glomEndTimer"] = performWithDelay( (GLOM_TIMEOUT - GLOM_END_TIMEOUT) * 1000, createGlomEndFade, nil, block ) end function createGlomEndFade( block ) local glomEnd = createMatchExpireAnimation( block[1]:getLoc() ) block[glomEndKey] = glomEnd block["glomEndFader"] = glomEnd:moveColor( 0, 0, 0, 1.0, GLOM_END_TIMEOUT, MOAIEaseType.LINEAR ) end function destroyGlomOver( block ) -- Doing this first since by calling stop it might trigger the callback, -- so the rest below will then reset what it does. if block["glomEndTimer"] then block["glomEndTimer"]:stop() block["glomEndTimer"] = nil end if block["glomFader"] then block["glomFader"]:stop() block["glomFader"] = nil end if block["glomUpFader"] then block["glomUpFader"]:stop() block["glomUpFader"] = nil end if block["glomEndFader"] then block["glomEndFader"]:stop() block["glomEndFader"] = nil end local glomOver = block[glomOverKey] if glomOver ~= nil then layer:removeProp( glomOver ) spriteDestroy( glomOver ) block[glomOverKey] = nil end local glomUp = block[glomUpKey] if glomUp ~= nil then layer:removeProp( glomUp ) spriteDestroy( glomUp ) block[glomUpKey] = nil end local glomEnd = block[glomEndKey] if glomEnd ~= nil then layer:removeProp( glomEnd ) spriteDestroy( glomEnd ) block[glomEndKey] = nil end end function pauseGlomOver( block, currentTime ) -- if block["glomEndTimer"] and block["glomEndTimer"].active then -- print("test1") -- block["glomEndTimerLeft"] = block["glomEndTimer"].span - (currentTime - block["glomEndTimer"].startTime) -- block["glomEndTimer"]:stop() -- end -- -- if block["glomFader"] and block["glomFader"].active then -- print("test2") -- block["glomFaderLeft"] = block["glomFader"].span - (currentTime - block["glomFader"].startTime) -- block["glomFader"]:stop() -- end -- if block["glomUpFader"] and block["glomUpFader"].active then -- print("test3") -- block["glomUpFaderLeft"] = block["glomUpFader"].span - (currentTime - block["glomUpFader"].startTime) -- block["glomUpFader"]:stop() -- end -- if block["glomEndFader"] and block["glomEndFader"].active then -- print("test4") -- block["glomEndFaderLeft"] = block["glomEndFader"].span - (currentTime - block["glomEndFader"].startTime) -- block["glomEndFader"]:stop() -- end local glomOver = block[glomOverKey] if glomOver ~= nil then layer:removeProp( glomOver ) end local glomUp = block[glomUpKey] if glomUp ~= nil then layer:removeProp( glomUp ) end local glomEnd = block[glomEndKey] if glomEnd ~= nil then layer:removeProp( glomEnd ) end -- if block["timeToRemove"] ~= nil then -- block["timeToRemove"] = block["timeToRemove"] - currentTime -- end end function resumeGlomOver( block, currentTime ) -- if block["glomEndTimerLeft"] then -- block["glomEndTimer"]:start() -- block["glomEndTimer"].span = block["glomEndTimerLeft"] -- end -- -- if block["glomFaderLeft"] then -- block["glomFader"]:start() -- block["glomFader"].span = block["glomFaderLeft"] -- end -- if block["glomUpFaderLeft"] then -- block["glomUpFader"]:start() -- block["glomUpFader"].span = block["glomUpFaderLeft"] -- end -- if block["glomEndFaderLeft"] then -- block["glomEndFader"]:start() -- block["glomEndFader"].span = block["glomEndFaderLeft"] -- end local glomOver = block[glomOverKey] if glomOver ~= nil then layer:insertProp( glomOver ) end local glomUp = block[glomUpKey] if glomUp ~= nil then layer:insertProp( glomUp ) end local glomEnd = block[glomEndKey] if glomEnd ~= nil then layer:insertProp( glomEnd ) end -- if block["timeToRemove"] ~= nil then -- block["timeToRemove"] = currentTime + block["timeToRemove"] -- end end function onGlomOverGone( anim ) anim:stop() local block = anim["block"] destroyGlomOver( block ) end function fadeOutGlomOver( block ) destroyGlomOver( block ) end --function levelingUnitTests() -- CURRENT_LEVEL = 0 -- burgersMatchCount = 0 -- -- print( "activeLevelCalc() should be 0" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 1 -- burgersMatchCount = 0 -- -- print( "activeLevelCalc() should be 1" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 0 -- burgersMatchCount = 10 -- -- print( "activeLevelCalc() should be 1" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 0 -- burgersMatchCount = 20 -- -- print( "activeLevelCalc() should be 1" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 0 -- burgersMatchCount = 29 -- -- print( "activeLevelCalc() should be 1" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 0 -- burgersMatchCount = 30 -- -- print( "activeLevelCalc() should be 2" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 0 -- burgersMatchCount = 31 -- -- print( "activeLevelCalc() should be 2" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 2 -- burgersMatchCount = 31 -- -- print( "activeLevelCalc() should be 3" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 9 -- burgersMatchCount = 50 -- -- print( "activeLevelCalc() should be 9" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 9 -- burgersMatchCount = 100 -- -- print( "activeLevelCalc() should be 10" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 9 -- burgersMatchCount = 99 -- -- print( "activeLevelCalc() should be 9" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 9 -- burgersMatchCount = 101 -- -- print( "activeLevelCalc() should be 10" ) -- print( activeLevelCalc() ) -- -- CURRENT_LEVEL = 10 -- burgersMatchCount = 50 -- -- print( "activeLevelCalc() should be 12" ) -- print( activeLevelCalc() ) --end