Fish.lua:

--[[
------------------------------------
一条鱼
------------------------------------
Ivan_han@2013/4/16 11:08:17
------------------------------------
]]

function CreateObj(pSpriteFrame)
    return CCSprite:createWithSpriteFrame(pSpriteFrame)
end

Fish = class("Fish", CreateObj)

Fish.__index = Fish
--Fish.isCatch = false
--Fish.fishType=1

CCLuaLog("Fish...................."..tostring(Fish.__index))

function Fish:spriteWithSpriteFrame(pSpriteFrame)
    local fish = Fish.new(pSpriteFrame)
    if (fish~=nil)then
    fish:autorelease()
          fish:retain()
 end
 return fish
end

function Fish:spriteWithSpriteFrameName(pszSpriteFrameName)
    if(pszSpriteFrameName == nil) then
        CCLuaLog("Fish.spriteWithSpriteFrameName.pszSpriteFrameName.Nil!")
        return nil
    end
    local pFrame = CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName(pszSpriteFrameName)
    if (pFrame~=nil)then
  return self:spriteWithSpriteFrame(pFrame)
 end
end

function Fish:randomCatch(level)
 local rnd = SIX_Utility:new():RNDNUM(0,9)
 if(rand >= level) then
        return true
    end
    return false
end

--[[
function Fish:getIsCatch()
    return isCatch
end

function Fish:setIsCatch(IsCatch)
    isCatch=IsCatch
end
]]

--[[
三阶贝塞尔曲线(P_0,P_1,P_2,P_3)退化为二阶贝塞尔曲线(P_0,P_1,P_2,即抛物线:起点P_0=控制点P_1,控制点P_2,终点P_3)
参数说明:
startP----轨迹起点
endP----轨迹终点
startAngle----
endAngle----
time----动画时长
]]
function Fish:moveWithParabola(startP,endP,startAngle,endAngle,time)
 local sx = startP.x;
 local sy = startP.y;
 local ex =endP.x;
 local ey =endP.y;

local h = self:getContentSize().height * 0.5;
 local pos=CCPoint(sx,sy);
 self:setPosition(pos);
 self:setRotation(startAngle);

-- 贝塞尔曲线
 local bezier=ccBezierConfig:new();
 -- 控制点1(起点)
 bezier.controlPoint_1 = ccp(sx, sy);
 -- 控制点2
 --bezier.controlPoint_2 = ccp(sx+(ex-sx)*0.5, sy+(ey-sy)*0.5);
 bezier.controlPoint_2 = ccp(sx+(ex-sx)*0.5, sy+(ey-sy)*0.5+100); 
 -- 终点
 bezier.endPosition = ccp(endP.x, endP.y);

local actionMove = CCBezierTo:create(time, bezier);
 local actionRotate = CCRotateTo:create(time, endAngle);
 local action = CCSpawn:createWithTwoActions(actionMove, actionRotate);
 local pcc=CCCallFunc:create(function()
          self:removeFromParentAndCleanup(true)
    end)
 local sq = CCSequence:createWithTwoActions(action,pcc); 
 self:runAction(sq);
end

function CircleTrace(t)
          --圆中心为(350,300),半径为150,轨迹起点为(500,300)的逆时针圆轨迹
          local x=150*math.cos(2*math.pi*t)
          local y=150*math.sin(2*math.pi*t)
          return ccp(350+x,300+y)
end

function EllipseTrace(t)
          --椭圆中心为(350,300),长半径为150,短半径为120,轨迹起点为(500,300),焦点F_1为(260,300),焦点F_2为(440,300)的逆时针椭圆轨迹
          local C=ccp(350,300)
          local a=150
          local b=120
          local c=90
          local x=a*math.cos(2*math.pi*t)
          local y=b*math.sin(2*math.pi*t)
          return ccp(C.x+x,C.y+y)
end

function SinTrace(t)
          --轨迹起点为(500,300),振幅为150的正弦曲线轨迹
          local C=ccp(350,300)
          local a=150
          local x=a*2*math.pi*t
          local y=a*math.sin(2*math.pi*t)
          return ccp(C.x+x,C.y+y)
end

