Skip to content

Instantly share code, notes, and snippets.

@young40
Created July 6, 2015 07:58
Show Gist options
  • Save young40/38e61d64393d2738a167 to your computer and use it in GitHub Desktop.
Save young40/38e61d64393d2738a167 to your computer and use it in GitHub Desktop.
Emacs lua-mode comment
local audioEngine = cc.SimpleAudioEngine:getInstance( )
BattleEffect = BattleEffect or { }
--[[ 士气 ]]
function BattleEffect:playMorale( )
end
--[[ 跳弹 ]]
function BattleEffect.playRicochet( ship )
--[[ 跳弹有BUG
local shipPos = cc.p( ship:getPosition() )
local sprHead = UI.spriteWithFrame( "blow_word_02.png" ) --cc.Sprite:createWithTexture( ship.bloodLayer.btahNode:getTexture(), cc.rect( 52, 62, 42, 23 ), true ) --
sprHead:setPosition( cc.p( shipPos.x - 40, shipPos.y + 75 ) )
ship.bloodLayer.btahNode:addChild( sprHead )
sprHead:runAction( cc.Sequence:create( cc.ScaleTo:create( 0.12, 2.5 ), cc.ScaleTo:create( 0.08, 1 ), cc.MoveBy:create( 0.2, cc.p( 0, 100 ) ),
cc.RemoveSelf:create( ) ) )
]]
end
--[[ 暴击 ]]
function BattleEffect.playCrit( ship, hp )
BattleEffect.playHpInternal( ship, -hp, "r_b_", 30, 40 )
end
function BattleEffect.playHpInternal( ship, hp, fontPrefix, fontWidth, fontHeight )
local shipPos = cc.p( ship:getPosition() )
local fileName = fontPrefix.."reduction.png"
if hp > 0 then
fileName = fontPrefix.."add.png"
end
local sprSymbol = UI.spriteWithFrame( fileName )
sprSymbol:setPosition( cc.p( shipPos.x - 28, shipPos.y + 70 ) )
ship.bloodLayer.btahNode:addChild( sprSymbol )
local i = 1
hp = math.abs( hp )
for index = string.len( hp ) - 1, 0, -1 do
local num = math.floor( hp / math.pow( 10, index ) % 10 )
local frameName = fontPrefix..string.format( "%d.png", num )
local spr = UI.spriteWithFrame( frameName )
spr:setPosition( cc.p( fontWidth/2 + fontWidth * i, fontHeight/2 ) )
sprSymbol:addChild( spr )
i = i + 1
end
sprSymbol:runAction( cc.Sequence:create( cc.ScaleTo:create( 0.12, 2.5 ), cc.ScaleTo:create( 0.08, 1 ), cc.MoveBy:create( 0.2, cc.p( 0, 100 ) ),
cc.CallFunc:create( function( sprSymbol ) sprSymbol:removeFromParent() end ) ) )
end
--[[ 掉血 ]]
function BattleEffect.playHp( ship, hp, attackType )
if attackType == dyt.AttackTypes.Torpedo then
BattleEffect.playHpInternal( ship, -hp, "r_y_", 22, 28 )
elseif attackType == dyt.AttackTypes.Artillery then
BattleEffect.playHpInternal( ship, -hp, "r_s_", 22, 28 )
else
BattleEffect.playHpInternal( ship, -hp, "r_s_", 22, 28 )
end
end
--[[ 加血 ]]
function BattleEffect.playAddHp( ship, hp )
BattleEffect.playHpInternal( ship, hp, "g_", 22, 28 )
end
--[[ 火炮水花 ]]
function BattleEffect.playSpray( sea, pos , zorder , effectName )
local csbName
if not effectName or effectName == "" then
csbName = "res/ui/particle/luoshui_01.csb"
else
csbName = "res/ui/particle/"..effectName
end
local ani = BattleResources:getAutoremoveTimelineNode( csbName )
ani:setPosition( pos )
ani:setScale( 0.5 + math.random( ) * 0.5 )
sea:addChild( ani , BattleMap.Z_SHIP )
end
--[[ 鱼雷水花 ]]
function BattleEffect.playSprayTorpedo( sea, pos, zorder )
local ani = BattleResources:getAutoremoveTimelineNode( Res.FileNames.res_ui_particle_spray4_csb , true )
ani:setPosition( pos )
sea:addChild( ani , BattleMap.Z_SHIP )
end
-- 副炮击中
function BattleEffect.playViceArtilleryExplosion( ship, pos )
local aniName = Res.FileNames.res_ui_particle_bomb1_csb
if math.random() < 0.5 then
aniName = Res.FileNames.res_ui_particle_bomb4_csb
end
local ani = BattleResources:getTimelineNode(aniName)
ani:setPosition( pos )
ani:setScale( 0.67 )
ship:addChild( ani , BattleMap.Z_SKILL )
UI.delayRemove( ani, 0.5 )
end
--[[ 主炮击中 ]]
function BattleEffect.playArtilleryExplosion( ship, pos, explosionEffect )
local effectName = "res/ui/particle/"..explosionEffect
local ani = BattleResources:getAutoremoveTimelineNode( effectName )
ani:setPosition( pos )
ani:setScale( 0.67 )
ship:addChild( ani , BattleMap.Z_SKILL )
end
--[[ 主炮击中 ]]
function BattleEffect.playArtilleryExplosion2( ship, pos, explosionEffect )
local effectName = "res/ui/particle/"..explosionEffect
local ani = BattleResources:getAutoremoveTimelineNode( effectName )
ani:setPosition( pos )
ani:setScale( 0.67 )
cc.Director:getInstance():getRunningScene():addChild( ani, BattleMap.Z_SKILL )
end
--[[ 鱼雷击中 ]]
function BattleEffect.playTorpedoExplosion( explosion1, explosion2, sea, pos )
local scale = math.random() * 0.5 + 0.5
local tropedo1 = BattleResources:getAutoremoveTimelineNode( "res/ui/particle/" .. explosion1 )
tropedo1:setPosition( pos )
tropedo1:setScale( scale )
sea:addChild( tropedo1, BattleMap.Z_SHIP )
local tropedo2 = BattleResources:getAutoremoveTimelineNode( "res/ui/particle/" .. explosion2 )
tropedo2:setPosition( pos )
tropedo2:setScale( scale )
sea:addChild( tropedo2 , BattleMap.Z_SPRAY )
end
--[[ 轰炸机投弹击中 ]]
function BattleEffect.playBombingPlaneExplosion( ship, pos )
local ani = BattleResources:getAutoremoveTimelineNode( Res.FileNames.res_ui_particle_zhongdan_09_csb )
ani:setPosition( pos )
ship:addChild( ani, BattleMap.Z_SKILL )
UI.delayRemove( ani, 1.0 )
end
--[[ 跳弹 ]]
function BattleEffect.playRicochetEffect( ship, pos , ricochet_effect )
local effectName = "res/ui/particle/"..ricochet_effect
local ani = BattleResources:getAutoremoveTimelineNode( effectName )
ani:setPosition( pos )
ship:addChild( ani , BattleMap.Z_SKILL )
end
-- 开火动画 --
--[[ 火炮开炮水面动画 ]]
function BattleEffect.playWaterShock( effectName, map, pos )
local effectName = "res/ui/particle/"..effectName
local ani = BattleResources:getAutoremoveTimelineNode( effectName )
ani:setPosition( pos )
map:addChild( ani , BattleMap.Z_FISH )
end
--[[ 主炮开火 ]]
function BattleEffect.playArtilleryFire( fireEffectName, map, pos , rotation )
local name = "res/ui/particle/"..fireEffectName
local ani = BattleResources:getAutoremoveTimelineNode( name )
ani:setPosition( pos )
ani:setRotation( rotation )
map:addChild( ani , BattleMap.Z_BULLET )
end
--[[ 副炮开火 ]]
-- weaponFireEffect是武器表中的fire_effect
-- #分割后可能有多重效果, 随机选取一种
function BattleEffect.playViceArtilleryFire( weaponFireEffect, map, pos , rotation )
local list = LuaUtils.Split(weaponFireEffect, "#")
local effect = list[math.random(1, #list)]
local name = "res/ui/particle/" .. effect
local ani = BattleResources:getAutoremoveTimelineNode( name )
ani:setPosition( pos )
ani:setRotation( -rotation )
map:addChild( ani , BattleMap.Z_BULLET )
end
--[[ 鱼雷开火 ]]
function BattleEffect.playTorpedoFire( torpedoEffect, map, pos, rotation )
local effectName = "res/ui/particle/" .. torpedoEffect
local ani = BattleResources:getAutoremoveTimelineNode( effectName )
ani:setPosition( pos )
ani:setRotation( rotation )
map:addChild( ani, BattleMap.Z_BULLET )
end
--[[ 船死亡 ]]
function BattleEffect.playShipDie( map, pos, shipType, tag )
--
local ani = nil
if shipType == dyt.ShipTypes .Destroyer then
ani = BattleResources:getAutoremoveTimelineNode( Res.FileNames.res_ui_particle_dead01_csb )
elseif shipType == dyt.ShipTypes .Cruiser then
ani = BattleResources:getAutoremoveTimelineNode( Res.FileNames.res_ui_particle_dead02_csb )
elseif shipType == dyt.ShipTypes .AircraftCarrier then
ani = BattleResources:getAutoremoveTimelineNode( Res.FileNames.res_ui_particle_dead04_csb )
else
ani = BattleResources:getAutoremoveTimelineNode( Res.FileNames.res_ui_particle_dead03_csb )
end
ani:setPosition( pos )
ani:setScale( 0.67 )
map:addChild( ani, BattleMap.Z_SHIP + 1 )
-- 死完音效
SoundEffect:playEffect( "battle_dead_01.mp3" , tag )
end
--[[ 飞机死亡 ]]
function BattleEffect.playPlaneDie( map, pos )
local r = math.random( )
local aniName = Res.FileNames.res_ui_particle_boom8_csb
if r < 0.333 then
aniName = Res.FileNames.res_ui_particle_boom9_csb
elseif r < 0.67 then
aniName = Res.FileNames.res_ui_particle_boom5_csb
end
local ani = BattleResources:getAutoremoveTimelineNode( aniName )
ani:setPosition( pos )
map:addChild( ani , BattleMap.Z_FIGHTER )
end
--[[ 早期 ]]
function BattleEffect.skillRelease( ship )
local ani = ccs.Armature:create( "skill_release" )
ani:getAnimation():playWithIndex( 0, -1, 0 )
ani:setPosition( cc.p( 0, 0 ) )
ani:setLocalZOrder( 100 )
ship:addChild( ani )
end
function BattleEffect.skillSmokeEffect( )
local ani = ccs.Armature:create( "skill_smoke" )
ani:getAnimation():playWithIndex( 0, -1, 0 )
ani:setPosition( cc.pSub( VisibleRect:center( ), cc.p( 100, -100 ) ) )
ani:setLocalZOrder( 100 )
cc.Director:getInstance():getRunningScene():addChild( ani )
end
function BattleEffect.skillRepairEffect( ship, duration )
local emitter = UI.particleRelative( Res.FileNames.res_particle_skill_repair_plist )
emitter:setPosition( cc.p( 0, 0 ) )
ship:addChild( emitter )
emitter:setDuration( duration )
end
function BattleEffect.skillConcentrateFireEffect( ship )
local ani = ccs.Armature:create( "skill_concentratefire" )
ani:getAnimation():playWithIndex( 0, -1, 0 )
ani:setPosition( cc.p( 0, 0 ) )
ani:setLocalZOrder( 100 )
ship:addChild( ani , -1 )
end
function BattleEffect.shockNode( node, delay, duration )
local a1 = cc.MoveBy:create( 0.05, cc.pMul( VisibleRect:leftTop(),0.03 ) )
local a2 = a1:reverse()
local a3 = cc.MoveBy:create( 0.05, cc.pMul( VisibleRect:leftTop(),0.03 ) )
local a4 = a3:reverse()
local a5 = cc.MoveBy:create( 0.05, cc.pMul( VisibleRect:leftTop(),0.03 ) )
local a6 = a5:reverse()
local action = cc.Sequence:create( cc.DelayTime:create( delay ),a1,a2,a3,a4,a5,a6 )
node:runAction( action )
end
function BattleEffect.smokeShell( battleMap, pos )
local emitter = UI.particleRelative( Res.FileNames.res_particle_skill_smoke_plist )
emitter:setPosition( pos )
battleMap:addChild( emitter, BattleMap.Z_BULEET )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment