dxrubynd 1.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +12 -0
- data/README.md +31 -0
- data/Rakefile +9 -0
- data/dxrubynd.gemspec +41 -0
- data/ext/dxruby/COPYING +13 -0
- data/ext/dxruby/collision.c +1460 -0
- data/ext/dxruby/collision.h +47 -0
- data/ext/dxruby/dxruby-i386-mswin32.def +4 -0
- data/ext/dxruby/dxruby.c +5861 -0
- data/ext/dxruby/dxruby.h +392 -0
- data/ext/dxruby/extconf.rb +29 -0
- data/ext/dxruby/font.c +686 -0
- data/ext/dxruby/font.h +20 -0
- data/ext/dxruby/image.c +3391 -0
- data/ext/dxruby/image.h +22 -0
- data/ext/dxruby/input.c +2522 -0
- data/ext/dxruby/input.h +4 -0
- data/ext/dxruby/matrix.c +1221 -0
- data/ext/dxruby/matrix.h +30 -0
- data/ext/dxruby/messagethread.c +1180 -0
- data/ext/dxruby/messagethread.h +22 -0
- data/ext/dxruby/sound.c +1516 -0
- data/ext/dxruby/sound.h +1 -0
- data/ext/dxruby/sprite.c +1313 -0
- data/ext/dxruby/sprite.h +29 -0
- data/ext/dxruby/version.h +10 -0
- data/lib/dxrubynd/version.rb +5 -0
- data/lib/dxrubynd.rb +4 -0
- data/sig/dxrubynd.rbs +4 -0
- metadata +91 -0
data/ext/dxruby/sprite.c
ADDED
@@ -0,0 +1,1313 @@
|
|
1
|
+
#define WINVER 0x0500 /* �o�[�W������` Windows2000�ȏ� */
|
2
|
+
#define _WIN32_WINNT WINVER
|
3
|
+
|
4
|
+
#include "ruby.h"
|
5
|
+
#ifndef RUBY_ST_H
|
6
|
+
#include "st.h"
|
7
|
+
#endif
|
8
|
+
|
9
|
+
#define DXRUBY_EXTERN 1
|
10
|
+
#include "dxruby.h"
|
11
|
+
#include "sprite.h"
|
12
|
+
#include "image.h"
|
13
|
+
#include "collision.h"
|
14
|
+
#ifdef DXRUBY15
|
15
|
+
#include "matrix.h"
|
16
|
+
#endif
|
17
|
+
|
18
|
+
static VALUE cSprite; /* �X�v���C�g�N���X */
|
19
|
+
#ifdef DXRUBY15
|
20
|
+
extern VALUE cVector;
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#ifdef DXRUBY_USE_TYPEDDATA
|
24
|
+
extern rb_data_type_t Image_data_type;
|
25
|
+
extern rb_data_type_t RenderTarget_data_type;
|
26
|
+
extern rb_data_type_t Shader_data_type;
|
27
|
+
#ifdef DXRUBY15
|
28
|
+
extern rb_data_type_t Matrix_data_type;
|
29
|
+
extern rb_data_type_t Vector_data_type;
|
30
|
+
#endif
|
31
|
+
#endif
|
32
|
+
|
33
|
+
ID id_shot;
|
34
|
+
ID id_hit;
|
35
|
+
ID id_update;
|
36
|
+
ID id_draw;
|
37
|
+
ID id_render;
|
38
|
+
ID id_vanished;
|
39
|
+
ID id_visible;
|
40
|
+
|
41
|
+
static VALUE Sprite_check( int argc, VALUE *argv, VALUE klass );
|
42
|
+
|
43
|
+
/*********************************************************************
|
44
|
+
* Sprite�N���X
|
45
|
+
*
|
46
|
+
* �`��v���~�e�B�u�Ƃ��Ē���X�v���C�g�@�\
|
47
|
+
*********************************************************************/
|
48
|
+
/*--------------------------------------------------------------------
|
49
|
+
�Q�Ƃ���Ȃ��Ȃ����Ƃ���GC����Ă���
|
50
|
+
---------------------------------------------------------------------*/
|
51
|
+
void Sprite_release( struct DXRubySprite *sprite )
|
52
|
+
{
|
53
|
+
free( sprite );
|
54
|
+
}
|
55
|
+
|
56
|
+
/*--------------------------------------------------------------------
|
57
|
+
Sprite�N���X��mark
|
58
|
+
---------------------------------------------------------------------*/
|
59
|
+
static void Sprite_mark( struct DXRubySprite *sprite )
|
60
|
+
{
|
61
|
+
rb_gc_mark( sprite->vx );
|
62
|
+
rb_gc_mark( sprite->vy );
|
63
|
+
rb_gc_mark( sprite->vz );
|
64
|
+
rb_gc_mark( sprite->vimage );
|
65
|
+
rb_gc_mark( sprite->vtarget );
|
66
|
+
rb_gc_mark( sprite->vangle );
|
67
|
+
rb_gc_mark( sprite->vscale_x );
|
68
|
+
rb_gc_mark( sprite->vscale_y );
|
69
|
+
rb_gc_mark( sprite->vcenter_x );
|
70
|
+
rb_gc_mark( sprite->vcenter_y );
|
71
|
+
rb_gc_mark( sprite->valpha );
|
72
|
+
rb_gc_mark( sprite->vblend );
|
73
|
+
rb_gc_mark( sprite->vvisible );
|
74
|
+
rb_gc_mark( sprite->vshader );
|
75
|
+
rb_gc_mark( sprite->vcollision );
|
76
|
+
rb_gc_mark( sprite->vcollision_enable );
|
77
|
+
rb_gc_mark( sprite->vcollision_sync );
|
78
|
+
#ifdef DXRUBY15
|
79
|
+
rb_gc_mark( sprite->vxy );
|
80
|
+
rb_gc_mark( sprite->vxyz );
|
81
|
+
#endif
|
82
|
+
rb_gc_mark( sprite->voffset_sync );
|
83
|
+
}
|
84
|
+
|
85
|
+
#ifdef DXRUBY_USE_TYPEDDATA
|
86
|
+
const rb_data_type_t Sprite_data_type = {
|
87
|
+
"Sprite",
|
88
|
+
{
|
89
|
+
Sprite_mark,
|
90
|
+
Sprite_release,
|
91
|
+
0,
|
92
|
+
},
|
93
|
+
NULL, NULL
|
94
|
+
};
|
95
|
+
#endif
|
96
|
+
|
97
|
+
/*--------------------------------------------------------------------
|
98
|
+
Sprite�N���X��allocate�B���������m�ۂ���ׂ�initialize�O�ɌĂ��B
|
99
|
+
---------------------------------------------------------------------*/
|
100
|
+
static VALUE Sprite_allocate( VALUE klass )
|
101
|
+
{
|
102
|
+
VALUE obj;
|
103
|
+
struct DXRubySprite *sprite;
|
104
|
+
|
105
|
+
/* DXRubySprite�̃������擾��Sprite�I�u�W�F�N�g���� */
|
106
|
+
sprite = malloc( sizeof(struct DXRubySprite) );
|
107
|
+
if( sprite == NULL ) rb_raise( eDXRubyError, "Out of memory - Sprite_allocate" );
|
108
|
+
#ifdef DXRUBY_USE_TYPEDDATA
|
109
|
+
obj = TypedData_Wrap_Struct( klass, &Sprite_data_type, sprite );
|
110
|
+
#else
|
111
|
+
obj = Data_Wrap_Struct(klass, Sprite_mark, Sprite_release, sprite);
|
112
|
+
#endif
|
113
|
+
sprite->vx = INT2FIX( 0 );
|
114
|
+
sprite->vy = INT2FIX( 0 );
|
115
|
+
sprite->vz = INT2FIX( 0 );
|
116
|
+
sprite->vimage = Qnil;
|
117
|
+
sprite->vtarget = Qnil;
|
118
|
+
sprite->vangle = INT2FIX( 0 );
|
119
|
+
sprite->vscale_x = INT2FIX( 1 );
|
120
|
+
sprite->vscale_y = INT2FIX( 1 );
|
121
|
+
sprite->vcenter_x = Qnil;
|
122
|
+
sprite->vcenter_y = Qnil;
|
123
|
+
sprite->valpha = INT2FIX( 255 );
|
124
|
+
sprite->vblend = Qnil;
|
125
|
+
sprite->vvisible = Qtrue;
|
126
|
+
sprite->vshader = Qnil;
|
127
|
+
sprite->vcollision = Qnil;
|
128
|
+
sprite->vcollision_enable = Qtrue;
|
129
|
+
sprite->vcollision_sync = Qtrue;
|
130
|
+
sprite->vanish = FALSE;
|
131
|
+
#ifdef DXRUBY15
|
132
|
+
sprite->vxy = Qnil;
|
133
|
+
sprite->vxyz = Qnil;
|
134
|
+
#endif
|
135
|
+
sprite->voffset_sync = Qfalse;
|
136
|
+
|
137
|
+
return obj;
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
/*--------------------------------------------------------------------
|
142
|
+
Sprite�N���X��Initialize
|
143
|
+
---------------------------------------------------------------------*/
|
144
|
+
static VALUE Sprite_initialize( int argc, VALUE *argv, VALUE self )
|
145
|
+
{
|
146
|
+
struct DXRubySprite *sprite = DXRUBY_GET_STRUCT( Sprite, self );
|
147
|
+
|
148
|
+
sprite->vx = (argc == 0 || argv[0] == Qnil) ? INT2FIX( 0 ) : argv[0];
|
149
|
+
sprite->vy = (argc < 2 || argv[1] == Qnil) ? INT2FIX( 0 ) : argv[1];
|
150
|
+
sprite->vimage = (argc < 3) ? Qnil : argv[2];
|
151
|
+
|
152
|
+
return self;
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
/*--------------------------------------------------------------------
|
157
|
+
Sprite�N���X��draw
|
158
|
+
---------------------------------------------------------------------*/
|
159
|
+
void Sprite_internal_draw( VALUE self, VALUE vrt )
|
160
|
+
{
|
161
|
+
struct DXRubyRenderTarget *rt = DXRUBY_GET_STRUCT( RenderTarget, vrt );
|
162
|
+
struct DXRubySprite *sprite = DXRUBY_GET_STRUCT( Sprite, self );
|
163
|
+
struct DXRubyImage *image;
|
164
|
+
float z;
|
165
|
+
|
166
|
+
if( !RTEST(sprite->vvisible) || sprite->vanish )
|
167
|
+
{
|
168
|
+
return;
|
169
|
+
}
|
170
|
+
|
171
|
+
/* �C���[�W�I�u�W�F�N�g���璆�g�����o�� */
|
172
|
+
if( sprite->vimage == Qnil )
|
173
|
+
{
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
|
177
|
+
DXRUBY_CHECK_IMAGE( sprite->vimage );
|
178
|
+
image = DXRUBY_GET_STRUCT( Image, sprite->vimage );
|
179
|
+
DXRUBY_CHECK_DISPOSE( image, texture );
|
180
|
+
|
181
|
+
if( sprite->vangle == INT2FIX( 0 ) && sprite->vscale_x == INT2FIX( 1 ) && sprite->vscale_y == INT2FIX( 1 ) )
|
182
|
+
{/* ��]�g�喳�� */
|
183
|
+
volatile VALUE temp;
|
184
|
+
struct DXRubyPicture_draw *picture;
|
185
|
+
|
186
|
+
picture = (struct DXRubyPicture_draw *)RenderTarget_AllocPictureList( rt, sizeof( struct DXRubyPicture_draw ) );
|
187
|
+
|
188
|
+
/* DXRubyPicture�I�u�W�F�N�g�ݒ� */
|
189
|
+
picture->x = (int)(NUM2FLOAT( sprite->vx ) - (RTEST(sprite->voffset_sync) ? (sprite->vcenter_x == Qnil ? image->width / 2.0f : NUM2FLOAT( sprite->vcenter_x )) : 0));
|
190
|
+
picture->y = (int)(NUM2FLOAT( sprite->vy ) - (RTEST(sprite->voffset_sync) ? (sprite->vcenter_y == Qnil ? image->height / 2.0f : NUM2FLOAT( sprite->vcenter_y )) : 0));
|
191
|
+
picture->x -= rt->ox;
|
192
|
+
picture->y -= rt->oy;
|
193
|
+
|
194
|
+
if( sprite->vshader == Qnil )
|
195
|
+
{/* �V�F�[�_�Ȃ� */
|
196
|
+
picture->func = RenderTarget_draw_func;
|
197
|
+
picture->value = sprite->vimage;
|
198
|
+
}
|
199
|
+
else
|
200
|
+
{/* �V�F�[�_���� */
|
201
|
+
struct DXRubyShader *shader;
|
202
|
+
struct DXRubyShaderCore *core;
|
203
|
+
|
204
|
+
DXRUBY_CHECK_TYPE( Shader, sprite->vshader );
|
205
|
+
shader = DXRUBY_GET_STRUCT( Shader, sprite->vshader );
|
206
|
+
core = DXRUBY_GET_STRUCT( ShaderCore, shader->vcore );
|
207
|
+
DXRUBY_CHECK_DISPOSE( core, pD3DXEffect );
|
208
|
+
|
209
|
+
temp = rb_ary_new3( 3, sprite->vimage, shader->vcore, shader->vparam );
|
210
|
+
picture->value = temp;
|
211
|
+
|
212
|
+
/* Shader����Image�I�u�W�F�N�g�����b�N���� */
|
213
|
+
// rb_hash_foreach( RARRAY_PTR( picture->value )[2], Window_drawShader_func_foreach_lock, RARRAY_PTR( picture->value )[1]);
|
214
|
+
|
215
|
+
picture->func = RenderTarget_drawShader_func;
|
216
|
+
}
|
217
|
+
|
218
|
+
picture->alpha = NUM2INT( sprite->valpha );
|
219
|
+
picture->blendflag = (sprite->vblend == Qnil ? 0 :
|
220
|
+
(sprite->vblend == symbol_add ? 4 :
|
221
|
+
(sprite->vblend == symbol_none ? 1 :
|
222
|
+
(sprite->vblend == symbol_add2 ? 5 :
|
223
|
+
(sprite->vblend == symbol_sub ? 6 :
|
224
|
+
(sprite->vblend == symbol_sub2 ? 7 : 0))))));
|
225
|
+
|
226
|
+
/* ���X�g�f�[�^�ɒlj� */
|
227
|
+
rt->PictureList[rt->PictureCount].picture = (struct DXRubyPicture *)picture;
|
228
|
+
z = NUM2FLOAT( sprite->vz );
|
229
|
+
rt->PictureList[rt->PictureCount].z = z;
|
230
|
+
picture->z = z;
|
231
|
+
rt->PictureCount++;
|
232
|
+
}
|
233
|
+
else
|
234
|
+
{
|
235
|
+
volatile VALUE temp;
|
236
|
+
struct DXRubyPicture_drawEx *picture;
|
237
|
+
|
238
|
+
picture = (struct DXRubyPicture_drawEx *)RenderTarget_AllocPictureList( rt, sizeof( struct DXRubyPicture_drawEx ) );
|
239
|
+
|
240
|
+
/* DXRubyPicture�I�u�W�F�N�g�ݒ� */
|
241
|
+
picture->func = RenderTarget_drawEx_func;
|
242
|
+
picture->x = (int)(NUM2FLOAT( sprite->vx ) - (RTEST(sprite->voffset_sync) ? (sprite->vcenter_x == Qnil ? image->width / 2.0f : NUM2FLOAT( sprite->vcenter_x )) : 0));
|
243
|
+
picture->y = (int)(NUM2FLOAT( sprite->vy ) - (RTEST(sprite->voffset_sync) ? (sprite->vcenter_y == Qnil ? image->height / 2.0f : NUM2FLOAT( sprite->vcenter_y )) : 0));
|
244
|
+
picture->x -= rt->ox;
|
245
|
+
picture->y -= rt->oy;
|
246
|
+
|
247
|
+
if( sprite->vshader != Qnil )
|
248
|
+
{/* �V�F�[�_���� */
|
249
|
+
struct DXRubyShader *shader;
|
250
|
+
struct DXRubyShaderCore *core;
|
251
|
+
DXRUBY_CHECK_TYPE( Shader, sprite->vshader );
|
252
|
+
shader = DXRUBY_GET_STRUCT( Shader, sprite->vshader );
|
253
|
+
core = DXRUBY_GET_STRUCT( ShaderCore, shader->vcore );
|
254
|
+
DXRUBY_CHECK_DISPOSE( core, pD3DXEffect );
|
255
|
+
|
256
|
+
temp = rb_ary_new3( 3, sprite->vimage, shader->vcore, shader->vparam );
|
257
|
+
picture->value = temp;
|
258
|
+
|
259
|
+
/* Shader����Image�I�u�W�F�N�g�����b�N���� */
|
260
|
+
// rb_hash_foreach( RARRAY_PTR( picture->value )[2], Window_drawShader_func_foreach_lock, RARRAY_PTR( picture->value )[1]);
|
261
|
+
}
|
262
|
+
else
|
263
|
+
{
|
264
|
+
picture->value = sprite->vimage;
|
265
|
+
}
|
266
|
+
|
267
|
+
picture->angle = NUM2FLOAT( sprite->vangle );
|
268
|
+
picture->scalex = NUM2FLOAT( sprite->vscale_x );
|
269
|
+
picture->scaley = NUM2FLOAT( sprite->vscale_y );
|
270
|
+
picture->centerx = (sprite->vcenter_x == Qnil ? image->width / 2.0f : NUM2FLOAT( sprite->vcenter_x ));
|
271
|
+
picture->centery = (sprite->vcenter_y == Qnil ? image->height / 2.0f : NUM2FLOAT( sprite->vcenter_y ));
|
272
|
+
|
273
|
+
picture->alpha = NUM2INT( sprite->valpha );
|
274
|
+
picture->blendflag = (sprite->vblend == Qnil ? 0 :
|
275
|
+
(sprite->vblend == symbol_add ? 4 :
|
276
|
+
(sprite->vblend == symbol_none ? 1 :
|
277
|
+
(sprite->vblend == symbol_add2 ? 5 :
|
278
|
+
(sprite->vblend == symbol_sub ? 6 :
|
279
|
+
(sprite->vblend == symbol_sub2 ? 7 : 0))))));
|
280
|
+
|
281
|
+
/* ���X�g�f�[�^�ɒlj� */
|
282
|
+
rt->PictureList[rt->PictureCount].picture = (struct DXRubyPicture *)picture;
|
283
|
+
z = NUM2FLOAT( sprite->vz );
|
284
|
+
rt->PictureList[rt->PictureCount].z = z;
|
285
|
+
picture->z = z;
|
286
|
+
rt->PictureCount++;
|
287
|
+
}
|
288
|
+
|
289
|
+
/* RenderTarget�������ꍇ�ɕ`��\�����update���� */
|
290
|
+
if( DXRUBY_CHECK( RenderTarget, sprite->vimage ) )
|
291
|
+
{
|
292
|
+
struct DXRubyRenderTarget *src_rt = DXRUBY_GET_STRUCT( RenderTarget, sprite->vimage );
|
293
|
+
|
294
|
+
if( src_rt->clearflag == 0 && src_rt->PictureCount == 0 )
|
295
|
+
{
|
296
|
+
g_pD3DDevice->lpVtbl->SetRenderTarget( g_pD3DDevice, 0, src_rt->surface );
|
297
|
+
g_pD3DDevice->lpVtbl->Clear( g_pD3DDevice, 0, NULL, D3DCLEAR_TARGET,
|
298
|
+
D3DCOLOR_ARGB( src_rt->a, src_rt->r, src_rt->g, src_rt->b ), 1.0f, 0 );
|
299
|
+
src_rt->clearflag = 1;
|
300
|
+
}
|
301
|
+
else if( src_rt->PictureCount > 0 )
|
302
|
+
{
|
303
|
+
RenderTarget_update( sprite->vimage );
|
304
|
+
}
|
305
|
+
}
|
306
|
+
|
307
|
+
/* �g��ꂽimage�̃��b�N */
|
308
|
+
// image->lockcount += 1;
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
VALUE Sprite_draw( VALUE self )
|
313
|
+
{
|
314
|
+
VALUE vrt;
|
315
|
+
struct DXRubySprite *sprite = DXRUBY_GET_STRUCT( Sprite, self );
|
316
|
+
|
317
|
+
if( sprite->vtarget == Qnil || sprite->vtarget == mWindow )
|
318
|
+
{
|
319
|
+
vrt = g_WindowInfo.render_target;
|
320
|
+
}
|
321
|
+
else
|
322
|
+
{
|
323
|
+
DXRUBY_CHECK_TYPE( RenderTarget, sprite->vtarget );
|
324
|
+
vrt = sprite->vtarget;
|
325
|
+
}
|
326
|
+
|
327
|
+
Sprite_internal_draw( self, vrt );
|
328
|
+
|
329
|
+
return self;
|
330
|
+
}
|
331
|
+
|
332
|
+
/*--------------------------------------------------------------------
|
333
|
+
�v���p�e�B��Setter/Getter
|
334
|
+
---------------------------------------------------------------------*/
|
335
|
+
/* x */
|
336
|
+
static VALUE Sprite_get_x( VALUE self )
|
337
|
+
{
|
338
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vx;
|
339
|
+
}
|
340
|
+
|
341
|
+
/* x= */
|
342
|
+
static VALUE Sprite_set_x( VALUE self, VALUE vx )
|
343
|
+
{
|
344
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vx = vx;
|
345
|
+
return vx;
|
346
|
+
}
|
347
|
+
|
348
|
+
/* y */
|
349
|
+
static VALUE Sprite_get_y( VALUE self )
|
350
|
+
{
|
351
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vy;
|
352
|
+
}
|
353
|
+
|
354
|
+
/* y= */
|
355
|
+
static VALUE Sprite_set_y( VALUE self, VALUE vy )
|
356
|
+
{
|
357
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vy = vy;
|
358
|
+
return vy;
|
359
|
+
}
|
360
|
+
|
361
|
+
/* z */
|
362
|
+
static VALUE Sprite_get_z( VALUE self )
|
363
|
+
{
|
364
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vz;
|
365
|
+
}
|
366
|
+
|
367
|
+
/* z= */
|
368
|
+
static VALUE Sprite_set_z( VALUE self, VALUE vz )
|
369
|
+
{
|
370
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vz = vz;
|
371
|
+
return vz;
|
372
|
+
}
|
373
|
+
|
374
|
+
/* angle */
|
375
|
+
static VALUE Sprite_get_angle( VALUE self )
|
376
|
+
{
|
377
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vangle;
|
378
|
+
}
|
379
|
+
|
380
|
+
/* angle= */
|
381
|
+
static VALUE Sprite_set_angle( VALUE self, VALUE vangle )
|
382
|
+
{
|
383
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vangle = vangle;
|
384
|
+
return vangle;
|
385
|
+
}
|
386
|
+
|
387
|
+
|
388
|
+
/* image */
|
389
|
+
static VALUE Sprite_get_image( VALUE self )
|
390
|
+
{
|
391
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vimage;
|
392
|
+
}
|
393
|
+
|
394
|
+
/* image= */
|
395
|
+
static VALUE Sprite_set_image( VALUE self, VALUE vimage )
|
396
|
+
{
|
397
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vimage = vimage;
|
398
|
+
return vimage;
|
399
|
+
}
|
400
|
+
|
401
|
+
/* blend */
|
402
|
+
static VALUE Sprite_get_blend( VALUE self )
|
403
|
+
{
|
404
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vblend;
|
405
|
+
}
|
406
|
+
|
407
|
+
/* blend= */
|
408
|
+
static VALUE Sprite_set_blend( VALUE self, VALUE vblend )
|
409
|
+
{
|
410
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vblend = vblend;
|
411
|
+
return vblend;
|
412
|
+
}
|
413
|
+
|
414
|
+
/* alpha */
|
415
|
+
static VALUE Sprite_get_alpha( VALUE self )
|
416
|
+
{
|
417
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->valpha;
|
418
|
+
}
|
419
|
+
|
420
|
+
/* alpha= */
|
421
|
+
static VALUE Sprite_set_alpha( VALUE self, VALUE valpha )
|
422
|
+
{
|
423
|
+
DXRUBY_GET_STRUCT( Sprite, self )->valpha = valpha;
|
424
|
+
return valpha;
|
425
|
+
}
|
426
|
+
|
427
|
+
/* target */
|
428
|
+
static VALUE Sprite_get_target( VALUE self )
|
429
|
+
{
|
430
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vtarget;
|
431
|
+
}
|
432
|
+
|
433
|
+
/* target= */
|
434
|
+
static VALUE Sprite_set_target( VALUE self, VALUE vtarget )
|
435
|
+
{
|
436
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vtarget = vtarget;
|
437
|
+
return vtarget;
|
438
|
+
}
|
439
|
+
|
440
|
+
/* shader */
|
441
|
+
static VALUE Sprite_get_shader( VALUE self )
|
442
|
+
{
|
443
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vshader;
|
444
|
+
}
|
445
|
+
|
446
|
+
/* shader= */
|
447
|
+
static VALUE Sprite_set_shader( VALUE self, VALUE vshader )
|
448
|
+
{
|
449
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vshader = vshader;
|
450
|
+
return vshader;
|
451
|
+
}
|
452
|
+
|
453
|
+
/* scale_x */
|
454
|
+
static VALUE Sprite_get_scale_x( VALUE self )
|
455
|
+
{
|
456
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vscale_x;
|
457
|
+
}
|
458
|
+
|
459
|
+
/* scale_x= */
|
460
|
+
static VALUE Sprite_set_scale_x( VALUE self, VALUE vscale_x )
|
461
|
+
{
|
462
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vscale_x = vscale_x;
|
463
|
+
return vscale_x;
|
464
|
+
}
|
465
|
+
|
466
|
+
/* scale_y */
|
467
|
+
static VALUE Sprite_get_scale_y( VALUE self )
|
468
|
+
{
|
469
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vscale_y;
|
470
|
+
}
|
471
|
+
|
472
|
+
/* scale_y= */
|
473
|
+
static VALUE Sprite_set_scale_y( VALUE self, VALUE vscale_y )
|
474
|
+
{
|
475
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vscale_y = vscale_y;
|
476
|
+
return vscale_y;
|
477
|
+
}
|
478
|
+
|
479
|
+
/* center_x */
|
480
|
+
static VALUE Sprite_get_center_x( VALUE self )
|
481
|
+
{
|
482
|
+
struct DXRubySprite *sprite = DXRUBY_GET_STRUCT( Sprite, self );
|
483
|
+
if( sprite->vcenter_x == Qnil )
|
484
|
+
{
|
485
|
+
struct DXRubyImage *image;
|
486
|
+
|
487
|
+
if( sprite->vimage == Qnil )
|
488
|
+
{
|
489
|
+
return Qnil;
|
490
|
+
}
|
491
|
+
|
492
|
+
DXRUBY_CHECK_IMAGE( sprite->vimage );
|
493
|
+
image = DXRUBY_GET_STRUCT( Image, sprite->vimage );
|
494
|
+
DXRUBY_CHECK_DISPOSE( image, texture );
|
495
|
+
return rb_float_new( image->width / 2.0f );
|
496
|
+
}
|
497
|
+
else
|
498
|
+
{
|
499
|
+
return sprite->vcenter_x;
|
500
|
+
}
|
501
|
+
}
|
502
|
+
|
503
|
+
/* center_x= */
|
504
|
+
static VALUE Sprite_set_center_x( VALUE self, VALUE vcenter_x )
|
505
|
+
{
|
506
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vcenter_x = vcenter_x;
|
507
|
+
return vcenter_x;
|
508
|
+
}
|
509
|
+
|
510
|
+
/* center_y */
|
511
|
+
static VALUE Sprite_get_center_y( VALUE self )
|
512
|
+
{
|
513
|
+
struct DXRubySprite *sprite = DXRUBY_GET_STRUCT( Sprite, self );
|
514
|
+
if( sprite->vcenter_y == Qnil )
|
515
|
+
{
|
516
|
+
struct DXRubyImage *image;
|
517
|
+
|
518
|
+
if( sprite->vimage == Qnil )
|
519
|
+
{
|
520
|
+
return Qnil;
|
521
|
+
}
|
522
|
+
|
523
|
+
DXRUBY_CHECK_IMAGE( sprite->vimage );
|
524
|
+
image = DXRUBY_GET_STRUCT( Image, sprite->vimage );
|
525
|
+
DXRUBY_CHECK_DISPOSE( image, texture );
|
526
|
+
return rb_float_new( image->height / 2.0f );
|
527
|
+
}
|
528
|
+
else
|
529
|
+
{
|
530
|
+
return sprite->vcenter_y;
|
531
|
+
}
|
532
|
+
}
|
533
|
+
|
534
|
+
/* center_y= */
|
535
|
+
static VALUE Sprite_set_center_y( VALUE self, VALUE vcenter_y )
|
536
|
+
{
|
537
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vcenter_y = vcenter_y;
|
538
|
+
return vcenter_y;
|
539
|
+
}
|
540
|
+
|
541
|
+
/* collision_enable */
|
542
|
+
static VALUE Sprite_get_collision_enable( VALUE self )
|
543
|
+
{
|
544
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vcollision_enable;
|
545
|
+
}
|
546
|
+
|
547
|
+
/* collision_enable= */
|
548
|
+
static VALUE Sprite_set_collision_enable( VALUE self, VALUE vcollision_enable )
|
549
|
+
{
|
550
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vcollision_enable = vcollision_enable;
|
551
|
+
return vcollision_enable;
|
552
|
+
}
|
553
|
+
|
554
|
+
/* collision_sync */
|
555
|
+
static VALUE Sprite_get_collision_sync( VALUE self )
|
556
|
+
{
|
557
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vcollision_sync;
|
558
|
+
}
|
559
|
+
|
560
|
+
/* collision_sync= */
|
561
|
+
static VALUE Sprite_set_collision_sync( VALUE self, VALUE vcollision_sync )
|
562
|
+
{
|
563
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vcollision_sync = vcollision_sync;
|
564
|
+
return vcollision_sync;
|
565
|
+
}
|
566
|
+
|
567
|
+
/* collision */
|
568
|
+
static VALUE Sprite_get_collision( VALUE self )
|
569
|
+
{
|
570
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vcollision;
|
571
|
+
// struct DXRubySprite *sprite = DXRUBY_GET_STRUCT( Sprite, self );
|
572
|
+
// struct DXRubyCollision temp;
|
573
|
+
// make_volume( rb_ary_new3(1, self), &temp );
|
574
|
+
// return rb_ary_new3( 4, rb_float_new(temp.x1), rb_float_new(temp.y1), rb_float_new(temp.x2), rb_float_new(temp.y2) );
|
575
|
+
}
|
576
|
+
|
577
|
+
/* collision= */
|
578
|
+
static VALUE Sprite_set_collision( VALUE self, VALUE vcollision )
|
579
|
+
{
|
580
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vcollision = vcollision;
|
581
|
+
return vcollision;
|
582
|
+
}
|
583
|
+
|
584
|
+
/* visible */
|
585
|
+
static VALUE Sprite_get_visible( VALUE self )
|
586
|
+
{
|
587
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vvisible;
|
588
|
+
}
|
589
|
+
|
590
|
+
/* visible= */
|
591
|
+
static VALUE Sprite_set_visible( VALUE self, VALUE vvisible )
|
592
|
+
{
|
593
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vvisible = vvisible;
|
594
|
+
return vvisible;
|
595
|
+
}
|
596
|
+
|
597
|
+
/* param_hash */
|
598
|
+
static VALUE Sprite_get_param_hash( VALUE self )
|
599
|
+
{
|
600
|
+
struct DXRubySprite *sprite = DXRUBY_GET_STRUCT( Sprite, self );
|
601
|
+
VALUE vresult;
|
602
|
+
|
603
|
+
vresult = rb_hash_new();
|
604
|
+
rb_hash_aset( vresult, symbol_angle, sprite->vangle );
|
605
|
+
rb_hash_aset( vresult, symbol_alpha, sprite->valpha );
|
606
|
+
rb_hash_aset( vresult, symbol_z, sprite->vz );
|
607
|
+
#ifdef DXRUBY15
|
608
|
+
rb_hash_aset( vresult, symbol_scale_x, sprite->vscale_x );
|
609
|
+
rb_hash_aset( vresult, symbol_scale_y, sprite->vscale_y );
|
610
|
+
rb_hash_aset( vresult, symbol_center_x, sprite->vcenter_x );
|
611
|
+
rb_hash_aset( vresult, symbol_center_y, sprite->vcenter_y );
|
612
|
+
#else
|
613
|
+
rb_hash_aset( vresult, symbol_scalex, sprite->vscale_x );
|
614
|
+
rb_hash_aset( vresult, symbol_scaley, sprite->vscale_y );
|
615
|
+
rb_hash_aset( vresult, symbol_centerx, sprite->vcenter_x );
|
616
|
+
rb_hash_aset( vresult, symbol_centery, sprite->vcenter_y );
|
617
|
+
#endif
|
618
|
+
rb_hash_aset( vresult, symbol_shader, sprite->vshader );
|
619
|
+
rb_hash_aset( vresult, symbol_blend, sprite->vblend );
|
620
|
+
rb_hash_aset( vresult, symbol_offset_sync, sprite->voffset_sync );
|
621
|
+
|
622
|
+
return vresult;
|
623
|
+
}
|
624
|
+
|
625
|
+
/* vanish */
|
626
|
+
static VALUE Sprite_vanish( VALUE self )
|
627
|
+
{
|
628
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vanish = TRUE;
|
629
|
+
return self;
|
630
|
+
}
|
631
|
+
|
632
|
+
/* vanish? */
|
633
|
+
static VALUE Sprite_get_vanish( VALUE self )
|
634
|
+
{
|
635
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->vanish ? Qtrue : Qfalse;
|
636
|
+
}
|
637
|
+
|
638
|
+
/* update */
|
639
|
+
static VALUE Sprite_update( VALUE self )
|
640
|
+
{
|
641
|
+
return self;
|
642
|
+
}
|
643
|
+
|
644
|
+
/* offset_sync */
|
645
|
+
static VALUE Sprite_get_offset_sync( VALUE self )
|
646
|
+
{
|
647
|
+
return DXRUBY_GET_STRUCT( Sprite, self )->voffset_sync;
|
648
|
+
}
|
649
|
+
|
650
|
+
/* offset_sync= */
|
651
|
+
static VALUE Sprite_set_offset_sync( VALUE self, VALUE voffset_sync )
|
652
|
+
{
|
653
|
+
DXRUBY_GET_STRUCT( Sprite, self )->voffset_sync = voffset_sync;
|
654
|
+
return voffset_sync;
|
655
|
+
}
|
656
|
+
|
657
|
+
#ifdef DXRUBY15
|
658
|
+
/* xy */
|
659
|
+
static VALUE Sprite_get_xy( VALUE self )
|
660
|
+
{
|
661
|
+
struct DXRubySprite *sprite = DXRUBY_GET_STRUCT( Sprite, self );
|
662
|
+
struct DXRubyVector *result;
|
663
|
+
VALUE vresult;
|
664
|
+
float sx, sy;
|
665
|
+
sx = NUM2FLOAT( sprite->vx );
|
666
|
+
sy = NUM2FLOAT( sprite->vy );
|
667
|
+
|
668
|
+
if( sprite->vxy != Qnil )
|
669
|
+
{
|
670
|
+
float x, y;
|
671
|
+
DXRUBY_CHECK_TYPE( Vector, sprite->vxy );
|
672
|
+
x = DXRUBY_GET_STRUCT( Vector, sprite->vxy )->v1;
|
673
|
+
y = DXRUBY_GET_STRUCT( Vector, sprite->vxy )->v2;
|
674
|
+
|
675
|
+
if( sx == x && sy == y )
|
676
|
+
{
|
677
|
+
return sprite->vxy;
|
678
|
+
}
|
679
|
+
}
|
680
|
+
|
681
|
+
vresult = Vector_allocate( cVector );
|
682
|
+
result = DXRUBY_GET_STRUCT( Vector, vresult );
|
683
|
+
result->x = 2;
|
684
|
+
result->v1 = sx;
|
685
|
+
result->v2 = sy;
|
686
|
+
sprite->vxy = vresult;
|
687
|
+
|
688
|
+
return vresult;
|
689
|
+
}
|
690
|
+
|
691
|
+
/* xy= */
|
692
|
+
static VALUE Sprite_set_xy( VALUE self, VALUE vxy )
|
693
|
+
{
|
694
|
+
struct DXRubyVector *vec;
|
695
|
+
|
696
|
+
DXRUBY_CHECK_TYPE( Vector, vxy );
|
697
|
+
vec = DXRUBY_GET_STRUCT( Vector, vxy );
|
698
|
+
|
699
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vxy = vxy;
|
700
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vx = rb_float_new( vec->v1 );
|
701
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vy = rb_float_new( vec->v2 );
|
702
|
+
|
703
|
+
return vxy;
|
704
|
+
}
|
705
|
+
|
706
|
+
/* xyz */
|
707
|
+
static VALUE Sprite_get_xyz( VALUE self )
|
708
|
+
{
|
709
|
+
struct DXRubySprite *sprite = DXRUBY_GET_STRUCT( Sprite, self );
|
710
|
+
struct DXRubyVector *result;
|
711
|
+
VALUE vresult;
|
712
|
+
float sx, sy, sz;
|
713
|
+
sx = NUM2FLOAT( sprite->vx );
|
714
|
+
sy = NUM2FLOAT( sprite->vy );
|
715
|
+
sz = NUM2FLOAT( sprite->vz );
|
716
|
+
|
717
|
+
if( sprite->vxyz != Qnil )
|
718
|
+
{
|
719
|
+
float x, y, z;
|
720
|
+
DXRUBY_CHECK_TYPE( Vector, sprite->vxyz );
|
721
|
+
x = DXRUBY_GET_STRUCT( Vector, sprite->vxyz )->v1;
|
722
|
+
y = DXRUBY_GET_STRUCT( Vector, sprite->vxyz )->v2;
|
723
|
+
z = DXRUBY_GET_STRUCT( Vector, sprite->vxyz )->v3;
|
724
|
+
|
725
|
+
if( sx == x && sy == y && sz == z)
|
726
|
+
{
|
727
|
+
return sprite->vxyz;
|
728
|
+
}
|
729
|
+
}
|
730
|
+
|
731
|
+
vresult = Vector_allocate( cVector );
|
732
|
+
result = DXRUBY_GET_STRUCT( Vector, vresult );
|
733
|
+
result->x = 3;
|
734
|
+
result->v1 = sx;
|
735
|
+
result->v2 = sy;
|
736
|
+
result->v3 = sz;
|
737
|
+
sprite->vxyz = vresult;
|
738
|
+
|
739
|
+
return vresult;
|
740
|
+
}
|
741
|
+
|
742
|
+
|
743
|
+
/* xyz= */
|
744
|
+
static VALUE Sprite_set_xyz( VALUE self, VALUE vxyz )
|
745
|
+
{
|
746
|
+
struct DXRubyVector *vec;
|
747
|
+
|
748
|
+
DXRUBY_CHECK_TYPE( Vector, vxyz );
|
749
|
+
vec = DXRUBY_GET_STRUCT( Vector, vxyz );
|
750
|
+
|
751
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vxyz = vxyz;
|
752
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vx = rb_float_new( vec->v1 );
|
753
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vy = rb_float_new( vec->v2 );
|
754
|
+
DXRUBY_GET_STRUCT( Sprite, self )->vz = rb_float_new( vec->v3 );
|
755
|
+
|
756
|
+
return vxyz;
|
757
|
+
}
|
758
|
+
#endif
|
759
|
+
|
760
|
+
/*--------------------------------------------------------------------
|
761
|
+
�P�̂Ɣz��̔���
|
762
|
+
---------------------------------------------------------------------*/
|
763
|
+
static VALUE Sprite_hitcheck( VALUE self, VALUE vsprite )
|
764
|
+
{
|
765
|
+
struct DXRubyCollisionGroup collision1;
|
766
|
+
VALUE vary;
|
767
|
+
|
768
|
+
/* �Փ˂����I�u�W�F�N�g������z�� */
|
769
|
+
vary = rb_ary_new();
|
770
|
+
|
771
|
+
/* self��AABB�{�����[���v�Z */
|
772
|
+
if( make_volume( self, &collision1 ) == 0 )
|
773
|
+
{
|
774
|
+
collision_clear();
|
775
|
+
return vary;
|
776
|
+
}
|
777
|
+
|
778
|
+
if( TYPE(vsprite) == T_ARRAY )
|
779
|
+
{
|
780
|
+
struct DXRubyCollisionGroup *collision2;
|
781
|
+
int i, d_total;
|
782
|
+
|
783
|
+
/* �Ώۂ�AABB�{�����[���v�Z */
|
784
|
+
collision2 = (struct DXRubyCollisionGroup *)malloc( get_volume_count( vsprite ) * sizeof(struct DXRubyCollisionGroup) );
|
785
|
+
d_total = make_volume_ary( vsprite, collision2 );
|
786
|
+
|
787
|
+
/* �ΏۃI�u�W�F�N�g�̃��[�v */
|
788
|
+
for( i = 0; i < d_total; i++ )
|
789
|
+
{
|
790
|
+
/* ���� */
|
791
|
+
if( check_box_box( &collision1, collision2 + i ) && check( &collision1, collision2 + i ) )
|
792
|
+
{
|
793
|
+
rb_ary_push( vary, (collision2 + i)->vsprite );
|
794
|
+
}
|
795
|
+
}
|
796
|
+
|
797
|
+
free( collision2 );
|
798
|
+
}
|
799
|
+
else
|
800
|
+
{
|
801
|
+
struct DXRubyCollisionGroup collision2;
|
802
|
+
|
803
|
+
/* �Ώۂ�AABB�{�����[���v�Z */
|
804
|
+
if( make_volume( vsprite, &collision2 ) > 0 )
|
805
|
+
{
|
806
|
+
/* ���� */
|
807
|
+
if( check_box_box( &collision1, &collision2 ) && check( &collision1, &collision2 ) )
|
808
|
+
{
|
809
|
+
rb_ary_push( vary, collision2.vsprite );
|
810
|
+
}
|
811
|
+
}
|
812
|
+
}
|
813
|
+
|
814
|
+
collision_clear();
|
815
|
+
return vary;
|
816
|
+
}
|
817
|
+
|
818
|
+
|
819
|
+
/*--------------------------------------------------------------------
|
820
|
+
�P�̂̔���
|
821
|
+
---------------------------------------------------------------------*/
|
822
|
+
static VALUE Sprite_compare( VALUE self, VALUE vsprite )
|
823
|
+
{
|
824
|
+
struct DXRubyCollisionGroup collision1;
|
825
|
+
VALUE vary;
|
826
|
+
|
827
|
+
/* �Փ˂����I�u�W�F�N�g������z�� */
|
828
|
+
vary = rb_ary_new();
|
829
|
+
|
830
|
+
/* self��AABB�{�����[���v�Z */
|
831
|
+
if( make_volume( self, &collision1 ) == 0 )
|
832
|
+
{
|
833
|
+
collision_clear();
|
834
|
+
return vary;
|
835
|
+
}
|
836
|
+
|
837
|
+
if( TYPE(vsprite) == T_ARRAY )
|
838
|
+
{
|
839
|
+
struct DXRubyCollisionGroup *collision2;
|
840
|
+
int i, d_total;
|
841
|
+
|
842
|
+
/* �Ώۂ�AABB�{�����[���v�Z */
|
843
|
+
collision2 = (struct DXRubyCollisionGroup *)malloc( get_volume_count( vsprite ) * sizeof(struct DXRubyCollisionGroup) );
|
844
|
+
d_total = make_volume_ary( vsprite, collision2 );
|
845
|
+
|
846
|
+
/* �ΏۃI�u�W�F�N�g�̃��[�v */
|
847
|
+
for( i = 0; i < d_total; i++ )
|
848
|
+
{
|
849
|
+
/* ���� */
|
850
|
+
if( check_box_box( &collision1, collision2 + i ) && check( &collision1, collision2 + i ) )
|
851
|
+
{
|
852
|
+
free( collision2 );
|
853
|
+
collision_clear();
|
854
|
+
return Qtrue;
|
855
|
+
}
|
856
|
+
}
|
857
|
+
|
858
|
+
free( collision2 );
|
859
|
+
}
|
860
|
+
else
|
861
|
+
{
|
862
|
+
struct DXRubyCollisionGroup collision2;
|
863
|
+
|
864
|
+
/* �Ώۂ�AABB�{�����[���v�Z */
|
865
|
+
if( make_volume( vsprite, &collision2 ) > 0 )
|
866
|
+
{
|
867
|
+
/* ���� */
|
868
|
+
if( check_box_box( &collision1, &collision2 ) && check( &collision1, &collision2 ) )
|
869
|
+
{
|
870
|
+
collision_clear();
|
871
|
+
return Qtrue;
|
872
|
+
}
|
873
|
+
}
|
874
|
+
}
|
875
|
+
|
876
|
+
collision_clear();
|
877
|
+
return Qfalse;
|
878
|
+
}
|
879
|
+
|
880
|
+
|
881
|
+
/*--------------------------------------------------------------------
|
882
|
+
�z�m�̔���
|
883
|
+
---------------------------------------------------------------------*/
|
884
|
+
static VALUE Sprite_check( int argc, VALUE *argv, VALUE klass )
|
885
|
+
{
|
886
|
+
int i, j;
|
887
|
+
int flag = 0; /* �ʃO���[�v�Ȃ�0�A�����O���[�v�Ȃ�1 */
|
888
|
+
VALUE hitflag = Qfalse; /* ��ł�����������Qtrue */
|
889
|
+
VALUE o, d;
|
890
|
+
ID id_shot_temp, id_hit_temp;
|
891
|
+
int shot_flg = 0, hit_flg = 0;
|
892
|
+
VALUE ary;
|
893
|
+
int ary_count = 0;
|
894
|
+
struct DXRubyCollisionGroup *collision1;
|
895
|
+
struct DXRubyCollisionGroup *collision2;
|
896
|
+
int o_total, d_total;
|
897
|
+
|
898
|
+
if( argc < 1 || argc > 4 ) rb_raise( rb_eArgError, "wrong number of arguments (%d for %d..%d)", argc, 1, 4 );
|
899
|
+
|
900
|
+
o = argv[0];
|
901
|
+
|
902
|
+
if( argc == 1 )
|
903
|
+
{
|
904
|
+
d = o;
|
905
|
+
}
|
906
|
+
else
|
907
|
+
{
|
908
|
+
d = argv[1];
|
909
|
+
}
|
910
|
+
|
911
|
+
/* �P�̎w��̏ꍇ�͂Ƃ肠�����z��ɓ˂����� */
|
912
|
+
if( TYPE(o) != T_ARRAY )
|
913
|
+
{
|
914
|
+
o = rb_ary_new3( 1, o );
|
915
|
+
}
|
916
|
+
if( TYPE(d) != T_ARRAY )
|
917
|
+
{
|
918
|
+
d = rb_ary_new3( 1, d );
|
919
|
+
}
|
920
|
+
|
921
|
+
/* �����z������flag�𗧂Ă� */
|
922
|
+
if( o == d )
|
923
|
+
{
|
924
|
+
flag = 1;
|
925
|
+
id_shot_temp = id_hit;
|
926
|
+
id_hit_temp = id_hit;
|
927
|
+
}
|
928
|
+
else
|
929
|
+
{
|
930
|
+
id_shot_temp = id_shot;
|
931
|
+
id_hit_temp = id_hit;
|
932
|
+
}
|
933
|
+
|
934
|
+
/* �Ăѐ惁�\�b�h */
|
935
|
+
if( argc > 2 )
|
936
|
+
{
|
937
|
+
if( TYPE(argv[2]) == T_STRING )
|
938
|
+
{
|
939
|
+
id_shot_temp = rb_intern( RSTRING_PTR(argv[2]) );
|
940
|
+
}
|
941
|
+
else if( TYPE(argv[2]) == T_SYMBOL )
|
942
|
+
{
|
943
|
+
id_shot_temp = SYM2ID( argv[2] );
|
944
|
+
}
|
945
|
+
else if( argv[2] == Qnil )
|
946
|
+
{
|
947
|
+
shot_flg = 1;
|
948
|
+
}
|
949
|
+
else
|
950
|
+
{
|
951
|
+
rb_raise( rb_eTypeError, "wrong argument type %s (expected String or Symbol)", rb_obj_classname( argv[2] ) );
|
952
|
+
}
|
953
|
+
}
|
954
|
+
|
955
|
+
if( argc > 3 )
|
956
|
+
{
|
957
|
+
if( TYPE(argv[3]) == T_STRING )
|
958
|
+
{
|
959
|
+
id_hit_temp = rb_intern( RSTRING_PTR(argv[3]) );
|
960
|
+
}
|
961
|
+
else if( TYPE(argv[3]) == T_SYMBOL )
|
962
|
+
{
|
963
|
+
id_hit_temp = SYM2ID( argv[3] );
|
964
|
+
}
|
965
|
+
else if( argv[3] == Qnil )
|
966
|
+
{
|
967
|
+
hit_flg = 1;
|
968
|
+
}
|
969
|
+
else
|
970
|
+
{
|
971
|
+
rb_raise( rb_eTypeError, "wrong argument type %s (expected String or Symbol)", rb_obj_classname( argv[3] ) );
|
972
|
+
}
|
973
|
+
}
|
974
|
+
|
975
|
+
/* AABB�{�����[���v�Z */
|
976
|
+
collision1 = (struct DXRubyCollisionGroup *)malloc( get_volume_count( o ) * sizeof(struct DXRubyCollisionGroup) );
|
977
|
+
o_total = make_volume_ary( o, collision1 );
|
978
|
+
|
979
|
+
if( flag == 0 )
|
980
|
+
{
|
981
|
+
collision2 = (struct DXRubyCollisionGroup *)malloc( get_volume_count( d ) * sizeof(struct DXRubyCollisionGroup) );
|
982
|
+
d_total = make_volume_ary( d, collision2 );
|
983
|
+
}
|
984
|
+
else
|
985
|
+
{
|
986
|
+
d_total = o_total;
|
987
|
+
collision2 = collision1;
|
988
|
+
}
|
989
|
+
|
990
|
+
/* �Փ˂��m�点�Ώ� */
|
991
|
+
// ary = (VALUE *)alloca( o_total * d_total * 2 * sizeof(VALUE *) );
|
992
|
+
ary = rb_ary_new();
|
993
|
+
|
994
|
+
/* �U�����I�u�W�F�N�g�̃��[�v */
|
995
|
+
for( i = 0; i < o_total - flag; i++ )
|
996
|
+
{
|
997
|
+
/* �h�䑤�I�u�W�F�N�g�̃��[�v */
|
998
|
+
for( j = (flag == 0 ? 0 : i + 1); j < d_total; j++ )
|
999
|
+
{
|
1000
|
+
/* ���� */
|
1001
|
+
if( check_box_box( collision1 + i, collision2 + j ) && check( collision1 + i, collision2 + j ) )
|
1002
|
+
{
|
1003
|
+
hitflag = Qtrue;
|
1004
|
+
rb_ary_push( ary, (collision1 + i)->vsprite );
|
1005
|
+
rb_ary_push( ary, (collision2 + j)->vsprite );
|
1006
|
+
// *(ary + ary_count) = (collision1 + i)->vsprite;
|
1007
|
+
// *(ary + ary_count + 1) = (collision2 + j)->vsprite;
|
1008
|
+
ary_count += 2;
|
1009
|
+
}
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
/* �Փ˂��m�点�R�[���o�b�N */
|
1014
|
+
for( i = 0; i < ary_count; i += 2 )
|
1015
|
+
{
|
1016
|
+
VALUE result;
|
1017
|
+
if( DXRUBY_GET_STRUCT(Sprite, RARRAY_AREF(ary, i))->vanish || DXRUBY_GET_STRUCT(Sprite, RARRAY_AREF(ary, i + 1))->vanish )
|
1018
|
+
{
|
1019
|
+
continue;
|
1020
|
+
}
|
1021
|
+
if( flag == 0 )
|
1022
|
+
{
|
1023
|
+
if( rb_respond_to( RARRAY_AREF(ary, i), id_shot_temp ) && !shot_flg )
|
1024
|
+
{
|
1025
|
+
if( rb_obj_method_arity( RARRAY_AREF(ary, i), id_shot_temp) == 0 ) /* ���������� */
|
1026
|
+
{
|
1027
|
+
result = rb_funcall( RARRAY_AREF(ary, i), id_shot_temp, 0 );
|
1028
|
+
}
|
1029
|
+
else /* ���������� */
|
1030
|
+
{
|
1031
|
+
result = rb_funcall( RARRAY_AREF(ary, i), id_shot_temp, 1, RARRAY_AREF(ary, i + 1) );
|
1032
|
+
}
|
1033
|
+
|
1034
|
+
if( result == symbol_discard )
|
1035
|
+
{ /* ��������Ȃ� */
|
1036
|
+
int j;
|
1037
|
+
for( j = i + 2; j < ary_count; j += 2) /* ����Sprite�������H���� */
|
1038
|
+
{
|
1039
|
+
if( RARRAY_AREF(ary, i) == RARRAY_AREF(ary, j) || RARRAY_AREF(ary, i) == RARRAY_AREF(ary, j + 1) ) /* �����I�u�W�F�N�g�������� */
|
1040
|
+
{
|
1041
|
+
RARRAY_ASET(ary, j, Qnil); /* ���� */
|
1042
|
+
RARRAY_ASET(ary, j + 1, Qnil);
|
1043
|
+
}
|
1044
|
+
}
|
1045
|
+
}
|
1046
|
+
}
|
1047
|
+
}
|
1048
|
+
else
|
1049
|
+
{
|
1050
|
+
if( rb_respond_to( RARRAY_AREF(ary, i), id_hit_temp ) && !hit_flg )
|
1051
|
+
{
|
1052
|
+
if( rb_obj_method_arity( RARRAY_AREF(ary, i), id_hit_temp) == 0 ) /* ���������� */
|
1053
|
+
{
|
1054
|
+
result = rb_funcall( RARRAY_AREF(ary, i), id_hit_temp, 0 );
|
1055
|
+
}
|
1056
|
+
else /* ���������� */
|
1057
|
+
{
|
1058
|
+
result = rb_funcall( RARRAY_AREF(ary, i), id_hit_temp, 1, RARRAY_AREF(ary, i + 1) );
|
1059
|
+
}
|
1060
|
+
|
1061
|
+
if( result == symbol_discard )
|
1062
|
+
{ /* ��������Ȃ� */
|
1063
|
+
int j;
|
1064
|
+
for( j = i + 2; j < ary_count; j += 2) /* ����Sprite�������H���� */
|
1065
|
+
{
|
1066
|
+
if( RARRAY_AREF(ary, i) == RARRAY_AREF(ary, j) || RARRAY_AREF(ary, i) == RARRAY_AREF(ary, j + 1) ) /* �����I�u�W�F�N�g�������� */
|
1067
|
+
{
|
1068
|
+
RARRAY_ASET(ary, j, Qnil); /* ���� */
|
1069
|
+
RARRAY_ASET(ary, j + 1, Qnil);
|
1070
|
+
}
|
1071
|
+
}
|
1072
|
+
}
|
1073
|
+
}
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
if( rb_respond_to( RARRAY_AREF(ary, i + 1), id_hit_temp ) && !hit_flg )
|
1077
|
+
{
|
1078
|
+
if( rb_obj_method_arity( RARRAY_AREF(ary, i + 1), id_hit_temp) == 0 ) /* ���������� */
|
1079
|
+
{
|
1080
|
+
result = rb_funcall( RARRAY_AREF(ary, i + 1), id_hit_temp, 0 );
|
1081
|
+
}
|
1082
|
+
else /* ���������� */
|
1083
|
+
{
|
1084
|
+
result = rb_funcall( RARRAY_AREF(ary, i + 1), id_hit_temp, 1, RARRAY_AREF(ary, i) );
|
1085
|
+
}
|
1086
|
+
|
1087
|
+
if( result == symbol_discard )
|
1088
|
+
{ /* ��������Ȃ� */
|
1089
|
+
int j;
|
1090
|
+
for( j = i + 2; j < ary_count; j += 2) /* ����Sprite�������H���� */
|
1091
|
+
{
|
1092
|
+
if( RARRAY_AREF(ary, i + 1) == RARRAY_AREF(ary, j) || RARRAY_AREF(ary, i + 1) == RARRAY_AREF(ary, j + 1) ) /* �����I�u�W�F�N�g�������� */
|
1093
|
+
{
|
1094
|
+
RARRAY_ASET(ary, j, Qnil); /* ���� */
|
1095
|
+
RARRAY_ASET(ary, j + 1, Qnil);
|
1096
|
+
}
|
1097
|
+
}
|
1098
|
+
}
|
1099
|
+
}
|
1100
|
+
}
|
1101
|
+
|
1102
|
+
free( collision1 );
|
1103
|
+
if( flag == 0 )
|
1104
|
+
{
|
1105
|
+
free( collision2 );
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
collision_clear();
|
1109
|
+
|
1110
|
+
return hitflag;
|
1111
|
+
}
|
1112
|
+
|
1113
|
+
|
1114
|
+
static VALUE Sprite_class_update( VALUE klass, VALUE ary )
|
1115
|
+
{
|
1116
|
+
int i;
|
1117
|
+
|
1118
|
+
if( TYPE( ary ) != T_ARRAY )
|
1119
|
+
{
|
1120
|
+
ary = rb_ary_new3( 1, ary );
|
1121
|
+
}
|
1122
|
+
|
1123
|
+
for( i = 0; i < RARRAY_LEN( ary ); i++ )
|
1124
|
+
{
|
1125
|
+
VALUE p = RARRAY_AREF( ary, i );
|
1126
|
+
|
1127
|
+
if( TYPE( p ) == T_ARRAY )
|
1128
|
+
{
|
1129
|
+
Sprite_class_update( cSprite, p );
|
1130
|
+
}
|
1131
|
+
else if( !rb_respond_to( p, id_vanished ) || !RTEST( rb_funcall2( p, id_vanished, 0, 0 ) ) )
|
1132
|
+
{
|
1133
|
+
if( rb_respond_to( p, id_update ) )
|
1134
|
+
{
|
1135
|
+
rb_funcall2( p, id_update, 0, 0 );
|
1136
|
+
}
|
1137
|
+
}
|
1138
|
+
}
|
1139
|
+
return Qnil;
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
|
1143
|
+
static VALUE Sprite_class_draw( VALUE klass, VALUE ary )
|
1144
|
+
{
|
1145
|
+
int i;
|
1146
|
+
|
1147
|
+
if( TYPE( ary ) != T_ARRAY )
|
1148
|
+
{
|
1149
|
+
ary = rb_ary_new3( 1, ary );
|
1150
|
+
}
|
1151
|
+
|
1152
|
+
for( i = 0; i < RARRAY_LEN( ary ); i++ )
|
1153
|
+
{
|
1154
|
+
VALUE p = RARRAY_AREF( ary, i );
|
1155
|
+
|
1156
|
+
if( TYPE( p ) == T_ARRAY )
|
1157
|
+
{
|
1158
|
+
Sprite_class_draw( cSprite, p );
|
1159
|
+
}
|
1160
|
+
else if( !rb_respond_to( p, id_vanished ) || !RTEST( rb_funcall2( p, id_vanished, 0, 0 ) ) )
|
1161
|
+
{
|
1162
|
+
if( rb_respond_to( p, id_draw ) )
|
1163
|
+
{
|
1164
|
+
rb_funcall2( p, id_draw, 0, 0 );
|
1165
|
+
}
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
return Qnil;
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
|
1172
|
+
static VALUE Sprite_class_render( VALUE klass, VALUE ary )
|
1173
|
+
{
|
1174
|
+
int i;
|
1175
|
+
|
1176
|
+
if( TYPE( ary ) != T_ARRAY )
|
1177
|
+
{
|
1178
|
+
ary = rb_ary_new3( 1, ary );
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
for( i = 0; i < RARRAY_LEN( ary ); i++ )
|
1182
|
+
{
|
1183
|
+
VALUE p = RARRAY_AREF( ary, i );
|
1184
|
+
|
1185
|
+
if( TYPE( p ) == T_ARRAY )
|
1186
|
+
{
|
1187
|
+
Sprite_class_draw( cSprite, p );
|
1188
|
+
}
|
1189
|
+
else if( !rb_respond_to( p, id_vanished ) || !RTEST( rb_funcall2( p, id_vanished, 0, 0 ) ) )
|
1190
|
+
{
|
1191
|
+
if( rb_respond_to( p, id_render ) )
|
1192
|
+
{
|
1193
|
+
rb_funcall2( p, id_render, 0, 0 );
|
1194
|
+
}
|
1195
|
+
}
|
1196
|
+
}
|
1197
|
+
return Qnil;
|
1198
|
+
}
|
1199
|
+
|
1200
|
+
|
1201
|
+
static VALUE Sprite_class_clean( VALUE klass, VALUE ary )
|
1202
|
+
{
|
1203
|
+
int i;
|
1204
|
+
|
1205
|
+
if( TYPE( ary ) != T_ARRAY )
|
1206
|
+
{
|
1207
|
+
return Qnil;
|
1208
|
+
}
|
1209
|
+
|
1210
|
+
for( i = 0; i < RARRAY_LEN( ary ); i++ )
|
1211
|
+
{
|
1212
|
+
VALUE p = RARRAY_AREF( ary, i );
|
1213
|
+
|
1214
|
+
if( TYPE( p ) == T_ARRAY )
|
1215
|
+
{
|
1216
|
+
Sprite_class_clean( cSprite, p );
|
1217
|
+
}
|
1218
|
+
else if( rb_respond_to( p, id_vanished ) && RTEST( rb_funcall2( p, id_vanished, 0, 0 ) ) )
|
1219
|
+
{
|
1220
|
+
RARRAY_ASET( ary, i, Qnil);
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
rb_funcall( ary, rb_intern("compact!"), 0 );
|
1225
|
+
|
1226
|
+
return Qnil;
|
1227
|
+
}
|
1228
|
+
|
1229
|
+
|
1230
|
+
/*
|
1231
|
+
***************************************************************
|
1232
|
+
*
|
1233
|
+
* Global functions
|
1234
|
+
*
|
1235
|
+
***************************************************************/
|
1236
|
+
|
1237
|
+
void Init_dxruby_Sprite()
|
1238
|
+
{
|
1239
|
+
/* Sprite�N���X��` */
|
1240
|
+
cSprite = rb_define_class_under( mDXRuby, "Sprite", rb_cObject );
|
1241
|
+
|
1242
|
+
rb_define_private_method( cSprite, "initialize", Sprite_initialize, -1 );
|
1243
|
+
rb_define_method( cSprite, "x", Sprite_get_x, 0 );
|
1244
|
+
rb_define_method( cSprite, "x=", Sprite_set_x, 1 );
|
1245
|
+
rb_define_method( cSprite, "y", Sprite_get_y, 0 );
|
1246
|
+
rb_define_method( cSprite, "y=", Sprite_set_y, 1 );
|
1247
|
+
rb_define_method( cSprite, "z", Sprite_get_z, 0 );
|
1248
|
+
rb_define_method( cSprite, "z=", Sprite_set_z, 1 );
|
1249
|
+
rb_define_method( cSprite, "angle", Sprite_get_angle, 0 );
|
1250
|
+
rb_define_method( cSprite, "angle=", Sprite_set_angle, 1 );
|
1251
|
+
rb_define_method( cSprite, "scale_x", Sprite_get_scale_x, 0 );
|
1252
|
+
rb_define_method( cSprite, "scale_x=", Sprite_set_scale_x, 1 );
|
1253
|
+
rb_define_method( cSprite, "scale_y", Sprite_get_scale_y, 0 );
|
1254
|
+
rb_define_method( cSprite, "scale_y=", Sprite_set_scale_y, 1 );
|
1255
|
+
rb_define_method( cSprite, "center_x", Sprite_get_center_x, 0 );
|
1256
|
+
rb_define_method( cSprite, "center_x=", Sprite_set_center_x, 1 );
|
1257
|
+
rb_define_method( cSprite, "center_y", Sprite_get_center_y, 0 );
|
1258
|
+
rb_define_method( cSprite, "center_y=", Sprite_set_center_y, 1 );
|
1259
|
+
rb_define_method( cSprite, "alpha", Sprite_get_alpha, 0 );
|
1260
|
+
rb_define_method( cSprite, "alpha=", Sprite_set_alpha, 1 );
|
1261
|
+
rb_define_method( cSprite, "blend", Sprite_get_blend, 0 );
|
1262
|
+
rb_define_method( cSprite, "blend=", Sprite_set_blend, 1 );
|
1263
|
+
rb_define_method( cSprite, "image", Sprite_get_image, 0 );
|
1264
|
+
rb_define_method( cSprite, "image=", Sprite_set_image, 1 );
|
1265
|
+
rb_define_method( cSprite, "target", Sprite_get_target, 0 );
|
1266
|
+
rb_define_method( cSprite, "target=", Sprite_set_target, 1 );
|
1267
|
+
rb_define_method( cSprite, "shader", Sprite_get_shader, 0 );
|
1268
|
+
rb_define_method( cSprite, "shader=", Sprite_set_shader, 1 );
|
1269
|
+
rb_define_method( cSprite, "collision", Sprite_get_collision, 0 );
|
1270
|
+
rb_define_method( cSprite, "collision=", Sprite_set_collision, 1 );
|
1271
|
+
rb_define_method( cSprite, "collision_enable", Sprite_get_collision_enable, 0 );
|
1272
|
+
rb_define_method( cSprite, "collision_enable=", Sprite_set_collision_enable, 1 );
|
1273
|
+
rb_define_method( cSprite, "collision_sync", Sprite_get_collision_sync, 0 );
|
1274
|
+
rb_define_method( cSprite, "collision_sync=", Sprite_set_collision_sync, 1 );
|
1275
|
+
rb_define_method( cSprite, "visible", Sprite_get_visible, 0 );
|
1276
|
+
rb_define_method( cSprite, "visible=", Sprite_set_visible, 1 );
|
1277
|
+
rb_define_method( cSprite, "update", Sprite_update, 0 );
|
1278
|
+
rb_define_method( cSprite, "draw", Sprite_draw, 0 );
|
1279
|
+
// rb_define_method( cSprite, "render", Sprite_draw, 0 );
|
1280
|
+
rb_define_method( cSprite, "===", Sprite_compare, 1 );
|
1281
|
+
rb_define_method( cSprite, "check", Sprite_hitcheck, 1 );
|
1282
|
+
rb_define_method( cSprite, "param_hash", Sprite_get_param_hash, 0 );
|
1283
|
+
rb_define_method( cSprite, "vanish", Sprite_vanish, 0 );
|
1284
|
+
rb_define_method( cSprite, "vanished?", Sprite_get_vanish, 0 );
|
1285
|
+
rb_define_method( cSprite, "offset_sync", Sprite_get_offset_sync, 0 );
|
1286
|
+
rb_define_method( cSprite, "offset_sync=", Sprite_set_offset_sync, 1 );
|
1287
|
+
#ifdef DXRUBY15
|
1288
|
+
rb_define_method( cSprite, "xy", Sprite_get_xy, 0 );
|
1289
|
+
rb_define_method( cSprite, "xy=", Sprite_set_xy, 1 );
|
1290
|
+
rb_define_method( cSprite, "xyz", Sprite_get_xyz, 0 );
|
1291
|
+
rb_define_method( cSprite, "xyz=", Sprite_set_xyz, 1 );
|
1292
|
+
#endif
|
1293
|
+
|
1294
|
+
/* Sprite�N���X�Ƀ��\�b�h�o�^ */
|
1295
|
+
rb_define_singleton_method( cSprite, "check", Sprite_check, -1 );
|
1296
|
+
rb_define_singleton_method( cSprite, "update", Sprite_class_update, 1 );
|
1297
|
+
rb_define_singleton_method( cSprite, "draw", Sprite_class_draw, 1 );
|
1298
|
+
// rb_define_singleton_method( cSprite, "render", Sprite_class_render, 1 );
|
1299
|
+
rb_define_singleton_method( cSprite, "clean", Sprite_class_clean, 1 );
|
1300
|
+
|
1301
|
+
rb_define_alloc_func( cSprite, Sprite_allocate );
|
1302
|
+
|
1303
|
+
id_shot = rb_intern("shot");
|
1304
|
+
id_hit = rb_intern("hit");
|
1305
|
+
id_update = rb_intern("update");
|
1306
|
+
id_draw = rb_intern("draw");
|
1307
|
+
id_render = rb_intern("render");
|
1308
|
+
id_vanished = rb_intern("vanished?");
|
1309
|
+
id_visible = rb_intern("visible");
|
1310
|
+
|
1311
|
+
collision_init();
|
1312
|
+
}
|
1313
|
+
|