diff options
| author | Amir Rajan <[email protected]> | 2020-09-02 13:23:46 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-09-02 13:23:46 -0500 |
| commit | b618bdd406a3817bcc53daed0612f79b2d9178f8 (patch) | |
| tree | 1772b9e1c332d350b34027e2fe344173887819f4 /dragon/numeric.rb | |
| parent | 64046616ce54fff32c3dd949a4b7702136f38a3e (diff) | |
| download | dragonruby-game-toolkit-contrib-b618bdd406a3817bcc53daed0612f79b2d9178f8.tar.gz dragonruby-game-toolkit-contrib-b618bdd406a3817bcc53daed0612f79b2d9178f8.zip | |
Synced with 1.18.
Diffstat (limited to 'dragon/numeric.rb')
| -rw-r--r-- | dragon/numeric.rb | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/dragon/numeric.rb b/dragon/numeric.rb index c2c461f..6d8b84d 100644 --- a/dragon/numeric.rb +++ b/dragon/numeric.rb @@ -28,12 +28,6 @@ class Numeric clamp(0, 255).to_i end - # For a given number, the elapsed frames since that number is returned. - # `Kernel.tick_count` is used to determine how many frames have elapsed. - # An override numeric value can be passed in which will be used instead - # of `Kernel.tick_count`. - # - # @gtk def elapsed_time tick_count_override = nil (tick_count_override || Kernel.tick_count) - self end @@ -51,25 +45,42 @@ class Numeric # moment in time. # # @gtk - def elapsed? offset, tick_count_override = nil - (self + offset) < (tick_count_override || Kernel.tick_count) + def elapsed? offset = 0, tick_count_override = Kernel.tick_count + (self + offset) < tick_count_override end - # This is helpful for determining the index of frame-by-frame sprite animation. - # The numeric value `self` represents the moment the animation started. `frame_index` - # takes three additional parameters: how many frames exist in the sprite animation; - # how long to hold each animation for; and whether the animation should repeat. - # - # @gtk - def frame_index frame_count, hold_for, repeat, tick_count_override = nil + def frame_index *opts + frame_count_or_hash, hold_for, repeat, tick_count_override = opts + if frame_count_or_hash.is_a? Hash + frame_count = frame_count_or_hash[:count] + hold_for = frame_count_or_hash[:hold_for] + repeat = frame_count_or_hash[:repeat] + tick_count_override = frame_count_or_hash[:tick_count_override] + else + frame_count = frame_count_or_hash + end + + tick_count_override ||= Kernel.tick_count animation_frame_count = frame_count animation_frame_hold_time = hold_for animation_length = animation_frame_hold_time * animation_frame_count - if !repeat && self.+(animation_length) < (tick_count_override || Kernel.tick_count).-(1) + return nil if Kernel.tick_count < self + + if !repeat && (self + animation_length) < (tick_count_override - 1) return nil else return self.elapsed_time.-(1).idiv(animation_frame_hold_time) % animation_frame_count end + rescue Exception => e + raise <<-S +* ERROR: +#{opts} +#{e} +S + end + + def zero? + self == 0 end def zero @@ -479,6 +490,11 @@ S def serialize self end + + def from_top + return 720 - self unless $gtk + $gtk.args.grid.h - self + end end class Fixnum |