--[[
获得圆上点的坐标
参数说明:
startP--轨迹起点坐标
centerP--圆心坐标
deltArg--相对于轨迹起点的辐角主值增量 
]]
function GetCirclePos(startP,centerP,deltArg)
          local startarg=math.atan2(startP.y-centerP.y,startP.x-centerP.x);--轨迹起点相对于圆心的辐角主值
          local tempx=(startP.x-centerP.x)*(startP.x-centerP.x);
    local tempy=(startP.y-centerP.y)*(startP.y-centerP.y);
    local r=math.sqrt(tempx+tempy);--圆的半径
          local x=r*math.cos(startarg+deltArg)--圆上点相对于圆心的X坐标偏移
          local y=r*math.sin(startarg+deltArg)--圆上点相对于圆心的Y坐标偏移
          return ccp(centerP.x+x,centerP.y+y)
end

--[[
圆轨迹
参数说明:
t----轨迹参数方程中的参数
startP----轨迹起点坐标
centerP----圆心坐标
direction----取值浮点数,表示圈数,正、负圈数分别表示逆、顺时针旋转
]]
--function CircleTraceFunc(t,startP,centerP,direction)
function CircleTraceFunc(t,startPx,startPy,centerPx,centerPy,direction)
          local startP=ccp(startPx,startPy)
          local centerP=ccp(centerPx,centerPy)
          --圆中心为centerP,半径为r,轨迹起点为startP的direction弧度圆轨迹
          local startarg=math.atan2(startP.y-centerP.y,startP.x-centerP.x);--轨迹起点相对于圆心的辐角主值
          local tempx=(startP.x-centerP.x)*(startP.x-centerP.x);
    local tempy=(startP.y-centerP.y)*(startP.y-centerP.y);
    local r=math.sqrt(tempx+tempy);--圆的半径
          local x=r*math.cos(startarg+2*math.pi*t*direction)
          local y=r*math.sin(startarg+2*math.pi*t*direction)
          --return ccp(centerP.x+x-startPx,centerP.y+y-startPy)--改为相对位置以支持CCRepeatForever无限次重复动画
          return ccp(centerP.x+x,centerP.y+y)
end

--[[
直线运动和匀速圆周运动合成的轨迹,我们称之为摆线
过原点startP=(0,0)、半径为r的摆线参数方程为
x=r(a-sina)
y=r(1-cosa)
在这里实参数a是在弧度之下,圆滚动的角度。对每一个给出的a ,圆心的坐标为(ra,r)。
参数说明:
t----轨迹参数方程中的参数
]]
function CycloidTrace(t)
          local startP=ccp(200,300)--摆线轨迹起点
          local direction=3
    local r=50;
          local a=2*math.pi*t*direction
          local x=r*(a-math.sin(a))
          local y=r*(1-math.cos(a))
          return ccp(startP.x+x,startP.y+y)
end

--[[
摆线轨迹
参数说明:
t----轨迹参数方程中的参数
startP----轨迹起点坐标
r----圆的半径
deltArg----取值浮点数,相对于轨迹起点的辐角主值增量
direction----拱形的个数
reserved----保留参数,reservedx保留,reservedy摆线轨迹整体逆时针旋转弧度
]]
--function CycloidTraceFunc(t,startPx,startPy,r,deltArg,direction)
function CycloidTraceFunc(t,startPx,startPy,r,deltArg,direction,reservedx,reservedy)
          local a=2*math.pi*t*direction        
          local x=r*(a-math.sin(a))
          local y=r*(1-math.cos(a))
          local startPt=ccp(x,y)
          local centerPt=ccp(r*a,r)--圆心坐标
    local retPt0=GetCirclePos(startPt,centerPt,deltArg)
    local retPt=ccp(retPt0.x*math.cos(reservedy)-retPt0.y*math.sin(reservedy),retPt0.x*math.sin(reservedy)+retPt0.y*math.cos(reservedy))--(x,y)逆时针旋转a之后变为(xcosa-ysina,xsina+ycosa)
          local startP=ccp(startPx,startPy)--摆线轨迹起点deltArg=0
          return ccp(startP.x+retPt.x,startP.y+retPt.y)     
end

--[[
具体的运动轨迹由轨迹类型、轨迹起点坐标、轨迹速度等相互独立的参数来控制
参数说明:
pathType--轨迹类型
arg1--第一个额外参数,圆轨迹要用到
]]
function Fish:addPath(pathType,arg1)
if(pathType==1)then
   --给定轨迹起点和恒定速度矢量(恒定速率和恒定方向)的匀速直线运动
   --self:setPosition(CCPoint(200,300));
--[[  
   local  actionBy = CCMoveBy:create(1, ccp(300,300));
   local  ac = CCRepeatForever:create(actionBy);
   self:runAction(ac);
  ]]
--右上角45度直线轨迹
   local pAction=CCMoveBy:create(15.0, ccp(1500,1500));
   self:runAction(pAction);  
end
if(pathType==2)then
   --self:setPosition(CCPoint(200,300));
--[[  
   local pAction=CCMoveBy:create(3.0, ccp(300,0));
   --self:runAction(pAction);
   local  ac = CCRepeatForever:create(pAction);
   self:runAction(ac);
]]
--水平向右直线轨迹
   local pAction=CCMoveBy:create(15.0, ccp(1500,0));
   self:runAction(pAction);  
   --local pAction=CCMoveTo:create(3.0, ccp(500,300));--直线轨迹。参数一为动画时长,参数二为要移动到的目标点。
     --创建一个加速直线运动(a>0)。1<r<2时,△a<0;r=2时,△a=0,a=2;r>2时,△a>0。 
   --local move_ease_in = CCEaseIn:create(pAction,2);--参数二r=2,加速度为a=2的匀加速直线运动
   --local move_ease_in = CCEaseIn:create(pAction,5);--参数二r>2,加速度越来越大的变加速直线运动
    --local move_ease_in = CCEaseIn:create(pAction,1.5);--参数二1<r<2,加速度越来越小的变加速直线运动
    --self:runAction(move_ease_in);  
    --创建一个加速度越来越大的减速直线运动(a<0),r>1,△a>0 
   --local move_ease_out = CCEaseOut:create(pAction,2);
   --self:runAction(move_ease_out);
end 
if(pathType==3)then
   --轨迹起点
   --self:setPosition(CCPoint(200,300));
   --圆逆时针运动轨迹,参数一为动画时长,参数二为当前圆上位置的对径点坐标,参数三为轨迹方向
   --给定轨迹起点和恒定速率的匀速圆周运动
   --self:setPosition(CCPoint(200,300));
--[[
   local  actionBy = CircleAction:create(1.0, ccp(500,300),1);
   local  ac = CCRepeatForever:create(actionBy);
   self:runAction(ac);
]]
  local startP=CCPoint(self:getPositionX(),self:getPositionY());
  --对于圆轨迹,arg1代表圆心坐标
   if(arg1==nil)then
      arg1=CCPoint(self:getPositionX()+150,self:getPositionY());
  end
  --对径点P
   local P=CCPoint(arg1.x*2-self:getPositionX(),arg1.y*2-self:getPositionY());
  --local P=CCPoint(self:getPositionX()+300,self:getPositionY());
   local  actionBy = CircleAction:create(5.0,P,1);
   local  ac = CCRepeatForever:create(actionBy);
   self:runAction(ac); 
end
if(pathType==4)then
   --轨迹起点
   --self:setPosition(CCPoint(200,300));
   --圆顺时针运动轨迹,参数一为动画时长,参数二为当前圆上位置的对径点坐标,参数三为轨迹方向
   self:runAction(CircleAction:create(3.0, ccp(500,300),-1));
end
if(pathType==5)then
   --自定义运动轨迹,参数一为动画时长,参数二为表示轨迹参数方程的LUA函数名
   --self:runAction(myAction:create(3.0,"CircleTrace"));
   --self:runAction(myAction:createCircle(3.0,"CircleTraceFunc",ccp(500,300),ccp(350,300),2));
  local startP=CCPoint(self:getPositionX(),self:getPositionY());
  --对于圆轨迹,arg1代表圆心坐标
   if(arg1==nil)then
      arg1=CCPoint(self:getPositionX()-150,self:getPositionY());
  end   
   self:runAction(myAction:createCircle(60.0,"CircleTraceFunc",startP,arg1,20)); 
end
if(pathType==6)then
   --圆中心为(350,300),半径为150,轨迹起点为(500,300)的逆时针圆轨迹
   --圆运动轨迹,参数一为动画时长,参数二为表示圆轨迹参数方程的LUA函数名,参数三为轨迹起点坐标,参数四为圆心坐标,参数五为正负圈数
   --self:runAction(myAction:createCircle(3.0,"CircleTraceFunc",ccp(500,300),ccp(350,300),1));
   --self:runAction(myAction:createMoveCircle(3.0,"MoveCircleTraceFunc",ccp(500,300),ccp(350,300),1,ccp(0,0)));
   --self:runAction(myAction:createMoveCircle(3.0,"MoveCircleTraceFunc",ccp(500,300),ccp(350,300),1,ccp(-250,0)));
   --local  actionBy =myAction:createMoveCircle(3.0,"MoveCircleTraceFunc",ccp(500,300),ccp(350,300),1,ccp(-50,0)); 
    --去掉了createMoveCircle,用createCycloid代替 
   local  actionBy =myAction:createCycloid(3.0,"CycloidTraceFunc",ccp(200,300),ccp(50,0),3,ccp(-50,math.pi*0.25));
   local  ac = CCRepeatForever:create(actionBy);
   self:runAction(ac);
end
if(pathType==7)then
   --自定义运动轨迹,参数一为动画时长,参数二为表示轨迹参数方程的LUA函数名
   --self:runAction(myAction:create(3.0,"EllipseTrace"));
   --self:runAction(myAction:create(3.0,"CycloidTrace"));
   --local rdeltArg=ccp(50,0)--表示圆的半径是50,辐角主值增量是0
   --self:runAction(myAction:createCircle(3.0,"CycloidTraceFunc",ccp(200,300),ccp(50,0),3));
   local startP=CCPoint(self:getPositionX(),self:getPositionY());
  --对于摆线轨迹,arg1代表半径和辐角主值增量
    if(arg1==nil)then
       arg1=CCPoint(50,0);
  end  
   --self:runAction(myAction:createCircle(3.0,"CycloidTraceFunc",startP,arg1,3));
   --self:runAction(myAction:createCycloid(15.0,"CycloidTraceFunc",startP,arg1,3,ccp(0,math.pi*0.25)));
   self:runAction(myAction:createCycloid(15.0,"CycloidTraceFunc",startP,arg1,3,ccp(0,math.pi)));
end
if(pathType==8)then
   --自定义运动轨迹,参数一为动画时长,参数二为表示轨迹参数方程的LUA函数名
   --self:runAction(myAction:create(3.0,"SinTrace"));
    --创建一个先加速再减速的正弦曲线轨迹运动
   local pAction=myAction:create(3.0,"SinTrace");
   local move_ease_inout = CCEaseInOut:create(pAction,2);
   self:runAction(move_ease_inout);  
end
if(pathType==9)then
   self:moveWithParabola(ccp(200, 300), ccp(500, 300), 0.0, 20.0, 3.0);
end    
end

--[[
------------------------------------
鱼精灵对象用到的精灵帧的管理
------------------------------------
Ivan_han@2013/4/20 14:15:17
------------------------------------
]]
FishManage = class("FishManage")
FishManage.__index = FishManage
FishManage.s_AllFish ={[1]=nil,[2]=nil,[3]=nil,[4]=nil,[5]=nil,[6]=nil,[7]=nil,[8]=nil,[9]=nil,[10]=nil,[12]=nil,[15]=nil,[18]=nil,[20]=nil,[25]=nil,[30]=nil,[40]=nil}
--1-10号炸弹对应1-10号鱼,11号炸弹是全屏炸弹,12号炸弹是龙虾炸弹
FishManage.s_AllBomb ={[1]=nil,[2]=nil,[3]=nil,[4]=nil,[5]=nil,[6]=nil,[7]=nil,[8]=nil,[9]=nil,[10]=nil,[11]=nil,[12]=nil}
--炸弹死亡帧数组
s_DeadBombFrames=nil

--[[
 <SpriteFrameCache file="Scene/Game/FishAndBomb/Fish_01.plist" />
 <SpriteFrameCache file="Scene/Game/FishAndBomb/Fish_02.plist" />
 <SpriteFrameCache file="Scene/Game/FishAndBomb/Bomb_01.plist" />
 <SpriteFrameCache file="Scene/Game/FishAndBomb/Bomb_02.plist" />
 ]]
