Class: GameWindow

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

Overview

class GameWindow

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGameWindow

Returns a new instance of GameWindow.



8
9
10
11
12
13
# File 'lib/misc/game_window.rb', line 8

def initialize
  super(256, 224, true)
  self.caption = 'Battle city'
  @unitsize = 8
  @mediamanager = MediaManager.new(self)
end

Instance Attribute Details

#mediamanagerObject

Returns the value of attribute mediamanager.



7
8
9
# File 'lib/misc/game_window.rb', line 7

def mediamanager
  @mediamanager
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/misc/game_window.rb', line 6

def state
  @state
end

Instance Method Details

#button_down(id) ⇒ Object



27
28
29
# File 'lib/misc/game_window.rb', line 27

def button_down(id)
  @state.button_down(id)
end

#drawObject



19
20
21
# File 'lib/misc/game_window.rb', line 19

def draw
  @state.draw
end

#keymapObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/misc/game_window.rb', line 31

def keymap
  keys = []
  keys.push(:p1up) if Gosu::button_down?(Gosu::KbUp)
  keys.push(:p1down) if Gosu::button_down?(Gosu::KbDown)
  keys.push(:p1left) if Gosu::button_down?(Gosu::KbLeft)
  keys.push(:p1right) if Gosu::button_down?(Gosu::KbRight)
  keys.push(:p2up) if Gosu::button_down?(Gosu::KbW)
  keys.push(:p2down) if Gosu::button_down?(Gosu::KbS)
  keys.push(:p2left) if Gosu::button_down?(Gosu::KbA)
  keys.push(:p2right) if Gosu::button_down?(Gosu::KbD)
  keys.push(:p1shoot) if Gosu::button_down?(Gosu::KbRightControl)
  keys.push(:p2shoot) if Gosu::button_down?(Gosu::KbLeftControl)
  keys
end

#needs_redraw?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/misc/game_window.rb', line 23

def needs_redraw?
  @state.needs_redraw?
end

#updateObject



15
16
17
# File 'lib/misc/game_window.rb', line 15

def update
  @state.update(keymap)
end