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,484 @@
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
+
31
+ static VALUE mSDL = Qnil;
32
+ static VALUE mMiyako = Qnil;
33
+ static VALUE eMiyakoError = Qnil;
34
+ static VALUE cWaitCounter = Qnil;
35
+ static VALUE sSpriteUnit = Qnil;
36
+ static VALUE sPoint = Qnil;
37
+ static VALUE sSize = Qnil;
38
+ static VALUE sRect = Qnil;
39
+ static VALUE sSquare = Qnil;
40
+ static VALUE sSegment = Qnil;
41
+ static VALUE nZero = Qnil;
42
+ static VALUE nOne = Qnil;
43
+ static volatile ID id_update = Qnil;
44
+ static volatile ID id_kakko = Qnil;
45
+ static volatile ID id_render = Qnil;
46
+ static volatile ID id_to_a = Qnil;
47
+ static volatile int zero = Qnil;
48
+ static volatile int one = Qnil;
49
+
50
+ #if 0
51
+ /*
52
+ :nodoc:
53
+ */
54
+ static void get_min_max(VALUE segment, VALUE *min, VALUE *max)
55
+ {
56
+ VALUE *tmp;
57
+ switch(TYPE(segment))
58
+ {
59
+ case T_ARRAY:
60
+ if(RARRAY_LEN(segment) < 2)
61
+ rb_raise(eMiyakoError, "pairs have illegal array! (above 2 elements)");
62
+ tmp = RARRAY_PTR(segment);
63
+ *min = *tmp++;
64
+ *max = *tmp;
65
+ break;
66
+ case T_STRUCT:
67
+ if(RSTRUCT_LEN(segment) < 2)
68
+ rb_raise(eMiyakoError, "pairs have illegal struct! (above 2 attributes)");
69
+ tmp = RSTRUCT_PTR(segment);
70
+ *min = *tmp++;
71
+ *max = *tmp;
72
+ break;
73
+ default:
74
+ *min = rb_funcall(segment, rb_intern("min"), 0);
75
+ *max = rb_funcall(segment, rb_intern("max"), 0);
76
+ break;
77
+ }
78
+ }
79
+ #endif
80
+
81
+ /*
82
+ :nodoc:
83
+ */
84
+ static VALUE counter_start(VALUE self)
85
+ {
86
+ rb_iv_set(self, "@st", rb_funcall(mSDL, rb_intern("getTicks"), 0));
87
+ rb_iv_set(self, "@counting", Qtrue);
88
+ return self;
89
+ }
90
+
91
+ /*
92
+ :nodoc:
93
+ */
94
+ static VALUE counter_stop(VALUE self)
95
+ {
96
+ rb_iv_set(self, "@st", INT2NUM(0));
97
+ rb_iv_set(self, "@counting", Qfalse);
98
+ return self;
99
+ }
100
+
101
+ /*
102
+ :nodoc:
103
+ */
104
+ static VALUE counter_wait_inner(VALUE self, VALUE f)
105
+ {
106
+ VALUE counting = rb_iv_set(self, "@counting", Qtrue);
107
+ if(counting == Qfalse){ return f == Qtrue ? Qfalse : Qtrue; }
108
+
109
+ int t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
110
+ int st = NUM2INT(rb_iv_get(self, "@st"));
111
+ int wait = NUM2INT(rb_iv_get(self, "@wait"));
112
+ if((t - st) < wait){ return f; }
113
+
114
+ rb_iv_set(cWaitCounter, "@counting", Qfalse);
115
+
116
+ return f == Qtrue ? Qfalse : Qtrue;
117
+ }
118
+
119
+ /*
120
+ :nodoc:
121
+ */
122
+ static VALUE counter_waiting(VALUE self)
123
+ {
124
+ return counter_wait_inner(self, Qtrue);
125
+ }
126
+
127
+ /*
128
+ :nodoc:
129
+ */
130
+ static VALUE counter_finish(VALUE self)
131
+ {
132
+ return counter_wait_inner(self, Qfalse);
133
+ }
134
+
135
+ /*
136
+ :nodoc:
137
+ */
138
+ static VALUE counter_wait(VALUE self)
139
+ {
140
+ int t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
141
+ int st = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
142
+ int wait = NUM2INT(rb_iv_get(self, "@wait"));
143
+ while((t - st) < wait){
144
+ t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
145
+ }
146
+ return self;
147
+ }
148
+
149
+ static VALUE su_move(VALUE self, VALUE dx, VALUE dy)
150
+ {
151
+ VALUE *st = RSTRUCT_PTR(self);
152
+ VALUE *px = st+5;
153
+ VALUE *py = st+6;
154
+ VALUE tx = *px;
155
+ VALUE ty = *py;
156
+ *px = INT2NUM(NUM2INT(tx)+NUM2INT(dx));
157
+ *py = INT2NUM(NUM2INT(ty)+NUM2INT(dy));
158
+ if(rb_block_given_p() == Qtrue){
159
+ VALUE ret = rb_yield(self);
160
+ if(ret == Qfalse || ret == Qnil)
161
+ {
162
+ *px = tx;
163
+ *py = ty;
164
+ }
165
+ }
166
+ return self;
167
+ }
168
+
169
+ static VALUE su_move_to(VALUE self, VALUE x, VALUE y)
170
+ {
171
+ VALUE *st = RSTRUCT_PTR(self);
172
+ VALUE *px = st+5;
173
+ VALUE *py = st+6;
174
+ VALUE tx = *px;
175
+ VALUE ty = *py;
176
+ *px = x;
177
+ *py = y;
178
+ if(rb_block_given_p() == Qtrue){
179
+ VALUE ret = rb_yield(self);
180
+ if(ret == Qfalse || ret == Qnil)
181
+ {
182
+ *px = tx;
183
+ *py = ty;
184
+ }
185
+ }
186
+ return self;
187
+ }
188
+
189
+ static VALUE point_move(VALUE self, VALUE dx, VALUE dy)
190
+ {
191
+ VALUE *st = RSTRUCT_PTR(self);
192
+ VALUE *px = st+0;
193
+ VALUE *py = st+1;
194
+ VALUE tx = *px;
195
+ VALUE ty = *py;
196
+ *px = INT2NUM(NUM2INT(tx)+NUM2INT(dx));
197
+ *py = INT2NUM(NUM2INT(ty)+NUM2INT(dy));
198
+ if(rb_block_given_p() == Qtrue){
199
+ VALUE ret = rb_yield(self);
200
+ if(ret == Qfalse || ret == Qnil)
201
+ {
202
+ *px = tx;
203
+ *py = ty;
204
+ }
205
+ }
206
+ return self;
207
+ }
208
+
209
+ static VALUE point_move_to(VALUE self, VALUE x, VALUE y)
210
+ {
211
+ VALUE *st = RSTRUCT_PTR(self);
212
+ VALUE *px = st+0;
213
+ VALUE *py = st+1;
214
+ VALUE tx = *px;
215
+ VALUE ty = *py;
216
+ *px = x;
217
+ *py = y;
218
+ if(rb_block_given_p() == Qtrue){
219
+ VALUE ret = rb_yield(self);
220
+ if(ret == Qfalse || ret == Qnil)
221
+ {
222
+ *px = tx;
223
+ *py = ty;
224
+ }
225
+ }
226
+ return self;
227
+ }
228
+
229
+ static VALUE size_resize(VALUE self, VALUE dw, VALUE dh)
230
+ {
231
+ VALUE *st = RSTRUCT_PTR(self);
232
+ VALUE *pw = st+0;
233
+ VALUE *ph = st+1;
234
+ VALUE tw = *pw;
235
+ VALUE th = *ph;
236
+ *pw = INT2NUM(NUM2INT(tw)+NUM2INT(dw));
237
+ *ph = INT2NUM(NUM2INT(th)+NUM2INT(dh));
238
+ if(rb_block_given_p() == Qtrue){
239
+ VALUE ret = rb_yield(self);
240
+ if(ret == Qfalse || ret == Qnil)
241
+ {
242
+ *pw = tw;
243
+ *ph = th;
244
+ }
245
+ }
246
+ return self;
247
+ }
248
+
249
+ static VALUE size_resize_to(VALUE self, VALUE w, VALUE h)
250
+ {
251
+ VALUE *st = RSTRUCT_PTR(self);
252
+ VALUE *pw = st+0;
253
+ VALUE *ph = st+1;
254
+ VALUE tw = *pw;
255
+ VALUE th = *ph;
256
+ *pw = w;
257
+ *ph = h;
258
+ if(rb_block_given_p() == Qtrue){
259
+ VALUE ret = rb_yield(self);
260
+ if(ret == Qfalse || ret == Qnil)
261
+ {
262
+ *pw = tw;
263
+ *ph = th;
264
+ }
265
+ }
266
+ return self;
267
+ }
268
+
269
+ static VALUE rect_resize(VALUE self, VALUE dw, VALUE dh)
270
+ {
271
+ VALUE *st = RSTRUCT_PTR(self);
272
+ VALUE *pw = st+2;
273
+ VALUE *ph = st+3;
274
+ VALUE tw = *pw;
275
+ VALUE th = *ph;
276
+ *pw = INT2NUM(NUM2INT(*pw) + NUM2INT(dw));
277
+ *ph = INT2NUM(NUM2INT(*pw) + NUM2INT(dh));
278
+ if(rb_block_given_p() == Qtrue){
279
+ VALUE ret = rb_yield(self);
280
+ if(ret == Qfalse || ret == Qnil)
281
+ {
282
+ *pw = tw;
283
+ *ph = th;
284
+ }
285
+ }
286
+ return self;
287
+ }
288
+
289
+ static VALUE rect_resize_to(VALUE self, VALUE w, VALUE h)
290
+ {
291
+ VALUE *st = RSTRUCT_PTR(self);
292
+ VALUE *pw = st+2;
293
+ VALUE *ph = st+3;
294
+ VALUE tw = *pw;
295
+ VALUE th = *ph;
296
+ *pw = w;
297
+ *ph = h;
298
+ if(rb_block_given_p() == Qtrue){
299
+ VALUE ret = rb_yield(self);
300
+ if(ret == Qfalse || ret == Qnil)
301
+ {
302
+ *pw = tw;
303
+ *ph = th;
304
+ }
305
+ }
306
+ return self;
307
+ }
308
+
309
+ static VALUE rect_in_range(VALUE self, VALUE vx, VALUE vy)
310
+ {
311
+ VALUE *st = RSTRUCT_PTR(self);
312
+ int l = NUM2INT(*(st+0));
313
+ int t = NUM2INT(*(st+1));
314
+ int w = NUM2INT(*(st+2));
315
+ int h = NUM2INT(*(st+3));
316
+ int x = NUM2INT(vx);
317
+ int y = NUM2INT(vy);
318
+
319
+ if(x >= l && y >= t && x < (l+w) && y < (t+h)){ return Qtrue; }
320
+ return Qfalse;
321
+ }
322
+
323
+ static VALUE square_move(VALUE self, VALUE dx, VALUE dy)
324
+ {
325
+ VALUE *st = RSTRUCT_PTR(self);
326
+ VALUE *pl = st+0;
327
+ VALUE *pt = st+1;
328
+ VALUE *pr = st+2;
329
+ VALUE *pb = st+3;
330
+ VALUE tl = *pl;
331
+ VALUE tt = *pt;
332
+ VALUE tr = *pr;
333
+ VALUE tb = *pb;
334
+ *pl = INT2NUM(NUM2INT(tl)+NUM2INT(dx));
335
+ *pt = INT2NUM(NUM2INT(tt)+NUM2INT(dy));
336
+ *pr = INT2NUM(NUM2INT(tr)+NUM2INT(dx));
337
+ *pb = INT2NUM(NUM2INT(tb)+NUM2INT(dy));
338
+ if(rb_block_given_p() == Qtrue){
339
+ VALUE ret = rb_yield(self);
340
+ if(ret == Qfalse || ret == Qnil)
341
+ {
342
+ *pl = tl;
343
+ *pt = tt;
344
+ *pr = tr;
345
+ *pb = tb;
346
+ }
347
+ }
348
+ return self;
349
+ }
350
+
351
+ static VALUE square_move_to(VALUE self, VALUE x, VALUE y)
352
+ {
353
+ VALUE *st = RSTRUCT_PTR(self);
354
+ VALUE *pl = st+0;
355
+ VALUE *pt = st+1;
356
+ VALUE *pr = st+2;
357
+ VALUE *pb = st+3;
358
+ VALUE tl = *pl;
359
+ VALUE tt = *pt;
360
+ VALUE tr = *pr;
361
+ VALUE tb = *pb;
362
+ int w = NUM2INT(tr)-NUM2INT(tl);
363
+ int h = NUM2INT(tb)-NUM2INT(tt);
364
+ *pl = x;
365
+ *pt = y;
366
+ *pr = INT2NUM(NUM2INT(x)+w);
367
+ *pb = INT2NUM(NUM2INT(y)+h);
368
+ if(rb_block_given_p() == Qtrue){
369
+ VALUE ret = rb_yield(self);
370
+ if(ret == Qfalse || ret == Qnil)
371
+ {
372
+ *pl = tl;
373
+ *pt = tt;
374
+ *pr = tr;
375
+ *pb = tb;
376
+ }
377
+ }
378
+ return self;
379
+ }
380
+
381
+ static VALUE square_resize(VALUE self, VALUE dw, VALUE dh)
382
+ {
383
+ VALUE *st = RSTRUCT_PTR(self);
384
+ VALUE *pr = st+2;
385
+ VALUE *pb = st+3;
386
+ VALUE tr = *pr;
387
+ VALUE tb = *pb;
388
+ *pr = INT2NUM(NUM2INT(*pr) + NUM2INT(dw));
389
+ *pb = INT2NUM(NUM2INT(*pb) + NUM2INT(dh));
390
+ if(rb_block_given_p() == Qtrue){
391
+ VALUE ret = rb_yield(self);
392
+ if(ret == Qfalse || ret == Qnil)
393
+ {
394
+ *pr = tr;
395
+ *pb = tb;
396
+ }
397
+ }
398
+ return self;
399
+ }
400
+
401
+ static VALUE square_resize_to(VALUE self, VALUE w, VALUE h)
402
+ {
403
+ VALUE *st = RSTRUCT_PTR(self);
404
+ VALUE *pl = st+0;
405
+ VALUE *pt = st+1;
406
+ VALUE *pr = st+2;
407
+ VALUE *pb = st+3;
408
+ VALUE tr = *pr;
409
+ VALUE tb = *pb;
410
+ *pr = INT2NUM(NUM2INT(*pl) + NUM2INT(w) - 1);
411
+ *pb = INT2NUM(NUM2INT(*pt) + NUM2INT(h) - 1);
412
+ if(rb_block_given_p() == Qtrue){
413
+ VALUE ret = rb_yield(self);
414
+ if(ret == Qfalse || ret == Qnil)
415
+ {
416
+ *pr = tr;
417
+ *pb = tb;
418
+ }
419
+ }
420
+ return self;
421
+ }
422
+
423
+ static VALUE square_in_range(VALUE self, VALUE vx, VALUE vy)
424
+ {
425
+ VALUE *st = RSTRUCT_PTR(self);
426
+ int l = NUM2INT(*(st+0));
427
+ int t = NUM2INT(*(st+1));
428
+ int r = NUM2INT(*(st+2));
429
+ int b = NUM2INT(*(st+3));
430
+ int x = NUM2INT(vx);
431
+ int y = NUM2INT(vy);
432
+
433
+ if(x >= l && y >= t && x <= r && y <= b){ return Qtrue; }
434
+ return Qfalse;
435
+ }
436
+
437
+ void Init_miyako_basicdata()
438
+ {
439
+ mSDL = rb_define_module("SDL");
440
+ mMiyako = rb_define_module("Miyako");
441
+ eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
442
+ cWaitCounter = rb_define_class_under(mMiyako, "WaitCounter", rb_cObject);
443
+ sSpriteUnit = rb_define_class_under(mMiyako, "SpriteUnitBase", rb_cStruct);
444
+ sPoint = rb_define_class_under(mMiyako, "PointStruct", rb_cStruct);
445
+ sSize = rb_define_class_under(mMiyako, "SizeStruct", rb_cStruct);
446
+ sRect = rb_define_class_under(mMiyako, "RectStruct", rb_cStruct);
447
+ sSquare = rb_define_class_under(mMiyako, "SquareStruct", rb_cStruct);
448
+ sSegment = rb_define_class_under(mMiyako, "SegmentsStruct", rb_cStruct);
449
+
450
+ id_update = rb_intern("update");
451
+ id_kakko = rb_intern("[]");
452
+ id_render = rb_intern("render");
453
+ id_to_a = rb_intern("to_a");
454
+
455
+ zero = 0;
456
+ nZero = INT2NUM(zero);
457
+ one = 1;
458
+ nOne = INT2NUM(one);
459
+
460
+ rb_define_method(cWaitCounter, "start", counter_start, 0);
461
+ rb_define_method(cWaitCounter, "stop", counter_stop, 0);
462
+ rb_define_method(cWaitCounter, "wait_inner", counter_wait_inner, 1);
463
+ rb_define_method(cWaitCounter, "waiting?", counter_waiting, 0);
464
+ rb_define_method(cWaitCounter, "finish?", counter_finish, 0);
465
+ rb_define_method(cWaitCounter, "wait", counter_wait, 0);
466
+
467
+ rb_define_method(sSpriteUnit, "move!", su_move, 2);
468
+ rb_define_method(sSpriteUnit, "move_to!", su_move_to, 2);
469
+
470
+ rb_define_method(sPoint, "move!", point_move, 2);
471
+ rb_define_method(sPoint, "move_to!", point_move_to, 2);
472
+ rb_define_method(sSize, "resize!", size_resize, 2);
473
+ rb_define_method(sSize, "resize_to!", size_resize_to, 2);
474
+ rb_define_method(sRect, "move!", point_move, 2);
475
+ rb_define_method(sRect, "move_to!", point_move_to, 2);
476
+ rb_define_method(sRect, "resize!", rect_resize, 2);
477
+ rb_define_method(sRect, "resize_to!", rect_resize_to, 2);
478
+ rb_define_method(sRect, "in_range?", rect_in_range, 2);
479
+ rb_define_method(sSquare, "move!", square_move, 2);
480
+ rb_define_method(sSquare, "move_to!", square_move_to, 2);
481
+ rb_define_method(sSquare, "resize!", square_resize, 2);
482
+ rb_define_method(sSquare, "resize_to!", square_resize_to, 2);
483
+ rb_define_method(sSquare, "in_range?", square_in_range, 2);
484
+ }