function FishManage:Init(pNode)
  --local fishType=1
  --[[
 CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile("action/Fish01/Fish01.plist");
 local pBatchName = CCString:create( "action/Fish01/Fish01.png" );

self.s_AllFish1 = CCSpriteBatchNode:create( pBatchName:getCString() );
 pNode:addChild( self.s_AllFish1 );--鱼精灵批处理结点对象s_AllFish1挂接到节点pNode上
 --FishManage:addOneFish(1) 
]]  
    local arr={1,2,3,4,5,6,7,8,9,10,12,15,18,20,25,30,40}
 for i=1,#arr do
  local fishType=arr[i]
     local pStrBuffer1 = string.format('Scene/Game/FishAndBomb/Fish_%02d.plist', fishType)
     CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile(pStrBuffer1);
     local pStrBuffer = string.format('Scene/Game/FishAndBomb/Fish_%02d.png', fishType) 
        local pBatchName = CCString:create(pStrBuffer);
     self.s_AllFish[fishType] = CCSpriteBatchNode:create( pBatchName:getCString() );
     pNode:addChild( self.s_AllFish[fishType] );
 end
 
    local arr1={1,2,3,4,5,6,7,8,9,10,11,12}
 for i=1,#arr1 do
  local BombType=arr1[i]
     local pStrBuffer1 = string.format('Scene/Game/FishAndBomb/Bomb_%02d.plist', BombType)
     CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile(pStrBuffer1);
     local pStrBuffer = string.format('Scene/Game/FishAndBomb/Bomb_%02d.png', BombType) 
        local pBatchName = CCString:create(pStrBuffer);
     self.s_AllBomb[BombType] = CCSpriteBatchNode:create( pBatchName:getCString() );
     pNode:addChild( self.s_AllBomb[BombType] );
 end

-- 炸弹死亡帧数组
      s_DeadBombFrames = CCArray:create()
      local frameWidth =1000
      local frameHeight =839
       
      for i=0,13 do
  local strBuffer = string.format('Scene/Game/FishAndBomb/DeadBomb/DeadBomb_%05d.png',i)
     local tex = CCTextureCache:sharedTextureCache():addImage(strBuffer)
  if not tex then
   break
  end   
        local rect = CCRectMake(0, 0, frameWidth, frameHeight)
        local pFrame = CCSpriteFrame:createWithTexture(tex, rect)         
  s_DeadBombFrames:addObject( pFrame );
   end
   s_DeadBombFrames:retain();
end

function FishManage:Release()
 --CCSpriteFrameCache:sharedSpriteFrameCache():removeSpriteFramesFromFile("action/Fish01/Fish01.plist")
    --local fishType=1
    local arr={1,2,3,4,5,6,7,8,9,10,12,15,18,20,25,30,40}
 for i=1,#arr do
  local fishType=arr[i]
     local pStrBuffer1 = string.format('Scene/Game/FishAndBomb/Fish_%02d.plist', fishType) 
     CCSpriteFrameCache:sharedSpriteFrameCache():removeSpriteFramesFromFile(pStrBuffer1) 
     self.s_AllFish[fishType]:removeAllChildrenWithCleanup( true )
 end 
  
    local arr1={1,2,3,4,5,6,7,8,9,10,11,12}
 for i=1,#arr1 do
  local BombType=arr1[i]
     local pStrBuffer1 = string.format('Scene/Game/FishAndBomb/Bomb_%02d.plist', BombType) 
     CCSpriteFrameCache:sharedSpriteFrameCache():removeSpriteFramesFromFile(pStrBuffer1) 
     self.s_AllBomb[BombType]:removeAllChildrenWithCleanup( true )
 end 
end

function FishManage:addOneGroupFish(fishgroupType)
--水平直线轨迹阵
if(fishgroupType==1)then
   FishManage:addOneFish(12,2);
   FishManage:addOneFish(12,2,ccp(0,350));
   FishManage:addOneFish(12,2,ccp(0,250));  
end
--斜直线轨迹阵
if(fishgroupType==2)then
   FishManage:addOneFish(40,1,ccp(-50,50))
   FishManage:addOneFish(40,1,ccp(-25,75))
   FishManage:addOneFish(40,1,ccp(0,100))
   FishManage:addOneFish(40,1,ccp(-70,25))  
