ruby-miyako 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/README +1115 -0
  2. data/Rakefile +7 -0
  3. data/defines.h +144 -0
  4. data/extconf.rb +44 -0
  5. data/extern.h +29 -0
  6. data/img/cursor.png +0 -0
  7. data/img/cursors.png +0 -0
  8. data/img/dice.png +0 -0
  9. data/img/wait_cursor.png +0 -0
  10. data/img/win_base.png +0 -0
  11. data/img/window.png +0 -0
  12. data/install_miyako.rb +87 -0
  13. data/lib/Miyako/API/audio.rb +584 -0
  14. data/lib/Miyako/API/basic_data.rb +1026 -0
  15. data/lib/Miyako/API/bitmap.rb +534 -0
  16. data/lib/Miyako/API/choices.rb +481 -0
  17. data/lib/Miyako/API/collision.rb +638 -0
  18. data/lib/Miyako/API/diagram.rb +586 -0
  19. data/lib/Miyako/API/drawing.rb +151 -0
  20. data/lib/Miyako/API/exceptions.rb +105 -0
  21. data/lib/Miyako/API/fixedmap.rb +462 -0
  22. data/lib/Miyako/API/font.rb +430 -0
  23. data/lib/Miyako/API/input.rb +456 -0
  24. data/lib/Miyako/API/layout.rb +644 -0
  25. data/lib/Miyako/API/map.rb +583 -0
  26. data/lib/Miyako/API/map_event.rb +222 -0
  27. data/lib/Miyako/API/modules.rb +357 -0
  28. data/lib/Miyako/API/movie.rb +166 -0
  29. data/lib/Miyako/API/parts.rb +188 -0
  30. data/lib/Miyako/API/plane.rb +205 -0
  31. data/lib/Miyako/API/screen.rb +341 -0
  32. data/lib/Miyako/API/shape.rb +443 -0
  33. data/lib/Miyako/API/sprite.rb +773 -0
  34. data/lib/Miyako/API/sprite_animation.rb +494 -0
  35. data/lib/Miyako/API/sprite_list.rb +1135 -0
  36. data/lib/Miyako/API/spriteunit.rb +168 -0
  37. data/lib/Miyako/API/story.rb +350 -0
  38. data/lib/Miyako/API/textbox.rb +773 -0
  39. data/lib/Miyako/API/utility.rb +419 -0
  40. data/lib/Miyako/API/viewport.rb +190 -0
  41. data/lib/Miyako/API/yuki.rb +1180 -0
  42. data/lib/Miyako/EXT/miyako_cairo.rb +62 -0
  43. data/lib/Miyako/EXT/raster_scroll.rb +138 -0
  44. data/lib/Miyako/EXT/slides.rb +157 -0
  45. data/lib/Miyako/miyako.rb +201 -0
  46. data/lib/Miyako/miyako_require_only.rb +35 -0
  47. data/logo/EGSR_logo.png +0 -0
  48. data/logo/EGSR_logo_bg.png +0 -0
  49. data/logo/EGSR_logo_fg.png +0 -0
  50. data/logo/EGSR_title_banner.png +0 -0
  51. data/logo/EGSR_title_logo.png +0 -0
  52. data/logo/miyako.png +0 -0
  53. data/logo/miyako_banner.png +0 -0
  54. data/logo/space.png +0 -0
  55. data/miyako_basicdata.c +484 -0
  56. data/miyako_bitmap.c +1225 -0
  57. data/miyako_collision.c +403 -0
  58. data/miyako_drawing.c +187 -0
  59. data/miyako_font.c +334 -0
  60. data/miyako_hsv.c +830 -0
  61. data/miyako_input_audio.c +254 -0
  62. data/miyako_layout.c +191 -0
  63. data/miyako_no_katana.c +1086 -0
  64. data/miyako_sprite2.c +431 -0
  65. data/miyako_transform.c +438 -0
  66. data/miyako_utility.c +288 -0
  67. data/sample/Animation1/m1ku.rb +68 -0
  68. data/sample/Animation1/m1ku_arm_0.png +0 -0
  69. data/sample/Animation1/m1ku_arm_1.png +0 -0
  70. data/sample/Animation1/m1ku_arm_2.png +0 -0
  71. data/sample/Animation1/m1ku_arm_3.png +0 -0
  72. data/sample/Animation1/m1ku_back.jpg +0 -0
  73. data/sample/Animation1/m1ku_body.png +0 -0
  74. data/sample/Animation1/m1ku_eye_0.png +0 -0
  75. data/sample/Animation1/m1ku_eye_1.png +0 -0
  76. data/sample/Animation1/m1ku_eye_2.png +0 -0
  77. data/sample/Animation1/m1ku_eye_3.png +0 -0
  78. data/sample/Animation1/m1ku_hair_front.png +0 -0
  79. data/sample/Animation1/m1ku_hair_rear.png +0 -0
  80. data/sample/Animation1/readme.txt +72 -0
  81. data/sample/Animation2/lex.rb +96 -0
  82. data/sample/Animation2/lex_back.png +0 -0
  83. data/sample/Animation2/lex_body.png +0 -0
  84. data/sample/Animation2/lex_roadroller.png +0 -0
  85. data/sample/Animation2/lex_wheel_0.png +0 -0
  86. data/sample/Animation2/lex_wheel_1.png +0 -0
  87. data/sample/Animation2/lex_wheel_2.png +0 -0
  88. data/sample/Animation2/readme.txt +72 -0
  89. data/sample/Animation2/song_title.png +0 -0
  90. data/sample/Diagram_sample/back.png +0 -0
  91. data/sample/Diagram_sample/chr01.png +0 -0
  92. data/sample/Diagram_sample/chr02.png +0 -0
  93. data/sample/Diagram_sample/cursor.png +0 -0
  94. data/sample/Diagram_sample/diagram_sample_yuki2.rb +329 -0
  95. data/sample/Diagram_sample/readme.txt +90 -0
  96. data/sample/Diagram_sample/wait_cursor.png +0 -0
  97. data/sample/Room3/blue.rb +297 -0
  98. data/sample/Room3/ending.rb +180 -0
  99. data/sample/Room3/green.rb +220 -0
  100. data/sample/Room3/image/akamatsu.png +0 -0
  101. data/sample/Room3/image/aoyama.png +0 -0
  102. data/sample/Room3/image/congra.png +0 -0
  103. data/sample/Room3/image/congratulation.png +0 -0
  104. data/sample/Room3/image/congratulation_bg.png +0 -0
  105. data/sample/Room3/image/cursor.png +0 -0
  106. data/sample/Room3/image/midori.png +0 -0
  107. data/sample/Room3/image/mittsu_no_oheya.png +0 -0
  108. data/sample/Room3/image/mittsu_no_oheya_logo.png +0 -0
  109. data/sample/Room3/image/room_blue.png +0 -0
  110. data/sample/Room3/image/room_green.png +0 -0
  111. data/sample/Room3/image/room_red.png +0 -0
  112. data/sample/Room3/image/start.png +0 -0
  113. data/sample/Room3/image/three_doors.png +0 -0
  114. data/sample/Room3/image/wait_cursor.png +0 -0
  115. data/sample/Room3/main.rb +120 -0
  116. data/sample/Room3/main_component.rb +59 -0
  117. data/sample/Room3/readme.txt +76 -0
  118. data/sample/Room3/red.rb +227 -0
  119. data/sample/Room3/room3.rb +25 -0
  120. data/sample/Room3/title.rb +184 -0
  121. data/sample/ball_action_sample.rb +204 -0
  122. data/sample/blit_rop.rb +70 -0
  123. data/sample/cairo_sample.rb +25 -0
  124. data/sample/circle_collision_test.rb +66 -0
  125. data/sample/collision_test.rb +33 -0
  126. data/sample/collision_test2.rb +108 -0
  127. data/sample/fixed_map_test/cursor.png +0 -0
  128. data/sample/fixed_map_test/fixed_map_sample.rb +140 -0
  129. data/sample/fixed_map_test/map.csv +19 -0
  130. data/sample/fixed_map_test/map_01.png +0 -0
  131. data/sample/fixed_map_test/mapchip.csv +23 -0
  132. data/sample/fixed_map_test/monster.png +0 -0
  133. data/sample/fixed_map_test/readme.txt +72 -0
  134. data/sample/map_test/chara.rb +58 -0
  135. data/sample/map_test/chr1.png +0 -0
  136. data/sample/map_test/cursor.png +0 -0
  137. data/sample/map_test/main_parts.rb +69 -0
  138. data/sample/map_test/main_scene.rb +153 -0
  139. data/sample/map_test/map.png +0 -0
  140. data/sample/map_test/map2.png +0 -0
  141. data/sample/map_test/map_layer.csv +127 -0
  142. data/sample/map_test/map_manager.rb +75 -0
  143. data/sample/map_test/map_test.rb +23 -0
  144. data/sample/map_test/mapchip.csv +21 -0
  145. data/sample/map_test/oasis.rb +71 -0
  146. data/sample/map_test/readme.txt +89 -0
  147. data/sample/map_test/route.rb +157 -0
  148. data/sample/map_test/sea.png +0 -0
  149. data/sample/map_test/town.rb +74 -0
  150. data/sample/map_test/wait_cursor.png +0 -0
  151. data/sample/map_test/window.png +0 -0
  152. data/sample/polygon_test.rb +35 -0
  153. data/sample/rasterscroll.rb +25 -0
  154. data/sample/takahashi.rb +42 -0
  155. data/sample/text.png +0 -0
  156. data/sample/textbox_sample.rb +192 -0
  157. data/sample/transform.rb +54 -0
  158. data/sample/utility_test.rb +73 -0
  159. data/sample/utility_test2.rb +61 -0
  160. data/sample/utility_test3.rb +64 -0
  161. data/sample/utility_test4.rb +73 -0
  162. data/uninstall_miyako.rb +19 -0
  163. data/win/miyako_no_katana.so +0 -0
  164. metadata +216 -0
