Class: Nyan::Flight
- Inherits:
-
Object
- Object
- Nyan::Flight
- Defined in:
- lib/nyan/flight.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Flight
constructor
A new instance of Flight.
- #next! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Flight
Returns a new instance of Flight.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nyan/flight.rb', line 3 def initialize( = {}) @framerate = .fetch(:framerate, 0.09) @stage = Stage.new(.fetch(:stage, {})) @rainbow = Sprite.new(:x => 0, :y => 17, :z => 1, :frames => Nyan::Rainbow.to_frames) @cat_head = Sprite.new(:x => Nyan::Rainbow::TOTAL_LENGTH - 2, :y => 17, :z => 100, :frames => Nyan::CatHead.to_frames, :animation => Proc.new do @initial_x ||= @x @initial_y ||= @y case offset = [@x == @initial_x && :initial || :offset, @y == @initial_y && :initial || :offset] when [:initial, :initial] then @y -= 2 when [:initial, :offset] then @x += 2 when [:offset, :offset] then @y += 2 when [:offset, :initial] then @x -= 2 end end) @pop_tart = Sprite.new(:x => @cat_head.x - 20, :y => @cat_head.y - 2, :z => @cat_head.z - 1, :frames => Nyan::PopTart.to_frames) @stage.add_sprite(@rainbow) @stage.add_sprite(@cat_head) @stage.add_sprite(@pop_tart) @tick_time = Time.now end |
Instance Method Details
#next! ⇒ Object
33 34 35 36 37 38 |
# File 'lib/nyan/flight.rb', line 33 def next! maybe_add_a_twinkly_star @stage.play! while Time.now - @tick_time < @framerate; end @tick_time = Time.now end |