Module: Ray

Defined in:
lib/ray/pp.rb,
lib/ray/dsl.rb,
lib/ray/ray.rb,
lib/ray/font.rb,
lib/ray/game.rb,
lib/ray/rect.rb,
lib/ray/text.rb,
lib/ray/view.rb,
lib/ray/audio.rb,
lib/ray/color.rb,
lib/ray/event.rb,
lib/ray/image.rb,
lib/ray/music.rb,
lib/ray/scene.rb,
lib/ray/sound.rb,
lib/ray/effect.rb,
lib/ray/helper.rb,
lib/ray/matrix.rb,
lib/ray/shader.rb,
lib/ray/sprite.rb,
lib/ray/target.rb,
lib/ray/turtle.rb,
lib/ray/vector.rb,
lib/ray/vertex.rb,
lib/ray/window.rb,
lib/ray/polygon.rb,
lib/ray/drawable.rb,
lib/ray/font_set.rb,
lib/ray/animation.rb,
lib/ray/dsl/event.rb,
lib/ray/gl/vertex.rb,
lib/ray/image_set.rb,
lib/ray/pixel_bus.rb,
lib/ray/scene_list.rb,
lib/ray/dsl/handler.rb,
lib/ray/dsl/matcher.rb,
lib/ray/text_helper.rb,
lib/ray/audio_source.rb,
lib/ray/gl/int_array.rb,
lib/ray/image_target.rb,
lib/ray/resource_set.rb,
lib/ray/sound_buffer.rb,
lib/ray/animation_list.rb,
lib/ray/buffer_renderer.rb,
lib/ray/dsl/event_raiser.rb,
lib/ray/dsl/event_runner.rb,
lib/ray/effect/generator.rb,
lib/ray/effect/grayscale.rb,
lib/ray/sound_buffer_set.rb,
lib/ray/animation/sequence.rb,
lib/ray/dsl/event_listener.rb,
lib/ray/dsl/event_translator.rb,
lib/ray/animation/combination.rb,
lib/ray/effect/black_and_white.rb,
lib/ray/effect/color_inversion.rb,
lib/ray/animation/block_animation.rb,
lib/ray/animation/circular_motion.rb,
lib/ray/animation/color_variation.rb,
lib/ray/animation/float_variation.rb,
lib/ray/animation/sprite_animation.rb,
lib/ray/animation/vector_variation.rb,
ext/ray.c

Defined Under Namespace

Modules: Audio, DSL, FontSet, GL, Helper, ImageSet, Matchers, PP, ResourceSet, SoundBufferSet, TextHelper Classes: Animation, AnimationList, AudioSource, BufferRenderer, Color, Drawable, Effect, Event, Font, Game, Image, ImageTarget, Input, Key, KeyMod, Matrix, Music, NoKeyError, NoPatternError, NoRunnerError, PixelBus, Polygon, Rect, Scene, SceneList, Shader, Sound, SoundBuffer, Sprite, Target, Text, Turtle, Vector2, Vector3, Vertex, View, Window

Constant Summary collapse

BigEndian =

True for big endian

([1].pack("I") == [1].pack("N"))
InternalEncoding =

Encoding used by Ray for text_entered events.

BigEndian ? "UTF-32BE" : "UTF-32LE"
Keys =
{}
Mod =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.describe_matcher(name) {|*args| ... } ⇒ Object

Examples:

Ray.describe_matcher(:match) do |regex|
  lambda { |str| str =~ regex }
end

Yields:

  • The block is called when creating the matcher.

Yield Parameters:

  • *args

    Arguments passed to the matcher.

Yield Returns:

  • (Proc)

    A proc returning taking a single argument and returning true when its argument should be matched by the matcher.


65
66
67
68
69
70
71
72
73
# File 'lib/ray/dsl/matcher.rb', line 65

def describe_matcher(name, &create_block)
  Matchers.module_eval do
    define_method(name) do |*args|
      DSL::Matcher.new(&create_block.call(*args))
    end

    module_function name
  end
end

.font_set(regex) {|*args| ... } ⇒ Object

Creates a new font set.

Parameters:

  • regex (Regexp)

    Regular expression used to match file

Yields:

  • (*args)

    Block returning the font

Yield Parameters:

  • args

    Regex captures


23
24
25
# File 'lib/ray/font_set.rb', line 23

def font_set(regex, &block)
  Ray::FontSet.add_set(regex, &block)
end

.game(title, opts = {}) { ... } ⇒ Object

