class SetState
Game state of settings screen
Attributes
settings[R]
TODO move out?
Public Class Methods
new()
click to toggle source
What to do just before state gets deactivated
def before_end end
Calls superclass method
# File lib/lib/game_states/set_state.rb, line 21 def initialize super @settings = { # TODO move out? 'axis_top' => true, 'axis_bottom' => false, 'axis_left' => true, 'axis_right' => false } end
Public Instance Methods
change_setting!(button)
click to toggle source
# File lib/lib/game_states/set_state.rb, line 62 def change_setting!(button) changed_setting = { Gosu::Kb1 => 'axis_top', Gosu::Kb2 => 'axis_bottom', Gosu::Kb3 => 'axis_left', Gosu::Kb4 => 'axis_right' }[button] old_value = @settings[changed_setting] @settings[changed_setting] = !@settings[changed_setting] # TODO other than boolean types? puts "setting #{changed_setting} changed from #{old_value} " \ "to #{@settings[changed_setting]}" end
draw()
click to toggle source
# File lib/lib/game_states/set_state.rb, line 41 def draw header_text = ' /-- /// /-/ -/- /-- ||| /-/ | /-- ||| | -/-' options_text = " 1 – show top axis: #{@settings['axis_top']} 2 – show bottom axis: #{@settings['axis_bottom']} 3 – show left axis: #{@settings['axis_left']} 4 – show right axis: #{@settings['axis_right']}\n Esc – return to menu" warning_text = ' Warning: settings are not saved when Empi is closed' menu = Gosu::Image.from_text( header_text + "\n\n\n\n\n" + options_text + "\n\n\n" + warning_text, 20) menu.draw((3*TILESIZE) + XTEXT, (2*TILESIZE) + YTEXT, ZTEXT) end
update(button)
click to toggle source
Process given button
# File lib/lib/game_states/set_state.rb, line 32 def update(button) case(button) when Gosu::Kb1, Gosu::Kb2, Gosu::Kb3, Gosu::Kb4 then change_setting!(button) when Gosu::KbEscape then GameState.switch!(WelcomeState.instance) end end