Sha256: 303a58a1a747beb13a24f8559d1afdcd88bbac60a0f0e8917338362d5989ac2f

Contents?: true

Size: 1.16 KB

Versions: 29

Compression:

Stored size: 1.16 KB

Contents

%w[xot beeps rays reflex]
  .map  {|s| File.expand_path "../../../#{s}/lib", __dir__}
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}

require 'reflexion/include'


$hit, $bang = [880, 440].map {|n| Sound.new Oscillator.new(freq: n), 0.1}

def add_shape (klass: RectShape, frame: [0, 0, 100, 100], color: :white, type: :static)
  window.add View.new {
    set frame: frame, background: color, type => true, shape: klass.new(density: 1, friction: 0, restitution: 1)
  }
end

setup do
  set size: [600, 400], friction: 0
  5.times do |y|
    10.times do |x|
      shape = add_shape frame: [(x + 1) * 50, (y + 1) * 20, 30, 10], color: [:white, :red, :green, :blue, :yellow][y]
      shape.on(:contact) {$hit.play; shape.remove_self}
    end
  end
  $bar   = add_shape frame: [0, 350, 100, 20], color: :blue
  bottom = add_shape frame: [0, window.h - 1, window.w, 1]
  bottom.on(:contact) {|e| $bang.play; e.view.remove_self}
end

pointer do |e|
  $bar.x = e.x - $bar.w / 2
  if e.down?
    ball = add_shape klass: [EllipseShape, RectShape].sample, frame: [e.x, $bar.y - 20, 20, 20], type: :dynamic
    ball.velocity = Point.new(rand(-1.0..1.0), -1).normal * 500
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
reflexion-0.3.4 samples/reflexion/breakout.rb
reflexion-0.3.3 samples/reflexion/breakout.rb
reflexion-0.3.2 samples/reflexion/breakout.rb
reflexion-0.3.1 samples/reflexion/breakout.rb
reflexion-0.3 samples/reflexion/breakout.rb
reflexion-0.2.1 samples/reflexion/breakout.rb
reflexion-0.2 samples/reflexion/breakout.rb
reflexion-0.1.57 samples/reflexion/breakout.rb
reflexion-0.1.56 samples/reflexion/breakout.rb
reflexion-0.1.55 samples/reflexion/breakout.rb
reflexion-0.1.54 samples/reflexion/breakout.rb
reflexion-0.1.53 samples/reflexion/breakout.rb
reflexion-0.1.52 samples/reflexion/breakout.rb
reflexion-0.1.51 samples/reflexion/breakout.rb
reflexion-0.1.50 samples/reflexion/breakout.rb
reflexion-0.1.49 samples/reflexion/breakout.rb
reflexion-0.1.48 samples/reflexion/breakout.rb
reflexion-0.1.47 samples/reflexion/breakout.rb
reflexion-0.1.46 samples/reflexion/breakout.rb
reflexion-0.1.45 samples/reflexion/breakout.rb