end
--圆轨迹阵 
if(fishgroupType==3)then
    local startP=ccp(0,300)
    local centerP=ccp(150,300)  
 local deltArg=math.pi*0.2
 for i=1,10 do
  local startP=GetCirclePos(startP,centerP,deltArg*(i-1))
  FishManage:addOneFish(7,3,startP,centerP)
 end 
end
--圆轨迹阵 
if(fishgroupType==4)then
    local startP=ccp(500,300)
    local centerP=ccp(350,300)  
 local deltArg=math.pi*0.2
 for i=1,10 do
  local startP=GetCirclePos(startP,centerP,deltArg*(i-1))
  FishManage:addOneFish(1,5,startP,centerP)
 end 
end
--摆线轨迹阵 
if(fishgroupType==5)then
    local startP=ccp(200,300)
    local rdeltArg=ccp(60,0)
 local deltArg=math.pi*0.2
 for i=1,10 do
  rdeltArg.y=deltArg*(i-1)
  FishManage:addOneFish(1,7,startP,rdeltArg)
 end 
end
--摆线轨迹阵 
if(fishgroupType==6)then
    local startP=ccp(400,300)
    local rdeltArg=ccp(60,0)
 local deltArg=math.pi*0.2
 for i=1,10 do
  rdeltArg.y=deltArg*(i-1)
  FishManage:addOneFish(2,7,startP,rdeltArg)
 end 
end 
end

--[[
添加一条鱼或一个炸弹
参数说明:
fishType----fishType/100=0时表示鱼,fishType%100表示几号鱼;fishType/100=1时表示炸弹,fishType%100表示几号炸弹;
]]
function FishManage:addOneFish(fishType,pathType,startP,arg1)
    if(startP==nil)then
        startP=ccp(0,300)
    end
    --[[
     if(arg1==nil)then
        arg1=ccp(150,300)
    end
   ]]
   --取商、取模
   local q=math.floor(fishType/100)--fishType/100
   local r=fishType-math.floor(fishType/100)*100--fishType%100,取模操作被定义为a%b==a-math.floor(a/b)*b
    local arr={[0]='Fish_%02d_%05d.png',[1]='Fish_%02d_00000.png',[2]='Bomb_%02d_%05d.png',[3]='Bomb_%02d_00000.png'}   
 local pArray = CCArray:create()
 --for i=0,9 do
 for i=0,24 do
  --local pStrBuffer = string.format('fish0%d_%d.png',fishType,i)
        --local pStrBuffer = string.format('Fish_%02d_%05d.png',fishType,i)
        local pStrBuffer = string.format(arr[2*q],r,i)
  local pSpriteFrame = CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName( pStrBuffer )
  if not pSpriteFrame then
   break
  end
  pArray:addObject( pSpriteFrame )
 end
 -- 由帧缓存生成action,帧延迟0.1f
 local pAnimation =CCAnimation:createWithSpriteFrames(pArray,0.1);
    local fish_act = CCRepeatForever:create(CCAnimate:create(pAnimation));
 -- 通过起始帧生成鱼实体
 --local Name="fish0"..tostring(fishType).."_1.png"
 --local Name=string.format('Fish_%02d_00000.png',fishType)
 local Name=string.format(arr[2*q+1],r) 
 local pFish = Fish:spriteWithSpriteFrameName(Name)
 if (pFish) then
   pFish:setScale(1.0);
   pFish:setTag(fishType);
   pFish:setObjName(qrName(fishType));
   pFish:setPosition(startP);
   --pFish:setIsCatch(false);
   pFish:runAction(fish_act);
   pFish:addPath(pathType,arg1);
   --self.s_AllFish1:addChild(pFish)--生成的鱼精灵对象挂接到鱼精灵批处理结点对象s_AllFish1上
   --生成的鱼精灵对象挂接到鱼精灵批处理结点对象s_AllFish1的父节点上
      local pNode=self.s_AllFish[1]:getParent()
   pNode:addChild( pFish );
   --self.s_AllFish[1]:addChild( pFish );
 end
 CCLuaLog("pFish="..tostring(pFish)) 
end

