rubydraw 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -1
- data/examples/image_ex.rb +3 -4
- data/examples/media/hooray.ogg +0 -0
- data/examples/sound_ex.rb +17 -0
- data/lib/rubydraw.rb +5 -5
- data/lib/rubydraw/events.rb +0 -1
- data/lib/rubydraw/sound.rb +45 -0
- data/lib/rubydraw/window.rb +1 -1
- metadata +7 -4
data/README
CHANGED
@@ -7,7 +7,7 @@ I would appreciate it if you notify me. So basically, I can't test anything with
|
|
7
7
|
for the inconvenience!
|
8
8
|
|
9
9
|
HOW TO INSTALL
|
10
|
-
To install this library
|
10
|
+
To install this library without RubyGems, navigate to this directory in the command
|
11
11
|
line tool and give "rubydraw/build_and_install" permissions to run. Then simply run it. Hooray, it
|
12
12
|
should be working now! Test it in irb with "require 'rubydraw'".
|
13
13
|
|
data/examples/image_ex.rb
CHANGED
@@ -3,10 +3,9 @@ require 'rubydraw'
|
|
3
3
|
|
4
4
|
class MyWindow < Rubydraw::Window
|
5
5
|
# Create a new window with an bug image inside it
|
6
|
-
def initialize
|
7
|
-
super(
|
6
|
+
def initialize
|
7
|
+
super(300, 300)
|
8
8
|
@image = Rubydraw::Image.new("media/bug.png")
|
9
|
-
@focused = true
|
10
9
|
whenever Rubydraw::Events::QuitRequest do
|
11
10
|
close
|
12
11
|
end
|
@@ -25,5 +24,5 @@ class MyWindow < Rubydraw::Window
|
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
|
-
w = MyWindow.new
|
27
|
+
w = MyWindow.new
|
29
28
|
w.open
|
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubydraw'
|
3
|
+
|
4
|
+
class MyWindow < Rubydraw::Window
|
5
|
+
def initialize
|
6
|
+
super(300, 300)
|
7
|
+
@sound = Rubydraw::Sound.new("media/hooray.ogg")
|
8
|
+
whenever Rubydraw::Events::QuitRequest do
|
9
|
+
close
|
10
|
+
end
|
11
|
+
whenever Rubydraw::Events::KeyPressed do
|
12
|
+
@sound.play
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
MyWindow.new.open
|
data/lib/rubydraw.rb
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
require 'ruby-sdl-ffi'
|
3
3
|
|
4
4
|
# Require all the rubydraw files
|
5
|
-
#files = ["window", "image", "sdl_error", "event_queue", "events", "point"]
|
6
5
|
files = %w[
|
7
6
|
window
|
8
7
|
image
|
9
|
-
|
10
|
-
keys
|
11
|
-
event_queue
|
8
|
+
sound
|
12
9
|
events
|
13
|
-
|
10
|
+
event_queue
|
11
|
+
keys
|
12
|
+
point
|
13
|
+
sdl_error]
|
14
14
|
files.each {|f| require("rubydraw/" + f)}
|
15
15
|
|
16
16
|
# Rubydraw is a high level game/graphics library, like Gosu or Rubygame, and is written completely
|
data/lib/rubydraw/events.rb
CHANGED
@@ -25,7 +25,6 @@ module Rubydraw
|
|
25
25
|
# Remove all the classes that don't want to be included in the search
|
26
26
|
event_classes.delete_if {|event_class| not event_class.wants_to_match?}
|
27
27
|
event_classes.each {|event_class| rubydraw_event = event_class.from_sdl_event(sdl_event) if event_class.matches?(sdl_event)}
|
28
|
-
#puts rubydraw_event.class
|
29
28
|
rubydraw_event
|
30
29
|
end
|
31
30
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Rubydraw
|
2
|
+
# Lets you access sound files and play them! A bit different then Gosu in
|
3
|
+
# that you don't have to specify the window here; just a matter of taste.
|
4
|
+
# Otherwise it's mostly the same:
|
5
|
+
#
|
6
|
+
# Rubydraw::Sound#new: Creates a new sound with the given file path
|
7
|
+
#
|
8
|
+
# Rubydraw::Sound#play: Plays the sound. *Note*: this method exits
|
9
|
+
# immediatley; it doesn't wait until the sound is finished.
|
10
|
+
class Sound
|
11
|
+
attr_accessor(:volume)
|
12
|
+
# Create a new sound with the given file path. Raise an SDLError if for
|
13
|
+
# some reason it couln't load the sound.
|
14
|
+
def initialize(path)
|
15
|
+
# In case program is being run from a different directory,
|
16
|
+
# provide the _full_ path. Nothing relative here.
|
17
|
+
full_path = File.expand_path path
|
18
|
+
SDL::Mixer.OpenAudio(22050, SDL::AUDIO_S16SYS, 2, 1024)
|
19
|
+
@sdl_sound = SDL::Mixer::LoadWAV(full_path)
|
20
|
+
# Ususally happens because the file doesn't exist.
|
21
|
+
if @sdl_sound.pointer.null?
|
22
|
+
raise SDLError "Failed to load sound from: #{full_path} because '#{SDL.GetError}'"
|
23
|
+
end
|
24
|
+
@volume = 1
|
25
|
+
@channel = -1
|
26
|
+
end
|
27
|
+
|
28
|
+
# Play this sound, and restart it if it's already playing.
|
29
|
+
def play
|
30
|
+
SDL::Mixer.HaltChannel(@channel)
|
31
|
+
@channel = SDL::Mixer.GroupAvailable(-1)
|
32
|
+
if @channel == -1
|
33
|
+
SDL::Mixer.AllocateChannel(SDL::Mixer.AllocateChannel(-1) + 1)
|
34
|
+
@channel = SDL::Mixer.GroupAvailible
|
35
|
+
end
|
36
|
+
SDL::Mixer.Volume(@channel, (SDL::Mixer::MAX_VOLUME * @volume).to_i)
|
37
|
+
result = SDL::Mixer.PlayChannelTimed(@channel, @sdl_sound, 0, -1)
|
38
|
+
raise(SDLError, "Failed to play sound: #{SDL.GetError}") if result == -1
|
39
|
+
self
|
40
|
+
|
41
|
+
#@playing = true
|
42
|
+
#SDL::Mixer::FadeInMusicPos(@sdl_sound, 0, 0, 0)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/rubydraw/window.rb
CHANGED
@@ -3,7 +3,7 @@ module Rubydraw
|
|
3
3
|
# Note: there can only be one window on the screen at a time; it is a limit
|
4
4
|
# of SDL. One important things about instances of Rubydraw::Window: its main loop
|
5
5
|
# (which starts when Rubydraw::Window#open is called) is *not* forked! It will break
|
6
|
-
# when Rubydraw::Window#close is called
|
6
|
+
# when Rubydraw::Window#close is called.
|
7
7
|
class Window
|
8
8
|
# Create a new window.
|
9
9
|
def initialize(width, height)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydraw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- J. Wostenberg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-16 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/rubydraw.rb
|
52
52
|
- lib/rubydraw/window.rb
|
53
53
|
- lib/rubydraw/image.rb
|
54
|
+
- lib/rubydraw/sound.rb
|
54
55
|
- lib/rubydraw/sdl_error.rb
|
55
56
|
- lib/rubydraw/keys.rb
|
56
57
|
- lib/rubydraw/event_queue.rb
|
@@ -58,7 +59,9 @@ files:
|
|
58
59
|
- lib/rubydraw/point.rb
|
59
60
|
- examples/window_ex.rb
|
60
61
|
- examples/image_ex.rb
|
62
|
+
- examples/sound_ex.rb
|
61
63
|
- examples/media/bug.png
|
64
|
+
- examples/media/hooray.ogg
|
62
65
|
has_rdoc: true
|
63
66
|
homepage: https://github.com/awostenberg/rubydraw
|
64
67
|
licenses: []
|