Class: CyberarmEngine::Engine
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- CyberarmEngine::Engine
- Defined in:
- lib/cyberarm_engine/engine.rb
Constant Summary collapse
- IMAGES =
{}
- SAMPLES =
{}
- SONGS =
{}
Instance Attribute Summary collapse
-
#last_frame_time ⇒ Object
readonly
Returns the value of attribute last_frame_time.
-
#show_cursor ⇒ Object
Returns the value of attribute show_cursor.
Class Method Summary collapse
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #button_up(id) ⇒ Object
- #current_state ⇒ Object
- #draw ⇒ Object
-
#draw_circle(cx, cy, r, z = 9999, color = Gosu::Color::GREEN, step = 10) ⇒ Object
Sourced from gist.github.com/ippa/662583.
- #dt ⇒ Object
-
#initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0/60, resizable: false) ⇒ Engine
constructor
A new instance of Engine.
- #needs_cursor? ⇒ Boolean
- #pop_state ⇒ Object
- #previous_state ⇒ Object
- #push_state(klass, options = {}) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0/60, resizable: false) ⇒ Engine
Returns a new instance of Engine.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cyberarm_engine/engine.rb', line 18 def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0/60, resizable: false) @show_cursor = false super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable) $window = self @last_frame_time = Gosu.milliseconds-1 @current_frame_time = Gosu.milliseconds self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.language}" @states = [] setup if defined?(setup) end |
Instance Attribute Details
#last_frame_time ⇒ Object (readonly)
Returns the value of attribute last_frame_time.
8 9 10 |
# File 'lib/cyberarm_engine/engine.rb', line 8 def last_frame_time @last_frame_time end |
#show_cursor ⇒ Object
Returns the value of attribute show_cursor.
7 8 9 |
# File 'lib/cyberarm_engine/engine.rb', line 7 def show_cursor @show_cursor end |
Class Method Details
.dt ⇒ Object
14 15 16 |
# File 'lib/cyberarm_engine/engine.rb', line 14 def self.dt $window.last_frame_time/1000.0 end |
.now ⇒ Object
10 11 12 |
# File 'lib/cyberarm_engine/engine.rb', line 10 def self.now Gosu.milliseconds end |
Instance Method Details
#button_down(id) ⇒ Object
50 51 52 53 |
# File 'lib/cyberarm_engine/engine.rb', line 50 def (id) super current_state.(id) if current_state end |
#button_up(id) ⇒ Object
55 56 57 58 |
# File 'lib/cyberarm_engine/engine.rb', line 55 def (id) super current_state.(id) if current_state end |
#current_state ⇒ Object
77 78 79 |
# File 'lib/cyberarm_engine/engine.rb', line 77 def current_state @states.last end |
#draw ⇒ Object
32 33 34 |
# File 'lib/cyberarm_engine/engine.rb', line 32 def draw current_state.draw if current_state end |
#draw_circle(cx, cy, r, z = 9999, color = Gosu::Color::GREEN, step = 10) ⇒ Object
Sourced from gist.github.com/ippa/662583
94 95 96 97 98 99 |
# File 'lib/cyberarm_engine/engine.rb', line 94 def draw_circle(cx,cy,r, z = 9999,color = Gosu::Color::GREEN, step = 10) 0.step(360, step) do |a1| a2 = a1 + step draw_line(cx + Gosu.offset_x(a1, r), cy + Gosu.offset_y(a1, r), color, cx + Gosu.offset_x(a2, r), cy + Gosu.offset_y(a2, r), color, z) end end |
#dt ⇒ Object
46 47 48 |
# File 'lib/cyberarm_engine/engine.rb', line 46 def dt @last_frame_time/1000.0 end |
#needs_cursor? ⇒ Boolean
42 43 44 |
# File 'lib/cyberarm_engine/engine.rb', line 42 def needs_cursor? @show_cursor end |
#pop_state ⇒ Object
89 90 91 |
# File 'lib/cyberarm_engine/engine.rb', line 89 def pop_state @states.pop end |
#previous_state ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/cyberarm_engine/engine.rb', line 81 def previous_state if @states.size > 1 && state = @states[@states.size-2] return state else return nil end end |
#push_state(klass, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cyberarm_engine/engine.rb', line 60 def push_state(klass, ={}) = {setup: true}.merge() if klass.instance_of?(klass.class) && defined?(klass.) @states << klass klass.setup if [:setup] else @states << klass.new() if child_of?(klass, GameState) @states << klass.new if child_of?(klass, Element::Container) current_state.setup if current_state.class == klass && [:setup] end end |
#update ⇒ Object
36 37 38 39 40 |
# File 'lib/cyberarm_engine/engine.rb', line 36 def update current_state.update if current_state @last_frame_time = Gosu.milliseconds-@current_frame_time @current_frame_time = Gosu.milliseconds end |