--[[
捕获一条鱼或一个炸弹
]]
function FishManage:CaptureOneFish()
    local pNode=self.s_AllFish[1]:getParent()
    local n=pNode:getChildrenCount()
    for i=0,n-1 do
          local node = pNode:getChildren():objectAtIndex(i)
       node = tolua.cast(node, "CCSprite")
       if(node~=nil)then
         --if(node:getTag()>0 and node:getTag()<200 and PtInScreenRect(ccp(node:getPositionX(),node:getPositionY())))then
         if(node:getObjName()=="Fish" or node:getObjName()=="Bomb" and PtInScreenRect(ccp(node:getPositionX(),node:getPositionY())))then
               --local a=node:getIsCatch()
               DieAnimation(node)
            break
            else
               CCLuaLog("not a Fish or Bomb in the screen");
         end
          else
           CCLuaLog("node~=nil not a CCSprite") 
       end
    end
end

--取商、取模
function qr(fishType)
    local q=math.floor(fishType/100)
    local r=fishType-math.floor(fishType/100)*100
 return q,r
end

function qrName(fishType)
    local q,r=qr(fishType)
    if q==0 then
       --local Name=string.format('Fish_%02d',r)
       --return Name
       return 'Fish'
 else
    --local Name=string.format('Bomb_%02d',r)
       --return Name
       return 'Bomb'
 end
end

function PtInScreenRect(pt) 
 if(pt.x>0 and pt.x<800 and pt.y>0 and pt.y<600)then
     return true
 else
  return false
 end
end

function FishStop(node) 
 node:removeAllChildrenWithCleanup( true )
 node:removeFromParentAndCleanup( true )
end

function DieAnimation(node)
 node:stopAllActions()
 node:setVisible( false )

local pArray= CCArray:create();
    local q,r=qr(node:getTag())
    if(q==0)then
   -- 死鱼
      for i=0,24,2 do
  local strBuffer = string.format('DeadFish_%02d_%05d.png',r, i)
  local pFrame = CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName( strBuffer )
  if not pFrame then
   break
  end
  pArray:addObject( pFrame );
   end
 else
        --死炸弹
  pArray=s_DeadBombFrames
    end 
    
 local pAnimation = CCAnimation:createWithSpriteFrames( pArray, 0.1 )
 local pAnimate = CCAnimate:create( pAnimation );
 node:setAnchorPoint(CCPoint:new(0.5,0.5));

-- 结束自己
 local FishActionArray = CCArray:create()
 FishActionArray:addObject(CCShow:create())
 FishActionArray:addObject(pAnimate)
 FishActionArray:addObject(CCCallFuncN:create( FishStop ))
 node:runAction( CCSequence:create(FishActionArray))
end

SceneGame.lua中调用Fish.lua:
-- 弹起(鼠标在控件区域内)
function onCCControlEventTouchUpInside(pSender,name)
 CCLuaLog("SceneGame.pSender["..tostring(pSender).."].name["..name.."].onCCControlEventTouchUpInside")
 --add by Ivan_han
    if name=="MyDepot" then
     --FishManage:addOneFish(1,1,ccp(0,100))
     FishManage:addOneGroupFish(2)
 elseif name=="Task" then
     --FishManage:addOneGroupFish(1)
     FishManage:CaptureOneFish()
 elseif name=="Help" then
     --FishManage:addOneFish(1,3)
     --FishManage:addOneGroupFish(3)
     FishManage:addOneFish(107,3)
 elseif name=="Shop" then
     --FishManage:addOneFish(1,4)
     FishManage:addOneGroupFish(6)
 elseif name=="Supplement" then
     --FishManage:addOneFish(1,5,ccp(500,300),ccp(350,300))
     --FishManage:addOneGroupFish(4)
     FishManage:addOneFish(2,5,ccp(500,300),ccp(350,300))
 elseif name=="Bullet" then
     --FishManage:addOneFish(1,6)
     FishManage:addOneFish(101,6)
 elseif name=="Set" then
     --FishManage:addOneFish(1,7)
        FishManage:addOneGroupFish(5)    
 else
     --FishManage:addOneFish(1,8)
     --FishManage:addOneFish(112,8)
     --FishManage:CaptureOneFish()
 end
end