@@ -0,0 +1,403 @@
1
+ /*
2
+ --
3
+ Miyako v2.0 Extend Library "Miyako no Katana"
4
+ Copyright (C) 2008 Cyross Makoto
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ ++
20
+ */
21
+
22
+ /*
23
+ =拡張ライブラリmiyako_no_katana
24
+ Authors:: サイロス誠
25
+ Version:: 2.0
26
+ Copyright:: 2007-2009 Cyross Makoto
27
+ License:: LGPL2.1
28
+ */
29
+ #include "defines.h"
30
+
31
+ static VALUE mSDL = Qnil;
32
+ static VALUE mMiyako = Qnil;
33
+ static VALUE eMiyakoError = Qnil;
34
+ static VALUE cCollision = Qnil;
35
+ static VALUE cCircleCollision = Qnil;
36
+ static VALUE cCollisions = Qnil;
37
+ static VALUE nZero = Qnil;
38
+ static VALUE nOne = Qnil;
39
+ static volatile ID id_update = Qnil;
40
+ static volatile ID id_kakko = Qnil;
41
+ static volatile ID id_render = Qnil;
42
+ static volatile ID id_to_a = Qnil;
43
+ static volatile int zero = Qnil;
44
+ static volatile int one = Qnil;
45
+
46
+ /*
47
+ :nodoc:
48
+ */
49
+ static VALUE collision_get_position(VALUE pos, VALUE *x, VALUE *y)
50
+ {
51
+ VALUE *tmp;
52
+ switch(TYPE(pos))
53
+ {
54
+ case T_ARRAY:
55
+ if(RARRAY_LEN(pos) < 2)
56
+ rb_raise(eMiyakoError, "pairs have illegal array!");
57
+ tmp = RARRAY_PTR(pos);
58
+ *x = *tmp++;
59
+ *y = *tmp;
60
+ break;
61
+ case T_STRUCT:
62
+ if(RSTRUCT_LEN(pos) < 2)
63
+ rb_raise(eMiyakoError, "pairs have illegal struct!");
64
+ tmp = RSTRUCT_PTR(pos);
65
+ *x = *tmp++;
66
+ *y = *tmp;
67
+ break;
68
+ default:
69
+ *x = rb_funcall(pos, rb_intern("x"), 0);
70
+ *y = rb_funcall(pos, rb_intern("y"), 0);
71
+ break;
72
+ }
73
+ return Qnil;
74
+ }
75
+
76
+ /*
77
+ :nodoc:
78
+ */
79
+ static VALUE collision_c_collision(VALUE self, VALUE c1, VALUE pos1, VALUE c2, VALUE pos2)
80
+ {
81
+ VALUE *prect1 = RSTRUCT_PTR(rb_iv_get(c1, "@rect"));
82
+ VALUE *prect2 = RSTRUCT_PTR(rb_iv_get(c2, "@rect"));
83
+ VALUE x1, y1, x2, y2;
84
+ collision_get_position(pos1, &x1, &y1);
85
+ collision_get_position(pos2, &x2, &y2);
86
+ double l1 = NUM2DBL(x1) + NUM2DBL(*prect1);
87
+ double t1 = NUM2DBL(y1) + NUM2DBL(*(prect1+1));
88
+ double r1 = l1 + NUM2DBL(*(prect1+2)) - 1;
89
+ double b1 = t1 + NUM2DBL(*(prect1+3)) - 1;
90
+ double l2 = NUM2DBL(x2) + NUM2DBL(*prect2);
91
+ double t2 = NUM2DBL(y2) + NUM2DBL(*(prect2+1));
92
+ double r2 = l2 + NUM2DBL(*(prect2+2)) - 1;
93
+ double b2 = t2 + NUM2DBL(*(prect2+3)) - 1;
94
+
95
+ if(l1 <= l2 && l2 <= r1 && t1 <= t2 && t2 <= b1) return Qtrue;
96
+ if(l1 <= r2 && r2 <= r1 && t1 <= b2 && b2 <= b1) return Qtrue;
97
+ if(l2 <= l1 && l1 <= r2 && t2 <= t1 && t1 <= b2) return Qtrue;
98
+ if(l2 <= r1 && r1 <= r2 && t2 <= b1 && b1 <= b2) return Qtrue;
99
+ return Qfalse;
100
+ }
101
+
102
+ /*
103
+ :nodoc:
104
+ */
105
+ static VALUE collision_c_meet(VALUE self, VALUE c1, VALUE pos1, VALUE c2, VALUE pos2)
106
+ {
107
+ VALUE *prect1 = RSTRUCT_PTR(rb_iv_get(c1, "@rect"));
108
+ VALUE *prect2 = RSTRUCT_PTR(rb_iv_get(c2, "@rect"));
109
+ VALUE x1, y1, x2, y2;
110
+ collision_get_position(pos1, &x1, &y1);
111
+ collision_get_position(pos2, &x2, &y2);
112
+ double l1 = NUM2DBL(x1) + NUM2DBL(*prect1);
113
+ double t1 = NUM2DBL(y1) + NUM2DBL(*(prect1+1));
114
+ double r1 = l1 + NUM2DBL(*(prect1+2)) - 1;
115
+ double b1 = t1 + NUM2DBL(*(prect1+3)) - 1;
116
+ double l2 = NUM2DBL(x2) + NUM2DBL(*prect2);
117
+ double t2 = NUM2DBL(y2) + NUM2DBL(*(prect2+1));
118
+ double r2 = l2 + NUM2DBL(*(prect2+2)) - 1;
119
+ double b2 = t2 + NUM2DBL(*(prect2+3)) - 1;
120
+
121
+ if(r1 == l2 || b1 == t2 || l1 == r2 || t1 == b2) return Qtrue;
122
+ return Qfalse;
123
+ }
124
+
125
+ /*
126
+ :nodoc:
127
+ */
128
+ static VALUE collision_c_cover(VALUE self, VALUE c1, VALUE pos1, VALUE c2, VALUE pos2)
129
+ {
130
+ VALUE *prect1 = RSTRUCT_PTR(rb_iv_get(c1, "@rect"));
131
+ VALUE *prect2 = RSTRUCT_PTR(rb_iv_get(c2, "@rect"));
132
+ VALUE x1, y1, x2, y2;
133
+ collision_get_position(pos1, &x1, &y1);
134
+ collision_get_position(pos2, &x2, &y2);
135
+ double l1 = NUM2DBL(x1) + NUM2DBL(*prect1);
136
+ double t1 = NUM2DBL(y1) + NUM2DBL(*(prect1+1));
137
+ double r1 = l1 + NUM2DBL(*(prect1+2)) - 1;
138
+ double b1 = t1 + NUM2DBL(*(prect1+3)) - 1;
139
+ double l2 = NUM2DBL(x2) + NUM2DBL(*prect2);
140
+ double t2 = NUM2DBL(y2) + NUM2DBL(*(prect2+1));
141
+ double r2 = l2 + NUM2DBL(*(prect2+2)) - 1;
142
+ double b2 = t2 + NUM2DBL(*(prect2+3)) - 1;
143
+
144
+ if(l1 >= l2 && r1 <= r2 && t1 >= t2 && b1 <= b2) return Qtrue;
145
+ if(l1 <= l2 && r1 >= r2 && t1 <= t2 && b1 >= b2) return Qtrue;
146
+ if(l2 >= l1 && r2 <= r1 && t2 >= t1 && b2 <= b1) return Qtrue;
147
+ if(l2 <= l1 && r2 >= r1 && t2 <= t1 && b2 >= b1) return Qtrue;
148
+ return Qfalse;
149
+ }
150
+
151
+ /*
152
+ :nodoc:
153
+ */
154
+ static VALUE collision_collision(VALUE self, VALUE pos1, VALUE c2, VALUE pos2)
155
+ {
156
+ return collision_c_collision(cCollision, self, pos1, c2, pos2);
157
+ }
158
+
159
+ /*
160
+ :nodoc:
161
+ */
162
+ static VALUE collision_meet(VALUE self, VALUE pos1, VALUE c2, VALUE pos2)
163
+ {
164
+ return collision_c_meet(cCollision, self, pos1, c2, pos2);
165
+ }
166
+
167
+ /*
168
+ :nodoc:
169
+ */
170
+ static VALUE collision_cover(VALUE self, VALUE pos1, VALUE c2, VALUE pos2)
171
+ {
172
+ return collision_c_cover(cCollision, self, pos1, c2, pos2);
173
+ }
174
+
175
+ /*
176
+ :nodoc:
177
+ */
178
+ static VALUE circlecollision_c_collision(VALUE self, VALUE c1, VALUE pos1, VALUE c2, VALUE pos2)
179
+ {
180
+ VALUE *pcenter1 = RSTRUCT_PTR(rb_iv_get(c1, "@center"));
181
+ VALUE *pcenter2 = RSTRUCT_PTR(rb_iv_get(c2, "@center"));
182
+ double r1 = NUM2DBL(rb_iv_get(c1, "@radius"));
183
+ double r2 = NUM2DBL(rb_iv_get(c2, "@radius"));
184
+ double r = (r1 + r2) * (r1 + r2);
185
+ VALUE x1, y1, x2, y2;
186
+ collision_get_position(pos1, &x1, &y1);
187
+ collision_get_position(pos2, &x2, &y2);
188
+ double cx1 = NUM2DBL(x1) + NUM2DBL(*pcenter1);
189
+ double cy1 = NUM2DBL(y1) + NUM2DBL(*(pcenter1+1));
190
+ double cx2 = NUM2DBL(x2) + NUM2DBL(*pcenter2);
191
+ double cy2 = NUM2DBL(y2) + NUM2DBL(*(pcenter2+1));
192
+ double d = (cx1-cx2) * (cx1-cx2) + (cy1-cy2) * (cy1-cy2);
193
+
194
+ if(d <= r) return Qtrue;
195
+ return Qfalse;
196
+ }
197
+
198
+ /*
199
+ :nodoc:
200
+ */
201
+ static VALUE circlecollision_c_meet(VALUE self, VALUE c1, VALUE pos1, VALUE c2, VALUE pos2)
202
+ {
203
+ VALUE *pcenter1 = RSTRUCT_PTR(rb_iv_get(c1, "@center"));
204
+ VALUE *pcenter2 = RSTRUCT_PTR(rb_iv_get(c2, "@center"));
205
+ double r1 = NUM2DBL(rb_iv_get(c1, "@radius"));
206
+ double r2 = NUM2DBL(rb_iv_get(c2, "@radius"));
207
+ double r = (r1 + r2) * (r1 + r2);
208
+ VALUE x1, y1, x2, y2;
209
+ collision_get_position(pos1, &x1, &y1);
210
+ collision_get_position(pos2, &x2, &y2);
211
+ double cx1 = NUM2DBL(x1) + NUM2DBL(*pcenter1);
212
+ double cy1 = NUM2DBL(y1) + NUM2DBL(*(pcenter1+1));
213
+ double cx2 = NUM2DBL(x2) + NUM2DBL(*pcenter2);
214
+ double cy2 = NUM2DBL(y2) + NUM2DBL(*(pcenter2+1));
215
+ double d = (cx1-cx2) * (cx1-cx2) + (cy1-cy2) * (cy1-cy2);
216
+
217
+ if(d == r) return Qtrue;
218
+ return Qfalse;
219
+ }
220
+
221
+ /*
222
+ :nodoc:
223
+ */
224
+ static VALUE circlecollision_c_cover(VALUE self, VALUE c1, VALUE pos1, VALUE c2, VALUE pos2)
225
+ {
226
+ VALUE *pcenter1 = RSTRUCT_PTR(rb_iv_get(c1, "@center"));
227
+ VALUE *pcenter2 = RSTRUCT_PTR(rb_iv_get(c2, "@center"));
228
+ double r1 = NUM2DBL(rb_iv_get(c1, "@radius"));
229
+ double r2 = NUM2DBL(rb_iv_get(c2, "@radius"));
230
+ double r = (r1 - r2) * (r1 - r2); // y = (x-a)^2 -> y = x^2 - 2ax + a^2
231
+ VALUE x1, y1, x2, y2;
232
+ collision_get_position(pos1, &x1, &y1);
233
+ collision_get_position(pos2, &x2, &y2);
234
+ double cx1 = NUM2DBL(x1) + NUM2DBL(*pcenter1);
235
+ double cy1 = NUM2DBL(y1) + NUM2DBL(*(pcenter1+1));
236
+ double cx2 = NUM2DBL(x2) + NUM2DBL(*pcenter2);
237
+ double cy2 = NUM2DBL(y2) + NUM2DBL(*(pcenter2+1));
238
+ double d = (cx1-cx2) * (cx1-cx2) + (cy1-cy2) * (cy1-cy2);
239
+
240
+ if(d <= r) return Qtrue;
241
+ return Qfalse;
242
+ }
243
+
244
+ /*
245
+ :nodoc:
246
+ */
247
+ static VALUE circlecollision_collision(VALUE self, VALUE pos1, VALUE c2, VALUE pos2)
248
+ {
249
+ return circlecollision_c_collision(cCircleCollision, self, pos1, c2, pos2);
250
+ }
251
+
252
+ /*
253
+ :nodoc:
254
+ */
255
+ static VALUE circlecollision_meet(VALUE self, VALUE pos1, VALUE c2, VALUE pos2)
256
+ {
257
+ return circlecollision_c_meet(cCircleCollision, self, pos1, c2, pos2);
258
+ }
259
+
260
+ /*
261
+ :nodoc:
262
+ */
263
+ static VALUE circlecollision_cover(VALUE self, VALUE pos1, VALUE c2, VALUE pos2)
264
+ {
265
+ return circlecollision_c_cover(cCircleCollision, self, pos1, c2, pos2);
266
+ }
267
+
268
+ /*
269
+ :nodoc:
270
+ */
271
+ static VALUE collisions_collision(VALUE self, VALUE c, VALUE pos)
272
+ {
273
+ VALUE collisions = rb_iv_get(self, "@collisions");
274
+ int i=0;
275
+ for(i=0; i<RARRAY_LEN(collisions); i++){
276
+ VALUE cs = *(RARRAY_PTR(collisions) + i);
277
+ VALUE *cc = RARRAY_PTR(cs);
278
+ if(collision_collision(c, pos, *cc, *(cc+1)) == Qtrue){ return cs; }
279
+ }
280
+ return Qnil;
281
+ }
282
+
283
+ /*
284
+ :nodoc:
285
+ */
286
+ static VALUE collisions_meet(VALUE self, VALUE c, VALUE pos)
287
+ {
288
+ VALUE collisions = rb_iv_get(self, "@collisions");
289
+ int i=0;
290
+ for(i=0; i<RARRAY_LEN(collisions); i++){
291
+ VALUE cs = *(RARRAY_PTR(collisions) + i);
292
+ VALUE *cc = RARRAY_PTR(cs);
293
+ if(collision_meet(c, pos, *cc, *(cc+1)) == Qtrue){ return cs; }
294
+ }
295
+ return Qnil;
296
+ }
297
+
298
+ /*
299
+ :nodoc:
300
+ */
301
+ static VALUE collisions_cover(VALUE self, VALUE c, VALUE pos)
302
+ {
303
+ VALUE collisions = rb_iv_get(self, "@collisions");
304
+ int i=0;
305
+ for(i=0; i<RARRAY_LEN(collisions); i++){
306
+ VALUE cs = *(RARRAY_PTR(collisions) + i);
307
+ VALUE *cc = RARRAY_PTR(cs);
308
+ if(collision_cover(c, pos, *cc, *(cc+1)) == Qtrue){ return cs; }
309
+ }
310
+ return Qnil;
311
+ }
312
+
313
+ /*
314
+ :nodoc:
315
+ */
316
+ static VALUE collisions_collision_all(VALUE self, VALUE c, VALUE pos)
317
+ {
318
+ VALUE collisions = rb_iv_get(self, "@collisions");
319
+ VALUE ret = rb_ary_new();
320
+ int i=0;
321
+ for(i=0; i<RARRAY_LEN(collisions); i++){
322
+ VALUE cs = *(RARRAY_PTR(collisions) + i);
323
+ VALUE *cc = RARRAY_PTR(cs);
324
+ if(collision_collision(c, pos, *cc, *(cc+1)) == Qtrue){ rb_ary_push(ret, cs); }
325
+ }
326
+ if(RARRAY_LEN(ret) == 0){ return Qnil; }
327
+ return ret;
328
+ }
329
+
330
+ /*
331
+ :nodoc:
332
+ */
333
+ static VALUE collisions_meet_all(VALUE self, VALUE c, VALUE pos)
334
+ {
335
+ VALUE collisions = rb_iv_get(self, "@collisions");
336
+ VALUE ret = rb_ary_new();
337
+ int i=0;
338
+ for(i=0; i<RARRAY_LEN(collisions); i++){
339
+ VALUE cs = *(RARRAY_PTR(collisions) + i);
340
+ VALUE *cc = RARRAY_PTR(cs);
341
+ if(collision_meet(c, pos, *cc, *(cc+1)) == Qtrue){ rb_ary_push(ret, cs); }
342
+ }
343
+ if(RARRAY_LEN(ret) == 0){ return Qnil; }
344
+ return ret;
345
+ }
346
+
347
+ /*
348
+ :nodoc:
349
+ */
350
+ static VALUE collisions_cover_all(VALUE self, VALUE c, VALUE pos)
351
+ {
352
+ VALUE collisions = rb_iv_get(self, "@collisions");
353
+ VALUE ret = rb_ary_new();
354
+ int i=0;
355
+ for(i=0; i<RARRAY_LEN(collisions); i++){
356
+ VALUE cs = *(RARRAY_PTR(collisions) + i);
357
+ VALUE *cc = RARRAY_PTR(cs);
358
+ if(collision_cover(c, pos, *cc, *(cc+1)) == Qtrue){ rb_ary_push(ret, cs); }
359
+ }
360
+ if(RARRAY_LEN(ret) == 0){ return Qnil; }
361
+ return ret;
362
+ }
363
+
364
+ void Init_miyako_collision()
365
+ {
366
+ mSDL = rb_define_module("SDL");
367
+ mMiyako = rb_define_module("Miyako");
368
+ eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
369
+ cCollision = rb_define_class_under(mMiyako, "Collision", rb_cObject);
370
+ cCircleCollision = rb_define_class_under(mMiyako, "CircleCollision", rb_cObject);
371
+ cCollisions = rb_define_class_under(mMiyako, "Collisions", rb_cObject);
372
+
373
+ id_update = rb_intern("update");
374
+ id_kakko = rb_intern("[]");
375
+ id_render = rb_intern("render");
376
+ id_to_a = rb_intern("to_a");
377
+
378
+ zero = 0;
379
+ nZero = INT2NUM(zero);
380
+ one = 1;
381
+ nOne = INT2NUM(one);
382
+
383
+ rb_define_singleton_method(cCollision, "collision?", collision_c_collision, 4);
384
+ rb_define_singleton_method(cCollision, "meet?", collision_c_meet, 4);
385
+ rb_define_singleton_method(cCollision, "cover?", collision_c_cover, 4);
386
+ rb_define_method(cCollision, "collision?", collision_collision, 3);
387
+ rb_define_method(cCollision, "meet?", collision_meet, 3);
388
+ rb_define_method(cCollision, "cover?", collision_cover, 3);
389
+
390
+ rb_define_singleton_method(cCircleCollision, "collision?", circlecollision_c_collision, 4);
391
+ rb_define_singleton_method(cCircleCollision, "meet?", circlecollision_c_meet, 4);
392
+ rb_define_singleton_method(cCircleCollision, "cover?", circlecollision_c_cover, 4);
393
+ rb_define_method(cCircleCollision, "collision?", circlecollision_collision, 3);
394
+ rb_define_method(cCircleCollision, "meet?", circlecollision_meet, 3);
395
+ rb_define_method(cCircleCollision, "cover?", circlecollision_cover, 3);
396
+
397
+ rb_define_method(cCollisions, "collision?", collisions_collision, 2);
398
+ rb_define_method(cCollisions, "meet?", collisions_meet, 2);
399
+ rb_define_method(cCollisions, "cover?", collisions_cover, 2);
400
+ rb_define_method(cCollisions, "collision_all?", collisions_collision_all, 2);
401
+ rb_define_method(cCollisions, "meet_all?", collisions_meet_all, 2);
402
+ rb_define_method(cCollisions, "cover_all?", collisions_cover_all, 2);
403
+ }
data/miyako_drawing.c ADDED
@@ -0,0 +1,187 @@
1
+ /*
2
+ --
3
+ Miyako v2.0 Extend Library "Miyako no Katana"
4
+ Copyright (C) 2008 Cyross Makoto
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ ++
20
+ */
21
+
22
+ /*
23
+ =拡張ライブラリmiyako_no_katana
24
+ Authors:: サイロス誠
25
+ Version:: 2.0
26
+ Copyright:: 2007-2008 Cyross Makoto
27
+ License:: LGPL2.1
28
+ */
29
+ #include "defines.h"
30
+ #include "extern.h"
31
+ #include <sge.h>
32
+
33
+ static VALUE mSDL = Qnil;
34
+ static VALUE mMiyako = Qnil;
35
+ static VALUE mScreen = Qnil;
36
+ static VALUE mDrawing = Qnil;
37
+ static VALUE eMiyakoError = Qnil;
38
+ static VALUE cSurface = Qnil;
39
+ static VALUE cColor = Qnil;
40
+
41
+ // from rubysdl_video.c
42
+ static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
43
+
44
+ static Uint32 value_2_color(VALUE color, SDL_PixelFormat *fmt, Uint8 *alpha)
45
+ {
46
+ VALUE *array = RARRAY_PTR(color);
47
+ if(alpha != NULL){ *alpha = (Uint8)(NUM2INT(*(array+3))); }
48
+ return SDL_MapRGBA(fmt,
49
+ (Uint8)(NUM2INT(*(array+0))),
50
+ (Uint8)(NUM2INT(*(array+1))),
51
+ (Uint8)(NUM2INT(*(array+2))),
52
+ (Uint8)(NUM2INT(*(array+3)))
53
+ );
54
+ }
55
+
56
+ /*
57
+ :nodoc:
58
+ */
59
+ static void get_position(VALUE pos, Sint16 *x, Sint16 *y)
60
+ {
61
+ VALUE *tmp;
62
+ switch(TYPE(pos))
63
+ {
64
+ case T_ARRAY:
65
+ if(RARRAY_LEN(pos) < 2)
66
+ rb_raise(eMiyakoError, "pairs have illegal array!");
67
+ tmp = RARRAY_PTR(pos);
68
+ *x = (Sint16)(NUM2INT(*tmp++));
69
+ *y = (Sint16)(NUM2INT(*tmp));
70
+ break;
71
+ case T_STRUCT:
72
+ if(RSTRUCT_LEN(pos) < 2)
73
+ rb_raise(eMiyakoError, "pairs have illegal struct!");
74
+ tmp = RSTRUCT_PTR(pos);
75
+ *x = (Sint16)(NUM2INT(*tmp++));
76
+ *y = (Sint16)(NUM2INT(*tmp));
77
+ break;
78
+ default:
79
+ *x = (Sint16)(NUM2INT(rb_funcall(pos, rb_intern("x"), 0)));
80
+ *y = (Sint16)(NUM2INT(rb_funcall(pos, rb_intern("y"), 0)));
81
+ break;
82
+ }
83
+ }
84
+
85
+ /*
86
+ ポリゴン描画
87
+ */
88
+ static VALUE drawing_draw_polygon(int argc, VALUE *argv, VALUE self)
89
+ {
90
+ VALUE vdst;
91
+ VALUE pairs;
92
+ VALUE mcolor;
93
+ VALUE fill;
94
+ VALUE aa;
95
+ Uint8 alpha;
96
+ Uint32 color;
97
+ int i, vertexes;
98
+
99
+ rb_scan_args(argc, argv, "32", &vdst, &pairs, &mcolor, &fill, &aa);
100
+
101
+ // bitmapメソッドを持っていれば、メソッドの値をvdstとする
102
+ VALUE methods = rb_funcall(vdst, rb_intern("methods"), 0);
103
+ if(rb_ary_includes(methods, rb_str_intern(rb_str_new2("to_unit"))) == Qfalse &&
104
+ rb_ary_includes(methods, rb_str_intern(rb_str_new2("bitmap"))) == Qfalse
105
+ )
106
+ rb_raise(eMiyakoError, "this method needs sprite have to_method or bitmap method!");
107
+ if(rb_ary_includes(methods, rb_str_intern(rb_str_new2("to_unit"))) == Qtrue)
108
+ vdst = rb_funcall(vdst, rb_intern("to_unit"), 0);
109
+ vdst = rb_funcall(vdst, rb_intern("bitmap"), 0);
110
+
111
+ vertexes = RARRAY_LEN(pairs);
112
+ // 頂点数チェック
113
+ if(vertexes > 65536)
114
+ rb_raise(eMiyakoError, "too many pairs. pairs is less than 65536.");
115
+
116
+ // 範囲チェック
117
+ for(i=0; i<vertexes; i++)
118
+ {
119
+ VALUE vertex = *(RARRAY_PTR(pairs)+i);
120
+ Sint16 x, y;
121
+ get_position(vertex, &x, &y);
122
+ }
123
+
124
+ SDL_Surface *dst = GetSurface(vdst)->surface;
125
+
126
+ color = value_2_color(rb_funcall(cColor, rb_intern("to_rgb"), 1, mcolor), dst->format, &alpha);
127
+
128
+ if(RTEST(fill) && RTEST(aa) && alpha < 255)
129
+ rb_raise(eMiyakoError, "can't draw filled antialiased alpha polygon");
130
+
131
+ Sint16 *px = (Sint16 *)malloc(sizeof(Sint16) * vertexes);
132
+ Sint16 *py = (Sint16 *)malloc(sizeof(Sint16) * vertexes);
133
+ for(i=0; i<vertexes; i++)
134
+ {
135
+ VALUE vertex = *(RARRAY_PTR(pairs)+i);
136
+ get_position(vertex, px+i, py+i);
137
+ }
138
+
139
+ if(!RTEST(fill) && !RTEST(aa) && alpha == 255)
140
+ {
141
+ for(i=0; i<vertexes-1; i++)
142
+ sge_Line(dst, px[i], py[i], px[i+1], py[i+1], color);
143
+ sge_Line(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color);
144
+ }
145
+ else if(!RTEST(fill) && !RTEST(aa) && alpha < 255)
146
+ {
147
+ for(i=0; i<vertexes-1; i++)
148
+ sge_LineAlpha(dst, px[i], py[i], px[i+1], py[i+1], color, alpha);
149
+ sge_LineAlpha(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color, alpha);
150
+ }
151
+ else if(!RTEST(fill) && RTEST(aa) && alpha == 255)
152
+ {
153
+ for(i=0; i<vertexes-1; i++)
154
+ sge_AALine(dst, px[i], py[i], px[i+1], py[i+1], color);
155
+ sge_AALine(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color);
156
+ }
157
+ else if(!RTEST(fill) && RTEST(aa) && alpha < 255)
158
+ {
159
+ for(i=0; i<vertexes-1; i++)
160
+ sge_AALineAlpha(dst, px[i], py[i], px[i+1], py[i+1], color, alpha);
161
+ sge_AALineAlpha(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color, alpha);
162
+ }
163
+ else if(RTEST(fill) && !RTEST(aa) && alpha == 255)
164
+ sge_FilledPolygon(dst, (Uint16)vertexes, px, py, color);
165
+ else if(RTEST(fill) && !RTEST(aa) && alpha < 255)
166
+ sge_FilledPolygonAlpha(dst, (Uint16)vertexes, px, py, color, alpha);
167
+ else if(RTEST(fill) && RTEST(aa) && alpha == 255)
168
+ sge_AAFilledPolygon(dst, (Uint16)vertexes, px, py, color);
169
+
170
+ free(py);
171
+ free(px);
172
+
173
+ return Qnil;
174
+ }
175
+
176
+ void Init_miyako_drawing()
177
+ {
178
+ mSDL = rb_define_module("SDL");
179
+ mMiyako = rb_define_module("Miyako");
180
+ mScreen = rb_define_module_under(mMiyako, "Screen");
181
+ mDrawing = rb_define_module_under(mMiyako, "Drawing");
182
+ eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
183
+ cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
184
+ cColor = rb_define_class_under(mMiyako, "Color", rb_cObject);
185
+
186
+ rb_define_singleton_method(mDrawing, "polygon", drawing_draw_polygon, -1);
187
+ }