Class: WelcomeState

Inherits:
GameState show all
Includes:
Singleton
Defined in:
lib/lib/game_states/welcome_state.rb

Overview

Game state of main menu

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GameState

#after_start, #before_end, switch!

Instance Attribute Details

#versionObject

Returns the value of attribute version.



13
14
15
# File 'lib/lib/game_states/welcome_state.rb', line 13

def version
  @version
end

Instance Method Details

#drawObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/lib/game_states/welcome_state.rb', line 49

def draw
  header_text = '
      /--  ///  /-/  -/-
      /--  |||  /-/   |
      /--  |||  |    -/-'

  # Is there active map? Is it won?
  if PlayState.instance.map
    unless WinState.instance.faction
      resume_text = "
      Esc – resume"
    else
      resume_text = "
      Esc – return to victory screen"
    end
  else
    resume_text = "\n"
  end

  options_text = "
      1 – start new: Map 01
      2 – start new: Map 02
      3 – start new: Map 03\n
      9, S – settings
      0, Q – quit"

  version_text = "
      version #{self.version}"

  menu = Gosu::Image.from_text(
    header_text + "\n\n\n" +
    resume_text + "\n" +
    options_text + "\n\n\n\n\n\n\n\n" +
    version_text, 20)
  menu.draw((3*TILESIZE) + XTEXT, (2*TILESIZE) + YTEXT, ZTEXT)
end

#update(button) ⇒ Object

Process given button



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lib/game_states/welcome_state.rb', line 24

def update(button)
  case(button)
  when Gosu::KbEscape then
    # If there is active map go either to it or to its win screen
    if PlayState.instance.map
      unless WinState.instance.faction
        GameState.switch!(PlayState.instance)
      else
        GameState.switch!(WinState.instance)
      end
    end
  when Gosu::Kb1, Gosu::Kb2, Gosu::Kb3 then
    PlayState.instance.desired_new_map = {
       Gosu::Kb1 => 'm01',
       Gosu::Kb2 => 'm02',
       Gosu::Kb3 => 'm03'
    }[button]
    GameState.switch!(PlayState.instance)
  when Gosu::Kb9, Gosu::KbS then
    GameState.switch!(SetState.instance)
  when Gosu::Kb0, Gosu::KbQ then
    GameState.switch!(QuitState.instance)
  end
end