class 'p03_l04_game01' (Script)

function p03_l04_game01:__init()super()
self.discObject={}
self.tweener={}
--MEMORY
self.inicialOne=true
end
--z2_part2; z2_part3; z2_part4; z2_part5
function p03_l04_game01:on_attach()
local scene = self:scene()

if self.inicialOne then
 for i=1,4 do
  self.discObject[i]= p03_l04_game01_disc()
  self.discObject[i].object= scene:object('z2_part'..(i+1))
  self.discObject[i].distanse=60
  self.discObject[i].speed=30
  self.discObject[i].direction=(-1)^i
  self.tweener[i]=tweener()
 end
self.discObject[1].object:set_angle(-60,Position((self.discObject[1].object:dimensions():lx()/2),(self.discObject[1].object:dimensions():ly()/2)),true)
 self.discObject[2].object:set_angle(60,Position((self.discObject[2].object:dimensions():lx()/2),(self.discObject[2].object:dimensions():ly()/2)),true)
 self.discObject[3].object:set_angle(-120,Position((self.discObject[3].object:dimensions():lx()/2),(self.discObject[3].object:dimensions():ly()/2)),true)
 self.discObject[4].object:set_angle(180,Position((self.discObject[4].object:dimensions():lx()/2),(self.discObject[4].object:dimensions():ly()/2)),true)
end
end

function p03_l04_game01:on_lb_down()
 local selected =self:scene():overed_object()

 if selected then
  for i=1,#self.discObject do
   if selected:name()== self.discObject[i].object:name() and self:completRotate()   then
    self.tweener[i]:setParamsRotate(self.discObject[i].object,self.discObject[i].speed,self.discObject[i].distanse,self.discObject[i].direction)
    self:completeGame()
    self:scene():play_sound('g_rotate_disk')
   end
  end
 end
end

function p03_l04_game01:completeGame()
 local count=0
 for i=1,#self.tweener do
  if math.abs(math.fmod(self.tweener[i]:getsFinishRotate(),360))<5 then
   -- print(self.tweener[i]:getsFinishRotate())
     count=count+1
  end
 end
 if count>3 then
     self:scene():play_sound('g_complete')
  self:scene():execute_action('complete_game01')
 end
end

function p03_l04_game01:on_update(dt)
 for i=1,#self.tweener do
  self.tweener[i]:update(dt)
 end
end

function p03_l04_game01:completRotate()
 local count=0
  for i=1,#self.tweener do

    if self.tweener[i]:completerot() then

    else
     return false
    end
  end
  return true
end




