Class: Lotu::Window

Inherits:
Gosu::Window
  • Object
show all
Extended by:
HasBehavior
Defined in:
lib/lotu/window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Resourceful

#is_resourceful

Methods included from Drawable

#is_drawable

Methods included from Controllable

#is_controllable

Methods included from Eventful

#is_eventful

Constructor Details

#initialize(params = {}) ⇒ Window

Returns a new instance of Window.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lotu/window.rb', line 9

def initialize(params={})
  super(640, 480, false)

  # Handy global window variable
  $window = self

  # Systems setup
  @update_queue = []
  @draw_queue = []
  @input_register = Hash.new{|hash,key| hash[key] = []}

  @fps_counter = FpsCounter.new
  @last_time = Gosu::milliseconds
  @font = Gosu::Font.new(self, Gosu::default_font_name, 14)

  # Initialize the behaviors included in subclasses
  init_behavior
end

Instance Attribute Details

#draw_queueObject

Returns the value of attribute draw_queue.



7
8
9
# File 'lib/lotu/window.rb', line 7

def draw_queue
  @draw_queue
end

#dtObject (readonly)

delta time



6
7
8
# File 'lib/lotu/window.rb', line 6

def dt
  @dt
end

#fontObject

Returns the value of attribute font.



7
8
9
# File 'lib/lotu/window.rb', line 7

def font
  @font
end

#input_listenersObject

Returns the value of attribute input_listeners.



7
8
9
# File 'lib/lotu/window.rb', line 7

def input_listeners
  @input_listeners
end

#update_queueObject

Returns the value of attribute update_queue.



7
8
9
# File 'lib/lotu/window.rb', line 7

def update_queue
  @update_queue
end

Instance Method Details

#button_down(id) ⇒ Object



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

def button_down(id)
  @input_register[id].each do |item|
    item.button_down(id)
  end
end

#button_up(id) ⇒ Object



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

def button_up(id)
  @input_register[id].each do |item|
    item.button_up(id)
  end
end

#drawObject



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

def draw
  @draw_queue.each do |item|
    item.draw
  end
end

#init_behaviorObject

Meant to be overriden by behaviors



70
# File 'lib/lotu/window.rb', line 70

def init_behavior;end

#register_for_draw(object) ⇒ Object



65
66
67
# File 'lib/lotu/window.rb', line 65

def register_for_draw(object)
  @draw_queue << object
end

#register_for_input(controller) ⇒ Object

Register controller



58
59
60
61
62
63
# File 'lib/lotu/window.rb', line 58

def register_for_input(controller)
  controller.keys.each_key do |key|
    @input_register[key] << controller
  end
  @update_queue << controller
end

#updateObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/lotu/window.rb', line 28

def update
  new_time = Gosu::milliseconds
  @dt = (new_time - @last_time)/1000.0
  @last_time = new_time
  @fps_counter.update(@dt)

  @update_queue.each do |item|
    item.update
  end
end