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



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

def initialize(width = (MAPX + 1) * TILESIZE, \
               height = (MAPY + 2) * TILESIZE, \
               fullscreen = false)
  super

  # Set version name
  version = '0.25'
  self.caption = "Empi: Ruby Edition #{version}"
  WelcomeState.instance.version = version

  # 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



34
35
36
# File 'lib/empi.rb', line 34

def button_up(key)
  @button = key
end

#drawObject

Draw according to current state



52
53
54
55
56
57
# File 'lib/empi.rb', line 52

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



47
48
49
# File 'lib/empi.rb', line 47

def needs_redraw?
  @button != BUTTON_PROCESSED
end

#updateObject

Process given button according to current state



39
40
41
42
43
44
# File 'lib/empi.rb', line 39

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