class 'blinklocation8_enter' (Script)

function blinklocation8_enter:__init() super()
end

function blinklocation8_enter:on_attach()
  local scene=self:scene()
  self.ob1=scene:object('lightning')
  self.count = 0

  self.ar_ob1={{alpha=1},{count=0 }, {timeIdle=0,timeGrowth=0,timeReduction=0,timebigIdle=0,alpha_start=0,alpha_finish=1},
           {timeIdlestatik=0.2,timeGrowthstatik=0.2,timeReductionstatik=0.2,timebigIdlestatik=6}}

  self:start_rand_inicial(self.ar_ob1)

  self:set_alpha()

end

function blinklocation8_enter:set_alpha()
 self.ob1:set_alpha(self.ar_ob1[1].alpha)
 end



function blinklocation8_enter:start_rand_inicial(ar)
  ar[3].timeIdle=  ar[4].timeIdlestatik*math.random()
  ar[3].timeGrowth=  ar[4].timeGrowthstatik*math.random()
  ar[3].timeReduction= ar[4].timeReductionstatik*math.random()
  ar[3].timebigIdle=ar[4].timebigIdlestatik*math.random()
  ar[1].alpha= ar[3].alpha_start
end

function blinklocation8_enter:on_update(dt)

   self:blinkObject(self.ob1,dt,self.ar_ob1)

end


function blinklocation8_enter:blinkObject(object,dt,alcount)
  local dtalpha= math.abs(alcount[3].alpha_finish-alcount[3].alpha_start)

  local itiration1 =alcount[3].timeIdle/dt
  local itiration2 =alcount[3].timeGrowth/dt
  local itiration3 =alcount[3].timeReduction/dt
  local itiration4 =alcount[3].timebigIdle/dt

  alcount[2].count= alcount[2].count+1


  if self.count<3 then
     if alcount[2].count <itiration3 and alcount[1].alpha<alcount[3].alpha_finish then
        --print(alcount[1].alpha)
            alcount[1].alpha=alcount[1].alpha+dtalpha*(1/itiration3)
            object:set_alpha( alcount[1].alpha)
    else
        if alcount[2].count <itiration3+itiration2 and alcount[1].alpha>alcount[3].alpha_start then
         	alcount[1].alpha=alcount[1].alpha-dtalpha*1/itiration2
        	object:set_alpha(alcount[1].alpha)
        else
            if alcount[2].count<itiration1+itiration2+itiration3 then
            else
                self.count=self.count+1
                alcount[2].count =0
               alcount[3].timeIdle= alcount[4].timeIdlestatik*math.random()
                alcount[3].timeGrowth= alcount[4].timeGrowthstatik*math.random()
               alcount[3].timeReduction=alcount[4].timeReductionstatik*math.random()
             end
         end
      end
  else
    if alcount[2].count<itiration1+itiration2+itiration3+itiration4 then
    else
     self.count=0
     alcount[2].count =0
     alcount[3].timeIdle= alcount[4].timeIdlestatik*math.random()+0.1
     alcount[3].timeGrowth= alcount[4].timeGrowthstatik*math.random()+0.1
     alcount[3].timeReduction=alcount[4].timeReductionstatik*math.random()+0.1
     alcount[3].timebigIdle= alcount[4].timebigIdlestatik*math.random()+5
    end

  end
end

