class 'Dropoil' (Script)

function Dropoil:__init() super()
end

function Dropoil:on_attach()
	local scene = self:scene()

 	 self.start_x =866
	 self.start_y =500
	 self.finish_x =885
	 self.finish_y =0
	 self.time_animation = 1
	 self.speed_x 		= 5
	 self.acceleration_x=3
	 self.speed_y 		= 5
	 self.acceleration_y=0
	 self.time=0;

	self.object = scene:object('oil')
	self.point_start=Position(self.start_x,self.start_y)
	self.point_finish = Position(self.finish_x,self.finish_y)

	self.chench_x = math.abs(self.start_x-self.finish_x)
	self.chench_y = math.abs(self.start_y-self.finish_y)
	self.cooficient = self.chench_x/self.chench_y

	self.current_x=self.start_x
	self.current_y=self.start_y

	self.speed_y=self.speed_x*(self.chench_y/self.chench_x)
	self.acceleration_y=  self.acceleration_x*(self.chench_y/self.chench_x)


	if self.start_x-self.finish_x>0 then
		self.direction_x = -1
	else
		self.direction_x = 1
	end

	if self.start_y-self.finish_y>0 then
		self.direction_y = -1
	else
		self.direction_y = 1
	end
end

function Dropoil:on_update(dt)


    self.time=self.time+dt;

	if (self.direction_x*self.current_x<self.finish_x) and (self.direction_y*self.current_y<self.finish_y) then
	    --print(self.time);
		self.current_x=self.start_x + self.direction_x*(self.speed_x*self.time + self.acceleration_x*self.time*self.time/2)
        self.current_y=self.start_y + self.direction_y*(self.speed_y*self.time + self.acceleration_y*self.time*self.time/2)
        self.object:set_position(Position(self.current_x,self.current_y), true)

    else
		self:scene():execute_action('stopoil')
	end

end