Class: Conjuration::Game

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/conjuration/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, target_fps: 120, **options) ⇒ Game

Returns a new instance of Game.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/conjuration/game.rb', line 7

def initialize(title:, target_fps: 120, **options)
  super(1920, 1080, update_interval: 1000.0 / target_fps, **options)

  self.caption = title

  @debug_manager = DebugManager.new
  @scene_manager = SceneManager.new(self)
  @input_manager = InputManager.new

  @target_fps = target_fps
end

Instance Attribute Details

#debug_managerObject (readonly)

Returns the value of attribute debug_manager.



5
6
7
# File 'lib/conjuration/game.rb', line 5

def debug_manager
  @debug_manager
end

#input_managerObject (readonly)

Returns the value of attribute input_manager.



5
6
7
# File 'lib/conjuration/game.rb', line 5

def input_manager
  @input_manager
end

#scene_managerObject (readonly)

Returns the value of attribute scene_manager.



5
6
7
# File 'lib/conjuration/game.rb', line 5

def scene_manager
  @scene_manager
end

#target_fpsObject (readonly)

Returns the value of attribute target_fps.



5
6
7
# File 'lib/conjuration/game.rb', line 5

def target_fps
  @target_fps
end

Instance Method Details

#button_down(id) ⇒ Object



28
29
30
31
# File 'lib/conjuration/game.rb', line 28

def button_down(id)
  @scene_manager.button_down(self, @input_manager.map_button(id))
  @debug_manager.button_down(self, id)
end

#button_up(id) ⇒ Object



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

def button_up(id)
  @scene_manager.button_up(self, @input_manager.map_button(id))
end

#drawObject



23
24
25
26
# File 'lib/conjuration/game.rb', line 23

def draw
  @scene_manager.draw(self)
  @debug_manager.draw(self)
end

#draw_circle(x, y, r, c, z = 0, thickness = 1, sides = nil, mode = :default) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/conjuration/game.rb', line 37

def draw_circle(x, y, r, c, z = 0, thickness = 1, sides = nil, mode = :default)
  # Unless specified, calculate a nice-looking "minimum" number of sides
  # sides = (r + Math::sqrt(r * 0.1) * 4).floor if sides.nil?
  sides = (2.0 * r * Math::PI).floor if sides.nil?

  # Calculate the inner and outer offsets from the "true" circle
  offs = thickness * 0.5
  r_in = r - offs
  r_out = r + offs

  # Calculate the angular increment
  ai = 360.0 / sides.to_f

  translate(x, y) {
    ang = 0
    while ang <= 359.9 do
      draw_quad(
        Gosu.offset_x(ang, r_in), Gosu.offset_y(ang, r_in), c,
        Gosu.offset_x(ang, r_out), Gosu.offset_y(ang, r_out), c,
        Gosu.offset_x(ang + ai, r_in), Gosu.offset_y(ang + ai, r_in), c,
        Gosu.offset_x(ang + ai, r_out), Gosu.offset_y(ang + ai, r_out), c,
        z, mode
      )
      ang += ai
    end
  }

end

#updateObject



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

def update
  @scene_manager.update(self)
end