class PirateGame::Background
Constants
- STATES
Public Class Methods
new(shoes, state=nil)
click to toggle source
# File lib/pirate_game/background.rb, line 5 def initialize shoes, state=nil @shoes = shoes set_state state @items = [] @items << PirateGame::Wave.new(@shoes, 0) @items << PirateGame::Wave.new(@shoes, 20) image = File.expand_path '../../../imgs/pirate_ship_sm.png', __FILE__ @items << PirateGame::Image.new(@shoes, image, 66, 55) [40, 60, 80, 100].each do |top| @items << PirateGame::Wave.new(@shoes, top) end end
Public Instance Methods
add_extra_item(item)
click to toggle source
# File lib/pirate_game/background.rb, line 82 def add_extra_item item @extra_items << item end
all_items()
click to toggle source
# File lib/pirate_game/background.rb, line 46 def all_items @items + @extra_items end
animate(frame)
click to toggle source
# File lib/pirate_game/background.rb, line 86 def animate frame all_items.each do |item| item.animate frame end end
color()
click to toggle source
# File lib/pirate_game/background.rb, line 50 def color case @state when :foggy @shoes.rgb(105, 138, 150, 180) else # :clear, :windy PirateGame::Boot::SKY_COLOR end end
draw() { || ... }
click to toggle source
# File lib/pirate_game/background.rb, line 59 def draw randomize_state @shoes.background color unless foreground? @items.each do |item| item.draw end @extra_items = [] yield if block_given? @extra_items.each do |item| item.draw end # doesn't draw over input items (buttons, text boxes, etc) >:( @shoes.background color if foreground? send_speed_to_items end
foreground?()
click to toggle source
# File lib/pirate_game/background.rb, line 92 def foreground? @state == :foggy end
randomize_state()
click to toggle source
# File lib/pirate_game/background.rb, line 28 def randomize_state case rand when 0.0..0.1 @state = :foggy when 0.2..0.3 @state = :windy else @state = :clear end end
send_speed_to_items()
click to toggle source
# File lib/pirate_game/background.rb, line 39 def send_speed_to_items case @state when :windy all_items.each {|item| item.speed = :fast} end end
set_state(state)
click to toggle source
# File lib/pirate_game/background.rb, line 23 def set_state state @state = state if STATES.include?(state) @state ||= :clear end