lib/lotu/systems/transformation_system.rb in lotu-0.1.12 vs lib/lotu/systems/transformation_system.rb in lotu-0.1.13

- old
+ new

@@ -13,42 +13,38 @@ :object => object, :property_getter => property, :property_setter => "#{property}=", :accum_time => 0, :calc => 0, - :init => opts[:init], - :end => opts[:end], + :init => Float(opts[:init]), + :end => Float(opts[:end]), :duration => opts[:duration] || 1, :start_in => opts[:start_in] || 0, :on_result => opts[:on_result], - :loop => opts[:loop] + :loop => opts[:loop], + :bounce => opts[:bounce], + :bouncing_back => false } @transformations << transformation end def update @transformations.each do |t| t[:accum_time] += dt if t[:accum_time] > t[:start_in] step = (t[:end] - t[:init])/t[:duration] * dt t[:calc] += step - if step > 0 - if t[:init] + t[:calc] > t[:end] - if t[:loop] - t[:calc] = 0 - else - t[:calc] = t[:end] - t[:init] - tag_for_deletion(t) - end + tag_for_deletion(t) if step == 0 + if(t[:init] + t[:calc] > t[:end] && step > 0) || (t[:init] + t[:calc] < t[:end] && step < 0) + if t[:loop] || (t[:bounce] && !t[:bouncing_back]) + t[:calc] = 0 + else + t[:calc] = t[:end] - t[:init] + tag_for_deletion(t) end - else - if t[:init] + t[:calc] < t[:end] - if t[:loop] - t[:calc] = 0 - else - t[:calc] = t[:end] - t[:init] - tag_for_deletion(t) - end + if t[:bounce] + t[:bouncing_back] = !t[:bouncing_back] + t[:init], t[:end] = t[:end], t[:init] end end value = t[:init] + t[:calc] value = value.send(t[:on_result]) if t[:on_result] t[:object].send(t[:property_setter], value)