LUA中测试鱼死亡动作、炸弹轨迹、炸弹爆炸动作相关推荐

  1. lua语言和python_[动态语言]python和lua中的三元操作符and-or

    在这两种语言中,表达式a and b的返回值不是true或false,而是a/b当中非真的值,而表示a or b返回的是a/b当中为真的那个. 因此,要想模拟C/C++中的三元操作符c ? a : b ...

  2. Lua中的模块与module函数详解

    很快就要开始介绍Lua里的"面向对象"了,在此之前,我们先来了解一下Lua的模块. 1.编写一个简单的模块 Lua的模块是什么东西呢?通常我们可以理解为是一个table,这个tab ...

  3. 两个函数彻底理解Lua中的闭包

    本文通过两个函数彻底搞懂Lua中的闭包,相信看完这两个函数,应该能理解什么是Lua闭包.废话不多说,上 code: 1 --[[************************************ ...

  4. Lua中的字符串函数库

    Lua解释器对字符串的支持很有限.一个程序可以创建字符串并连接字符串,但不能截取子串,检查字符串的大小,检测字符串的内容.在Lua中操纵字符串的功能基本来自于string库. 字符串库中的一些函数是非 ...

  5. lua中的魔法字符转义问题

    ❤️强烈推荐人工智能学习网站❤️ lua中的魔法字符有( ) . % + - * ? [ ] ^ $ ,在表示它们时候要考虑用到转义,转义符号为%,但有些却不需要转义.下面我们通过实际代码来测试一下. ...

  6. Lua中的loadfile、dofile、require详解

    这篇文章主要介绍了Lua中的loadfile.dofile.require详解,本文分别用实例讲解它的用法和特点等内容,需要的朋友可以参考下 本来今天不应该讨论这几个函数的,不过,为了凑字数..不,为 ...

  7. Lua中的模块和使用

    简介 从Lua5.1版本开始,就对模块/包添加了新的支持,可是使用require函数和package函数来加载模块,使用table模拟module来定义模块. 函数require用于加载模块,modu ...

  8. lua中keyvalue_40行中的持久性KeyValue Server和一个可悲的事实

    lua中keyvalue 再次出现...彼得斯撰写了有关Unsafe用法的书面概述 ,我将简要介绍一下Java中的低级技术如何通过启用更高级别的抽象或允许Java性能级别来节省开发工作可能很多人都不知 ...

  9. android lua loadluafile 相对路径,Lua中的loadfile、dofile、require详解

    1.loadfile--只编译,不运行java loadfile故名思议,它只会加载文件,编译代码,不会运行文件里的代码. 好比,咱们有一个hellofile.lua文件:函数 复制代码代码以下: p ...

最新文章

  1. 9、ctemplate文档,简记(2)
  2. 【tenserflow】——数据类型以及常用属性
  3. 如何使用Dockerfile构建镜像
  4. python中cmd全称_【转】Python中执行cmd的三种方式
  5. .Net页面中使用在线编辑框实例
  6. Dubbo的负载均衡、集群容错、服务降级等机制详解
  7. 超柔磨绒印花空调被(200*230cm) -凡客诚品工商银行团购专区- VANCL凡客诚品
  8. JDK1.8HashMap底层实现原理
  9. linux下sctp的安装、使用与编程
  10. 使用Modular QoS CLI(MQC)基于FR的DLCI号对包进行分类
  11. 智能车OS照搬安卓没有出路,特别是在中国
  12. 戴尔科技 赢在“边缘”
  13. java电影院购票系统概况_电影院售票管理系统
  14. 改变CEdit中字体大小与颜色
  15. 任丘虚拟服务器,河北任丘联通dns服务器地址
  16. 12步解N-S方程之第五步(1)
  17. 新发现!免翻免费看网飞
  18. 已知有十六支男子足球队参加2008 北京奥运会
  19. 坑!mongodb安装踩坑坑坑坑!
  20. 将身份证正反面放在一个文档

热门文章

  1. can总线不加末端电阻_汽车总线故障检修与典型案例
  2. Intel ax200 WiFi6吞吐量测试
  3. 一篇文章了解分治算法
  4. 如何画场景插画?场景插画的起稿、构图技巧!
  5. s5pv210-nand-dm9000-dts-2
  6. 如何下载CSDN的文章?
  7. 计算机最彻底的杀毒方法,手把手教你Win10创意者彻底关闭windows defender杀毒软件方法...
  8. 信安之星(iSecStar)U盘安全管理系统
  9. 彩票抽奖机模拟器(祝君早中大奖)
  10. 达美乐披萨:一家把自己“送”上市的企业