rubygame 2.3.0-x86-mswin32-60
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/CREDITS +60 -0
- data/LICENSE +504 -0
- data/NEWS +252 -0
- data/README +123 -0
- data/ROADMAP +109 -0
- data/Rakefile +440 -0
- data/doc/extended_readme.rdoc +49 -0
- data/doc/getting_started.rdoc +47 -0
- data/doc/macosx_install.rdoc +70 -0
- data/doc/windows_install.rdoc +123 -0
- data/ext/rubygame/rubygame_core.so +0 -0
- data/ext/rubygame/rubygame_event.c +644 -0
- data/ext/rubygame/rubygame_event.h +48 -0
- data/ext/rubygame/rubygame_event.obj +0 -0
- data/ext/rubygame/rubygame_gfx.c +942 -0
- data/ext/rubygame/rubygame_gfx.h +101 -0
- data/ext/rubygame/rubygame_gfx.obj +0 -0
- data/ext/rubygame/rubygame_gfx.so +0 -0
- data/ext/rubygame/rubygame_gl.c +154 -0
- data/ext/rubygame/rubygame_gl.h +32 -0
- data/ext/rubygame/rubygame_gl.obj +0 -0
- data/ext/rubygame/rubygame_image.c +252 -0
- data/ext/rubygame/rubygame_image.h +41 -0
- data/ext/rubygame/rubygame_image.obj +0 -0
- data/ext/rubygame/rubygame_image.so +0 -0
- data/ext/rubygame/rubygame_joystick.c +247 -0
- data/ext/rubygame/rubygame_joystick.h +41 -0
- data/ext/rubygame/rubygame_joystick.obj +0 -0
- data/ext/rubygame/rubygame_main.c +155 -0
- data/ext/rubygame/rubygame_main.h +36 -0
- data/ext/rubygame/rubygame_main.obj +0 -0
- data/ext/rubygame/rubygame_mixer.c +1024 -0
- data/ext/rubygame/rubygame_mixer.h +36 -0
- data/ext/rubygame/rubygame_mixer.obj +0 -0
- data/ext/rubygame/rubygame_mixer.so +0 -0
- data/ext/rubygame/rubygame_music.c +1017 -0
- data/ext/rubygame/rubygame_music.h +29 -0
- data/ext/rubygame/rubygame_music.obj +0 -0
- data/ext/rubygame/rubygame_screen.c +448 -0
- data/ext/rubygame/rubygame_screen.h +43 -0
- data/ext/rubygame/rubygame_screen.obj +0 -0
- data/ext/rubygame/rubygame_shared.c +272 -0
- data/ext/rubygame/rubygame_shared.h +68 -0
- data/ext/rubygame/rubygame_shared.obj +0 -0
- data/ext/rubygame/rubygame_sound.c +863 -0
- data/ext/rubygame/rubygame_sound.h +29 -0
- data/ext/rubygame/rubygame_sound.obj +0 -0
- data/ext/rubygame/rubygame_surface.c +1151 -0
- data/ext/rubygame/rubygame_surface.h +62 -0
- data/ext/rubygame/rubygame_surface.obj +0 -0
- data/ext/rubygame/rubygame_time.c +183 -0
- data/ext/rubygame/rubygame_time.h +32 -0
- data/ext/rubygame/rubygame_time.obj +0 -0
- data/ext/rubygame/rubygame_ttf.c +599 -0
- data/ext/rubygame/rubygame_ttf.h +69 -0
- data/ext/rubygame/rubygame_ttf.obj +0 -0
- data/ext/rubygame/rubygame_ttf.so +0 -0
- data/lib/rubygame.rb +41 -0
- data/lib/rubygame/clock.rb +128 -0
- data/lib/rubygame/color.rb +79 -0
- data/lib/rubygame/color/models/base.rb +111 -0
- data/lib/rubygame/color/models/hsl.rb +153 -0
- data/lib/rubygame/color/models/hsv.rb +149 -0
- data/lib/rubygame/color/models/rgb.rb +78 -0
- data/lib/rubygame/color/palettes/css.rb +49 -0
- data/lib/rubygame/color/palettes/palette.rb +100 -0
- data/lib/rubygame/color/palettes/x11.rb +177 -0
- data/lib/rubygame/constants.rb +238 -0
- data/lib/rubygame/event.rb +313 -0
- data/lib/rubygame/ftor.rb +370 -0
- data/lib/rubygame/hotspot.rb +265 -0
- data/lib/rubygame/keyconstants.rb +237 -0
- data/lib/rubygame/mediabag.rb +94 -0
- data/lib/rubygame/named_resource.rb +254 -0
- data/lib/rubygame/queue.rb +288 -0
- data/lib/rubygame/rect.rb +612 -0
- data/lib/rubygame/sfont.rb +223 -0
- data/lib/rubygame/sprite.rb +511 -0
- data/samples/FreeSans.ttf +0 -0
- data/samples/GPL.txt +340 -0
- data/samples/README +40 -0
- data/samples/chimp.bmp +0 -0
- data/samples/chimp.rb +302 -0
- data/samples/demo_gl.rb +151 -0
- data/samples/demo_gl_tex.rb +197 -0
- data/samples/demo_music.rb +77 -0
- data/samples/demo_rubygame.rb +296 -0
- data/samples/demo_sfont.rb +52 -0
- data/samples/demo_ttf.rb +193 -0
- data/samples/demo_utf8.rb +53 -0
- data/samples/fist.bmp +0 -0
- data/samples/load_and_blit.rb +22 -0
- data/samples/panda.png +0 -0
- data/samples/punch.wav +0 -0
- data/samples/ruby.png +0 -0
- data/samples/song.ogg +0 -0
- data/samples/term16.png +0 -0
- data/samples/whiff.wav +0 -0
- metadata +164 -0
data/samples/demo_gl.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This demonstrates the use of ruby-opengl alongside rubygame to produce
|
4
|
+
# hardware-accelerated three-dimensional graphics.
|
5
|
+
#
|
6
|
+
# Please note that rubygame itself does not perform any OpenGL functions,
|
7
|
+
# it only allows ruby-opengl to use the Screen as its viewport. You MUST
|
8
|
+
# have ruby-opengl installed to run this demo!
|
9
|
+
|
10
|
+
require 'rubygame'
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'opengl'
|
14
|
+
rescue LoadError
|
15
|
+
puts "ATTENTION: This demo requires the opengl extension for ruby."
|
16
|
+
raise
|
17
|
+
end
|
18
|
+
|
19
|
+
WIDE = 640
|
20
|
+
HIGH = 480
|
21
|
+
|
22
|
+
Rubygame.init
|
23
|
+
|
24
|
+
Rubygame::GL.set_attrib(Rubygame::GL::RED_SIZE, 5)
|
25
|
+
Rubygame::GL.set_attrib(Rubygame::GL::GREEN_SIZE, 5)
|
26
|
+
Rubygame::GL.set_attrib(Rubygame::GL::BLUE_SIZE, 5)
|
27
|
+
Rubygame::GL.set_attrib(Rubygame::GL::DEPTH_SIZE, 16)
|
28
|
+
Rubygame::GL.set_attrib(Rubygame::GL::DOUBLEBUFFER, 1)
|
29
|
+
|
30
|
+
Rubygame::Screen.set_mode([WIDE,HIGH], 16, [Rubygame::OPENGL])
|
31
|
+
queue = Rubygame::EventQueue.new()
|
32
|
+
clock = Rubygame::Clock.new { |c| c.target_framerate = 60 }
|
33
|
+
|
34
|
+
ObjectSpace.garbage_collect
|
35
|
+
GL::Viewport( 0, 0, WIDE, HIGH )
|
36
|
+
|
37
|
+
GL::MatrixMode( GL::PROJECTION )
|
38
|
+
GL::LoadIdentity( )
|
39
|
+
GLU::Perspective( 35, WIDE/(HIGH.to_f), 3, 10)
|
40
|
+
|
41
|
+
GL::MatrixMode( GL::MODELVIEW )
|
42
|
+
GL::LoadIdentity( )
|
43
|
+
|
44
|
+
GL::Enable(GL::DEPTH_TEST)
|
45
|
+
GL::DepthFunc(GL::LESS)
|
46
|
+
|
47
|
+
GL::ShadeModel(GL::FLAT)
|
48
|
+
|
49
|
+
color =
|
50
|
+
[[ 1.0, 1.0, 0.0],
|
51
|
+
[ 1.0, 0.0, 0.0],
|
52
|
+
[ 0.0, 0.0, 0.0],
|
53
|
+
[ 0.0, 1.0, 0.0],
|
54
|
+
[ 0.0, 1.0, 1.0],
|
55
|
+
[ 1.0, 1.0, 1.0],
|
56
|
+
[ 1.0, 0.0, 1.0],
|
57
|
+
[ 0.0, 0.0, 1.0]]
|
58
|
+
|
59
|
+
cube =
|
60
|
+
[[ 0.5, 0.5, -0.5],
|
61
|
+
[ 0.5, -0.5, -0.5],
|
62
|
+
[-0.5, -0.5, -0.5],
|
63
|
+
[-0.5, 0.5, -0.5],
|
64
|
+
[-0.5, 0.5, 0.5],
|
65
|
+
[ 0.5, 0.5, 0.5],
|
66
|
+
[ 0.5, -0.5, 0.5],
|
67
|
+
[-0.5, -0.5, 0.5]]
|
68
|
+
|
69
|
+
cube_list = 1
|
70
|
+
|
71
|
+
GL::NewList(cube_list,GL::COMPILE_AND_EXECUTE)
|
72
|
+
GL::PushMatrix()
|
73
|
+
GL::Begin(GL::QUADS)
|
74
|
+
GL::Color(1.0, 0.0, 0.0);
|
75
|
+
GL::Vertex(cube[0]);
|
76
|
+
GL::Vertex(cube[1]);
|
77
|
+
GL::Vertex(cube[2]);
|
78
|
+
GL::Vertex(cube[3]);
|
79
|
+
|
80
|
+
GL::Color(0.0, 1.0, 0.0);
|
81
|
+
GL::Vertex(cube[3]);
|
82
|
+
GL::Vertex(cube[4]);
|
83
|
+
GL::Vertex(cube[7]);
|
84
|
+
GL::Vertex(cube[2]);
|
85
|
+
|
86
|
+
GL::Color(0.0, 0.0, 1.0);
|
87
|
+
GL::Vertex(cube[0]);
|
88
|
+
GL::Vertex(cube[5]);
|
89
|
+
GL::Vertex(cube[6]);
|
90
|
+
GL::Vertex(cube[1]);
|
91
|
+
|
92
|
+
GL::Color(0.0, 1.0, 1.0);
|
93
|
+
GL::Vertex(cube[5]);
|
94
|
+
GL::Vertex(cube[4]);
|
95
|
+
GL::Vertex(cube[7]);
|
96
|
+
GL::Vertex(cube[6]);
|
97
|
+
|
98
|
+
GL::Color(1.0, 1.0, 0.0);
|
99
|
+
GL::Vertex(cube[5]);
|
100
|
+
GL::Vertex(cube[0]);
|
101
|
+
GL::Vertex(cube[3]);
|
102
|
+
GL::Vertex(cube[4]);
|
103
|
+
|
104
|
+
GL::Color(1.0, 0.0, 1.0);
|
105
|
+
GL::Vertex(cube[6]);
|
106
|
+
GL::Vertex(cube[1]);
|
107
|
+
GL::Vertex(cube[2]);
|
108
|
+
GL::Vertex(cube[7]);
|
109
|
+
GL::PopMatrix()
|
110
|
+
GL::End()
|
111
|
+
GL::EndList()
|
112
|
+
|
113
|
+
angle = 0
|
114
|
+
|
115
|
+
catch(:rubygame_quit) do
|
116
|
+
loop do
|
117
|
+
queue.each do |event|
|
118
|
+
case event
|
119
|
+
when Rubygame::KeyDownEvent
|
120
|
+
case event.key
|
121
|
+
when Rubygame::K_ESCAPE
|
122
|
+
throw :rubygame_quit
|
123
|
+
when Rubygame::K_Q
|
124
|
+
throw :rubygame_quit
|
125
|
+
end
|
126
|
+
when Rubygame::QuitEvent
|
127
|
+
throw :rubygame_quit
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
GL.ClearColor(0.0, 0.0, 0.0, 1.0);
|
132
|
+
GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
|
133
|
+
|
134
|
+
GL::MatrixMode(GL::MODELVIEW);
|
135
|
+
GL::LoadIdentity( )
|
136
|
+
GL::Translate(0, 0, -4)
|
137
|
+
GL::Rotate(45, 0, 1, 0)
|
138
|
+
GL::Rotate(45, 1, 0, 0)
|
139
|
+
GL::Rotate(angle, 0.0, 0.0, 1.0)
|
140
|
+
GL::Rotate(angle*2, 0.0, 1.0, 0.0)
|
141
|
+
|
142
|
+
GL::CallList(cube_list)
|
143
|
+
|
144
|
+
Rubygame::GL.swap_buffers()
|
145
|
+
ObjectSpace.garbage_collect
|
146
|
+
|
147
|
+
angle += clock.tick()/50.0
|
148
|
+
angle -= 360 if angle >= 360
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This demonstrates the use of ruby-opengl alongside rubygame to produce
|
4
|
+
# hardware-accelerated three-dimensional graphics. Additionally, it
|
5
|
+
# demonstrates the use of rubygame Surfaces as OpenGL textures.
|
6
|
+
#
|
7
|
+
# Please note that rubygame itself does not perform any OpenGL functions,
|
8
|
+
# it only allows ruby-opengl to use the Screen as its viewport. You MUST
|
9
|
+
# have ruby-opengl installed to run this demo!
|
10
|
+
|
11
|
+
require 'rubygame'
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'opengl'
|
15
|
+
rescue LoadError
|
16
|
+
puts "ATTENTION: This demo requires the opengl extension for ruby."
|
17
|
+
raise
|
18
|
+
end
|
19
|
+
|
20
|
+
WIDE = 640
|
21
|
+
HIGH = 480
|
22
|
+
SCALE = 500.0
|
23
|
+
shadedCube=true
|
24
|
+
TEXTURE = "ruby.png"
|
25
|
+
|
26
|
+
Rubygame.init
|
27
|
+
|
28
|
+
Rubygame::GL.set_attrib(Rubygame::GL::RED_SIZE, 5)
|
29
|
+
Rubygame::GL.set_attrib(Rubygame::GL::GREEN_SIZE, 5)
|
30
|
+
Rubygame::GL.set_attrib(Rubygame::GL::BLUE_SIZE, 5)
|
31
|
+
Rubygame::GL.set_attrib(Rubygame::GL::DEPTH_SIZE, 16)
|
32
|
+
Rubygame::GL.set_attrib(Rubygame::GL::DOUBLEBUFFER, 1)
|
33
|
+
|
34
|
+
Rubygame::Screen.set_mode([WIDE,HIGH], 16, [Rubygame::OPENGL])
|
35
|
+
queue = Rubygame::EventQueue.new()
|
36
|
+
clock = Rubygame::Clock.new { |c| c.target_framerate = 60 }
|
37
|
+
|
38
|
+
ObjectSpace.garbage_collect
|
39
|
+
GL::Viewport( 0, 0, WIDE, HIGH )
|
40
|
+
|
41
|
+
GL::MatrixMode( GL::PROJECTION )
|
42
|
+
GL::LoadIdentity( )
|
43
|
+
GLU::Perspective( 35, WIDE/(HIGH.to_f), 3, 10)
|
44
|
+
|
45
|
+
GL::MatrixMode( GL::MODELVIEW )
|
46
|
+
GL::LoadIdentity( )
|
47
|
+
|
48
|
+
GL::Enable(GL::DEPTH_TEST)
|
49
|
+
GL::DepthFunc(GL::LESS)
|
50
|
+
|
51
|
+
GL::ShadeModel(GL::FLAT)
|
52
|
+
|
53
|
+
surface = Rubygame::Surface.load_image(TEXTURE)
|
54
|
+
|
55
|
+
tex_id = GL::GenTextures(1)
|
56
|
+
GL::BindTexture(GL::TEXTURE_2D, tex_id[0])
|
57
|
+
GL::TexImage2D(GL::TEXTURE_2D, 0, GL::RGB, surface.w, surface.h, 0, GL::RGB,
|
58
|
+
GL::UNSIGNED_BYTE, surface.pixels)
|
59
|
+
GL::TexParameter(GL::TEXTURE_2D,GL::TEXTURE_MIN_FILTER,GL::NEAREST);
|
60
|
+
GL::TexParameter(GL::TEXTURE_2D,GL::TEXTURE_MAG_FILTER,GL::LINEAR);
|
61
|
+
|
62
|
+
color =
|
63
|
+
[[ 1.0, 1.0, 0.0],
|
64
|
+
[ 1.0, 0.0, 0.0],
|
65
|
+
[ 0.0, 0.0, 0.0],
|
66
|
+
[ 0.0, 1.0, 0.0],
|
67
|
+
[ 0.0, 1.0, 1.0],
|
68
|
+
[ 1.0, 1.0, 1.0],
|
69
|
+
[ 1.0, 0.0, 1.0],
|
70
|
+
[ 0.0, 0.0, 1.0]]
|
71
|
+
|
72
|
+
cube =
|
73
|
+
[[ 0.5, 0.5, -0.5],
|
74
|
+
[ 0.5, -0.5, -0.5],
|
75
|
+
[-0.5, -0.5, -0.5],
|
76
|
+
[-0.5, 0.5, -0.5],
|
77
|
+
[-0.5, 0.5, 0.5],
|
78
|
+
[ 0.5, 0.5, 0.5],
|
79
|
+
[ 0.5, -0.5, 0.5],
|
80
|
+
[-0.5, -0.5, 0.5]]
|
81
|
+
|
82
|
+
cube_st =
|
83
|
+
[[[ 1, 1], [ 1, 0], [ 0, 0], [ 0, 1]],
|
84
|
+
[[ 1, 1], [ 1, 0], [ 0, 0], [ 0, 1]],
|
85
|
+
[[ 1, 1], [ 1, 0], [ 0, 0], [ 0, 1]],
|
86
|
+
[[ 1, 1], [ 1, 0], [ 0, 0], [ 0, 1]],
|
87
|
+
[[ 1, 1], [ 1, 0], [ 0, 0], [ 0, 1]],
|
88
|
+
[[ 1, 1], [ 1, 0], [ 0, 0], [ 0, 1]],
|
89
|
+
[[ 1, 1], [ 1, 0], [ 0, 0], [ 0, 1]],
|
90
|
+
[[ 1, 1], [ 1, 0], [ 0, 0], [ 0, 1]]]
|
91
|
+
|
92
|
+
cube_list = 1
|
93
|
+
|
94
|
+
GL::NewList(cube_list,GL::COMPILE_AND_EXECUTE)
|
95
|
+
GL::PushMatrix()
|
96
|
+
GL::Enable(GL::TEXTURE_2D)
|
97
|
+
GL::BindTexture(GL::TEXTURE_2D, tex_id[0])
|
98
|
+
|
99
|
+
GL::Begin(GL::QUADS)
|
100
|
+
|
101
|
+
GL::TexCoord(cube_st[0][0]);
|
102
|
+
GL::Vertex(cube[0]);
|
103
|
+
GL::TexCoord(cube_st[0][1]);
|
104
|
+
GL::Vertex(cube[1]);
|
105
|
+
GL::TexCoord(cube_st[0][2]);
|
106
|
+
GL::Vertex(cube[2]);
|
107
|
+
GL::TexCoord(cube_st[0][3]);
|
108
|
+
GL::Vertex(cube[3]);
|
109
|
+
|
110
|
+
GL::TexCoord(cube_st[1][0]);
|
111
|
+
GL::Vertex(cube[3]);
|
112
|
+
GL::TexCoord(cube_st[1][1]);
|
113
|
+
GL::Vertex(cube[4]);
|
114
|
+
GL::TexCoord(cube_st[1][2]);
|
115
|
+
GL::Vertex(cube[7]);
|
116
|
+
GL::TexCoord(cube_st[1][3]);
|
117
|
+
GL::Vertex(cube[2]);
|
118
|
+
|
119
|
+
GL::TexCoord(cube_st[2][0]);
|
120
|
+
GL::Vertex(cube[0]);
|
121
|
+
GL::TexCoord(cube_st[2][1]);
|
122
|
+
GL::Vertex(cube[5]);
|
123
|
+
GL::TexCoord(cube_st[2][2]);
|
124
|
+
GL::Vertex(cube[6]);
|
125
|
+
GL::TexCoord(cube_st[2][3]);
|
126
|
+
GL::Vertex(cube[1]);
|
127
|
+
|
128
|
+
GL::TexCoord(cube_st[3][0]);
|
129
|
+
GL::Vertex(cube[5]);
|
130
|
+
GL::TexCoord(cube_st[3][1]);
|
131
|
+
GL::Vertex(cube[4]);
|
132
|
+
GL::TexCoord(cube_st[3][2]);
|
133
|
+
GL::Vertex(cube[7]);
|
134
|
+
GL::TexCoord(cube_st[3][3]);
|
135
|
+
GL::Vertex(cube[6]);
|
136
|
+
|
137
|
+
GL::TexCoord(cube_st[4][0]);
|
138
|
+
GL::Vertex(cube[5]);
|
139
|
+
GL::TexCoord(cube_st[4][1]);
|
140
|
+
GL::Vertex(cube[0]);
|
141
|
+
GL::TexCoord(cube_st[4][2]);
|
142
|
+
GL::Vertex(cube[3]);
|
143
|
+
GL::TexCoord(cube_st[4][3]);
|
144
|
+
GL::Vertex(cube[4]);
|
145
|
+
|
146
|
+
GL::TexCoord(cube_st[5][0]);
|
147
|
+
GL::Vertex(cube[6]);
|
148
|
+
GL::TexCoord(cube_st[5][1]);
|
149
|
+
GL::Vertex(cube[1]);
|
150
|
+
GL::TexCoord(cube_st[5][2]);
|
151
|
+
GL::Vertex(cube[2]);
|
152
|
+
GL::TexCoord(cube_st[5][3]);
|
153
|
+
GL::Vertex(cube[7]);
|
154
|
+
GL::PopMatrix()
|
155
|
+
GL::End()
|
156
|
+
GL::EndList()
|
157
|
+
|
158
|
+
angle = 0
|
159
|
+
|
160
|
+
catch(:rubygame_quit) do
|
161
|
+
loop do
|
162
|
+
queue.each do |event|
|
163
|
+
case event
|
164
|
+
when Rubygame::KeyDownEvent
|
165
|
+
case event.key
|
166
|
+
when Rubygame::K_ESCAPE
|
167
|
+
throw :rubygame_quit
|
168
|
+
when Rubygame::K_Q
|
169
|
+
throw :rubygame_quit
|
170
|
+
end
|
171
|
+
when Rubygame::QuitEvent
|
172
|
+
throw :rubygame_quit
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
GL.ClearColor(0.0, 0.0, 0.0, 1.0);
|
178
|
+
GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
|
179
|
+
|
180
|
+
GL::MatrixMode(GL::MODELVIEW);
|
181
|
+
GL::LoadIdentity( )
|
182
|
+
GL::Translate(0, 0, -4)
|
183
|
+
GL::Rotate(45, 0, 1, 0)
|
184
|
+
GL::Rotate(45, 1, 0, 0)
|
185
|
+
GL::Rotate(angle, 0.0, 0.0, 1.0)
|
186
|
+
GL::Rotate(angle*2, 0.0, 1.0, 0.0)
|
187
|
+
|
188
|
+
GL::CallList(cube_list)
|
189
|
+
|
190
|
+
Rubygame::GL.swap_buffers()
|
191
|
+
ObjectSpace.garbage_collect
|
192
|
+
|
193
|
+
angle += clock.tick()/50.0
|
194
|
+
angle -= 360 if angle >= 360
|
195
|
+
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygame'
|
4
|
+
|
5
|
+
include Rubygame
|
6
|
+
Rubygame.init()
|
7
|
+
|
8
|
+
def test_music()
|
9
|
+
|
10
|
+
# Use the lines below to get rid of artsd and contact ALSA directly on Linux.
|
11
|
+
# ARTSD happens to be buggy on my old, old linux distro.
|
12
|
+
if false
|
13
|
+
if RUBY_PLATFORM =~ /linux/
|
14
|
+
`killall artsd`
|
15
|
+
ENV['SDL_AUDIODRIVER'] = "alsa"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
puts "Using audio driver:" + Rubygame.audio_driver
|
20
|
+
|
21
|
+
if ARGV[0]
|
22
|
+
file = ARGV[0]
|
23
|
+
else
|
24
|
+
file = "song.ogg"
|
25
|
+
puts "If you want, you could give a filename as an argument to this script."
|
26
|
+
end
|
27
|
+
|
28
|
+
Music.autoload_dirs = [ File.dirname(__FILE__) ]
|
29
|
+
mus = Music[file];
|
30
|
+
|
31
|
+
unless mus
|
32
|
+
puts "ERROR: Couldn't find audio file '#{file}'."
|
33
|
+
end
|
34
|
+
|
35
|
+
puts "Testing fading in over 3 seconds, repeating forever."
|
36
|
+
mus.play( :fade_in => 3, :repeats => -1 );
|
37
|
+
puts('ERROR: Music not fading in') unless mus.fading?(:in)
|
38
|
+
sleep 3
|
39
|
+
|
40
|
+
puts "Playing for 2 seconds."
|
41
|
+
sleep 2
|
42
|
+
|
43
|
+
puts "Lowering volume to half for 3 seconds."
|
44
|
+
mus.volume = 0.5;
|
45
|
+
puts "ERROR: Volume wasn't adjusted" unless mus.volume == 0.5
|
46
|
+
sleep 3
|
47
|
+
|
48
|
+
puts "Restoring volume to full."
|
49
|
+
mus.volume = 1.0;
|
50
|
+
sleep 2
|
51
|
+
|
52
|
+
puts "Pausing for 1 seconds."
|
53
|
+
mus.pause
|
54
|
+
puts "ERROR: Music not paused." unless mus.paused?
|
55
|
+
sleep 1
|
56
|
+
|
57
|
+
puts "Resuming."
|
58
|
+
mus.unpause
|
59
|
+
puts "ERROR: Music not resumed" unless mus.playing?
|
60
|
+
|
61
|
+
puts "Playing for 2 seconds."
|
62
|
+
sleep 2
|
63
|
+
|
64
|
+
puts "Fading out over 2 seconds."
|
65
|
+
mus.fade_out(2);
|
66
|
+
puts "ERROR: Music not fading out " unless mus.fading?(:out)
|
67
|
+
|
68
|
+
while mus.playing? or mus.fading? == :out do Thread.pass end
|
69
|
+
# Test playing of music to the end
|
70
|
+
|
71
|
+
puts "ERROR: Music not ended" if mus.playing?
|
72
|
+
end
|
73
|
+
|
74
|
+
music_thread = Thread.new do test_music() end
|
75
|
+
music_thread.join
|
76
|
+
Rubygame.quit()
|
77
|
+
|
@@ -0,0 +1,296 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This program is released to the PUBLIC DOMAIN.
|
4
|
+
# It is distributed in the hope that it will be useful,
|
5
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
6
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
7
|
+
|
8
|
+
# This script is messy, but it demonstrates almost all of
|
9
|
+
# Rubygame's features, so it acts as a test program to see
|
10
|
+
# whether your installation of Rubygame is working.
|
11
|
+
|
12
|
+
require "rubygame"
|
13
|
+
include Rubygame
|
14
|
+
|
15
|
+
$stdout.sync = true
|
16
|
+
|
17
|
+
# Use smooth scaling/rotating? You can toggle this with S key
|
18
|
+
$smooth = false
|
19
|
+
|
20
|
+
Rubygame.init()
|
21
|
+
|
22
|
+
queue = EventQueue.new() # new EventQueue with autofetch
|
23
|
+
queue.ignore = [MouseMotionEvent]
|
24
|
+
clock = Clock.new()
|
25
|
+
clock.target_framerate = 50
|
26
|
+
|
27
|
+
unless ($gfx_ok = (VERSIONS[:sdl_gfx] != nil))
|
28
|
+
raise "SDL_gfx is not available. Bailing out."
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Set up autoloading for Surfaces. Surfaces will be loaded automatically
|
33
|
+
# the first time you use Surface["filename"]. Check out the docs for
|
34
|
+
# Rubygame::NamedResource for more info about that.
|
35
|
+
#
|
36
|
+
Surface.autoload_dirs = [ File.dirname(__FILE__) ]
|
37
|
+
|
38
|
+
|
39
|
+
class Panda
|
40
|
+
include Sprites::Sprite
|
41
|
+
|
42
|
+
# Autoload the "panda.png" image and set its colorkey
|
43
|
+
@@pandapic = Surface["panda.png"]
|
44
|
+
@@pandapic.set_colorkey(@@pandapic.get_at(0,0))
|
45
|
+
|
46
|
+
attr_accessor :vx, :vy, :speed
|
47
|
+
def initialize(x,y)
|
48
|
+
super()
|
49
|
+
@vx, @vy = 0,0
|
50
|
+
@speed = 40
|
51
|
+
@image = @@pandapic
|
52
|
+
@rect = Rect.new(x,y,*@@pandapic.size)
|
53
|
+
end
|
54
|
+
|
55
|
+
def update_image(time)
|
56
|
+
# do nothing in base class, rotate/zoom image in subs
|
57
|
+
end
|
58
|
+
|
59
|
+
def update(time)
|
60
|
+
x,y = @rect.center
|
61
|
+
self.update_image(time)
|
62
|
+
@rect.size = @image.size
|
63
|
+
|
64
|
+
base = @speed * time/1000.0
|
65
|
+
@rect.centerx = x + @vx * base
|
66
|
+
@rect.centery = y + @vy * base
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
class SpinnyPanda < Panda
|
72
|
+
attr_accessor :rate
|
73
|
+
def initialize(x,y,rate=0.1)
|
74
|
+
super(x,y)
|
75
|
+
@rate = rate
|
76
|
+
@angle = 0
|
77
|
+
end
|
78
|
+
|
79
|
+
def update_image(time)
|
80
|
+
@angle += (@rate * time) % 360
|
81
|
+
@image = @@pandapic.rotozoom(@angle,1,$smooth)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class ExpandaPanda < Panda
|
86
|
+
attr_accessor :rate
|
87
|
+
def initialize(x,y,rate=0.1)
|
88
|
+
super(x,y)
|
89
|
+
@rate = rate
|
90
|
+
@delta = 0
|
91
|
+
end
|
92
|
+
|
93
|
+
def update_image(time)
|
94
|
+
@delta = (@delta + time*@rate/36) % (Math::PI*2)
|
95
|
+
zoom = 1 + Math.sin(@delta)/2
|
96
|
+
@image = @@pandapic.zoom(zoom,$smooth)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class WobblyPanda < Panda
|
101
|
+
attr_accessor :rate
|
102
|
+
def initialize(x,y,rate=0.1)
|
103
|
+
super(x,y)
|
104
|
+
@rate = rate
|
105
|
+
@delta = 0
|
106
|
+
end
|
107
|
+
|
108
|
+
def update_image(time)
|
109
|
+
@delta = (@delta + time*@rate/36) % (Math::PI*2)
|
110
|
+
zoomx = (1.5 + Math.sin(@delta)/6) * @@pandapic.width
|
111
|
+
zoomy = (1.5 + Math.cos(@delta)/5) * @@pandapic.height
|
112
|
+
@image = @@pandapic.zoom_to(zoomx,zoomy,$smooth)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
pandas = Sprites::Group.new
|
117
|
+
pandas.extend(Sprites::UpdateGroup)
|
118
|
+
pandas.extend(Sprites::DepthSortGroup)
|
119
|
+
|
120
|
+
# Create the SDL window
|
121
|
+
screen = Screen.set_mode([320,240])
|
122
|
+
screen.title = "Rubygame test"
|
123
|
+
screen.show_cursor = false;
|
124
|
+
|
125
|
+
# Create the very cute panda objects!
|
126
|
+
panda1 = SpinnyPanda.new(100,50)
|
127
|
+
panda2 = ExpandaPanda.new(150,50)
|
128
|
+
panda3 = WobblyPanda.new(200,50,0.5)
|
129
|
+
|
130
|
+
panda1.depth = 0 # in between the others
|
131
|
+
panda2.depth = 10 # behind both of the others
|
132
|
+
panda3.depth = -10 # in front of both of the others
|
133
|
+
|
134
|
+
# Put the pandas in a sprite group
|
135
|
+
pandas.push(panda1,panda2,panda3)
|
136
|
+
|
137
|
+
# Make the background surface
|
138
|
+
background = Surface.new(screen.size)
|
139
|
+
|
140
|
+
# Filling with colors in a variety of ways
|
141
|
+
background.fill( Color::ColorRGB.new([0.1, 0.2, 0.35]) )
|
142
|
+
background.fill( :black, [70,120,80,80] )
|
143
|
+
background.fill( "dark red", [80,110,80,80] )
|
144
|
+
|
145
|
+
# Create and test a new surface
|
146
|
+
a = Surface.new([100,100])
|
147
|
+
|
148
|
+
# Draw a bunch of shapes on the new surface to try out the drawing module
|
149
|
+
a.fill([70,70,255])
|
150
|
+
rect1 = Rect.new([3,3,94,94])
|
151
|
+
a.fill([40,40,1500],rect1)
|
152
|
+
a.draw_box_s([30,30],[70,70],[0,0,0])
|
153
|
+
a.draw_box([31,31],[69,69],[255,255,255])
|
154
|
+
a.draw_circle_s([50,50],10,[100,150,200])
|
155
|
+
# Two diagonal white lines, the right anti-aliased, the left not.
|
156
|
+
a.draw_line([31,69],[49,31],[255,255,255])
|
157
|
+
a.draw_line_a([49,31],[69,69],[255,255,255])
|
158
|
+
# Finally, copy this interesting surface onto the background image
|
159
|
+
a.blit(background,[50,50],[0,0,90,80])
|
160
|
+
|
161
|
+
# Draw some shapes on the background for fun
|
162
|
+
# ... a filled pentagon with a lighter border
|
163
|
+
background.draw_polygon_s(\
|
164
|
+
[[50,150],[100,140],[150,160],[120,180],[60,170]],\
|
165
|
+
[100,100,100])
|
166
|
+
background.draw_polygon_a(\
|
167
|
+
[[50,150],[100,140],[150,160],[120,180],[60,170]],\
|
168
|
+
[200,200,200])
|
169
|
+
# ... a pepperoni pizza!! (if you use your imagination...)
|
170
|
+
background.draw_arc_s([250,200],34,[210,150],[180,130,50])
|
171
|
+
background.draw_arc_s([250,200],30,[210,150],[230,180,80])
|
172
|
+
background.draw_circle_s( [240,180], 4, :dark_red )
|
173
|
+
background.draw_circle_s( [265,185], 4, :dark_red )
|
174
|
+
background.draw_circle_s( [258,200], 4, :dark_red )
|
175
|
+
background.draw_circle_s( [240,215], 4, :dark_red )
|
176
|
+
background.draw_circle_s( [260,220], 4, :dark_red )
|
177
|
+
|
178
|
+
# _Try_ to make an anti-aliased, filled ellipse, but it doesn't work well.
|
179
|
+
# If you look closely at the white ellipse, you can see that it isn't
|
180
|
+
# AA on the left and right side, and there are some black specks on the top
|
181
|
+
# and bottom where the two ellipses don't quite match.
|
182
|
+
background.draw_ellipse_s([200,150],[30,25], :beige )
|
183
|
+
background.draw_ellipse_a([200,150],[30,25], :beige )
|
184
|
+
|
185
|
+
# Let's make some labels
|
186
|
+
require "rubygame/sfont"
|
187
|
+
sfont = SFont.new( Surface["term16.png"] )
|
188
|
+
sfont.render("Arrow keys move the spinning panda!").blit(background,[10,10])
|
189
|
+
|
190
|
+
TTF.setup()
|
191
|
+
ttfont_path = File.join(File.dirname(__FILE__),"FreeSans.ttf")
|
192
|
+
ttfont = TTF.new( ttfont_path, 20 )
|
193
|
+
ttfont.render("This is some TTF text!",true,[250,250,250]).blit(background,[20,200])
|
194
|
+
|
195
|
+
|
196
|
+
# Create another surface to test transparency blitting
|
197
|
+
b = Surface.new([200,50])
|
198
|
+
b.fill([150,20,40])
|
199
|
+
b.set_alpha(123)# approx. half transparent
|
200
|
+
b.blit(background,[20,40])
|
201
|
+
background.blit(screen,[0,0])
|
202
|
+
|
203
|
+
# Refresh the screen once. During the loop, we'll use 'dirty rect' updating
|
204
|
+
# to refresh only the parts of the screen that have changed.
|
205
|
+
screen.update()
|
206
|
+
|
207
|
+
if Joystick.num_joysticks > 0
|
208
|
+
Joystick.new(0) # So that joystick events will appear on the queue
|
209
|
+
end
|
210
|
+
|
211
|
+
update_time = 0
|
212
|
+
framerate = 0
|
213
|
+
|
214
|
+
catch(:rubygame_quit) do
|
215
|
+
loop do
|
216
|
+
queue.each do |event|
|
217
|
+
case event
|
218
|
+
when KeyDownEvent
|
219
|
+
case event.key
|
220
|
+
when K_ESCAPE
|
221
|
+
throw :rubygame_quit
|
222
|
+
when K_Q
|
223
|
+
throw :rubygame_quit
|
224
|
+
when K_UP
|
225
|
+
panda1.vy = -1
|
226
|
+
when K_DOWN
|
227
|
+
panda1.vy = 1
|
228
|
+
when K_LEFT
|
229
|
+
panda1.vx = -1
|
230
|
+
when K_RIGHT
|
231
|
+
panda1.vx = 1
|
232
|
+
when K_S
|
233
|
+
$smooth = !$smooth
|
234
|
+
puts "#{$smooth?'En':'Dis'}abling smooth scale/rotate."
|
235
|
+
else
|
236
|
+
print "%s"%[event.string]
|
237
|
+
end
|
238
|
+
when KeyUpEvent
|
239
|
+
case event.key
|
240
|
+
when K_UP
|
241
|
+
panda1.vy = 0
|
242
|
+
when K_DOWN
|
243
|
+
panda1.vy = 0
|
244
|
+
when K_LEFT
|
245
|
+
panda1.vx = 0
|
246
|
+
when K_RIGHT
|
247
|
+
panda1.vx = 0
|
248
|
+
end
|
249
|
+
when ActiveEvent
|
250
|
+
# ActiveEvent appears when the window gains or loses focus.
|
251
|
+
# This helps to ensure everything is refreshed after the Rubygame
|
252
|
+
# window has been covered up by a different window.
|
253
|
+
screen.update()
|
254
|
+
when QuitEvent
|
255
|
+
throw :rubygame_quit
|
256
|
+
when MouseDownEvent
|
257
|
+
puts "click: [%d,%d]"%event.pos
|
258
|
+
when JoyDownEvent
|
259
|
+
case event.button
|
260
|
+
when 4; panda1.speed = 80
|
261
|
+
when 5; panda2.speed = 80
|
262
|
+
end
|
263
|
+
#puts "jdown: %d"%[event.button]
|
264
|
+
when JoyUpEvent
|
265
|
+
case event.button
|
266
|
+
when 4; panda1.speed = 40
|
267
|
+
when 5; panda2.speed = 40
|
268
|
+
end
|
269
|
+
#puts "jup: %d"%[event.button]
|
270
|
+
when JoyAxisEvent
|
271
|
+
# max = 32767
|
272
|
+
case(event.axis)
|
273
|
+
when 0; panda1.vx = event.value / 32767.0
|
274
|
+
when 1; panda1.vy = event.value / 32767.0
|
275
|
+
when 2; panda2.vx = event.value / 32767.0
|
276
|
+
when 3; panda2.vy = event.value / 32767.0
|
277
|
+
end
|
278
|
+
#puts "jaxis: %d %d"%[event.axis,event.value]
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
pandas.undraw(screen,background)
|
283
|
+
pandas.update(update_time)
|
284
|
+
dirty_rects = pandas.draw(screen)
|
285
|
+
screen.update_rects(dirty_rects)
|
286
|
+
|
287
|
+
update_time = clock.tick()
|
288
|
+
unless framerate == clock.framerate
|
289
|
+
framerate = clock.framerate
|
290
|
+
screen.title = "Rubygame test [%d fps]"%framerate
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
puts "Quitting!"
|
296
|
+
Rubygame.quit()
|