cyross-ruby-miyako 2.0.0

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.
Files changed (125) hide show
  1. data/README +977 -0
  2. data/Rakefile +7 -0
  3. data/img/cursor.png +0 -0
  4. data/img/cursors.png +0 -0
  5. data/img/dice.png +0 -0
  6. data/img/wait_cursor.png +0 -0
  7. data/img/win_base.png +0 -0
  8. data/img/window.png +0 -0
  9. data/install_miyako.rb +75 -0
  10. data/lib/Miyako/API/audio.rb +198 -0
  11. data/lib/Miyako/API/basic_data.rb +431 -0
  12. data/lib/Miyako/API/bitmap.rb +35 -0
  13. data/lib/Miyako/API/choices.rb +308 -0
  14. data/lib/Miyako/API/collision.rb +444 -0
  15. data/lib/Miyako/API/diagram.rb +573 -0
  16. data/lib/Miyako/API/drawing.rb +110 -0
  17. data/lib/Miyako/API/fixedmap.rb +315 -0
  18. data/lib/Miyako/API/font.rb +384 -0
  19. data/lib/Miyako/API/input.rb +440 -0
  20. data/lib/Miyako/API/layout.rb +451 -0
  21. data/lib/Miyako/API/map.rb +403 -0
  22. data/lib/Miyako/API/map_event.rb +198 -0
  23. data/lib/Miyako/API/modules.rb +109 -0
  24. data/lib/Miyako/API/movie.rb +151 -0
  25. data/lib/Miyako/API/parts.rb +154 -0
  26. data/lib/Miyako/API/plane.rb +131 -0
  27. data/lib/Miyako/API/screen.rb +257 -0
  28. data/lib/Miyako/API/shape.rb +362 -0
  29. data/lib/Miyako/API/sprite.rb +338 -0
  30. data/lib/Miyako/API/sprite_animation.rb +461 -0
  31. data/lib/Miyako/API/spriteunit.rb +113 -0
  32. data/lib/Miyako/API/story.rb +224 -0
  33. data/lib/Miyako/API/textbox.rb +496 -0
  34. data/lib/Miyako/API/viewport.rb +435 -0
  35. data/lib/Miyako/API/yuki.rb +779 -0
  36. data/lib/Miyako/EXT/miyako_cairo.rb +60 -0
  37. data/lib/Miyako/EXT/raster_scroll.rb +138 -0
  38. data/lib/Miyako/EXT/slides.rb +136 -0
  39. data/lib/Miyako/miyako.rb +172 -0
  40. data/miyako.png +0 -0
  41. data/miyako_banner.png +0 -0
  42. data/miyako_no_katana/extconf.rb +34 -0
  43. data/miyako_no_katana/miyako_no_katana.c +3301 -0
  44. data/sample/Animation1/m1ku.rb +89 -0
  45. data/sample/Animation1/m1ku_arm_0.png +0 -0
  46. data/sample/Animation1/m1ku_arm_1.png +0 -0
  47. data/sample/Animation1/m1ku_arm_2.png +0 -0
  48. data/sample/Animation1/m1ku_arm_3.png +0 -0
  49. data/sample/Animation1/m1ku_back.jpg +0 -0
  50. data/sample/Animation1/m1ku_body.png +0 -0
  51. data/sample/Animation1/m1ku_eye_0.png +0 -0
  52. data/sample/Animation1/m1ku_eye_1.png +0 -0
  53. data/sample/Animation1/m1ku_eye_2.png +0 -0
  54. data/sample/Animation1/m1ku_eye_3.png +0 -0
  55. data/sample/Animation1/m1ku_hair_front.png +0 -0
  56. data/sample/Animation1/m1ku_hair_rear.png +0 -0
  57. data/sample/Animation1/readme.txt +72 -0
  58. data/sample/Animation2/lex.rb +95 -0
  59. data/sample/Animation2/lex_back.png +0 -0
  60. data/sample/Animation2/lex_body.png +0 -0
  61. data/sample/Animation2/lex_roadroller.png +0 -0
  62. data/sample/Animation2/lex_wheel_0.png +0 -0
  63. data/sample/Animation2/lex_wheel_1.png +0 -0
  64. data/sample/Animation2/lex_wheel_2.png +0 -0
  65. data/sample/Animation2/readme.txt +72 -0
  66. data/sample/Animation2/song_title.png +0 -0
  67. data/sample/Diagram_sample/back.png +0 -0
  68. data/sample/Diagram_sample/chr01.png +0 -0
  69. data/sample/Diagram_sample/chr02.png +0 -0
  70. data/sample/Diagram_sample/cursor.png +0 -0
  71. data/sample/Diagram_sample/diagram_sample_yuki2.rb +283 -0
  72. data/sample/Diagram_sample/readme.txt +87 -0
  73. data/sample/Diagram_sample/wait_cursor.png +0 -0
  74. data/sample/Room3/blue.rb +250 -0
  75. data/sample/Room3/ending.rb +175 -0
  76. data/sample/Room3/green.rb +185 -0
  77. data/sample/Room3/image/akamatsu.png +0 -0
  78. data/sample/Room3/image/aoyama.png +0 -0
  79. data/sample/Room3/image/congra.png +0 -0
  80. data/sample/Room3/image/congratulation.png +0 -0
  81. data/sample/Room3/image/congratulation_bg.png +0 -0
  82. data/sample/Room3/image/cursor.png +0 -0
  83. data/sample/Room3/image/midori.png +0 -0
  84. data/sample/Room3/image/mittsu_no_oheya.png +0 -0
  85. data/sample/Room3/image/mittsu_no_oheya_logo.png +0 -0
  86. data/sample/Room3/image/room_blue.png +0 -0
  87. data/sample/Room3/image/room_green.png +0 -0
  88. data/sample/Room3/image/room_red.png +0 -0
  89. data/sample/Room3/image/start.png +0 -0
  90. data/sample/Room3/image/three_doors.png +0 -0
  91. data/sample/Room3/image/wait_cursor.png +0 -0
  92. data/sample/Room3/main.rb +102 -0
  93. data/sample/Room3/main_component.rb +58 -0
  94. data/sample/Room3/readme.txt +76 -0
  95. data/sample/Room3/red.rb +200 -0
  96. data/sample/Room3/room3.rb +26 -0
  97. data/sample/Room3/title.rb +171 -0
  98. data/sample/fixed_map_test/cursor.png +0 -0
  99. data/sample/fixed_map_test/fixed_map_sample.rb +149 -0
  100. data/sample/fixed_map_test/map.csv +19 -0
  101. data/sample/fixed_map_test/map_01.png +0 -0
  102. data/sample/fixed_map_test/map_sample.rb +121 -0
  103. data/sample/fixed_map_test/mapchip.csv +23 -0
  104. data/sample/fixed_map_test/monster.png +0 -0
  105. data/sample/fixed_map_test/readme.txt +72 -0
  106. data/sample/map_test/chara.rb +50 -0
  107. data/sample/map_test/chr1.png +0 -0
  108. data/sample/map_test/cursor.png +0 -0
  109. data/sample/map_test/main_parts.rb +48 -0
  110. data/sample/map_test/main_scene.rb +137 -0
  111. data/sample/map_test/map.png +0 -0
  112. data/sample/map_test/map2.png +0 -0
  113. data/sample/map_test/map_layer.csv +127 -0
  114. data/sample/map_test/map_manager.rb +92 -0
  115. data/sample/map_test/map_test.rb +23 -0
  116. data/sample/map_test/mapchip.csv +21 -0
  117. data/sample/map_test/oasis.rb +65 -0
  118. data/sample/map_test/readme.txt +87 -0
  119. data/sample/map_test/route.rb +144 -0
  120. data/sample/map_test/sea.png +0 -0
  121. data/sample/map_test/town.rb +68 -0
  122. data/sample/map_test/wait_cursor.png +0 -0
  123. data/sample/map_test/window.png +0 -0
  124. data/win/miyako_no_katana.so +0 -0
  125. metadata +194 -0
