Class: CyberarmEngine::Window

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/cyberarm_engine/window.rb

Constant Summary collapse

IMAGES =
{}
SAMPLES =
{}
SONGS =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false) ⇒ Window

Returns a new instance of Window.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cyberarm_engine/window.rb', line 19

def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
  @show_cursor = false

  super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable, borderless: borderless)
  $window = self
  @last_frame_time = Gosu.milliseconds - 1
  @current_frame_time = Gosu.milliseconds
  self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.language}"

  @states = []
  @exit_on_opengl_error = false

  setup if defined?(setup)
end

Instance Attribute Details

#exit_on_opengl_error=(value) ⇒ Object (writeonly)

Sets the attribute exit_on_opengl_error

Parameters:

  • value

    the value to set the attribute exit_on_opengl_error to.



8
9
10
# File 'lib/cyberarm_engine/window.rb', line 8

def exit_on_opengl_error=(value)
  @exit_on_opengl_error = value
end

#last_frame_timeObject (readonly)

Returns the value of attribute last_frame_time.



9
10
11
# File 'lib/cyberarm_engine/window.rb', line 9

def last_frame_time
  @last_frame_time
end

#show_cursorObject

Returns the value of attribute show_cursor.



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

def show_cursor
  @show_cursor
end

Class Method Details

.dtObject



15
16
17
# File 'lib/cyberarm_engine/window.rb', line 15

def self.dt
  $window.last_frame_time / 1000.0
end

.nowObject



11
12
13
# File 'lib/cyberarm_engine/window.rb', line 11

def self.now
  Gosu.milliseconds
end

Instance Method Details

#aspect_ratioObject



54
55
56
# File 'lib/cyberarm_engine/window.rb', line 54

def aspect_ratio
  width / height.to_f
end

#button_down(id) ⇒ Object



62
63
64
65
# File 'lib/cyberarm_engine/window.rb', line 62

def button_down(id)
  super
  current_state.button_down(id) if current_state
end

#button_up(id) ⇒ Object



67
68
69
70
# File 'lib/cyberarm_engine/window.rb', line 67

def button_up(id)
  super
  current_state.button_up(id) if current_state
end

#current_stateObject



89
90
91
# File 'lib/cyberarm_engine/window.rb', line 89

def current_state
  @states.last
end

#drawObject



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

def draw
  current_state.draw if current_state
end

#draw_circle(cx, cy, r, z = 9999, color = Gosu::Color::GREEN, step = 10) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/cyberarm_engine/window.rb', line 104

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

#dtObject



50
51
52
# File 'lib/cyberarm_engine/window.rb', line 50

def dt
  @last_frame_time / 1000.0
end

#exit_on_opengl_error?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/cyberarm_engine/window.rb', line 58

def exit_on_opengl_error?
  @exit_on_opengl_error
end

#needs_cursor?Boolean

Returns:

  • (Boolean)


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

def needs_cursor?
  @show_cursor
end

#pop_stateObject



99
100
101
# File 'lib/cyberarm_engine/window.rb', line 99

def pop_state
  @states.pop
end

#previous_stateObject



93
94
95
96
97
# File 'lib/cyberarm_engine/window.rb', line 93

def previous_state
  if @states.size > 1 && state = @states[@states.size - 2]
    state
  end
end

#push_state(klass, options = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cyberarm_engine/window.rb', line 72

def push_state(klass, options = {})
  options = { setup: true }.merge(options)

  if klass.instance_of?(klass.class) && defined?(klass.options)
    @states << klass
    klass.setup if options[:setup]
  else
    @states << klass.new(options) if child_of?(klass, GameState)
    @states << klass.new if child_of?(klass, Element::Container)
    current_state.setup if current_state.instance_of?(klass) && options[:setup]
  end
end

#updateObject



38
39
40
41
42
43
44
# File 'lib/cyberarm_engine/window.rb', line 38

def update
  Stats.clear

  current_state.update if current_state
  @last_frame_time = Gosu.milliseconds - @current_frame_time
  @current_frame_time = Gosu.milliseconds
end