Creates a new game.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :window (Ray::Window) — default: nil

    If set, this window will be used instead of creating a new one

  • :size (Ray::Vector2, #to_vector2) — default: [640, 480]

    Size of the window.

  • :fullscreen (true, false) — default: false

    True to make the window fullscreen.

  • :resizable (true, false) — default: false

    True to make the window resizable.

  • :no_frame (true, false) — default: false

    True to create a window with no decorations.

Yields:

  • If a block is given, it is instance evaluated. #run will then be called.


240
241
242
# File 'lib/ray/game.rb', line 240

def game(title, opts = {}, &block)
  Ray::Game.new(title, opts, &block)
end

.image_set(regex) {|*args| ... } ⇒ Object

Creates a new image set.

Parameters:

  • regex (Regexp)

    Regular expression used to match file

Yields:

  • (*args)

    Block returning the image

Yield Parameters:

  • args

    Regex captures


22
23
24
# File 'lib/ray/image_set.rb', line 22

def image_set(regex, &block)
  Ray::ImageSet.add_set(regex, &block)
end

.screen_sizeRay::Vector2

Returns Size of the screen.

Returns:


12
13
14
15
16
# File 'ext/ray.c', line 12

static
VALUE ray_screen_size(VALUE self) {
  return ray_vector2_to_rb(say_make_vector2(say_imp_screen_get_width(),
                                            say_imp_screen_get_height()));
}

.sound_buffer_set(regex) {|*args| ... } ⇒ Object

Creates a new sound buffer set.

Parameters:

  • regex (Regexp)

    Regular expression used to match file

Yields:

  • (*args)

    Block returning the sound buffer

Yield Parameters:

  • args

    Regex captures


22
23
24
# File 'lib/ray/sound_buffer_set.rb', line 22

def sound_buffer_set(regex, &block)
  Ray::SoundBufferSet.add_set(regex, &block)
end

Instance Method Details

#almostDSL::Matcher

Note:

the maximum and the minimum will only be computed once.

Returns A matcher matching a value close of x.

Examples:

on :win, almost(10_000, 500) do ... end
on :win, where { |x| x <= 10_000 + 500 && x >= 10_000 - 500 } do ... end

Returns:


100
101
102
103
# File 'lib/ray/dsl/matcher.rb', line 100

describe_matcher(:almost) do |x, precision|
  min, max = (x - precision), (x + precision)
  lambda { |o| (o <= max) && (o >= min) }
end

#anythingDSL::Matcher

Returns A matcher matching anything (always true).

Returns:

  • (DSL::Matcher)

    A matcher matching anything (always true)


78
79
80
# File 'lib/ray/dsl/matcher.rb', line 78

describe_matcher(:anything) do
  lambda { |o| true }
end

#colliding_with(x, y[, w, h]) ⇒ DSL::Matcher #colliding_with(rect) ⇒ DSL::Matcher #colliding_with(array) ⇒ DSL::Matcher

Returns A matching matching any rect colliding with the argument.

Returns:

  • (DSL::Matcher)

    A matching matching any rect colliding with the argument.


131
132
133
134
# File 'lib/ray/dsl/matcher.rb', line 131

describe_matcher(:colliding_with) do |*args|
  rect = args.size > 1 ? Ray::Rect.new(*args) : args.first.to_rect
  lambda { |o| o.collide? rect }
end

#inside(x, y[, w, h]) ⇒ DSL::Matcher #inside(rect) ⇒ DSL::Matcher #inside(array) ⇒ DSL::Matcher

Returns A matching matching any rect inside the argument.

Returns:

  • (DSL::Matcher)

    A matching matching any rect inside the argument.


110
111
112
113
# File 'lib/ray/dsl/matcher.rb', line 110

describe_matcher(:inside) do |*args|
  rect = args.size > 1 ? Ray::Rect.new(*args) : args.first.to_rect
  lambda { |o| o.inside? rect }
end

#less_thanDSL::Matcher

Returns A matcher matching anything that is less than x (comparaison using <).

Returns:

  • (DSL::Matcher)

    A matcher matching anything that is less than x (comparaison using <)


90
91
92
# File 'lib/ray/dsl/matcher.rb', line 90

describe_matcher(:less_than) do |x|
  lambda { |o| o < x }
end

#more_thanDSL::Matcher

Returns A matcher matching anything greater than x (comparaison using >).

Returns:

  • (DSL::Matcher)

    A matcher matching anything greater than x (comparaison using >)


84
85
86
# File 'lib/ray/dsl/matcher.rb', line 84

describe_matcher(:more_than) do |x|
  lambda { |o| o > x }
end

#outside(x, y[, w, h]) ⇒ DSL::Matcher #outside(rect) ⇒ DSL::Matcher #outside(array) ⇒ DSL::Matcher

Returns A matching matching any rect outside the argument.

Returns:

  • (DSL::Matcher)

    A matching matching any rect outside the argument.


120
121
122
123
# File 'lib/ray/dsl/matcher.rb', line 120

describe_matcher(:outside) do |*args|
  rect = args.size > 1 ? Ray::Rect.new(*args) : args.first.to_rect
  lambda { |o| o.outside? rect }
end