rubysdl-mswin32-1.8 2.1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/NEWS.en +280 -0
  2. data/NEWS.ja +291 -0
  3. data/README.en +118 -0
  4. data/README.en.win32 +72 -0
  5. data/README.ja +166 -0
  6. data/README.ja.win32 +80 -0
  7. data/dll/SDL.dll +0 -0
  8. data/dll/SDL_image.dll +0 -0
  9. data/dll/SDL_mixer.dll +0 -0
  10. data/dll/SDL_ttf.dll +0 -0
  11. data/dll/SGE.dll +0 -0
  12. data/dll/jpeg.dll +0 -0
  13. data/dll/libcharset-1.dll +0 -0
  14. data/dll/libfreetype-6.dll +0 -0
  15. data/dll/libiconv-2.dll +0 -0
  16. data/dll/libogg-0.dll +0 -0
  17. data/dll/libpng12-0.dll +0 -0
  18. data/dll/libtiff-3.dll +0 -0
  19. data/dll/libvorbis-0.dll +0 -0
  20. data/dll/libvorbisfile-3.dll +0 -0
  21. data/dll/smpeg.dll +0 -0
  22. data/dll/zlib1.dll +0 -0
  23. data/doc/cdrom.rd +305 -0
  24. data/doc/collision.rd +121 -0
  25. data/doc/event.rd +1090 -0
  26. data/doc/font.rd +625 -0
  27. data/doc/general.rd +60 -0
  28. data/doc/init.rd +142 -0
  29. data/doc/joystick.rd +301 -0
  30. data/doc/mixer.rd +584 -0
  31. data/doc/mpeg.rd +420 -0
  32. data/doc/opengl.rd +144 -0
  33. data/doc/rsd.rb +158 -0
  34. data/doc/sdlskk.rd +404 -0
  35. data/doc/time.rd +34 -0
  36. data/doc/video.rd +2269 -0
  37. data/doc/wm.rd +78 -0
  38. data/ext/opengl.so +0 -0
  39. data/ext/sdl.so +0 -0
  40. data/install_rubysdl.rb +30 -0
  41. data/lib/rubysdl_aliases.rb +303 -0
  42. data/lib/rubysdl_compatible_ver1.rb +243 -0
  43. data/lib/sdl.rb +224 -0
  44. data/rubysdl_doc_old.en.rd +2181 -0
  45. data/rubysdl_doc_old.rd +2402 -0
  46. data/rubysdl_ref.html +5888 -0
  47. data/rubysdl_ref.rd +6577 -0
  48. data/sample/aadraw.rb +25 -0
  49. data/sample/alpha.rb +26 -0
  50. data/sample/alphadraw.rb +25 -0
  51. data/sample/bfont.rb +24 -0
  52. data/sample/cdrom.rb +24 -0
  53. data/sample/collision.rb +97 -0
  54. data/sample/cursor.bmp +0 -0
  55. data/sample/cursor.rb +22 -0
  56. data/sample/ellipses.rb +39 -0
  57. data/sample/event2.rb +34 -0
  58. data/sample/font.bmp +0 -0
  59. data/sample/font.rb +26 -0
  60. data/sample/fpstimer.rb +175 -0
  61. data/sample/icon.bmp +0 -0
  62. data/sample/icon.bmp.gz +0 -0
  63. data/sample/icon.png +0 -0
  64. data/sample/joy2.rb +81 -0
  65. data/sample/kanji.rb +36 -0
  66. data/sample/load_from_io.rb +45 -0
  67. data/sample/movesp.rb +94 -0
  68. data/sample/playmod.rb +13 -0
  69. data/sample/plaympeg.rb +44 -0
  70. data/sample/playwave.rb +15 -0
  71. data/sample/randrect.rb +40 -0
  72. data/sample/rubysdl.rb +34 -0
  73. data/sample/sample.ttf +0 -0
  74. data/sample/sdlskk.rb +70 -0
  75. data/sample/sgetest.rb +33 -0
  76. data/sample/stetris.rb +274 -0
  77. data/sample/testgl.rb +165 -0
  78. data/sample/testsprite.rb +69 -0
  79. data/sample/transformblit.rb +42 -0
  80. metadata +135 -0
