Class: GameWindow

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/empi.rb

Overview

Main class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width = (MAPX + 1) * TILESIZE, height = (MAPY + 2) * TILESIZE, fullscreen = false) ⇒ GameWindow

Returns a new instance of GameWindow.



18
19
20
21
22
23
24
25
26
27
# File 'lib/empi.rb', line 18

def initialize(width = (MAPX + 1) * TILESIZE, \
               height = (MAPY + 2) * TILESIZE, \
               fullscreen = false)
  super
  self.caption = 'Empi: Ruby Edition 0.24'

  # Activate first state
  $window = self
  GameState.switch!(WelcomeState.instance)
end

Instance Attribute Details

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

Instance Method Details

#button_up(key) ⇒ Object

Catch the released button



30
31
32
# File 'lib/empi.rb', line 30

def button_up(key)
  @button = key
end

#drawObject

Draw according to current state



48
49
50
51
52
53
54
# File 'lib/empi.rb', line 48

def draw

  @button = BUTTON_PROCESSED # draw just once after each button release
  unless $window.state.nil?
    @state.draw
  end
end

#needs_redraw?Boolean

Draw only after some button was released and in the start

Returns:

  • (Boolean)


43
44
45
# File 'lib/empi.rb', line 43

def needs_redraw?
  @button != BUTTON_PROCESSED
end

#updateObject

Process given button according to current state



35
36
37
38
39
40
# File 'lib/empi.rb', line 35

def update
  # No (new) keys
  unless @button == BUTTON_PROCESSED || @button.nil?
    @state.update(@button)
  end
end