Class: SetState
- Includes:
- Singleton
- Defined in:
- lib/lib/game_states/set_state.rb
Overview
Game state of settings screen
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
TODO move out?.
Instance Method Summary collapse
- #change_setting!(button) ⇒ Object
- #draw ⇒ Object
-
#initialize ⇒ SetState
constructor
What to do just before state gets deactivated def before_end end.
-
#update(button) ⇒ Object
Process given button.
Methods inherited from GameState
#after_start, #before_end, switch!
Constructor Details
#initialize ⇒ SetState
What to do just before state gets deactivated def before_end end
21 22 23 24 25 26 27 28 29 |
# 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 |
Instance Attribute Details
#settings ⇒ Object (readonly)
TODO move out?
11 12 13 |
# File 'lib/lib/game_states/set_state.rb', line 11 def settings @settings end |
Instance Method Details
#change_setting!(button) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lib/game_states/set_state.rb', line 62 def change_setting!() changed_setting = { Gosu::Kb1 => 'axis_top', Gosu::Kb2 => 'axis_bottom', Gosu::Kb3 => 'axis_left', Gosu::Kb4 => 'axis_right' }[] 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 ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lib/game_states/set_state.rb', line 41 def draw header_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' = Gosu::Image.from_text( header_text + "\n\n\n\n\n" + + "\n\n\n" + warning_text, 20) .draw((3*TILESIZE) + XTEXT, (2*TILESIZE) + YTEXT, ZTEXT) end |
#update(button) ⇒ Object
Process given button
32 33 34 35 36 37 38 39 |
# File 'lib/lib/game_states/set_state.rb', line 32 def update() case() when Gosu::Kb1, Gosu::Kb2, Gosu::Kb3, Gosu::Kb4 then change_setting!() when Gosu::KbEscape then GameState.switch!(WelcomeState.instance) end end |