home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume19 / xblckbst / part05 < prev    next >
Encoding:
Text File  |  1993-04-27  |  18.3 KB  |  666 lines

  1. Newsgroups: comp.sources.x
  2. From: master@cats.UCSC.EDU (Mark Wedel)
  3. Subject: v19i048:  xblockbuster - a variation of the break-out type games, Part05/05
  4. Message-ID: <1993Mar17.160341.718@sparky.imd.sterling.com>
  5. X-Md4-Signature: 0c0e4d28c089b40dd79905677b19006b
  6. Date: Wed, 17 Mar 1993 16:03:41 GMT
  7. Approved: chris@sparky.imd.sterling.com
  8.  
  9. Submitted-by: master@cats.UCSC.EDU (Mark Wedel)
  10. Posting-number: Volume 19, Issue 48
  11. Archive-name: xblockbuster/part05
  12. Environment: X11R5
  13.  
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 5 (of 5)."
  22. # Contents:  balls_pallet.c
  23. # Wrapped by master@sleipner on Sat Mar 13 02:21:02 1993
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'balls_pallet.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'balls_pallet.c'\"
  27. else
  28. echo shar: Extracting \"'balls_pallet.c'\" \(16058 characters\)
  29. sed "s/^X//" >'balls_pallet.c' <<'END_OF_FILE'
  30. X/*
  31. X * File:       balls_pallet.c
  32. X * Author:     Eric Van Gestel
  33. X * Updated for X11 by Mark S. Wedel
  34. X *
  35. X * For:                xblockbuster
  36. X *
  37. X * Implementation:
  38. X *     Drawing is to be done twice with the same coordinates such that
  39. X *     the second removes the first while restoring the context.
  40. X *     The procedure move_balls is called on timeout (xblockbuster.c)
  41. X *     The procedure draw_pallet is called whenever the pallet changes (mouse
  42. X *     movement event, button 1 or 2, or hitting a clipper.)
  43. X *     Auxilary print functions added by MSW to help clean up the code a
  44. X *     little.
  45. X *     The auxiliary functions return a boolean value indicating whether
  46. X *     the hit might have increased the score.
  47. X */
  48. X
  49. X
  50. X#include "xblockbuster.h"
  51. X
  52. X#include "icons/ball.pr"
  53. X
  54. Xstatic char    str[256];
  55. X
  56. X
  57. Xvoid print_score()
  58. X{
  59. X    sprintf(str, "Score:  %d ", score );
  60. X    XDrawImageString(display, win, gc, OFFSET_SCORE, font_height, str, 
  61. X            strlen(str));
  62. X}
  63. X
  64. Xvoid print_balls()
  65. X{
  66. X    sprintf(str, "Balls left:  %d ", balls_left);
  67. X    XDrawImageString(display, win, gc, OFFSET_BALLS, font_height, str, 
  68. X            strlen(str));
  69. X}
  70. X
  71. XPixmap ball_pr;
  72. Xextern int    in_event, do_balls, timer_active;
  73. X
  74. Xvoid ball_init()
  75. X{
  76. X    ball_pr = XCreateBitmapFromData(display, win, ball_bits, ball_width, ball_height);
  77. X}
  78. X
  79. X/* Macro to draw a ball */
  80. X
  81. X#define draw_ball( ball )      \
  82. X    XCopyPlane(display, ball_pr, win, gc_xor, 0, 0, 16, 16, \
  83. X        (int)( (ball)->x ) - 8, (int)( (ball)->y ) - 8, 1)
  84. X
  85. X
  86. X/* Procedure to draw the pallet */
  87. Xvoid
  88. Xdraw_pallet(  )
  89. X{
  90. X    XDrawLine( display, win, gc_xor, pallet_xI - pallet_lengthI + 2, pallet_yI,
  91. X           pallet_xI + pallet_lengthI - 2, pallet_yI);
  92. X    XDrawLine( display, win, gc_xor, pallet_xI - pallet_lengthI + 1, pallet_yI + 1,
  93. X           pallet_xI + pallet_lengthI - 1, pallet_yI + 1);
  94. X    XDrawLine( display, win, gc_xor, pallet_xI - pallet_lengthI, pallet_yI + 2,
  95. X           pallet_xI + pallet_lengthI, pallet_yI + 2);
  96. X    XDrawLine( display, win, gc_xor, pallet_xI - 1, pallet_yI + 3,
  97. X           pallet_xI - 1, pallet_yI + 6);
  98. X    XDrawLine( display, win, gc_xor, pallet_xI - 1, pallet_yI + 6,
  99. X           pallet_xI + 1, pallet_yI + 6);
  100. X    XDrawLine( display, win, gc_xor, pallet_xI + 1, pallet_yI + 6,
  101. X           pallet_xI + 1, pallet_yI + 3);
  102. X    XDrawLine( display, win, gc_xor, 0, mouse_yI - 1,    /* <HC> */
  103. X           10, mouse_yI - 1);
  104. X    XDrawLine( display, win, gc_xor, 0, mouse_yI,
  105. X           10, mouse_yI);
  106. X    XDrawLine( display, win, gc_xor, 0, mouse_yI + 1,    /* <HC> */
  107. X           10, mouse_yI + 1);
  108. X    XDrawLine( display, win, gc_xor, STAGE_WIDTH_IN_PIXELS - 1, mouse_yI - 1,    /* <HC> */
  109. X           STAGE_WIDTH_IN_PIXELS - 11, mouse_yI - 1);
  110. X    XDrawLine( display, win, gc_xor, STAGE_WIDTH_IN_PIXELS - 1, mouse_yI,
  111. X           STAGE_WIDTH_IN_PIXELS - 11, mouse_yI);
  112. X    XDrawLine( display, win, gc_xor, STAGE_WIDTH_IN_PIXELS - 1, mouse_yI + 1,    /* <HC> */
  113. X           STAGE_WIDTH_IN_PIXELS - 11, mouse_yI + 1);
  114. X}
  115. X
  116. X
  117. X/* Procedure to show the speeds */
  118. X#define SX     OFFSET_SPEED + 70
  119. Xvoid
  120. Xshow_speeds(  )
  121. X{
  122. X    int             sp;
  123. X
  124. X    XDrawImageString(display, win, gc, OFFSET_SPEED, font_height,
  125. X        "Speed:          ",16);
  126. X
  127. X    /* scale line */
  128. X    XDrawLine( display, win, gc, SX, font_height - 1, SX + SPEED_RESOLUTION - 1, font_height - 1);
  129. X    XDrawLine( display, win, gc, SX, font_height, SX + SPEED_RESOLUTION, font_height);
  130. X    XDrawLine( display, win, gc, SX, font_height + 1, SX + SPEED_RESOLUTION - 1, font_height + 1);
  131. X
  132. X    /* base bar */
  133. X    XDrawLine( display, win, gc, SX, font_height - 12, SX, font_height + 3);
  134. X    XDrawLine( display, win, gc, SX + 1, font_height - 12, SX + 1, font_height + 3);
  135. X
  136. X    /* launch speed bar */
  137. X    sp = ( int ) ( launch_speed * SPEED_RESOLUTION_FACTOR );
  138. X    if ( launch_speed < MAX_SPEED )
  139. X        XDrawLine( display, win, gc, SX + sp, font_height - 2, SX + sp, font_height + 2);
  140. X    else
  141. X        XDrawLine( display, win, gc, SX + sp, font_height - 2, SX + sp, font_height + 2);
  142. X
  143. X    /* ball lines */
  144. X    if ( ball1.quadrant ) {
  145. X        sp = ( int ) ( ball1.speed * SPEED_RESOLUTION_FACTOR );
  146. X        XDrawLine( display, win, gc, SX, font_height - 4, SX + sp, font_height - 4);
  147. X    }
  148. X    if ( ball2.quadrant ) {
  149. X        sp = ( int ) ( ball2.speed * SPEED_RESOLUTION_FACTOR );
  150. X        XDrawLine( display, win, gc, SX, font_height - 7, SX + sp, font_height - 7);
  151. X    }
  152. X    if ( ball3.quadrant ) {
  153. X        sp = ( int ) ( ball3.speed * SPEED_RESOLUTION_FACTOR );
  154. X        XDrawLine( display, win, gc, SX, font_height - 10, SX + sp, font_height - 10);
  155. X    }
  156. X}
  157. X
  158. X
  159. X
  160. X/* auxiliary procedures */
  161. Xvoid
  162. Xnew_ball( ball )
  163. X    register struct Ball *ball;
  164. X{
  165. X    if ( balls_left-- ) {
  166. X        ball->quadrant = launch_quadrant;
  167. X        ball->angle = 0.0;
  168. X        ball->row = launch_row;
  169. X        ball->col = launch_col;
  170. X        ball->x = launch_x;
  171. X        ball->y = launch_y;
  172. X        ball->speed = launch_speed;
  173. X        ball->x_speed = launch_speed * ( ( ball->quadrant == NE ) ? M_SQRT2_2
  174. X                          /* NW */ : -M_SQRT2_2 );
  175. X        ball->y_speed = launch_speed * -M_SQRT2_2;
  176. X        /* initial ball image */
  177. X        draw_ball( ball );
  178. X        /* show balls left */
  179. X        print_balls();
  180. X        /* show speeds */
  181. X        show_speeds(  );
  182. X    } else {
  183. X        balls_left = 0;    /* kludge */
  184. X        XDrawImageString(display, win, gc, 0, font_height,
  185. X            "Game Over.",10 );
  186. X        sleep( 2 );
  187. X        show_score_board(  );    /* BYE !! */
  188. X    }
  189. X}
  190. X
  191. X
  192. Xvoid
  193. Xblow_up( row, col )
  194. X    register int    row, col;
  195. X{
  196. X    if ( stage[row][col].code == ' ' )
  197. X        return;        /* nothing there */
  198. X    if ( IS_HIT_BRICK( stage[row][col].code ) )
  199. X        nbricks--;
  200. X    stage[row][col].code = 'R';
  201. X    draw_brick( row, col );
  202. X}
  203. X
  204. X
  205. Xint                /* boolean */
  206. Xhit_brick( hit, ball )
  207. X    register int    hit;    /* enumeration { HORIZONTAL, VERTICAL } */
  208. X    register struct Ball *ball;
  209. X{
  210. X    register struct Brick *brick = &stage[ball->row][ball->col];
  211. X    register int    busted = FALSE;
  212. X    register int    redraw = FALSE;
  213. X    register int    score_hit = FALSE;
  214. X    char        str[80];
  215. X
  216. X    /* has the ball left the stage vertically ? */
  217. X    if ( ball->row < 0 || ball->row > MAX_ROW ) {
  218. X        ball->quadrant = NO_BALL;    /* so much for this ball */
  219. X        return ( score_hit );
  220. X    }
  221. X    /* check for looping */
  222. X    switch ( brick->code ) {
  223. X    case ' ':        /* no hit */
  224. X        break;
  225. X    case '#':
  226. X    case '/':
  227. X    case '\\':
  228. X    case '^':
  229. X    case '0':
  230. X    case 'A':
  231. X    case 'R':
  232. X    case 'S':
  233. X    case 'U':        /* because it may undo another one */
  234. X    case 'W':
  235. X    case '%':
  236. X        if ( !( ++loop_nhits % LOOP_MAX ) )
  237. X            ball->x -=
  238. X                ball->x_speed * ( double ) ( loop_nhits / LOOP_MAX ) + 1;
  239. X        /* horizontal shift, trying to get out of a bounce loop */
  240. X        /* negative to try to avoid leaving the stage */
  241. X        break;
  242. X    default:        /* non-solid brick */
  243. X        loop_nhits = 0;
  244. X    }
  245. X
  246. X    /* advance score taking special action if needed */
  247. X    switch ( brick->code ) {
  248. X    case ' ':        /* clear space */
  249. X        /* has the ball left the stage horizontally ? */
  250. X        if ( ball->col <= 0 || ball->col >= MAX_COL ) {
  251. X            ball->quadrant = NO_BALL;    /* so much for this ball */
  252. X        }
  253. X        return ( score_hit );    /* no hit */
  254. X
  255. X    case '#':        /* solid wall */
  256. X    case '/':        /* launchpad NE */
  257. X    case '\\':        /* launchpad NW */
  258. X    case '^':        /* emitter */
  259. X        break;
  260. X
  261. X    case '0':        /* solid brick */
  262. X        score += score_incr;
  263. X        score_hit = TRUE;
  264. X        break;
  265. X
  266. X    case 'A':        /* absorber */
  267. X        ball->x += ( double ) ( emit_col - ball->col ) * 64;
  268. X        ball->y += ( double ) ( emit_row - ball->row ) * 16;
  269. X        break;
  270. X    case 'C':        /* clipper */
  271. X        if ( ++( brick->nhits ) == 2 ) {
  272. X            draw_pallet();
  273. X            pallet_lengthI -= pallet_lengthI / 5;
  274. X            if ( pallet_lengthI < MIN_PALLET_LENGTH )
  275. X                pallet_lengthI = MIN_PALLET_LENGTH;
  276. X            pallet_length = ( double ) pallet_lengthI;
  277. X            busted = TRUE;
  278. X            draw_pallet();
  279. X        }
  280. X        break;
  281. X    case 'D':        /* double */
  282. X        if ( ++( brick->nhits ) == 2 ) {
  283. X            score_incr *= 2;
  284. X            busted = TRUE;
  285. X            sprintf(str,"Bonus x%d",score_incr);
  286. X            XDrawImageString(display, win, gc,
  287. X             OFFSET_SCORE, font_height*2, str, 
  288. X                strlen(str));
  289. X        }
  290. X        break;
  291. X    case 'E':        /* extra ball */
  292. X        if ( ++( brick->nhits ) == 2 ) {
  293. X            balls_left++;
  294. X            print_balls();
  295. X            busted = TRUE;
  296. X        }
  297. X        break;
  298. X    case 'G':        /* gap */
  299. X        if ( ++( brick->nhits ) == 2 ) {
  300. X            ball->quadrant = NO_BALL;    /* so much for this ball */
  301. X            busted = TRUE;
  302. X        }
  303. X        break;
  304. X    case 'H':        /* halt */
  305. X        if ( ++( brick->nhits ) == 3 )
  306. X            busted = TRUE;
  307. X        {
  308. X            double          pause = 0.1 * ( double ) ( 10 - brick->nhits );
  309. X
  310. X            ball->speed *= pause;
  311. X            ball->x_speed *= pause;
  312. X            ball->y_speed *= pause;
  313. X        }
  314. X        /* approximative; will be corrected on next pallet deflection */
  315. X        show_speeds(  );
  316. X        break;
  317. X    case 'I':        /* invisible brick */
  318. X        score += score_incr;
  319. X        brick->code = '1';
  320. X        nbricks++;
  321. X        score_hit = redraw = TRUE;
  322. X        break;
  323. X    case 'L':        /* launch ball */
  324. X        if ( ++( brick->nhits ) == 2 ) {
  325. X            balls_left++;    /* kludge to avoid consuming a ball */
  326. X            if ( !ball1.quadrant )
  327. X                new_ball( &ball1 );
  328. X            else if ( !ball2.quadrant )
  329. X                new_ball( &ball2 );
  330. X            else if ( !ball3.quadrant )
  331. X                new_ball( &ball3 );
  332. X            else
  333. X                print_balls();
  334. X            show_speeds(  );
  335. X            busted = TRUE;
  336. X        }
  337. X        break;
  338. X    case 'M':        /* mine */
  339. X        if ( ++( brick->nhits ) == 3 ) {
  340. X            blow_up( ball->row - 1, ball->col - 1 );
  341. X            blow_up( ball->row - 1, ball->col );
  342. X            blow_up( ball->row - 1, ball->col + 1 );
  343. X            blow_up( ball->row, ball->col - 1 );
  344. X            blow_up( ball->row, ball->col + 1 );
  345. X            blow_up( ball->row + 1, ball->col - 1 );
  346. X            blow_up( ball->row + 1, ball->col );
  347. X            blow_up( ball->row + 1, ball->col + 1 );
  348. X            busted = TRUE;
  349. X        }
  350. X        break;
  351. X    case 'P':        /* pause */
  352. X        if ( ++( brick->nhits ) == 8 ) {
  353. X            launch_speed -= ( launch_speed - INIT_SPEED ) * 0.3;
  354. X            busted = TRUE;
  355. X        }
  356. X        show_speeds(  );
  357. X        break;
  358. X    case 'R':        /* refractor */
  359. X        ball->angle = -( ball->angle );
  360. X        {
  361. X            register int    sign = ( ball->x_speed * ball->y_speed ) < 0;
  362. X            register double tmp = ball->x_speed;
  363. X
  364. X            ball->x_speed = sign ? -( ball->y_speed ) : ball->y_speed;
  365. X            ball->y_speed = sign ? -tmp : tmp;
  366. X            /*
  367. X             * note no check for NEAR_HORIZONTAL and none needed
  368. X             * since,
  369. X             */
  370. X            /*
  371. X             * if it gets too horizontal, it probably will hit it
  372. X             * again.
  373. X             */
  374. X        }
  375. X        return ( FALSE );    /* no deflection */
  376. X    case 'S':        /* speeder */
  377. X        if ( ball->speed < SPEED_LIMIT ) {
  378. X            ball->speed += SPEED_INCR;
  379. X            ball->x_speed += ( ball->x_speed < 0 ) ? -SPEED_INCR_2
  380. X                : SPEED_INCR_2;
  381. X            ball->y_speed += ( ball->y_speed < 0 ) ? -SPEED_INCR_2
  382. X                : SPEED_INCR_2;
  383. X            /*
  384. X             * approximative; will be corrected on next pallet
  385. X             * deflection
  386. X             */
  387. X            show_speeds(  );
  388. X        } else
  389. X            pallet_modif++;
  390. X        break;
  391. X    case 'T':        /* triple */
  392. X        if ( ++( brick->nhits ) == 3 ) {
  393. X            score_incr *= 3;
  394. X            busted = TRUE;
  395. X            sprintf(str,"Bonus x%d",score_incr);
  396. X            XDrawImageString(display, win, gc,
  397. X             OFFSET_SCORE, font_height*2, str, 
  398. X                strlen(str));
  399. X        }
  400. X        break;
  401. X    case 'U': /* undo */ ;
  402. X        /* effective only after something has been busted */
  403. X        if ( last_busted_brick ) {
  404. X            last_busted_brick->code = last_busted_code;
  405. X            last_busted_brick->nhits = 0;
  406. X            if ( IS_HIT_BRICK( last_busted_code ) )
  407. X                nbricks++;
  408. X            draw_brick( last_busted_row, last_busted_col );
  409. X            busted = TRUE;
  410. X        }
  411. X        break;
  412. X    case 'W': /* open window */ ;
  413. X        brick->code = '%';
  414. X         /* redraw = TRUE */ draw_brick( ball->row, ball->col );
  415. X        return ( score_hit );    /* no deflection */
  416. X    case '%': /* closed window */ ;
  417. X        brick->code = 'W';
  418. X        redraw = TRUE;
  419. X        break;
  420. X    case 'X':        /* expander */
  421. X        if ( ++( brick->nhits ) == 4 ) {
  422. X            pallet_modif -= 2 * PALLET_INCR;
  423. X            busted = TRUE;
  424. X        }
  425. X        break;
  426. X
  427. X    default:
  428. X        if ( brick->code >= '1' && brick->code <= '9' ) {
  429. X            /* hit bricks */
  430. X            score += ++( brick->nhits ) * score_incr;
  431. X            score_hit = TRUE;
  432. X            if ( brick->nhits == brick->code - '0' )
  433. X                busted = TRUE;
  434. X            else
  435. X                redraw = TRUE;
  436. X        } else {    /* 'a' .. 'e' & 'j' */
  437. X            /* bonus= bricks */
  438. X            if ( ++( brick->nhits ) > brick->code - 'a' + 1 ) {
  439. X                score += ( brick->code - 'a' + 1 ) * 10 * score_incr;
  440. X                score_hit = busted = TRUE;
  441. X            }
  442. X        }
  443. X    }
  444. X    if ( busted ) {
  445. X        last_busted_brick = brick;
  446. X        last_busted_code = brick->code;
  447. X        last_busted_row = ball->row;
  448. X        last_busted_col = ball->col;
  449. X        if ( IS_HIT_BRICK( brick->code ) )
  450. X            nbricks--;
  451. X        brick->code = ' ';
  452. X        redraw = TRUE;
  453. X    }
  454. X    /* redraw brick (never on the sides) */
  455. X    if ( redraw ) {
  456. X        if ( pallet_row == ball->row )
  457. X            draw_pallet(  );    /* avoid shadow */
  458. X        draw_brick( ball->row, ball->col );
  459. X        if ( pallet_row == ball->row )
  460. X            draw_pallet(  );    /* restore */
  461. X    }
  462. X    /* deflection */
  463. X    if ( ball->col <= 0 || ball->col >= MAX_COL ) {
  464. X        /*
  465. X         * kludge to avoid tunnelling out through the side (or
  466. X         * corner)
  467. X         */
  468. X        if ( ( ball->col <= 0 &&
  469. X               ( ball->quadrant == NW || ball->quadrant == SW ) ) ||
  470. X             ( ball->col >= MAX_COL &&
  471. X               ( ball->quadrant == NE || ball->quadrant == SE ) ) )
  472. X            brick_deflection( VERTICAL, ball );
  473. X        if ( ( ball->row == 0 &&
  474. X               ( ball->quadrant == NE || ball->quadrant == NW ) ) ||
  475. X             ( ball->row == MAX_ROW &&
  476. X               ( ball->quadrant == SE || ball->quadrant == SW ) ) )
  477. X            brick_deflection( HORIZONTAL, ball );
  478. X    } else
  479. X        brick_deflection( hit, ball );
  480. X
  481. X    return ( score_hit );
  482. X}
  483. X
  484. Xint                /* boolean */
  485. Xmove_ball( ball )
  486. X    register struct Ball *ball;
  487. X{
  488. X    register int    tmp;    /* tmp row or col designation */
  489. X    register int    hit = FALSE;    /* enumeration { FALSE, HORIZONTAL,
  490. X                     * VERTICAL } */
  491. X    register int    score_hit = FALSE;    /* boolean */
  492. X
  493. X    /* erase ball image */
  494. X    draw_ball( ball );
  495. X
  496. X    /* move ball */
  497. X    ball->x += ball->x_speed;
  498. X    ball->y += ball->y_speed;
  499. X
  500. X    /* might it have hit a brick ? */
  501. X    if ( ( tmp = X_COL( ball->x ) ) != ball->col ) {
  502. X        ball->col = tmp;
  503. X        hit = VERTICAL;
  504. X    }
  505. X    if ( ( tmp = Y_ROW( ball->y ) ) != ball->row ) {
  506. X        ball->row = tmp;
  507. X        hit = HORIZONTAL;    /* HORIZONTAL takes precedence over
  508. X                     * VERTICAL */
  509. X    }
  510. X    if ( hit )
  511. X        score_hit = hit_brick( hit, ball );
  512. X    if ( !ball->quadrant ) {
  513. X        /* so much for this ball */
  514. X        show_speeds(  );
  515. X        return ( score_hit );
  516. X    }
  517. X    /* might it have hit the pallet ? */
  518. X    if ( ball->y >= pallet_y - 0.1 &&    /* round of protection */
  519. X         ball->y <= pallet_y + ball->y_speed &&
  520. X         ball->x >= pallet_x - pallet_length &&
  521. X         ball->x <= pallet_x + pallet_length ) {
  522. X        loop_nhits = 0;
  523. X        pallet_deflection( ball );
  524. X    }
  525. X    /* redraw ball image */
  526. X    draw_ball( ball );
  527. X
  528. X    return ( score_hit );
  529. X}
  530. X
  531. Xvoid check_ball(ball, old_pallet_y)
  532. Xregister struct Ball *ball;
  533. Xdouble old_pallet_y;
  534. X{
  535. X    if ( ball->y >= pallet_y - 0.1 &&    /* round of protection */
  536. X         ball->y <= old_pallet_y + ball->y_speed &&
  537. X         ball->x >= pallet_x - pallet_length &&
  538. X         ball->x <= pallet_x + pallet_length ) {
  539. X        loop_nhits = 0;
  540. X        pallet_deflection( ball );
  541. X    }
  542. X}
  543. X
  544. Xvoid
  545. Xcheck_deflections(old_pallet_y )
  546. Xdouble old_pallet_y;
  547. X{
  548. X    if (ball1.quadrant) check_ball(&ball1,old_pallet_y);
  549. X    if (ball2.quadrant) check_ball(&ball3,old_pallet_y);
  550. X    if (ball3.quadrant) check_ball(&ball3,old_pallet_y);
  551. X}
  552. X
  553. X
  554. Xvoid draw_balls()
  555. X{
  556. X    if ( ball1.quadrant ) draw_ball(&ball1);
  557. X    if ( ball2.quadrant ) draw_ball(&ball2);
  558. X    if ( ball3.quadrant ) draw_ball(&ball3);
  559. X}
  560. X
  561. X
  562. X/*** on timeout event ***/
  563. Xvoid move_balls( )
  564. X{
  565. X    register int    score_hit1 = FALSE, score_hit2 = FALSE, score_hit3 = FALSE;
  566. X
  567. X    /* start new ball if none left */
  568. X    if ( !ball1.quadrant && !ball2.quadrant && !ball3.quadrant ) {
  569. X        new_ball( &ball1 );
  570. X    }
  571. X
  572. X    /* move balls */
  573. X    if ( ball1.quadrant )
  574. X        score_hit1 = move_ball( &ball1 );
  575. X    if ( ball2.quadrant )
  576. X        score_hit2 = move_ball( &ball2 );
  577. X    if ( ball3.quadrant )
  578. X        score_hit3 = move_ball( &ball3 );
  579. X
  580. X    /* start new stage if no more bricks to bust */
  581. X    if ( nbricks <= 0 ) {
  582. X
  583. X        /* add stage bonus */
  584. X        score += 100;
  585. X
  586. X        XFillRectangle( display,win, gc_erase,
  587. X            0, 0, STAGE_WIDTH_IN_PIXELS - 1, MSG_HEIGHT);
  588. X        XDrawImageString(display, win, gc,
  589. X             0,font_height, " Stage bonus: 100",17);
  590. X
  591. X
  592. X        /* erase ball images */
  593. X        if ( ball1.quadrant ) {
  594. X            ball1.quadrant = NO_BALL;
  595. X            balls_left++;    /* kludge to avoid consuming the ball */
  596. X            draw_ball( &ball1 );
  597. X        }
  598. X        if ( ball2.quadrant ) {
  599. X            ball2.quadrant = NO_BALL;
  600. X            balls_left++;    /* kludge to avoid consuming the ball */
  601. X            draw_ball( &ball2 );
  602. X        }
  603. X        if ( ball3.quadrant ) {
  604. X            ball3.quadrant = NO_BALL;
  605. X            balls_left++;    /* kludge to avoid consuming the ball */
  606. X            draw_ball( &ball3 );
  607. X        }
  608. X        /* update score */
  609. X        print_score();
  610. X        timer_active=0;
  611. X        /* off we go again */
  612. X        new_stage(  );
  613. X
  614. X    } else {
  615. X
  616. X        /* update score */
  617. X        if ( score_hit1 || score_hit2 || score_hit3 )
  618. X            print_score();
  619. X
  620. X
  621. X        if (!ball1.quadrant && !ball2.quadrant && !ball3.quadrant) {
  622. X            timer_active=0;
  623. X            XFlush(display);
  624. X            if (balls_left==0) {
  625. X                print_balls();
  626. X                show_score_board(  );    /* BYE !! */
  627. X            }
  628. X        }
  629. X    }
  630. X
  631. X}
  632. X
  633. X
  634. X
  635. END_OF_FILE
  636. if test 16058 -ne `wc -c <'balls_pallet.c'`; then
  637.     echo shar: \"'balls_pallet.c'\" unpacked with wrong size!
  638. fi
  639. # end of 'balls_pallet.c'
  640. fi
  641. echo shar: End of archive 5 \(of 5\).
  642. cp /dev/null ark5isdone
  643. MISSING=""
  644. for I in 1 2 3 4 5 ; do
  645.     if test ! -f ark${I}isdone ; then
  646.     MISSING="${MISSING} ${I}"
  647.     fi
  648. done
  649. if test "${MISSING}" = "" ; then
  650.     echo You have unpacked all 5 archives.
  651.     rm -f ark[1-9]isdone
  652. else
  653.     echo You still need to unpack the following archives:
  654.     echo "        " ${MISSING}
  655. fi
  656. ##  End of shell archive.
  657. exit 0
  658.  
  659.  
  660. exit 0 # Just in case...
  661. -- 
  662.   // chris@IMD.Sterling.COM            | Send comp.sources.x submissions to:
  663. \X/  Amiga - The only way to fly!      |
  664.  "It's intuitively obvious to the most |    sources-x@imd.sterling.com
  665.   casual observer..."                  |
  666.