class 'blinklocation82' (Script)

function blinklocation82:__init() super()
end

function blinklocation82:on_attach()
  local scene=self:scene()
 self.ob1=scene:object('lightwindow')



  self.ar_ob1={{alpha=1},{count=0 }, {timeIdle=0,timeGrowth=0,timeReduction=0,alpha_start=0.5,alpha_finish=1},
          {timeIdlestatik=10,timeGrowthstatik=1,timeReductionstatik=3}}

  self:start_rand_inicial(self.ar_ob1)

  self:set_alpha()

end

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

end


function blinklocation82: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[1].alpha= ar[3].alpha_start
end

function blinklocation82:on_update(dt)

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


end


function blinklocation82: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

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

  if alcount[2].count <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 <itiration2+itiration3 and alcount[1].alpha<alcount[3].alpha_finish then
      alcount[1].alpha=alcount[1].alpha+dtalpha*(1/itiration3)
      object:set_alpha( alcount[1].alpha)
    else
      if alcount[2].count<itiration1+itiration2+itiration3 then

      else
      alcount[2].count =0
       alcount[3].timeIdle= alcount[4].timeIdlestatik*math.random() +0.2
       alcount[3].timeGrowth= alcount[4].timeGrowthstatik*math.random()+0.1
       alcount[3].timeReduction=alcount[4].timeReductionstatik*math.random()+0.1
     end
    end
  end
end

