Sha256: 4a599b04cc410569f4b3eeb5113dd0fe520f325e6c57eb989326fb7203ff316f
Contents?: true
Size: 1010 Bytes
Versions: 3
Compression:
Stored size: 1010 Bytes
Contents
require 'publisher' class CurtainView < ActorView def draw(target,x_off,y_off,z) target.fill 0,0,1024,800, [0,0,0,@actor.height], z end end class Curtain < Actor extend Publisher can_fire :curtain_up, :curtain_down has_behavior :updatable, :layered => {:layer => 99_999} attr_accessor :height FULL_CURTAIN = 255 NO_CURTAIN = 0 def setup @duration_in_ms = @opts[:duration] @duration_in_ms ||= 1000 case @opts[:dir] when :up @height = FULL_CURTAIN @dir = -1 when :down @height = NO_CURTAIN @dir = 1 end end # Update curtain height 0-255 (alpha) def update(time) perc_change = time.to_f/@duration_in_ms amount = FULL_CURTAIN * perc_change * @dir @height += amount.floor if @height < 0 @height = 0 if alive? fire :curtain_up remove_self end elsif @height > 255 @height = 255 if alive? fire :curtain_down remove_self end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
gamebox-0.3.4 | lib/gamebox/actors/curtain.rb |
gamebox-0.3.3 | lib/gamebox/actors/curtain.rb |
gamebox-0.3.2 | lib/gamebox/actors/curtain.rb |