@@ -0,0 +1,461 @@
1
+ # -*- encoding: utf-8 -*-
2
+ =begin
3
+ --
4
+ Miyako v1.5
5
+ Copyright (C) 2007-2008 Cyross Makoto
6
+
7
+ This library is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU Lesser General Public
9
+ License as published by the Free Software Foundation; either
10
+ version 2.1 of the License, or (at your option) any later version.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public
18
+ License along with this library; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ ++
21
+ =end
22
+
23
+ module Miyako
24
+ #==アニメーション管理クラス
25
+ #スプライトのアニメーションの構築・実行を管理するクラス
26
+ class SpriteAnimation
27
+ include SpriteBase
28
+ include Animation
29
+ include Layout
30
+ include SingleEnumerable
31
+
32
+ #===インスタンスの作成
33
+ #アニメーションを行うための初期設定を行う。
34
+ #アニメーションは2種類の方法があり、
35
+ #
36
+ #「一つのスプライトをow,ohプロパティで分割して、表示開始位置をずらすことでアニメーションを行う」方法と、
37
+ #
38
+ #(RPGのキャラチップを想定。 以降、「単体アニメーション」と呼ぶ)
39
+ #
40
+ #「複数枚のスプライトの配列を渡し、要素順に表示させることでアニメーションを行う」方法がある。
41
+ #
42
+ #(いわゆる「ぱらぱら漫画」方式。 以降、「配列アニメーション」と呼ぶ)
43
+ #
44
+ #「パターン番号」は、キャラクタパターン(画像を一定の大きさ(ow,oh)で切り分けた単位)の番号を意味する。
45
+ #
46
+ #単体アニメーションのときは、画像の左上から0,1,2,...と数える。
47
+ #
48
+ #配列アニメーションのときは、配列のインデックスがパターン番号となる。
49
+ #
50
+ #
51
+ #
52
+ #利用できるパラメータは以下の通り
53
+ #
54
+ #:sprite => sprite|spriteの配列 アニメーションさせるスプライト(インスタンス単体もしくはインスタンスの配列)。必須パラメータ
55
+ #
56
+ #:dir => :h|:v 単体アニメーションのとき、縦方向に位置をずらして表示させる(:h指定時)か、横方向か(:v指定時)を決定する。デフォルトは:h
57
+ #
58
+ #:pattern_list => 表示させるパターン番号を指定するための配列。配列の要素の順にパターンが表示される
59
+ #
60
+ #:loop => アニメーションを繰り返し更新するかどうかを示すフラグ。falseのときは、1回パターンを実行した後、アニメーションを終了する(true/false)
61
+ #
62
+ #_hash_:: パラメータ名とパラメータとのハッシュ
63
+ #返却値:: 生成されたインスタンス
64
+ def initialize(hash)
65
+ init_layout
66
+ @units = Array.new
67
+ @slist = nil
68
+
69
+ hash[:dir] ||= :h
70
+ @dir = hash[:dir]
71
+ s = hash[:sprite]
72
+ hash[:pattern_list] ||= nil
73
+ @plist = hash[:pattern_list]
74
+ hash[:wait] ||= 0
75
+ wait = hash[:wait]
76
+ hash[:move_offset] ||= nil
77
+ @move_offset = hash[:move_offset]
78
+ hash[:position_offset] ||= nil
79
+ @pos_offset = hash[:position_offset]
80
+ hash[:align] ||= :max
81
+ @align = hash[:align]
82
+ hash[:loop] ||= true
83
+ @loop = hash[:loop]
84
+
85
+ @pat_len = 1
86
+ @pat_olen = 1
87
+ @chr_len = 1
88
+ @chr_olen = 1
89
+
90
+ @slist = Array.new
91
+ if s.kind_of?(Sprite)
92
+ set_layout_size(s.ow, s.oh)
93
+ move_to(s.x, s.y)
94
+ s.snap(self)
95
+ s.left
96
+ s.top
97
+ @pat_len = @dir == :h ? s.h : s.w
98
+ @pat_olen = @dir == :h ? s.oh : s.ow
99
+ @chr_len = @dir == :h ? s.w : s.h
100
+ @chr_olen = @dir == :h ? s.ow : s.oh
101
+ @pats = @pat_len / @pat_olen
102
+ elsif s.kind_of?(Array)
103
+ first = s[0]
104
+ set_layout_size(first.ow, first.oh)
105
+ move_to(first.x, first.y)
106
+ @slist = s.map{|ss|
107
+ ss.snap(self)
108
+ ss.left.top
109
+ }
110
+ @pat_len = @slist.length
111
+ @pats = @slist.length
112
+ else
113
+ raise MiyakoError, "Illegal sprite list for SpriteAnimation."
114
+ end
115
+
116
+ if @plist
117
+ if @align == :min
118
+ @pats = @plist.length if @pats > @plist.length
119
+ else
120
+ @pats = @plist.length if @pats < @plist.length
121
+ end
122
+ else
123
+ @plist = Array.new unless @plist
124
+ end
125
+
126
+ if @move_offset
127
+ if @align == :min
128
+ @pats = @move_offset.length if @pats > @move_offset.length
129
+ else
130
+ @pats = @move_offset.length if @pats < @move_offset.length
131
+ end
132
+ else
133
+ @move_offset = Array.new
134
+ end
135
+
136
+ if @pos_offset
137
+ if @align == :min
138
+ @pats = @pos_offset.length if @pats > @pos_offset.length
139
+ else
140
+ @pats = @pos_offset.length if @pats < @pos_offset.length
141
+ end
142
+ else
143
+ @pos_offset = Array.new
144
+ end
145
+
146
+ if wait.kind_of?(Array)
147
+ @waits = wait.collect{|w| w.kind_of?(Float) ? WaitCounter.new(w) : w }
148
+ if @align == :min
149
+ @pats = @waits.length if @pats > @waits.length
150
+ else
151
+ @pats = @waits.length if @pats < @waits.length
152
+ end
153
+ else
154
+ @waits = Array.new
155
+ end
156
+
157
+ if @plist.length == 0
158
+ @pats.times{|p| @plist.push(p)}
159
+ elsif @plist.length < @pats
160
+ @plist = @plist.cycle.take(@pats)
161
+ end
162
+
163
+ if @slist.length == 0
164
+ @slist = Array.new(@pats){|pat| s }
165
+ @units = Array.new(@pats){|pat|
166
+ u = SpriteUnitFactory.create(:bitmap=>@slist[pat].bitmap,
167
+ :ox => @slist[pat].ox,
168
+ :oy => @slist[pat].oy,
169
+ :ow => @slist[pat].ow,
170
+ :oh => @slist[pat].oh)
171
+ px = pat % (@pat_len / @pat_olen)
172
+ if @dir == :h
173
+ u.oy = @slist[pat].oh * @plist[px]
174
+ else
175
+ u.ox = @slist[pat].ow * @plist[px]
176
+ end
177
+ u
178
+ }
179
+ elsif @slist.length < @pats
180
+ tmp = @slist
181
+ @slist = @slist.cycle.take(@pats)
182
+ @units = Array.new(@pats){|pat|
183
+ SpriteUnitFactory.create(:bitmap=>@slist[pat].bitmap,
184
+ :ox => @slist[pat].ox,
185
+ :oy => @slist[pat].oy,
186
+ :ow => @slist[pat].ow,
187
+ :oh => @slist[pat].oh)
188
+ }
189
+ else
190
+ @units = Array.new(@pats){|pat|
191
+ SpriteUnitFactory.create(:bitmap=>@slist[p].bitmap,
192
+ :ox => @slist[p].ox,
193
+ :oy => @slist[p].oy,
194
+ :ow => @slist[p].ow,
195
+ :oh => @slist[p].oh)
196
+ }
197
+ end
198
+
199
+ if @move_offset.length == 0
200
+ @move_offset = Array.new(@pats){|pat| Point.new(0,0) }
201
+ elsif @move_offset.length < @pats
202
+ @move_offset = @move_offset.cycle.take(@pats)
203
+ end
204
+
205
+ if @pos_offset.length == 0
206
+ @pos_offset = Array.new(@pats){|pat| 0 }
207
+ elsif @pos_offset.length < @pats
208
+ @pos_offset = @pos_offset.cycle.take(@pats)
209
+ end
210
+
211
+ if @waits.length == 0
212
+ if wait.kind_of?(Integer)
213
+ @waits = Array.new(@pats){|pat| wait}
214
+ elsif wait.kind_of?(Float)
215
+ @waits = Array.new(@pats){|pat| WaitCounter.new(wait)}
216
+ else
217
+ raise MiyakoError, "Illegal wait counter for SpriteAnimation."
218
+ end
219
+ elsif @waits.length < @pats
220
+ @waits = @waits.cycle.take(@pats)
221
+ end
222
+
223
+ @chrs = @chr_len / @chr_olen
224
+
225
+ @cnum = 0
226
+ @pnum = 0
227
+ @cnt = 0
228
+ @exec = false
229
+ @visible = false
230
+
231
+ @now = @units[0]
232
+ @now.move_to(@slist[@plist[@pnum]].x + @move_offset[@pnum][0],
233
+ @slist[@plist[@pnum]].y + @move_offset[@pnum][1])
234
+ end
235
+
236
+ attr_accessor :visible
237
+
238
+ def update_layout_position #:nodoc:
239
+ @now.move_to(*@layout.pos) if @now
240
+ end
241
+
242
+ #===現在表示しているスプライトのowを取得する
243
+ #返却値:: スプライトのow
244
+ def ow
245
+ return @now.ow
246
+ end
247
+
248
+ #===現在表示しているスプライトのohを取得する
249
+ #返却値:: スプライトのoh
250
+ def oh
251
+ return @now.oh
252
+ end
253
+
254
+ #===表示するパターンの番号を変更する
255
+ #_pnum_:: パターン番号
256
+ #返却値:: 自分自身
257
+ def pattern(pnum)
258
+ @pnum = pnum if pnum < @pats
259
+ set_pat
260
+ @cnt = @waits[@plist[@pnum]] if @exec
261
+ return self
262
+ end
263
+
264
+ #===現在表示しているパターンを取得する
265
+ #返却値:: 現在表示しているスプライトのインスタンス
266
+ def get_pattern
267
+ return @plist[@pnum]
268
+ end
269
+
270
+ #===あとで書く
271
+ #_cnum_:: あとで書く
272
+ #返却値:: あとで書く
273
+ def character(cnum)
274
+ return self if cnum >= @chrs
275
+ @cnum = cnum
276
+ set_chr
277
+ return self
278
+ end
279
+
280
+ #===あとで書く
281
+ #_d_:: あとで書く
282
+ #返却値:: あとで書く
283
+ def move_character(d)
284
+ @cnum = (@cnum + d) % @chrs
285
+ @cnum = @cnum + @chrs if @cnum < 0
286
+ set_chr
287
+ return self
288
+ end
289
+
290
+ def get_character #:nodoc:
291
+ return @cnum
292
+ end
293
+
294
+ #===アニメーションを開始する
295
+ #パターンがリセットされていないときは、一時停止から復帰した時と同じ動作をする
296
+ #返却値:: 自分自身
297
+ def start
298
+ return self if @exec
299
+ set_pat
300
+ @now.move_to(@slist[@plist[@pnum]].x + @move_offset[@pnum][0],
301
+ @slist[@plist[@pnum]].y + @move_offset[@pnum][1])
302
+ if @dir == :h
303
+ @now.oy += @pos_offset[@pnum]
304
+ else
305
+ @now.ox += @pos_offset[@pnum]
306
+ end
307
+ @cnt = @waits[@plist[@pnum]]
308
+ @cnt.start if @cnt.kind_of?(WaitCounter)
309
+ @exec = true
310
+ return self
311
+ end
312
+
313
+ #===アニメーションを停止する
314
+ #停止しても、表示していたパターンはリセットされていない
315
+ #返却値:: 自分自身
316
+ def stop
317
+ return self unless @exec
318
+ if @dir == :h
319
+ @now.oy -= @pos_offset[@pnum]
320
+ else
321
+ @now.ox -= @pos_offset[@pnum]
322
+ end
323
+ @cnt.stop if @cnt.kind_of?(WaitCounter)
324
+ @exec = false
325
+ return self
326
+ end
327
+
328
+ #===アニメーションの開始・停止を切り替える
329
+ #返却値:: 自分自身
330
+ def toggle_exec
331
+ if @exec
332
+ stop
333
+ else
334
+ start
335
+ end
336
+ return self
337
+ end
338
+
339
+ #===アニメーションの更新を行う
340
+ #アニメーションのカウントをチェックし、カウントが終了したときは新しいパターンに切り替えて、カウントを開始する
341
+ #すべてのパターンのアニメーションが終了すれば、最初のパターンに戻り、カウントを開始する
342
+ #但し、インスタンス生成時に:loop->falseを設定していれば、アニメーションを終了する
343
+ #返却値:: アニメーションパターンが切り替わればtrue、切り替わらないとき、アニメーションが終了したときはfalseを返す
344
+ def update_animation
345
+ is_change = false
346
+ return is_change unless @exec
347
+ if @dir == :h
348
+ @now.oy -= @pos_offset[@pnum]
349
+ else
350
+ @now.ox -= @pos_offset[@pnum]
351
+ end
352
+ if @cnt.kind_of?(Integer)
353
+ is_change = update_frame
354
+ else
355
+ is_change = update_wait_counter
356
+ end
357
+ @now.move_to(@slist[@plist[@pnum]].x + @move_offset[@pnum][0],
358
+ @slist[@plist[@pnum]].y + @move_offset[@pnum][1])
359
+ if @dir == :h
360
+ @now.oy += @pos_offset[@pnum]
361
+ else
362
+ @now.ox += @pos_offset[@pnum]
363
+ end
364
+ return is_change
365
+ end
366
+
367
+ def update_frame #:nodoc:
368
+ if @cnt > 0
369
+ @cnt -= 1
370
+ return false
371
+ end
372
+ @pnum = (@pnum + 1) % @pats
373
+ if @loop == false && @pnum == 0
374
+ stop
375
+ return false
376
+ end
377
+ set_pat
378
+ @cnt = @waits[@plist[@pnum]]
379
+ return true
380
+ end
381
+
382
+ def update_wait_counter #:nodoc:
383
+ return false if @cnt.waiting?
384
+ @pnum = (@pnum + 1) % @pats
385
+ if @loop == false && @pnum == 0
386
+ stop
387
+ return false
388
+ end
389
+ set_pat
390
+ @cnt = @waits[@plist[@pnum]]
391
+ @cnt.start
392
+ return true
393
+ end
394
+
395
+ def set_pat #:nodoc:
396
+ @now = @units[@plist[@pnum]]
397
+ end
398
+
399
+ def set_chr #:nodoc:
400
+ @units.each{|u|
401
+ if @dir == :h
402
+ u.ox = @chr_olen * @cnum
403
+ else
404
+ u.oy = @chr_olen * @cnum
405
+ end
406
+ }
407
+ end
408
+
409
+ #===アニメーションのパターンをリセットする
410
+ #返却値:: 自分自身
411
+ def reset
412
+ @pnum = 0
413
+ @cnt = 0
414
+ return self
415
+ end
416
+
417
+ #===アニメーションが実行中かを返す
418
+ #返却値:: アニメーションが実行されていれば true
419
+ def exec?
420
+ return @exec
421
+ end
422
+
423
+ # 現在実行中のパターンの元になったスプライトユニットを返す
424
+ # 返却値:: 現在表示しているスプライトユニット
425
+ def to_unit
426
+ return @now.dup
427
+ end
428
+
429
+ # 現在実行中のパターンの画像を返す
430
+ # 返却値:: 現在表示している画像(bitmap)
431
+ def bitmap
432
+ return @now.bitmap
433
+ end
434
+
435
+ #===現在実行中のパターンの元になったインスタンスを返す
436
+ #取得するパターンは、元になったインスタンスのto_spriteメソッドを呼び出した時の値となる
437
+ # 返却値:: 現在表示しているスプライト
438
+ def to_sprite
439
+ return @slist[@plist[@pnum]].to_sprite
440
+ end
441
+
442
+ #===現在の画面の最大の大きさを矩形で取得する
443
+ #現在のパターンの大きさと同じため、rectメソッドの値と同一となる
444
+ #返却値:: 生成された矩形(Rect構造体のインスタンス)
445
+ def broad_rect
446
+ return self.rect
447
+ end
448
+
449
+ #===インスタンスに束縛されているオブジェクトを解放する
450
+ def dispose
451
+ @slist.clear
452
+ @units.each{|u| u.bitmap = nil}
453
+ @units.clear
454
+ @waits.clear
455
+ @plist.clear
456
+ @move_offset.clear
457
+ @pos_offset.clear
458
+ end
459
+ end
460
+ end
461
+
@@ -0,0 +1,113 @@
1
+ # -*- encoding: utf-8 -*-
2
+ =begin
3
+ --
4
+ Miyako v2.0
5
+ Copyright (C) 2007-2008 Cyross Makoto
6
+
7
+ This library is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU Lesser General Public
9
+ License as published by the Free Software Foundation; either
10
+ version 2.1 of the License, or (at your option) any later version.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public
18
+ License along with this library; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ ++
21
+ =end
22
+
23
+ # スプライト関連クラス群
24
+ module Miyako
25
+ #==SpriteUnitを生成するための構造体クラス
26
+ #Structクラスからの継承
27
+ #--
28
+ #SpriteUnit = Struct.new([:dp], :bitmap, :ox, :oy, :ow, :oh, :x, :y, :dx, :dy, [:effect], [:viewport], :angle, :xscale, :yscale, :px, :py, :qx, :qy)
29
+ #++
30
+ class SpriteUnitBase < Struct
31
+ #===位置を変更する(変化量を指定)
32
+ #_dx_:: 移動量(x方向)。単位はピクセル
33
+ #_dy_:: 移動量(y方向)。単位はピクセル
34
+ #返却値:: 自分自身を返す
35
+ def move(dx, dy)
36
+ self.x+=dx
37
+ self.y+=dy
38
+ return self
39
+ end
40
+
41
+ #===位置を変更する(位置指定)
42
+ #_x_:: 移動先位置(x方向)。単位はピクセル
43
+ #_y_:: 移動先位置(y方向)。単位はピクセル
44
+ #返却値:: 自分自身を返す
45
+ def move_to(x, y)
46
+ self.x=x
47
+ self.y=y
48
+ return self
49
+ end
50
+
51
+ #===自分自身を返す
52
+ #SpriteUnit対応
53
+ #ダックタイピング用のメソッド
54
+ #返却値:: 自分自身(複製して返す)
55
+ def to_unit
56
+ return self.dup
57
+ end
58
+
59
+ #===画像の表示矩形を取得する
60
+ #画像が表示されているときの矩形を取得する。矩形は、[x,y,ow,oh]で取得する。
61
+ #返却値:: 生成された矩形
62
+ def rect
63
+ return Rect.new(self.x, self.y, self.ow, self.oh)
64
+ end
65
+
66
+ #===現在の画面の最大の大きさを矩形で取得する
67
+ #但し、SpriteUnitの場合は最大の大きさ=画像の大きさなので、rectと同じ値が得られる
68
+ #返却値:: 画像の大きさ(Rect構造体のインスタンス)
69
+ def broad_rect
70
+ return self.rect
71
+ end
72
+ end
73
+
74
+ #==スプライト出力情報構造体
75
+ #基本的なことは、Sprite.renderで行うことが出来るが、凝った処理を行う場合は、SpriteUnitを使う
76
+ #--
77
+ #SpriteUnit = Struct.new([:dp], :bitmap, :ox, :oy, :ow, :oh, :x, :y, [:effect], [:viewport], :angle, :xscale, :yscale, :cx, :cy)
78
+ #++
79
+ #([数字])は、配列として認識したときのインデックス番号に対応(Struct#[]メソッドを呼び出した時のインデックス)
80
+ #:bitmap([0]) -> 画像データ(SDL::Surfaceクラスのインスタンス)
81
+ #:ox([1]) -> 描画開始位置(x方向)
82
+ #:oy([2]) -> 描画開始位置(y方向)
83
+ #:ow([3]) -> 描画幅
84
+ #:oh([4]) -> 描画高さ
85
+ #:x([5]) -> 描画幅
86
+ #:y([6]) -> 描画高さ
87
+ #:angle([7]) -> 回転角度(ラジアン単位)
88
+ #:xscale([8]) -> X方向拡大・縮小・鏡像の割合(実数。変換後の幅が32768を切る様にすること)
89
+ #:yscale([9]) -> Y方向拡大・縮小・鏡像の割合(実数。変換後の幅が32768を切る様にすること)
90
+ #:cx([10]) -> 回転・拡大・縮小・鏡像の中心座標(x方向)
91
+ #:cy([11]) -> 回転・拡大・縮小・鏡像の中心座標(y方向)
92
+ SpriteUnit = SpriteUnitBase.new(:bitmap, :ox, :oy, :ow, :oh, :x, :y, :angle, :xscale, :yscale, :cx, :cy)
93
+
94
+ #==SpriteUnit生成ファクトリクラス
95
+ #SpriteUnit構造体のインスタンスを生成するためのクラス
96
+ class SpriteUnitFactory
97
+ PARAMS = [:bitmap, :ox, :oy, :ow, :oh, :x, :y, :angle, :xscale, :yscale, :cx, :cy]
98
+ #==SpriteUnitのインスタンスを生成する
99
+ #params: 初期化するSpriteUnit構造体の値。ハッシュ引数。引数のキーは、SpriteUnitのアクセサ名と同一。省略可能
100
+ def SpriteUnitFactory.create(params = nil)
101
+ unit = SpriteUnit.new(nil, 0, 0, 0, 0, 0, 0, 0, 1.0, 1.0, 0, 0)
102
+ return SpriteUnitFactory.apply(unit, params)
103
+ end
104
+
105
+ #==SpriteUnitの各アクセサに対応した値を設定する
106
+ #unit: 設定対象のSpriteUnit構造体
107
+ #params: 設定するSpriteUnit構造体の値。ハッシュ引数。引数のキーは、SpriteUnitのアクセサ名と同一
108
+ def SpriteUnitFactory.apply(unit, params)
109
+ PARAMS.each{|prm| unit[prm] = params[prm] if params.has_key?(prm) } if params
110
+ return unit
111
+ end
112
+ end
113
+ end