data/sample/sgetest.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'sdl'
2
+
3
+ SDL.init( SDL::INIT_VIDEO )
4
+ screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
5
+ SDL::WM.set_caption $0, $0
6
+
7
+ format = screen.format
8
+ # draw red pixel at (200,200)
9
+ screen[200,200]= format.map_rgb(255,0,0)
10
+ # draw green pixel at (250,200)
11
+ screen[250,200]= format.map_rgb(0,255,0)
12
+ # draw blue pixel at (200,200)
13
+ screen[300,200]= format.map_rgb(0,0,255)
14
+
15
+ Red=format.map_rgb(255,0,0)
16
+ screen.draw_line(20,20,300,200,Red)
17
+ screen.draw_rect(49,59,80,80,Red)
18
+ screen.draw_circle(100,100,50,[87,87,87])
19
+ screen.draw_circle(300,300,30,Red, true)
20
+ screen.draw_circle(230, 300, 30, Red, true, true)
21
+
22
+ screen.flip
23
+
24
+ while true
25
+ while event = SDL::Event.poll
26
+ case event
27
+ when SDL::Event::KeyDown, SDL::Event::Quit
28
+ exit
29
+ end
30
+ end
31
+
32
+ sleep 0.2
33
+ end
data/sample/stetris.rb ADDED
@@ -0,0 +1,274 @@
1
+ # This sample need ruby 1.8 or 1.6 with shim
2
+ # Thanks to Simon Strandgaard
3
+ require 'sdl'
4
+ if RUBY_VERSION < "1.7" then
5
+ require 'features/ruby18'
6
+ end
7
+
8
+ class Object
9
+ def deep_clone
10
+ Marshal::load(Marshal.dump(self))
11
+ end
12
+ end
13
+
14
+ class Array
15
+ def random
16
+ at(Kernel.rand(size))
17
+ end
18
+ end
19
+
20
+ class Pattern
21
+ def initialize(x, y, *data)
22
+ @x = x
23
+ @y = y
24
+ @data = data
25
+ end
26
+ attr_reader :data, :x, :y
27
+ alias width x
28
+ def rotate
29
+ @data = @data.reverse.transpose
30
+ @x, @y = @y, @x
31
+ end
32
+ PAT1 = Pattern.new(4, 1, [1, 1, 1, 1])
33
+ PAT2 = Pattern.new(3, 2, [1, 1, 1], [0, 1, 0])
34
+ PAT3 = Pattern.new(3, 2, [1, 1, 1], [1, 0, 0])
35
+ PAT4 = Pattern.new(3, 2, [1, 1, 1], [0, 0, 1])
36
+ PAT5 = Pattern.new(2, 2, [1, 1], [1, 1])
37
+ PAT6 = Pattern.new(3, 2, [1, 1, 0], [0, 1, 1])
38
+ PAT7 = Pattern.new(3, 2, [0, 1, 1], [1, 1, 0])
39
+ def Pattern::patterns
40
+ [PAT1, PAT2, PAT3, PAT4, PAT5, PAT6, PAT7]
41
+ end
42
+ end
43
+
44
+ class Level
45
+ def initialize(width=10, height=15)
46
+ @height = height
47
+ @width = width
48
+ @data = Array.new(height) { Array.new(width, 0) }
49
+ backup_background
50
+ end
51
+ attr_reader :width, :height
52
+ def test
53
+ @data[0][0] = 1
54
+ @data[0][@width-1] = 1
55
+ @data[@height-1][0] = 1
56
+ @data[@height-1][@width-1] = 1
57
+ end
58
+ def bg_is_collision(offset_x, offset_y, pattern)
59
+ return true if pattern.x + offset_x > @width
60
+ return true if pattern.y + offset_y > @height
61
+ y = offset_y
62
+ pattern.data.each do |row|
63
+ x = offset_x
64
+ row.each do |cell|
65
+ if (cell != 0) and (@bg[y][x] != 0)
66
+ return true
67
+ end
68
+ x += 1
69
+ end
70
+ y += 1
71
+ end
72
+ return false
73
+ end
74
+ def restore_background
75
+ @data = @bg
76
+ end
77
+ def backup_background
78
+ @bg = @data.deep_clone
79
+ end
80
+ def or_pattern(offset_x, offset_y, pattern)
81
+ backup_background
82
+ y = offset_y
83
+ pattern.data.each do |row|
84
+ x = offset_x
85
+ row.each do |cell|
86
+ @data[y][x] = cell if cell != 0
87
+ x += 1
88
+ end
89
+ y += 1
90
+ end
91
+ end
92
+ def find_filled_rows
93
+ res = []
94
+ @data.each_index do |y|
95
+ ok = true
96
+ @data[y].each do |cell|
97
+ if cell == 0
98
+ ok = false
99
+ break
100
+ end
101
+ end
102
+ res << y if ok
103
+ end
104
+ res
105
+ end
106
+ def remove_rows(*rows)
107
+ rows.uniq!
108
+ rows.each do |y|
109
+ @bg[y] = nil
110
+ end
111
+ @bg.compact!
112
+ extra = Array.new(rows.size) { Array.new(@width, 0) }
113
+ @bg = extra + @bg
114
+ raise "integrity error" if @bg.size != @height
115
+ end
116
+ end
117
+
118
+ class Level
119
+ def load_render_data
120
+ @image = SDL::Surface.load_bmp("icon.bmp")
121
+ @image.set_color_key( SDL::SRCCOLORKEY ,0)
122
+ @image = @image.display_format
123
+ @step_x = 32 # todo: image width
124
+ @step_y = 32 # todo: image height
125
+ # todo: raise exception is level does not fit to screen!
126
+ @offset_x = 100
127
+ @offset_y = 20
128
+
129
+ @fill_removal_dir = false
130
+ end
131
+ def render
132
+ y = @offset_y
133
+ @data.each do |row|
134
+ render_line(y, row)
135
+ y += @step_y
136
+ end
137
+ end
138
+ def render_line(y, cells)
139
+ x = @offset_x
140
+ cells.each do |cell|
141
+ i = (cell == 0) ? 63 : 255
142
+ @image.set_alpha(SDL::SRCALPHA,i)
143
+ $screen.put(@image,x,y)
144
+ x += @step_x
145
+ end
146
+ end
147
+ FILL = (20 * 256*256) + (0 * 256) + 10
148
+ def render_removal(rows)
149
+ $screen.fill_rect(0,0,640,512,0)
150
+ render
151
+ rows.reverse_each do |row|
152
+ y = (row * @step_y) + @offset_y
153
+
154
+ if @fill_removal_dir
155
+ i = 0
156
+ x = @offset_x
157
+ while i < @width
158
+ $screen.fill_rect(x,y,@step_x,@step_y,FILL)
159
+ $screen.flip
160
+ i += 1
161
+ x += @step_x
162
+ end
163
+ @fill_removal_dir = false
164
+ else
165
+ i = 0
166
+ x = @offset_x + ((@width-1)*@step_x)
167
+ while i < @width
168
+ $screen.fill_rect(x,y,@step_x,@step_y,FILL)
169
+ $screen.flip
170
+ i += 1
171
+ x -= @step_x
172
+ end
173
+ @fill_removal_dir = true
174
+ end
175
+ end
176
+ end
177
+ end
178
+
179
+ SDL.init( SDL::INIT_VIDEO )
180
+ $screen = SDL::Screen.open(640,512,24,SDL::SWSURFACE)
181
+ level = Level.new
182
+ level.test
183
+ level.load_render_data
184
+ pat = Pattern::PAT3.clone
185
+ pat_x = 5
186
+ pat_y = 0
187
+ time_step = 0.5
188
+ time = Time.now
189
+ launch_new_pattern = true
190
+ loop do
191
+ if launch_new_pattern
192
+ launch_new_pattern = false
193
+ time_step = 0.5
194
+ time = Time.now
195
+ pat = Pattern::patterns.random.clone
196
+ pat_x = 5
197
+ pat_y = 0
198
+ level.backup_background
199
+ if level.bg_is_collision(pat_x, pat_y, pat)
200
+ puts "Sorry you are game over"
201
+ sleep 3
202
+ raise "game over"
203
+ end
204
+ level.or_pattern(pat_x, pat_y, pat)
205
+ end
206
+
207
+ # timer events
208
+ while Time.now > time + time_step
209
+ pat_y += 1
210
+ if level.bg_is_collision(pat_x, pat_y, pat)
211
+ launch_new_pattern = true
212
+ rows = level.find_filled_rows
213
+ if rows.size > 0
214
+ puts "rows filled"
215
+ p rows
216
+ level.render_removal(rows)
217
+
218
+ level.backup_background
219
+ level.remove_rows(*rows)
220
+ level.restore_background
221
+ end
222
+ else
223
+ level.restore_background
224
+ level.or_pattern(pat_x, pat_y, pat)
225
+ end
226
+ time += time_step
227
+ end
228
+
229
+ old_pat_x = pat_x
230
+ old_pat_y = pat_y
231
+ rotate = false
232
+
233
+ # handle keystrokes
234
+ while event = SDL::Event.poll
235
+ case event
236
+ when SDL::Event::Quit then exit
237
+ when SDL::Event::KeyDown
238
+ case event.sym
239
+ when SDL::Key::ESCAPE then exit
240
+ when SDL::Key::UP then rotate = true
241
+ when SDL::Key::DOWN then time_step = 0.1
242
+ when SDL::Key::LEFT
243
+ pat_x -= 1 if pat_x > 0
244
+ when SDL::Key::RIGHT
245
+ pat_x += 1 if pat_x < (level.width - pat.width)
246
+ end
247
+ end
248
+ end
249
+ SDL::Key.scan
250
+
251
+ # move pattern & do collition tests
252
+ if (pat_x <=> old_pat_x) or (pat_y <=> old_pat_y) or (rotate == true)
253
+
254
+ old_pat = pat.clone
255
+ pat.rotate if rotate
256
+
257
+ # if collision then restore last working-state
258
+ if level.bg_is_collision(pat_x, pat_y, pat)
259
+ pat_x = old_pat_x
260
+ pat_y = old_pat_y
261
+ pat = old_pat
262
+ else
263
+ # collision avoided.. therefore don't launch new pattern
264
+ launch_new_pattern = false
265
+ level.restore_background
266
+ level.or_pattern(pat_x, pat_y, pat)
267
+ end
268
+ end
269
+
270
+ # repaint screen
271
+ $screen.fill_rect(0,0,640,512,0)
272
+ level.render
273
+ $screen.flip
274
+ end
data/sample/testgl.rb ADDED
@@ -0,0 +1,165 @@
1
+ require 'sdl'
2
+ require 'opengl'
3
+
4
+ # initialize SDL and opengl
5
+ SDL.init SDL::INIT_VIDEO
6
+ SDL::GL.set_attr SDL::GL_RED_SIZE,5
7
+ SDL::GL.set_attr SDL::GL_GREEN_SIZE,5
8
+ SDL::GL.set_attr SDL::GL_BLUE_SIZE,5
9
+ SDL::GL.set_attr SDL::GL_DEPTH_SIZE,16
10
+ SDL::GL.set_attr SDL::GL_DOUBLEBUFFER,1
11
+ SDL::Screen.open 640,400,16,SDL::OPENGL
12
+
13
+ GL::Viewport( 0, 0, 640, 400 );
14
+ GL::MatrixMode( GL::PROJECTION );
15
+ GL::LoadIdentity( );
16
+
17
+ GL::MatrixMode( GL::MODELVIEW );
18
+ GL::LoadIdentity( );
19
+
20
+ GL::Enable(GL::DEPTH_TEST);
21
+
22
+ GL::DepthFunc(GL::LESS);
23
+
24
+ GL::ShadeModel(GL::SMOOTH);
25
+
26
+ shadedCube=true
27
+
28
+ color =
29
+ [[ 1.0, 1.0, 0.0],
30
+ [ 1.0, 0.0, 0.0],
31
+ [ 0.0, 0.0, 0.0],
32
+ [ 0.0, 1.0, 0.0],
33
+ [ 0.0, 1.0, 1.0],
34
+ [ 1.0, 1.0, 1.0],
35
+ [ 1.0, 0.0, 1.0],
36
+ [ 0.0, 0.0, 1.0]]
37
+
38
+ cube =
39
+ [[ 0.5, 0.5, -0.5],
40
+ [ 0.5, -0.5, -0.5],
41
+ [-0.5, -0.5, -0.5],
42
+ [-0.5, 0.5, -0.5],
43
+ [-0.5, 0.5, 0.5],
44
+ [ 0.5, 0.5, 0.5],
45
+ [ 0.5, -0.5, 0.5],
46
+ [-0.5, -0.5, 0.5]]
47
+
48
+
49
+ loop do
50
+
51
+ while event = SDL::Event2.poll
52
+ case event
53
+ when SDL::Event2::Quit, SDL::Event2::KeyDown
54
+ exit
55
+ end
56
+ end
57
+
58
+ GL.ClearColor(0.0, 0.0, 0.0, 1.0);
59
+ GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
60
+
61
+
62
+ GL::Begin(GL::QUADS)
63
+
64
+ if shadedCube then
65
+ GL::Color(color[0]);
66
+ GL::Vertex(cube[0]);
67
+ GL::Color(color[1]);
68
+ GL::Vertex(cube[1]);
69
+ GL::Color(color[2]);
70
+ GL::Vertex(cube[2]);
71
+ GL::Color(color[3]);
72
+ GL::Vertex(cube[3]);
73
+
74
+ GL::Color(color[3]);
75
+ GL::Vertex(cube[3]);
76
+ GL::Color(color[4]);
77
+ GL::Vertex(cube[4]);
78
+ GL::Color(color[7]);
79
+ GL::Vertex(cube[7]);
80
+ GL::Color(color[2]);
81
+ GL::Vertex(cube[2]);
82
+
83
+ GL::Color(color[0]);
84
+ GL::Vertex(cube[0]);
85
+ GL::Color(color[5]);
86
+ GL::Vertex(cube[5]);
87
+ GL::Color(color[6]);
88
+ GL::Vertex(cube[6]);
89
+ GL::Color(color[1]);
90
+ GL::Vertex(cube[1]);
91
+
92
+ GL::Color(color[5]);
93
+ GL::Vertex(cube[5]);
94
+ GL::Color(color[4]);
95
+ GL::Vertex(cube[4]);
96
+ GL::Color(color[7]);
97
+ GL::Vertex(cube[7]);
98
+ GL::Color(color[6]);
99
+ GL::Vertex(cube[6]);
100
+
101
+ GL::Color(color[5]);
102
+ GL::Vertex(cube[5]);
103
+ GL::Color(color[0]);
104
+ GL::Vertex(cube[0]);
105
+ GL::Color(color[3]);
106
+ GL::Vertex(cube[3]);
107
+ GL::Color(color[4]);
108
+ GL::Vertex(cube[4]);
109
+
110
+ GL::Color(color[6]);
111
+ GL::Vertex(cube[6]);
112
+ GL::Color(color[1]);
113
+ GL::Vertex(cube[1]);
114
+ GL::Color(color[2]);
115
+ GL::Vertex(cube[2]);
116
+ GL::Color(color[7]);
117
+ GL::Vertex(cube[7]);
118
+
119
+ else
120
+ GL::Color(1.0, 0.0, 0.0);
121
+ GL::Vertex(cube[0]);
122
+ GL::Vertex(cube[1]);
123
+ GL::Vertex(cube[2]);
124
+ GL::Vertex(cube[3]);
125
+
126
+ GL::Color(0.0, 1.0, 0.0);
127
+ GL::Vertex(cube[3]);
128
+ GL::Vertex(cube[4]);
129
+ GL::Vertex(cube[7]);
130
+ GL::Vertex(cube[2]);
131
+
132
+ GL::Color(0.0, 0.0, 1.0);
133
+ GL::Vertex(cube[0]);
134
+ GL::Vertex(cube[5]);
135
+ GL::Vertex(cube[6]);
136
+ GL::Vertex(cube[1]);
137
+
138
+ GL::Color(0.0, 1.0, 1.0);
139
+ GL::Vertex(cube[5]);
140
+ GL::Vertex(cube[4]);
141
+ GL::Vertex(cube[7]);
142
+ GL::Vertex(cube[6]);
143
+
144
+ GL::Color(1.0, 1.0, 0.0);
145
+ GL::Vertex(cube[5]);
146
+ GL::Vertex(cube[0]);
147
+ GL::Vertex(cube[3]);
148
+ GL::Vertex(cube[4]);
149
+
150
+ GL::Color(1.0, 0.0, 1.0);
151
+ GL::Vertex(cube[6]);
152
+ GL::Vertex(cube[1]);
153
+ GL::Vertex(cube[2]);
154
+ GL::Vertex(cube[7]);
155
+
156
+ end
157
+
158
+ GL::End()
159
+
160
+ GL::MatrixMode(GL::MODELVIEW);
161
+ GL::Rotate(5.0, 1.0, 1.0, 1.0);
162
+
163
+ SDL::GL.swap_buffers
164
+
165
+ end