Class: Lotu::Window
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Lotu::Window
- Extended by:
- HasBehavior
- Defined in:
- lib/lotu/window.rb
Instance Attribute Summary collapse
-
#draw_queue ⇒ Object
Returns the value of attribute draw_queue.
-
#dt ⇒ Object
readonly
delta time.
-
#font ⇒ Object
Returns the value of attribute font.
-
#input_listeners ⇒ Object
Returns the value of attribute input_listeners.
-
#update_queue ⇒ Object
Returns the value of attribute update_queue.
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #button_up(id) ⇒ Object
- #draw ⇒ Object
-
#init_behavior ⇒ Object
Meant to be overriden by behaviors.
-
#initialize(params = {}) ⇒ Window
constructor
A new instance of Window.
- #register_for_draw(object) ⇒ Object
-
#register_for_input(controller) ⇒ Object
Register controller.
- #update ⇒ Object
Methods included from Resourceful
Methods included from Drawable
Methods included from Controllable
Methods included from 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_queue ⇒ Object
Returns the value of attribute draw_queue.
7 8 9 |
# File 'lib/lotu/window.rb', line 7 def draw_queue @draw_queue end |
#dt ⇒ Object (readonly)
delta time
6 7 8 |
# File 'lib/lotu/window.rb', line 6 def dt @dt end |
#font ⇒ Object
Returns the value of attribute font.
7 8 9 |
# File 'lib/lotu/window.rb', line 7 def font @font end |
#input_listeners ⇒ Object
Returns the value of attribute input_listeners.
7 8 9 |
# File 'lib/lotu/window.rb', line 7 def input_listeners @input_listeners end |
#update_queue ⇒ Object
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 (id) @input_register[id].each do |item| item.(id) end end |
#button_up(id) ⇒ Object
51 52 53 54 55 |
# File 'lib/lotu/window.rb', line 51 def (id) @input_register[id].each do |item| item.(id) end end |
#draw ⇒ Object
39 40 41 42 43 |
# File 'lib/lotu/window.rb', line 39 def draw @draw_queue.each do |item| item.draw end end |
#init_behavior ⇒ Object
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 |
#update ⇒ Object
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 |