samples/audio/spacial.rb in ray-0.1.0.pre1 vs samples/audio/spacial.rb in ray-0.1.0
- old
+ new
@@ -7,38 +7,52 @@
require 'ray'
SPEED = 5
-Ray::Game.new("Spacial sounds") do
+Ray.game "Spacial sounds" do
register do
add_hook :quit, method(:exit!)
end
scene :spacial do
- @sound = sound path_of("pop.wav")
- @sound.attenuation = 0.1
+ center = window.size / 2
+
+ @sound = music path_of("pop.wav")
+ @sound.attenuation = 0.5
@sound.min_distance = 10
- @sound.pos = [(640 / 2) - 5, (480 / 2) - 5, 0]
+ @sound.pos = [center.x, center.y, 0]
+ @sound.looping = true
+ @sound.pitch = 1
+ @sound.relative = false
- @rect = Ray::Rect.new(0, 0, 10, 10)
+ @sound.play
- always do
- @sound.play if (Time.now.to_i % 2) == 0
+ @rect = Ray::Polygon.rectangle([0, 0, 10, 10], Ray::Color.blue)
+ @source = Ray::Polygon.rectangle([center.x, center.y, 10, 10],
+ Ray::Color.green)
+ on :key_press, key(:+) do
+ @sound.pitch += 0.1
+ end
+
+ on :key_press, key(:-) do
+ @sound.pitch -= 0.1
+ end
+
+ always do
@rect.x += SPEED if holding? :right
@rect.x -= SPEED if holding? :left
@rect.y += SPEED if holding? :down
@rect.y -= SPEED if holding? :up
Ray::Audio.pos = [@rect.x, @rect.y, 0]
end
render do |win|
- win.fill(Ray::Color.black)
- win.draw_filled_rect(@rect, Ray::Color.green)
- win.draw_filled_rect([(640 / 2) - 5, (480 / 2) - 5, 10, 10], Ray::Color.red)
+ win.draw @rect
+ win.draw @source
end
end
- push_scene :spacial
+ scenes << :spacial
end