class 'blinkesli' (Script)

function blinkesli:__init() super()
end

function blinkesli:on_attach()
  local scene=self:scene()
  self.light1=scene:object('light1')
  self.light2=scene:object('light2')
  self.light3=scene:object('light3')
  self.lightning=scene:object('lightning')
  self.lightningwindow=scene:object('lightning_window')


  self.ar1={{alpha=1},{count=0 }, {timeIdle=0,timeGrowth=0,timeReduction=0},
            {timeIdlestatik=10,timeGrowthstatik=1.5,timeReductionstatik=0.3}}
  self.ar2={{alpha=1},{count=0},{timeIdle=0,timeGrowth=0,timeReduction=0},
            {timeIdlestatik=10,timeGrowthstatik=1.5,timeReductionstatik=0.3}}
  self.ar3={{alpha=1},{count=0},{timeIdle=0,timeGrowth=0,timeReduction=0},
            {timeIdlestatik=10,timeGrowthstatik=1.5,timeReductionstatik=0.3} }
  self.arlightning={{alpha=1},{count=0},{timeIdle=0,timeGrowth=0,timeReduction=0},
                   {timeIdlestatik=10,timeGrowthstatik=0.3,timeReductionstatik=1} }

  self.ar1[3].timeIdle=  self.ar1[4].timeIdlestatik*math.random()
  self.ar1[3].timeGrowth=  self.ar1[4].timeGrowthstatik*math.random()
  self.ar1[3].timeReduction= self.ar1[4].timeReductionstatik*math.random()

  self.ar2[3].timeIdle=  self.ar1[4].timeIdlestatik*math.random()
  self.ar2[3].timeGrowth=  self.ar1[4].timeGrowthstatik*math.random()
  self.ar2[3].timeReduction= self.ar1[4].timeReductionstatik*math.random()

  self.ar3[3].timeIdle=  self.ar1[4].timeIdlestatik*math.random()
  self.ar3[3].timeGrowth=  self.ar2[4].timeGrowthstatik*math.random()
  self.ar3[3].timeReduction= self.ar3[4].timeReductionstatik*math.random()

   self.arlightning[3].timeIdle=  self.arlightning[4].timeIdlestatik*math.random()
  self.arlightning[3].timeGrowth=  self.arlightning[4].timeGrowthstatik*math.random()
  self.arlightning[3].timeReduction= self.arlightning[4].timeReductionstatik*math.random()

  self.light1:set_alpha(self.ar1[1].alpha)
  self.light2:set_alpha(self.ar2[1].alpha)
  self.light3:set_alpha(self.ar3[1].alpha)
  self.lightning:set_alpha(self.arlightning[1].alpha)
  self.lightningwindow:set_alpha(self.arlightning[1].alpha)

end

function blinkesli:on_update(dt)

   self:blinkObject(self.light1,dt,self.ar1)
   self:blinkObject(self.light2,dt,self.ar2)
   self:blinkObject(self.light3,dt,self.ar3)
   self:blinkObjectlightning(self.lightning,self.lightningwindow,dt,self.arlightning)

end

function blinkesli:blinkObjectlightning(object,object2,dt,alcount)
  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<1 then
       alcount[1].alpha=alcount[1].alpha+1/(itiration2)
       object:set_alpha(alcount[1].alpha)
       object2:set_alpha(alcount[1].alpha)
   else
    if alcount[2].count <itiration2+itiration3 and alcount[1].alpha>0 then
      alcount[1].alpha=alcount[1].alpha-1/(itiration3)
      object:set_alpha( alcount[1].alpha)
      object2: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()
       alcount[3].timeGrowth= alcount[4].timeGrowthstatik*math.random()
       alcount[3].timeReduction=alcount[4].timeReductionstatik*math.random()
      end
    end
  end
end

function blinkesli:blinkObject(object,dt,alcount)
  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 <itiration3 and alcount[1].alpha>0.5 then
       alcount[1].alpha=alcount[1].alpha-1/(itiration3*2)
       object:set_alpha(alcount[1].alpha)
   else
    if alcount[2].count <itiration2+itiration3 and alcount[1].alpha<1 then
      alcount[1].alpha=alcount[1].alpha+1/(itiration2*2)
      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()
       alcount[3].timeGrowth= alcount[4].timeGrowthstatik*math.random()
       alcount[3].timeReduction=alcount[4].timeReductionstatik*math.random()
      end
    end
  end
end

