Class: AdventureRL::Window

Inherits:
Gosu::Window
  • Object
show all
Includes:
Helpers::MethodHelper
Defined in:
lib/AdventureRL/Window.rb

Constant Summary collapse

@@WINDOW =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings_arg = {}) ⇒ Window



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/AdventureRL/Window.rb', line 16

def initialize settings_arg = {}
  @@WINDOW = self
  settings_arg = {}  unless (settings_arg)
  settings = Settings.new(
    DEFAULT_SETTINGS.get(:window)
  ).merge(settings_arg)
  @_layer = Layer.new(
    position:           settings.get(:position),
    size:               settings.get(:size),
    origin:             settings.get(:origin),
    has_solids_manager: settings.get(:has_solids_manager)
  )
  Helpers::PipeMethods.pipe_methods_from self, to: @_layer
  @_target_fps        = settings.get(:fps)
  @background_color   = settings.get(:background_color)    if (settings.get(:background_color))
  @background_z_index = settings.get(:background_z_index)
  #@_solids_manager = SolidsManager.new
  super(
    get_size(:width), get_size(:height),
    fullscreen:      settings.get(:fullscreen),
    update_interval: _get_update_inteval_from_fps(@_target_fps)
  )
  self.caption = settings.get(:caption)
  _call_setup_method settings_arg
end

Class Method Details

.get_windowObject

This returns the current Window. As there should always only be one instance of Window, this should be fine.



11
12
13
# File 'lib/AdventureRL/Window.rb', line 11

def get_window
  return @@WINDOW
end

Instance Method Details

#button_down(btnid) ⇒ Object

If you use #button_down in your game, be sure to call super at the beginning of the method, to take advantage of the framework’s button events.



85
86
87
88
# File 'lib/AdventureRL/Window.rb', line 85

def button_down btnid
  EventHandlers::Buttons.button_down btnid
  Menu.button_down btnid
end

#button_up(btnid) ⇒ Object

If you use #button_up in your game, be sure to call super at the beginning of the method, to take advantage of the framework’s button events.



93
94
95
96
# File 'lib/AdventureRL/Window.rb', line 93

def button_up btnid
  EventHandlers::Buttons.button_up btnid
  Menu.button_up btnid
end

#drawObject

Default #draw method. You might want to call super if you overwrite this method.



116
117
118
119
# File 'lib/AdventureRL/Window.rb', line 116

def draw
  @_layer.draw
  draw_background_color  if (@background_color)
end

#draw_background_colorObject



121
122
123
124
125
126
127
128
# File 'lib/AdventureRL/Window.rb', line 121

def draw_background_color
  Gosu.draw_rect(
    *get_corner(:left, :top).values,
    *get_size.values,
    @background_color,
    @background_z_index
  )
end

#get_fpsObject

Returns the current FPS. This is just a wrapper method around Gosu.fps to maintain the design pattern with get_* methods.



50
51
52
# File 'lib/AdventureRL/Window.rb', line 50

def get_fps
  return Gosu.fps
end

#get_target_fpsObject

Returns the expected FPS. These were passed to #initialize in the settings.



56
57
58
# File 'lib/AdventureRL/Window.rb', line 56

def get_target_fps
  return @_target_fps
end

#is_fullscreen?Boolean

Wrapper method around Gosu::Window#fullscreen?, just to follow the design pattern.



67
68
69
# File 'lib/AdventureRL/Window.rb', line 67

def is_fullscreen?
  return fullscreen?
end

#needs_cursor?Boolean

Show cursor.



99
100
101
# File 'lib/AdventureRL/Window.rb', line 99

def needs_cursor?
  return true
end

#set_fullscreen(state) ⇒ Object

Wrapper method around Gosu::Window#fullscreen=, just to follow the design pattern.



73
74
75
# File 'lib/AdventureRL/Window.rb', line 73

def set_fullscreen state
  self.fullscreen = !!state
end

#setup(args) ⇒ Object

This method can be overwritten by user, and will be called after #initialize.



44
45
# File 'lib/AdventureRL/Window.rb', line 44

def setup args
end

#showObject

Overwrite the Gosu#show method, so we can call Deltatime#reset on all previously created Deltatimes.



132
133
134
135
# File 'lib/AdventureRL/Window.rb', line 132

def show
  Deltatime::DELTATIMES.each &:reset
  super
end

#toggle_fullscreenObject

Toggle beteween fullscreen and windowed states.



78
79
80
# File 'lib/AdventureRL/Window.rb', line 78

def toggle_fullscreen
  set_fullscreen !is_fullscreen?
end

#updateObject

Default #update method. If you overwrite this, be sure to call super in your method.



106
107
108
109
110
111
# File 'lib/AdventureRL/Window.rb', line 106

def update
  @_layer.update
  #@_solids_manager.update
  EventHandlers::Buttons.update
  Menu.update
end