1 #include "xtama_move.h"
2
3 /* ����Ƥ����̤���ꤹ�� */
tama_set(tx1,ty1,tx2,ty2,color1,color2)4 void tama_set( tx1 , ty1 , tx2 , ty2 , color1 , color2)
5 int tx1 , tx2 , color1 , color2 , ty1 , ty2 ;
6 {
7
8 if( ty1 >= 0 && ( net ? (int)(ty1/4)<19 : (int)(ty1/4)<12) ) map[ tx1 ][ (int)(ty1 / 4) ] = color1 + 1 ;
9 if( ty2 >= 0 && ( net ? (int)(ty2/4)<19 : (int)(ty2/4)<12) ) map[ tx2 ][ (int)(ty2 / 4) ] = color2 + 1 ;
10
11 return ;
12 }
13
14 /* �̤������˰�ư��ǽ��Ƚ�Ǥ��Ƽ¹Ԥ��� */
tama_moveside(int * tx1,int * ty1,int * tx2,int * ty2,int dir,int color1,int color2)15 void tama_moveside( int *tx1 , int *ty1 , int *tx2 , int *ty2 ,int dir , int color1 , int color2 )
16 {
17 int atti ;
18 int x = 0 ;
19
20 atti = attitu( *tx1 , *ty1 , *tx2 , *ty2 ) ;
21
22 if ( dir == LEFT ) /* ����ư�λ� */
23 switch ( atti )
24 {
25 case LEFT:
26 if ( !vmap( *tx2 - 1 , *ty2 ) && *tx2 > 0 )
27 x -- ;
28 break ;
29 case RIGHT:
30 if ( !vmap( *tx1 - 1 , *ty1 ) && *tx1 > 0 )
31 x -- ;
32 break ;
33 case UPPER:
34 if ( !vmap( *tx1 - 1 , *ty1 ) && *tx1 > 0 )
35 x -- ;
36 break ;
37 case LOWER:
38 if ( !vmap( *tx2 - 1 , *ty2 ) && *tx2 > 0 )
39 x -- ;
40 break ;
41 }
42 else
43 switch ( atti ) /* ����ư�λ� */
44 {
45 case LEFT:
46 if ( !vmap( *tx1 + 1 , *ty2 ) && *tx1 < 7 )
47 x ++ ;
48 break ;
49 case RIGHT:
50 if ( !vmap( *tx2 + 1 , *ty1 ) && *tx2 < 7 )
51 x ++ ;
52 break ;
53 case UPPER:
54 if ( !vmap( *tx1 + 1 , *ty1 ) && *tx1 < 7 )
55 x ++ ;
56 break;
57 case LOWER:
58 if ( !vmap( *tx2 + 1 , *ty2 ) && *tx2 < 7 )
59 x ++ ;
60 break;
61 }
62
63 (*tx1) += x ;
64 (*tx2) += x ;
65
66 if ( x ) MoveWindow ( color1 , color2 , *tx1 , *ty1 , *tx2 , *ty2 , True ,
67 *tx1 - x , *ty1 , *tx2 - x , *ty2 , back ) ;
68 }
69
70
71 /* �̤��桼������˾�������˲�뤫�ɤ���Ƚ�Ǥ��Ƽ¹Ԥ��� */
tama_roll(int * tx1,int * ty1,int * tx2,int * ty2,int dir,int color1,int color2)72 void tama_roll( int *tx1 , int *ty1 , int *tx2 , int *ty2 , int dir , int color1 , int color2 )
73 {
74 int atti ;
75
76 atti = attitu( *tx1 , *ty1 , *tx2 ,*ty2 ) ;
77
78 if ( dir == LEFT )
79 switch ( atti )
80 {
81 case LEFT:
82 rolling( tx1 , ty1 , tx2 ,ty2 , 1 , -1 , color1 , color2 ) ;
83 break;
84 case RIGHT:
85 rolling( tx1 , ty1 , tx2 ,ty2 , - 1 , 1 , color1 , color2 ) ;
86 break;
87 case UPPER:
88 rolling( tx1 , ty1 , tx2 ,ty2 , -1 , -1 , color1 , color2 ) ;
89 break;
90 case LOWER:
91 rolling( tx1 , ty1 , tx2 ,ty2 , 1 , 1 , color1 , color2 ) ;
92 break;
93 }
94 else
95 switch ( atti )
96 {
97 case LEFT:
98 rolling( tx1 , ty1 , tx2 ,ty2 , 1 , 1 , color1 , color2 ) ;
99 break;
100 case RIGHT:
101 rolling( tx1 , ty1 , tx2 ,ty2 , -1 , -1 , color1 , color2 ) ;
102 break;
103 case UPPER:
104 rolling( tx1 , ty1 , tx2 ,ty2 , 1 , -1 , color1 , color2 ) ;
105 break;
106 case LOWER:
107 rolling( tx1 , ty1 , tx2 ,ty2 , -1 , 1 , color1 , color2 ) ;
108 break;
109
110 }
111 }
112
rolling(int * tx1,int * ty1,int * tx2,int * ty2,int ax,int ay,int color1,int color2)113 void rolling( int *tx1 , int *ty1 ,int *tx2 , int *ty2 ,int ax ,int ay , int color1 , int color2 )
114 {
115 int atti ;
116
117 /* ����̵������� */
118 if ( *tx2 +ax > -1 && *tx2 + ax < 8 && *ty2 + ay * 4 >= 0 )
119 if ( !vmap( *tx2 + ax , *ty2 + ay * 4 )) {
120 (*tx2) += ax ;
121 (*ty2) += ay * 4 ;
122 MoveWindow( color1 , color2 , *tx1 , *ty1 , *tx2 , *ty2 ,
123 True , *tx1 , *ty1 , *tx2 - ax, *ty2 - ay * 4, back ) ;
124 return ;
125 }
126
127 atti = attitu( *tx1 , *ty1 , *tx2 , *ty2 ) ;
128
129 /* ���̤�ü�λ��ν��� */
130 if (( *tx1 == 0 && ax < 0 && atti != RIGHT ) ||
131 ( *tx1 == 7 && ax > 0 && atti != LEFT )){
132 if ( !vmap( *tx1 - ax , *ty1 )) {
133 (*tx1) -= ax ;
134 (*ty2) += ay * 4 ;
135 MoveWindow( color1 , color2 , *tx1 , *ty1 , *tx2 , *ty2 ,
136 True , *tx1 + ax , *ty1 , *tx2 , *ty2 - ay * 4, back) ;
137 return ;
138 }
139 else return ;
140 }
141
142 /* ��ž���Ʋ����Ĥä�������ν��� */
143 if ( ay < 0 && ((( atti == LEFT || atti == RIGHT ) && *ty1 < 4) ||
144 vmap( *tx2 , *ty2 + ay * 4))){
145 (*ty1) += 4 ;
146 (*tx2) += ax ;
147 MoveWindow( color1 , color2 , *tx1 , *ty1 , *tx2 , *ty2 ,
148 True , *tx1 , *ty1 - 4 , *tx2 - ax, *ty2 , back ) ;
149 return ;
150 }
151
152 /* ��ž���Ʋ����Ĥä�������ν��� */
153 if ( atti == UPPER || atti == LOWER )
154 if ( vmap( *tx2 + ax , *ty2 + ay * 4 )){
155 if( !vmap( *tx1 - ax , *ty1 )) {
156 (*tx1) -= ax ;
157 (*ty2) += ay * 4 ;
158 MoveWindow( color1 , color2 , *tx1 , *ty1 , *tx2 , *ty2 ,
159 True , *tx1 + ax , *ty1 , *tx2 , *ty2 - ay * 4 , back ) ;
160
161 return ;
162 }
163 return ;
164 }
165
166 }
167
168
tama_fall(int * tx1,int * ty1,int * tx2,int * ty2,int sw,int color1,int color2)169 int tama_fall( int *tx1 , int *ty1 , int *tx2 , int *ty2 , int sw , int color1 , int color2 )
170 {
171 int atti ;
172
173 atti = attitu( *tx1 , *ty1 , *tx2 , *ty2 ) ;
174
175 if ( *ty1 -1 >= 0 && !vmap( *tx1 , *ty1 - 1 ) &&
176 *ty2 -1 >= 0 && !vmap( *tx2 , *ty2 - 1 )) {
177 if ( sw ){
178 *ty1 -= 1 ;
179 *ty2 -= 1 ;
180 MoveWindow( color1 , color2 , *tx1 , *ty1 , *tx2 , *ty2 ,
181 True , *tx1 , *ty1 + 1 , *tx2 , *ty2 + 1 , back ) ;
182 }
183 else {
184 *ty1 -= 1 ;
185 *ty2 -= 1 ;
186 MoveWindow( color1 , color2 , *tx1 , *ty1 , *tx2 , *ty2 ,
187 True , *tx1 , *ty1 + 1 , *tx2 , *ty2 + 1 , back ) ;
188 }
189 XSync( dpy , 0 );
190 if ( sw ) tama_score ( 3 ) ;
191 return True ;
192 }
193
194 if ( *ty1 == 0 && *ty2 == 0 )
195 return False ;
196
197 /* �������Ĥλ� */
198 if ( atti == UPPER || atti == LOWER ) {
199 game_end(*tx1,*ty1) ;
200 return False ;
201 }
202
203 if ( !vmap( *tx1 , *ty1 - 1 ) && !vmap( *tx2 , *ty2 - 1 )) {
204 game_end(*tx1,*ty1) ;
205 return False ;
206 }
207
208 if ( vmap( *tx1 , *ty1 - 1 ))
209 while ( !vmap( *tx2 , *ty2 - 1 ) && ( *ty2 - 1 ) >= 0 ) {
210 *ty2 -= 1 ;
211 MoveWindow ( color1 , color2 , *tx1 , *ty1 , *tx2 , *ty2 , True ,
212 *tx1 , *ty1 , *tx2 , *ty2 + 1 , back ) ;
213 XSync( dpy , 0 );
214 }
215
216 else if ( vmap( *tx2 , *ty2 - 1 ))
217 while ( !vmap( *tx1 , *ty1 - 1 ) && ( *ty1 - 1 ) >= 0 ) {
218 *ty1 -= 1 ;
219 MoveWindow ( color1 , color2 , *tx1 , *ty1 , *tx2 , *ty2 , True ,
220 *tx1 , *ty1 + 1 , *tx2 , *ty2 , back ) ;
221 XSync( dpy , 0 );
222 }
223 game_end(*tx1,*ty1);
224 return False ;
225
226 }
227
228
attitu(x1,y1,x2,y2)229 int attitu( x1 , y1 , x2 , y2 )
230 int x1 , x2 , y1 , y2 ;
231 {
232
233 if ( x2 < x1 && y2 == y1 )
234 return LEFT ;
235
236 if ( x2 > x1 && y2 == y1 )
237 return RIGHT ;
238
239 if ( x2 == x1 && y2 > y1 )
240 return UPPER ;
241
242 if ( x2 == x1 && y2 < y1 )
243 return LOWER ;
244
245 return False ;
246 }
247
248
tama_fall2(int x,int * y,int color)249 int tama_fall2( int x , int *y , int color )
250 {
251 XGCValues gcval ;
252 int values ;
253
254 color -- ;
255
256 XClearArea( dpy , back , x * 40 ,440 - (*y) * 10 , 40 , 40 , 0 ) ;
257
258 (*y) -= 4 ;
259
260 values = GCTileStipXOrigin|GCTileStipYOrigin |
261 GCClipXOrigin|GCClipYOrigin| GCTile |GCClipMask ;
262
263 gcval.ts_x_origin = gcval.clip_x_origin = x * 40 ;
264 gcval.ts_y_origin = gcval.clip_y_origin = 440 - (*y) * 10 ;
265 gcval.tile = ball[color] ;
266 gcval.clip_mask = vmask[color<7 ? 0 : 1] ;
267 XSync( dpy , 0 ) ;
268 XChangeGC( dpy , gc3 , values , &gcval) ;
269
270 XFillRectangle( dpy , back , gc3 , x * 40 , 440 - (*y) * 10 , 40 , 40 ) ;
271
272 XSync( dpy , 0 ) ;
273
274 if ( *y == 0 || vmap( x , *y - 4 ) )
275 {
276 map[x][(*y)/4] = color + 1 ;
277 return False ;
278 }
279
280 return True ;
281
282 }
283
284
game_end(int x,int y)285 void game_end( int x , int y )
286 {
287 if ( vmap( 3 , 44) )
288 {
289 XGCValues gcval ;
290 int values ;
291
292 values = GCStipple | GCClipMask | GCTileStipXOrigin|GCTileStipYOrigin |
293 GCClipXOrigin|GCClipYOrigin |GCFillStyle | GCForeground;
294 gcval.foreground = iro[RED] ;
295 gcval.stipple = over[net] ;
296 gcval.clip_mask = over[net] ;
297 gcval.fill_style = FillStippled ;
298
299 if ( net ){
300 gcval.ts_y_origin = gcval.clip_y_origin = 230 ;
301 gcval.ts_x_origin = gcval.clip_x_origin = 90 ;
302 }
303 else {
304 gcval.ts_y_origin = gcval.clip_y_origin = 230 ;
305 gcval.ts_x_origin = gcval.clip_x_origin = 70 ;
306 }
307 XChangeGC( dpy , gc3 , values , &gcval) ;
308 if ( net )
309 XFillRectangle( dpy , back , gc3 , 90 , 230 , 121 , 35 ) ;
310 else
311 XFillRectangle( dpy , back , gc3 , 70 , 230 , 199 , 40 ) ;
312 Setcursor( 3 ) ;
313 XSync( dpy , 0 ) ;
314 gcval.fill_style = FillTiled ;
315 XChangeGC( dpy , gc3 ,GCFillStyle,&gcval ) ;
316 gameover = True ;
317 sleep(1) ;
318 }
319 }
320
tama_kaitou(int x,int y,int color,int sw)321 void tama_kaitou( int x , int y , int color , int sw )
322 {
323 XGCValues gcval ;
324 int values ;
325
326 map[x][y] = color + 1 * ( sw ? 0 : 7 ) ;
327
328 values = GCTileStipXOrigin|GCTileStipYOrigin |
329 GCClipXOrigin|GCClipYOrigin| GCTile | GCClipMask ;
330
331 gcval.ts_x_origin = gcval.clip_x_origin = x * 40 ;
332 gcval.ts_y_origin = gcval.clip_y_origin = 440 - y * 40 ;
333 gcval.tile = ball[ map[x][y] - 1 ] ;
334 gcval.clip_mask = vmask[!sw] ;
335 XChangeGC( dpy , gc3 , values , &gcval) ;
336
337 XClearArea( dpy , back , x * 40 , 440 - y * 40 , 40 , 40 , 0 ) ;
338 XFillRectangle( dpy , back , gc3 , x * 40 , 440 - y * 40 , 40 , 40 ) ;
339
340 XSync( dpy , 0 ) ;
341
342 }
343
MoveWindow(int color1,int color2,int tx1,int ty1,int tx2,int ty2,int sw,int xx1,int yy1,int xx2,int yy2,Window win)344 int MoveWindow( int color1 , int color2 , int tx1 , int ty1 , int tx2 , int ty2 ,int sw , int xx1 , int yy1 , int xx2 , int yy2 , Window win )
345 {
346 XGCValues gcval ;
347 int values ;
348 int y1 , y2 ;
349
350 y1 = 44 - yy1 ;
351 y2 = 44 - yy2 ;
352
353 if ( sw )
354 {
355 XClearArea( dpy , win , xx1 * 40 , y1 * 10 , 40 , 40 , 0 ) ;
356 XClearArea( dpy , win , xx2 * 40 , y2 * 10 , 40 , 40 , 0 ) ;
357 }
358
359 y1 = 44 - ty1 ;
360 y2 = 44 - ty2 ;
361
362 values = GCTileStipXOrigin|GCTileStipYOrigin |
363 GCClipXOrigin|GCClipYOrigin| GCTile | GCClipMask ;
364
365 if ( color1 > -1 ){
366 gcval.ts_x_origin = gcval.clip_x_origin = tx1 * 40 ;
367 gcval.ts_y_origin = gcval.clip_y_origin = y1 * 10 ;
368 gcval.tile = ball[color1] ;
369 gcval.clip_mask = vmask[color1<7 ? 0 : 1] ;
370 XChangeGC( dpy , gc3 , values , &gcval) ;
371 XFillRectangle( dpy , win , gc3 , tx1 * 40 , y1 * 10 , 40 , 40 ) ;
372 }
373 if ( color2 > -1 ){
374 gcval.ts_x_origin = gcval.clip_x_origin = tx2 * 40 ;
375 gcval.ts_y_origin = gcval.clip_y_origin = y2 * 10 ;
376 gcval.tile = ball[color2] ;
377 gcval.clip_mask = vmask[color2<7 ? 0 : 1] ;
378 XChangeGC( dpy , gc3 , values , &gcval) ;
379 XFillRectangle( dpy , win , gc3 , tx2 * 40 , y2 * 10 , 40 , 40 ) ;
380 XSync( dpy , 0 ) ;
381 }
382 return 0 ;
383 }
384
tama_pulas(int num)385 int tama_pulas( int num )
386 {
387 XGCValues gcval ;
388 int values ;
389 int i , x ;
390 static int xx = 0 ;
391 static int kotama = 0 ;
392
393 tama_run(num) ;
394
395 values = GCTileStipXOrigin|GCTileStipYOrigin |
396 GCClipXOrigin|GCClipYOrigin| GCTile | GCClipMask ;
397
398 gcval.tile = ball[7 + ( ++kotama % 5 )] ;
399
400 if ( net && num > 8 )
401 num = (int)( (num - ( 8 - xx % 8 )) / 8 ) * 8 + ( 8 - xx % 8 ) ;
402
403 gcval.clip_mask = vmask[1] ;
404 gcval.ts_y_origin = gcval.clip_y_origin = 11 * 40 ;
405
406 for ( x = 0 ; x < num ; x ++ ){
407 for ( i = ( net ? 18 : 11 ) ; i > 0 ; i -- )
408 map[ xx % 8 ][ i ] = map[ xx % 8 ][ i - 1 ] ;
409
410 if ( net ) {
411 if ( !(( xx ) % 8) ) kotama ++ ;
412 gcval.tile = ball[7 + (kotama % 5) ] ;
413 map[ xx % 8 ][ 0 ] = 8 + (kotama % 5) ;
414 }
415 else map[ xx % 8 ][ 0 ] = 8 + (kotama % 5) ;
416
417
418 XCopyArea( dpy , back , back , gc ,
419 ( xx % 8 ) * 40 , 40 , 40 , 440 , ( xx % 8 ) * 40 , 0 ) ;
420
421 gcval.ts_x_origin = gcval.clip_x_origin = ( xx % 8 ) * 40 ;
422 XChangeGC( dpy , gc3 , values , &gcval) ;
423 XClearArea( dpy , back , ( xx % 8 ) * 40 , 11 * 40 , 40 , 40 , False ) ;
424 XFillRectangle( dpy , back , gc3 , ( xx % 8 ) * 40 , 11 * 40 , 40 , 40 ) ;
425 XSync( dpy , 0 ) ;
426 xx ++ ;
427 }
428
429 rensa = Dairensa = 0 ;
430 tama_scan();
431 tamakazu -= rensa ;
432
433 return num ;
434 }
435
tama_run(num)436 void tama_run( num )
437 int num ;
438 {
439 XGCValues gcval ;
440 int values ;
441 int i ;
442
443 values = GCTileStipXOrigin|GCTileStipYOrigin |
444 GCClipXOrigin|GCClipYOrigin| GCTile | GCClipMask ;
445
446 for ( i = 0 ; i < 22 ; i ++ ) {
447 gcval.tile = tama[ (i % 2) * 2 ] ;
448 gcval.clip_mask = tama[ (i % 2) * 2 + 1 ] ;
449 gcval.ts_y_origin = gcval.clip_y_origin = 515 ;
450 gcval.ts_x_origin = gcval.clip_x_origin = 300 - 17 * i ;
451 XChangeGC( dpy , gc3 , values , &gcval) ;
452 XClearArea( dpy , frame , 300 - 17 * (i - 1) , 515 , 100 , 35 , False ) ;
453 XFillRectangle( dpy , frame , gc3 , 300 - 17 * i , 515 , 100 , 35 ) ;
454 XSync( dpy , 0 ) ;
455 if ( net ) timer( 50000 ) ;
456 else timer( 50000 - num * 400 ) ;
457 }
458
459 XClearArea( dpy , frame , 300 - 17 * ( i- 1) , 515 , 100 , 35 , False ) ;
460 XSync( dpy , 0 ) ;
461 }
462
vmap(x,y)463 Bool vmap( x , y )
464 int x , y ;
465 {
466 if ( y < 0 ){
467 y = 0 ;
468 }
469
470 if (!( y % 4 )) {
471 if ( map[x][(int)(y/4)] )
472 return( True ) ;
473 return ( False ) ;
474 }
475
476 if ( map[x][(int)(y/4)] || map[x][(int)(y/4) + 1] )
477 return( True ) ;
478 return( False ) ;
479 }
480
Setcursor(int sw)481 void Setcursor( int sw )
482 {
483 static int before ;
484 int x , y , number ;
485
486 if ( sw == -1 ){
487 number = 0 ;
488
489 for ( x = 0 ; x < 8 ; x ++ )
490 for ( y = 0 ; y < 12 ; y ++ )
491 if ( map[x][y] )
492 number ++ ;
493 number -= 10 ;
494 x = number / 30 ;
495 if ( x < 0 ) x = 0 ;
496 if ( x > 3 ) x = 3 ;
497 if ( before != x )
498 XDefineCursor( dpy , frame , setcursor[x] ) ;
499 before = x ;
500 }
501 else
502 XDefineCursor( dpy , frame , setcursor[sw] ) ;
503 XSync( dpy , 0 ) ;
504
505 }
506