Class: Game::Window::Window

Inherits:
Object
  • Object
show all
Includes:
MetaTools
Defined in:
lib/game/window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Window

This method is abstract.

Override and call ‘super` after you’ve setup the width, height, and title.

Initialize the game window.



24
25
26
27
28
29
30
# File 'lib/game/window.rb', line 24

def initialize(options={})
  # Complain if @title isn't set?
  # Complain if @width isn't set?
  # Complain if height isn't set?
  init_window
  @started_at = Time.now
end

Instance Attribute Details

#fullscreen(value = nil) ⇒ Object



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

def fullscreen(value=nil)
  @fullscreen = value unless value.nil?
  @fullscreen
end

#height(value = nil) ⇒ Object



45
46
47
48
# File 'lib/game/window.rb', line 45

def height(value=nil)
  @height = value unless value.nil?
  @height
end

#started_atObject (readonly)

Returns the value of attribute started_at.



19
20
21
# File 'lib/game/window.rb', line 19

def started_at
  @started_at
end

#title(value = nil) ⇒ Object



33
34
35
36
# File 'lib/game/window.rb', line 33

def title(value=nil)
  @title = value unless value.nil?
  @title
end

#width(value = nil) ⇒ Object



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

def width(value=nil)
  @width = value unless value.nil?
  @width
end

Instance Method Details

#add_entity(entity, *args) {|entity_instance| ... } ⇒ Object

Yields:

  • (entity_instance)


60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/game/window.rb', line 60

def add_entity(entity, *args, &blk)
  entity_name, entity = entity, args.shift if entity.is_a?(Symbol)
  entity_name ||= entity.to_s.split('::').last.gsub(/[A-Z]/, '_\0').gsub(/^_/, '').downcase
  
  meta_def(entity_name) { entity }
  
  entities << entity_instance = entity.new(@window, *args)
  
  yield(entity_instance) if block_given?
  
  entity
end

#entitiesObject



56
57
58
# File 'lib/game/window.rb', line 56

def entities
  @entities ||= []
end

#init_windowObject

This method is abstract.

Must be overridden by an adapter.

Initialize the underlying adapter window.

Raises:

  • (NotImplementedError)


76
77
78
# File 'lib/game/window.rb', line 76

def init_window
  raise NotImplementedError
end