Created
April 7, 2012 21:48
-
-
Save practicingruby/2332328 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'ray' | |
| require 'io/console' | |
| Ray.game "Test" do | |
| register { add_hook :quit, method(:exit!) } | |
| scene :square do | |
| self.frames_per_second = 5 | |
| @sound = Ray::Sound.new("Beep.wav") | |
| @sound.pos = [rand(20..40), rand(20..40),0] | |
| always do | |
| Ray::Audio.pos += [0,2,0] if holding?(:w) | |
| Ray::Audio.pos += [-2,0,0] if holding?(:a) | |
| Ray::Audio.pos += [0,-2,0] if holding?(:s) | |
| Ray::Audio.pos += [2,0,0] if holding?(:d) | |
| dx = Ray::Audio.pos.x - @sound.pos.x | |
| if dx > 0 | |
| next_x = rand(2..3) | |
| elsif dx < 0 | |
| next_x = -rand(2..3) | |
| else | |
| next_x = 0 | |
| end | |
| dy = Ray::Audio.pos.y - @sound.pos.y | |
| if dy > 0 | |
| next_y = rand(0..3) | |
| elsif dy < 0 | |
| next_y = -rand(0..3) | |
| else | |
| next_y = 0 | |
| end | |
| @sound.pos += [next_x, next_y, 0] | |
| if @sound.pos == Ray::Audio.pos | |
| @sound.stop | |
| grenade = Ray::Sound.new("grenade.wav") | |
| grenade.play | |
| sleep grenade.duration | |
| exit! | |
| end | |
| end | |
| render do |win| | |
| @sound.play | |
| end | |
| end | |
| scenes << :square | |
| end | |
| =begin | |
| sound = Ray::Sound.new("Beep.wav") | |
| sound.pos = [10,10,0] | |
| sound.looping = true | |
| sound.play | |
| def m | |
| rand(0..3) | |
| end | |
| loop do | |
| case $stdin.getch | |
| when 'w' | |
| Ray::Audio.pos += [0,3,0] | |
| when 'a' | |
| Ray::Audio.pos += [-3,0,0] | |
| when 's' | |
| Ray::Audio.pos += [0,-3,0] | |
| when 'd' | |
| Ray::Audio.pos += [3,0,0] | |
| end | |
| sound.pos += [ Ray::Audio.pos.x < sound.pos.x ? -m : m, Ray::Audio.pos.y < sound.pos.y ? -m : m, 0 ] | |
| if sound.pos == Ray::Audio.pos | |
| grenade = Ray::Sound.new("grenade.wav") | |
| sound.stop | |
| grenade.play | |
| sleep grenade.duration | |
| exit | |
| end | |
| end | |
| =end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment