Module: Metro::Game

Extended by:
Game
Included in:
Game
Defined in:
lib/metro/game.rb,
lib/metro/game/dsl.rb

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



99
100
101
# File 'lib/metro/game.rb', line 99

def config
  @config
end

#execution_parametersObject

The original parameters specified during execution. These are the args found on the command-line that are passed in when the game started.



23
24
25
# File 'lib/metro/game.rb', line 23

def execution_parameters
  @execution_parameters ||= []
end

#windowObject (readonly)

Returns the current game window.

Returns:

  • the current game window.



32
33
34
# File 'lib/metro/game.rb', line 32

def window
  @window
end

Instance Method Details

#authorsObject



79
80
81
# File 'lib/metro/game.rb', line 79

def authors
  fetch(:authors)
end

#boundsObject



55
56
57
# File 'lib/metro/game.rb', line 55

def bounds
  Units::RectangleBounds.new left: 0, right: width, top: 0, bottom: height
end

#centerObject



63
64
65
# File 'lib/metro/game.rb', line 63

def center
  Units::Point.at width / 2 , height / 2
end

#contactObject



87
88
89
# File 'lib/metro/game.rb', line 87

def contact
  fetch(:contact)
end

#controlsObject



91
92
93
# File 'lib/metro/game.rb', line 91

def controls
  config.controls.defined_controls
end

#current_sceneScene, NilClass

Returns the current scene that is being displayed. If this is called before the window is being displayed when this will return a nil value.

Returns:

  • (Scene, NilClass)

    the current scene that is being displayed. If this is called before the window is being displayed when this will return a nil value.



39
40
41
# File 'lib/metro/game.rb', line 39

def current_scene
  window ? window.scene : nil
end

#debug?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/metro/game.rb', line 71

def debug?
  !!fetch(:debug)
end

#dimensionsObject



59
60
61
# File 'lib/metro/game.rb', line 59

def dimensions
  Units::Dimensions.of width, height
end

#fetch(name, fallback = nil) ⇒ Object



95
96
97
# File 'lib/metro/game.rb', line 95

def fetch(name,fallback = nil)
  config.send(name) rescue fallback
end

#first_sceneObject



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

def first_scene
  fetch(:first_scene)
end

#fullscreen?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/metro/game.rb', line 67

def fullscreen?
  !!fetch(:fullscreen)
end

#heightObject



51
52
53
# File 'lib/metro/game.rb', line 51

def height
  fetch(:height,600)
end

#nameObject



75
76
77
# File 'lib/metro/game.rb', line 75

def name
  fetch(:name)
end

#setup(game_configuration) ⇒ Object



7
8
9
# File 'lib/metro/game.rb', line 7

def setup(game_configuration)
  @config = game_configuration
end

#start!Object

Creates a window and starts the game with the game parameters.



14
15
16
17
18
19
# File 'lib/metro/game.rb', line 14

def start!
  @window = Window.new width, height, fullscreen?
  window.caption = name
  window.scene = Scenes.generate(first_scene)
  window.show
end

#websiteObject



83
84
85
# File 'lib/metro/game.rb', line 83

def website
  fetch(:website,Metro::WEBSITE)
end

#widthObject



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

def width
  fetch(:width,800)
end