class MiniGL::GameWindow

The main class for a MiniGL game, holds references to globally accessible objects and constants.

Public Class Methods

new(scr_w, scr_h = nil, fullscreen = true, gravity = Vector.new(0, 1), min_speed = Vector.new(0.01, 0.01), ramp_contact_threshold = 4, ramp_slip_threshold = 1, ramp_slip_force = 1, kb_held_delay = 40, kb_held_interval = 5, double_click_delay = 8) click to toggle source

Creates a game window (initializing a game with all MiniGL features enabled).

Parameters:

scr_w

Width of the window, in pixels.

scr_h

Height of the window, in pixels.

fullscreen

Whether the window must be initialized in full screen mode.

gravity

A Vector object representing the horizontal and vertical components of the force of gravity. Essentially, this force will be applied to every object which calls move, from the Movement module.

min_speed

A Vector with the minimum speed for moving objects, i.e., the value below which the speed will be rounded to zero.

ramp_contact_threshold

The maximum horizontal movement an object can perform in a single frame and keep contact with a ramp when it’s above one.

ramp_slip_threshold

The maximum ratio between height and width of a ramp above which the objects will always slip down when trying to ‘climb’ that ramp.

ramp_slip_force

The force that will be applied in the horizontal direction when the object is slipping from a steep ramp.

kb_held_delay

The number of frames a key must be held by the user before the “held” event (that can be checked with KB.key_held?) starts to trigger.

kb_held_interval

The interval, in frames, between each triggering of the “held” event, after the key has been held for more than kb_held_delay frames.

double_click_delay

The maximum interval, in frames, between two clicks, to trigger the “double click” event (checked with Mouse.double_click?).

Obs.: This method accepts named parameters, but scr_w and scr_h are mandatory.

Calls superclass method
# File lib/minigl/global.rb, line 199
def initialize(scr_w, scr_h = nil, fullscreen = true,
               gravity = Vector.new(0, 1), min_speed = Vector.new(0.01, 0.01),
               ramp_contact_threshold = 4, ramp_slip_threshold = 1, ramp_slip_force = 1,
               kb_held_delay = 40, kb_held_interval = 5, double_click_delay = 8)
  if scr_w.is_a? Hash
    scr_h = scr_w[:scr_h]
    fullscreen = scr_w.fetch(:fullscreen, true)
    gravity = scr_w.fetch(:gravity, Vector.new(0, 1))
    min_speed = scr_w.fetch(:min_speed, Vector.new(0.01, 0.01))
    ramp_contact_threshold = scr_w.fetch(:ramp_contact_threshold, 4)
    ramp_slip_threshold = scr_w.fetch(:ramp_slip_threshold, 1.1)
    ramp_slip_force = scr_w.fetch(:ramp_slip_force, 0.1)
    kb_held_delay = scr_w.fetch(:kb_held_delay, 40)
    kb_held_interval = scr_w.fetch(:kb_held_interval, 5)
    double_click_delay = scr_w.fetch(:double_click_delay, 8)
    scr_w = scr_w[:scr_w]
  end

  super scr_w, scr_h, fullscreen
  G.window = self
  G.gravity = gravity
  G.min_speed = min_speed
  G.ramp_contact_threshold = ramp_contact_threshold
  G.ramp_slip_threshold = ramp_slip_threshold
  G.ramp_slip_force = ramp_slip_force
  G.kb_held_delay = kb_held_delay
  G.kb_held_interval = kb_held_interval
  G.double_click_delay = double_click_delay
  KB.initialize
  Mouse.initialize
  Res.initialize
end

Public Instance Methods

button_down(id) click to toggle source
Calls superclass method
# File lib/minigl/global.rb, line 249
def button_down(id)
  super
  Mouse.register_button_down(id)
end
button_up(id) click to toggle source
Calls superclass method
# File lib/minigl/global.rb, line 254
def button_up(id)
  super
  Mouse.register_button_up(id)
end
clear(color) click to toggle source

Draws a rectangle with the size of the entire screen, in the given color.

Parameters:

color

Color of the rectangle to be drawn, in hexadecimal RRGGBB format.

# File lib/minigl/global.rb, line 236
def clear(color)
  color |= 0xff000000
  draw_quad 0, 0, color,
            width, 0, color,
            width, height, color,
            0, height, color, 0
end
toggle_fullscreen() click to toggle source

Toggles the window between windowed and full screen mode.

# File lib/minigl/global.rb, line 245
def toggle_fullscreen
  self.fullscreen = !fullscreen?
end