Class: MenuState

Inherits:
GameState show all
Includes:
Singleton
Defined in:
lib/gamestates/menu_state.rb

Overview

class MenuState

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GameState

#needs_redraw?, switch

Constructor Details

#initializeMenuState

Returns a new instance of MenuState.



10
11
12
13
14
# File 'lib/gamestates/menu_state.rb', line 10

def initialize
  @message = Gosu::Image.from_text($window, "Battle\ncity", $window.mediamanager.font, 45)
  @choice = Sprite.new(:player1_1right, true)
  @multiplayer = false
end

Instance Attribute Details

#multiplayerObject

Returns the value of attribute multiplayer.



8
9
10
# File 'lib/gamestates/menu_state.rb', line 8

def multiplayer
  @multiplayer
end

Instance Method Details

#button_down(id) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/gamestates/menu_state.rb', line 38

def button_down(id)
  $window.close if id == Gosu::KbEscape
  if id == Gosu::KbLeftShift || id == Gosu::KbRightShift
    @multiplayer ^= true # prevraceni hodnoty bool
  end
  GameState.switch(PlayState.new(@multiplayer)) if id == Gosu::KbReturn || id == Gosu::KbEnter
end

#drawObject



30
31
32
33
34
35
36
# File 'lib/gamestates/menu_state.rb', line 30

def draw
  @message.draw($window.width / 2 - @message.width / 2, $window.height / 2 - @message.height / 2 - 50, 10)
  @pl1.draw($window.width / 2 - @pl1.width / 2, $window.height / 2 - @pl1.height / 2 + 30, 10)
  @pl2.draw($window.width / 2 - @pl1.width / 2, $window.height / 2 - @pl2.height / 2 + 50, 10)
  @choice.draw($window.width / 2 - @pl1.width / 2 - 30, $window.height / 2 - @pl1.height / 2 + 30, 10) unless @multiplayer
  @choice.draw($window.width / 2 - @pl1.width / 2 - 30, $window.height / 2 - @pl2.height / 2 + 50, 10) if @multiplayer
end

#enterObject



16
17
18
# File 'lib/gamestates/menu_state.rb', line 16

def enter
  # play some music
end

#leaveObject



20
21
22
# File 'lib/gamestates/menu_state.rb', line 20

def leave
  # play some music
end

#update(_keymap) ⇒ Object



24
25
26
27
28
# File 'lib/gamestates/menu_state.rb', line 24

def update(_keymap)
  @pl1 = Gosu::Image.from_text($window, '1 Player', $window.mediamanager.font, 16)
  @pl2 = Gosu::Image.from_text($window, '2 Players', $window.mediamanager.font, 16)
  @choice.update
end