home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI10.ARJ / ictari.10 / C / BOINKOUT / BOUT4.C < prev    next >
C/C++ Source or Header  |  1987-04-22  |  14KB  |  625 lines

  1. /********************************************
  2. *        Bout4.c                                *
  3. *        Samuel Streeper 90/01/26            *
  4. *                                            *
  5. *                                            *
  6. *    Copyright 1990 by Antic Publishing Inc.    *
  7. *                                            *
  8. *    Miscellaneous boinkout routines            *
  9. *                                            *
  10. ********************************************/
  11.  
  12. /* edited with tabsize = 4 */
  13.  
  14. #include <obdefs.h>
  15. #include <gemdefs.h>
  16. #include <osbind.h>
  17. #include "boinkout.h"
  18.  
  19. extern MFDB digitsource, windsource, pic_buf, ballsource, levelsource;
  20. extern MFDB permbricksource, bricksource, twobricksource, screen_fdb;
  21. extern int brickarray[], handle, level, lives, xwork, ywork, num_balls;
  22. extern int ball_ani(), fuji_ani(), eye_ani(), appear[], gl_hbox;
  23. extern int w_hand, num_bricks, wwork, hwork, ani_count, paddle_x;
  24. extern int paddle_y, pad_y_max, pad_y_min, n_redraws, paddlearray[];
  25. extern int max_xspeed, magic_bottom, mode, *lineaptr, fastmode;
  26. extern int wdesk, hidden, maxy, text_ht, fuji_ht, fmask_ht, ball_ht;
  27. extern int bh, btw, bleft, bth, btop, pad_ht, planes, pad_y_top, cheat;
  28. extern char warray[], parray[], title_bar[];
  29. extern char brickcount[];
  30. extern long score, bonus_life;
  31. extern BALL_STRUCT bs[];
  32. extern RECT region[];        /* a list of redraw regions */
  33. extern long get_time();
  34.  
  35. int invis;
  36.  
  37. int bonus[] = {        /* bonus sound effect */
  38.     0x000,0x100,0x200,0x300,0x400,0x500,0x600,0x7FE,
  39.     0x80F,0x900,0xA00,0xB00,0xC00,0xD00,
  40.     0x8040,0x8100,0xfd31,
  41.     0x8040,0x8100,0xfd31,
  42.     0x8040,0x8100,0xfd31,
  43.     0x800,0xFF00
  44.     };
  45.  
  46. prinl(num, x, y, fill)
  47. register long num;
  48. {
  49.     register int ndx = 0;
  50.     char buf[10];
  51.  
  52.     /* make sure the number is in the acceptable range */
  53.  
  54.     if ((num < 0L) || (num > 9999999L)) num = 0L;
  55.  
  56.     /* if number is zero, be sure to show one digit */
  57.     if (!num) buf[ndx++] = 0;
  58.  
  59.     /* build the number in reverse order */
  60.     while (num)
  61.     {
  62.         buf[ndx++] = (num % 10);
  63.         num /= 10;
  64.     }
  65.  
  66.     if (fill)
  67.     {    x += 8 * (7-ndx);
  68.     }
  69.  
  70.     while (--ndx >= 0)
  71.     {
  72.         brickarray[0] = buf[ndx] * 8;
  73.         brickarray[1] = 0;
  74.         brickarray[2] = brickarray[0] + 7;
  75.         brickarray[3] = text_ht - 1;
  76.         brickarray[4] = x;
  77.         brickarray[5] = y;
  78.         brickarray[6] = x + 7;
  79.         brickarray[7] = y + text_ht - 1;
  80.  
  81.         vro_cpyfm(handle,3,brickarray,&digitsource,&pic_buf);
  82.         vro_cpyfm(handle,3,brickarray,&digitsource,&windsource);
  83.  
  84.         x += 8;
  85.     }
  86. }
  87.  
  88. show_score()
  89. {
  90.     prinl(score,375,2,TRUE);
  91.     add_region(xwork+375,ywork+2,7*8,text_ht);
  92.     if (score >= bonus_life)
  93.     {
  94.         Dosound(bonus);
  95.         bonus_life += BONUS;
  96.         lives++;
  97.         show_lives();
  98.     }
  99. }
  100.  
  101. show_lives()
  102. {
  103.     prinl((long)lives,25,2,FALSE);
  104.     add_region(xwork+25,ywork+2,7*8,text_ht);
  105. }
  106.  
  107. show_level()
  108. {
  109.     prinl((long)level+1,170 + 6*8,2,FALSE);
  110.     add_region(xwork+(170 + 6*8),ywork+2,7*8,text_ht);
  111. }
  112.  
  113. clear_areas()
  114. {
  115.     /* put a ball in the corner */
  116.     brickarray[0] = brickarray[1] = brickarray[4] = brickarray[5] = 0;
  117.     brickarray[2] = brickarray[6] = 20;
  118.     brickarray[3] = brickarray[7] = ball_ht;
  119.     vro_cpyfm(handle,3,brickarray,&ballsource,&pic_buf);
  120.  
  121.     /* clear lives area */
  122.     clear(21,0,4*8,text_ht + 4);
  123.  
  124.     /* clear level area */
  125.     clear(168,0,10*8,text_ht + 4);
  126.  
  127.     /* clear score area */
  128.     clear(375,0,7*8,text_ht + 4);
  129.  
  130.     /* put in word 'level' */
  131.     brickarray[0] = brickarray[1] = 0;
  132.     brickarray[2] = 8*5 - 1;
  133.     brickarray[3] = text_ht - 1;
  134.     brickarray[4] = 170;
  135.     brickarray[5] = 2;
  136.     brickarray[6] = 170 + 39;
  137.     brickarray[7] = 170 + text_ht - 1;
  138.     vro_cpyfm(handle,3,brickarray,&levelsource,&pic_buf);
  139. }
  140.  
  141. char afn[] = {BALL,EYE,BALL,FUJI,BALL,EYE,BALL,EYE    };
  142. add_ball(x,y,xspeed,yspeed,allow_fuji)
  143. {
  144.     register BALL_STRUCT *p;
  145.     int ndx;
  146.  
  147.     if (num_balls >= MAX_BALLS) return;
  148.  
  149.     ndx = Random() & 7;
  150.     p = &bs[num_balls];
  151.  
  152.     switch(afn[ndx])
  153.     {
  154.         case BALL:                /* ball */
  155. b1:            p->id = BALL;
  156.             p->ani_funct = ball_ani;
  157.             p->ball_ht = ball_ht;
  158.             p->ball_wid = 20;
  159.             p->half_ht = ball_ht / 2;
  160.             p->half_wid = 10;
  161.             break;
  162.  
  163.         case FUJI:
  164.             if (!allow_fuji) goto b1;
  165.             p->id = FUJI;
  166.             p->ani_funct = fuji_ani;
  167.             p->ball_ht = fmask_ht;
  168.             p->ball_wid = 16;
  169.             p->half_ht = fmask_ht / 2;
  170.             p->half_wid = 8;
  171.             break;
  172.  
  173.         case EYE:
  174.             p->id = EYE;
  175.             p->ani_funct = eye_ani;
  176.             p->ball_ht = ball_ht;
  177.             p->ball_wid = 20;
  178.             p->half_ht = ball_ht / 2;
  179.             p->half_wid = 10;
  180.             break;
  181.     }
  182.  
  183.     p->y = y;
  184.     p->x = p->array[4] = x;
  185.     p->array[5] = p->y;
  186.     p->array[6] = x + p->ball_wid;
  187.     p->array[7] = y + p->ball_ht - 1;
  188.     p->xspeed = xspeed;
  189.     p->yspeed = yspeed;
  190.     p->spin_dir = 1;
  191.  
  192.     num_balls++;
  193. }
  194.  
  195. kill_ball(i)
  196. {
  197.     register BALL_STRUCT *p;
  198.     register int x;
  199.  
  200.     p = &bs[i];
  201.  
  202.     p->l = p->array[0] = p->array[4];
  203.     p->t = p->array[1] = p->array[5];
  204.     p->r = p->array[2] = p->array[6];
  205.     p->b = p->array[3] = p->array[7];
  206.  
  207.     /* Restore the background picture to its virgin state    */
  208.     /* i.e.  remove the image of the ball from it.            */
  209.  
  210.     vro_cpyfm(handle,mode,p->array,&pic_buf,&windsource);
  211.     add_region(xwork + p->l, ywork + p->t,
  212.         p->r - p->l + 1, p->b - p->t + 1);
  213.  
  214.  
  215.     num_balls--;
  216.     for (x=i;x<num_balls;x++) bs[x] = bs[x+1];
  217. }
  218.  
  219.  
  220. /********************************************/
  221. /* magic - make something weird happen        */
  222. /********************************************/
  223. char mfn[] = {0,1,0,2,0,3,0,0};
  224. magic(i)
  225. {
  226.     register BALL_STRUCT *p;
  227.     register int j, ts;
  228.     int ndx, count;
  229.  
  230.     p = &bs[i];
  231.  
  232.     ndx = Random() & 7;
  233.     if (mode == BLACKMODE || invis)
  234.     {
  235.         if ((num_balls >= MAX_BALLS))
  236.         {
  237.             if (mode == BLACKMODE && cheat) restore_level();
  238.             return;
  239.         }
  240.  
  241.         restore_level();
  242.         ndx = 0;
  243.     }
  244.  
  245.     switch(mfn[ndx])
  246.     {
  247.         case 0:        /*** multiple balls ***/
  248.             ts = p->xspeed;
  249.             if (ts <= -max_xspeed) ts = -max_xspeed + 1;
  250.             else if (ts >= max_xspeed) ts = max_xspeed - 1;
  251.  
  252.             /* get random # of balls */
  253.             count = (Supexec(get_time) & 3);
  254.             if (!count) count = 1;
  255.             if (num_balls >= 3) count = 1;
  256.  
  257.             for (j=0; j<count; j++)
  258.             {
  259.                 add_ball(p->x,p->y+1-j,ts+1-j,p->yspeed,TRUE);
  260.             }
  261.             break;
  262.  
  263.         case 1:        /*** magic bottom ***/
  264.             magic_bottom += 2;
  265.             break;
  266.  
  267.         case 2:        /*** bricks invisible ***/
  268.             invis = TRUE;
  269.             brickarray[0] = brickarray[1] = brickarray[4] = brickarray[5] = 0;
  270.             brickarray[2] = brickarray[6] = wwork;
  271.             brickarray[3] = brickarray[7] = hwork;
  272.             vro_cpyfm(handle,3,brickarray,&pic_buf,&windsource);
  273.             n_redraws = 0;
  274.             add_region(xwork,ywork,xwork+wwork,ywork+hwork);
  275.             break;
  276.  
  277.         case 3:        /*** background black ***/
  278.             brickarray[0] = brickarray[1] = brickarray[4] = brickarray[5] = 0;
  279.             brickarray[2] = brickarray[6] = wwork;
  280.             brickarray[3] = brickarray[7] = hwork;
  281.             vro_cpyfm(handle,15,brickarray,&pic_buf,&windsource);
  282.             mode = BLACKMODE;
  283.             show_score();
  284.  
  285.             n_redraws = 0;
  286.             add_region(xwork,ywork,xwork+wwork,ywork+hwork);
  287.             break;
  288.     }
  289. }
  290.  
  291. /********************************************/
  292. /* restart a level without restoring        */
  293. /* brick counts                                */
  294. /********************************************/
  295. cont_level()
  296. {
  297.     register BALL_STRUCT *p;
  298.     register int x, y, image, ndx;
  299.     int i;
  300.  
  301.     if (w_hand == NO_WINDOW) return;
  302.  
  303.     clear_areas();
  304.  
  305.     num_bricks = 0;
  306.     bncpy(warray,parray,20272);
  307.  
  308.     show_lives();
  309.     show_level();
  310.     show_score();
  311.  
  312.     brickarray[1] = 0;
  313.     brickarray[3] = bh - 1;
  314.  
  315.     ndx = 0;
  316.     for (y=0; y<7; y++)
  317.     {
  318.         for (x=0; x < 9; x++)
  319.         {
  320.             brickarray[0] = 0;
  321.             brickarray[2] = 43;
  322.             brickarray[4] = bleft + x * btw;
  323.             brickarray[5] = btop + y * bth;
  324.             brickarray[6] = brickarray[4] + 43;
  325.             brickarray[7] = brickarray[5] + bh - 1;
  326.  
  327.             switch(brickcount[ndx])
  328.             {
  329.                 case -1:        /* permanent */
  330.                     vro_cpyfm(handle,3,brickarray,&permbricksource,&windsource);
  331.                     break;
  332.  
  333.                 case 1:            /* normal */
  334.                     num_bricks++;
  335.                     break;
  336.  
  337.                 case 2:            /* magic */
  338.                     vro_cpyfm(handle,4,brickarray,&bricksource,&windsource);
  339.                     vro_cpyfm(handle,7,brickarray,&twobricksource,&windsource);
  340.                     num_bricks++;
  341.                     break;
  342.  
  343.                 case 3:
  344.                 case 4:
  345.                 case 5:
  346.                 case 6:
  347.                     num_bricks++;
  348.                     break;
  349.             }
  350.             ndx++;
  351.         }
  352.     }
  353.  
  354.     n_redraws = 0;
  355.     add_region(xwork,ywork,wwork,hwork);
  356.     do_redraw();
  357.  
  358.     evnt_timer(150,0);
  359.     Dosound(appear);
  360.     evnt_timer(250,0);
  361.  
  362.     for (image = 3; image >= 0; image--)
  363.     {
  364.         ndx = 0;
  365.         brickarray[0] = image * btw;
  366.         brickarray[2] = brickarray[0] + 43;
  367.  
  368.         for (y=0; y<7; y++)
  369.         {
  370.             for (x=0; x < 9; x++)
  371.             {
  372.                 brickarray[4] = bleft + x * btw;
  373.                 brickarray[5] = btop + y * bth;
  374.                 brickarray[6] = brickarray[4] + 43;
  375.                 brickarray[7] = brickarray[5] + bh - 1;
  376.  
  377.                 switch(brickcount[ndx++])
  378.                 {
  379.                     case 1:
  380.                         vro_cpyfm(handle,7,brickarray,&bricksource,&windsource);
  381.                         break;
  382.                 case 3:
  383.                 case 4:
  384.                 case 5:
  385.                 case 6:
  386.                     if (image > 0) vro_cpyfm(handle,7,
  387.                         brickarray,&twobricksource,&windsource);
  388.                     break;
  389.                 }
  390.             }
  391.         }
  392.         add_region(xwork,ywork,wwork,hwork);
  393.         do_redraw();
  394.     }
  395.     evnt_timer(500,0);
  396.  
  397.     ani_count = 0;
  398.     paddle_x = 0;
  399.     paddle_y = pad_y_max;
  400.     paddlearray[4] = 0;
  401.     paddlearray[5] = pad_y_max;
  402.     paddlearray[6] = 52;
  403.     paddlearray[7] = pad_y_max + pad_ht;
  404.  
  405.     num_balls = 0;
  406.     add_ball(0, pad_y_min - ball_ht, 2, 2, FALSE);
  407.     mode = BNORMAL;
  408.     invis = FALSE;
  409. }
  410.  
  411.  
  412. /********************************************/
  413. /* restore a level in progress to normal    */
  414. /* and keep playing                            */
  415. /********************************************/
  416. restore_level()
  417. {
  418.     register BALL_STRUCT *p;
  419.     register int x, y, image, ndx;
  420.     int i;
  421.  
  422.     mode = BNORMAL;
  423.     invis = FALSE;
  424.  
  425.     clear_areas();
  426.  
  427.     bncpy(warray,parray,20272);
  428.  
  429.     show_lives();
  430.     show_level();
  431.     show_score();
  432.  
  433.     brickarray[1] = 0;
  434.     brickarray[3] = bh - 1;
  435.  
  436.     ndx = 0;
  437.     for (y=0; y<7; y++)
  438.     {
  439.         for (x=0; x < 9; x++)
  440.         {
  441.             brickarray[4] = bleft + x * btw;
  442.             brickarray[5] = btop + y * bth;
  443.             brickarray[6] = brickarray[4] + 43;
  444.             brickarray[7] = brickarray[5] + bh - 1;
  445.  
  446.             switch(brickcount[ndx])
  447.             {
  448.                 case -1:        /* permanent */
  449.                     brickarray[0] = 0;
  450.                     brickarray[2] = 43;
  451.                     vro_cpyfm(handle,3,brickarray,&permbricksource,&windsource);
  452.                     break;
  453.  
  454.                 case 1:            /* normal */
  455.                     brickarray[0] = 0;
  456.                     brickarray[2] = 43;
  457.                     vro_cpyfm(handle,7,brickarray,&bricksource,&windsource);
  458.                     break;
  459.  
  460.                 case 2:            /* magic */
  461.                     brickarray[0] = 0;
  462.                     brickarray[2] = 43;
  463.                     vro_cpyfm(handle,4,brickarray,&bricksource,&windsource);
  464.                     vro_cpyfm(handle,7,brickarray,&twobricksource,&windsource);
  465.                     break;
  466.  
  467.                 case 3:
  468.                 case 4:
  469.                 case 5:
  470.                 case 6:
  471.                     brickarray[0] = btw;
  472.                     brickarray[2] = btw + 43;
  473.                     vro_cpyfm(handle,7,brickarray,&twobricksource,&windsource);
  474.                     break;
  475.             }
  476.             ndx++;
  477.         }
  478.     }
  479.  
  480.     n_redraws = 0;
  481.     add_region(xwork,ywork,wwork,hwork);
  482.     do_redraw();
  483. }
  484.  
  485. fast_mode()
  486. {
  487.     int test, ret;
  488.  
  489.     wind_get(w_hand,WF_TOP,&test,&ret,&ret,&ret);
  490.     if (test != w_hand) return;
  491.  
  492.     wind_update(TRUE);
  493.  
  494.     wind_set(w_hand, WF_NAME," Both Mouse Keys to Resume ",0,0);
  495.     fastmode = TRUE;
  496.  
  497.     while ((((*(lineaptr - 298)) & 3) != 3) && lives > 0)
  498.     {
  499.         new_ball();
  500.     }
  501.  
  502.     fastmode = FALSE;
  503.     wind_set(w_hand, WF_NAME,title_bar,0,0);
  504.  
  505.     wind_update(FALSE);
  506. }
  507.  
  508. fast_redraw()
  509. {
  510.     register RECT *p;
  511.     RECT t;
  512.     register int i;
  513.     int array[8];
  514.     int x_pos,y_pos, mxmin, mxmax, mymin, mymax;
  515.  
  516.     x_pos = *(lineaptr - 301);
  517.     y_pos = *(lineaptr - 300);
  518.  
  519.     mxmin = x_pos - 20;
  520.     mxmax = x_pos + 20;
  521.     mymin = y_pos - 20;
  522.     mymax = y_pos + 20;
  523.  
  524.     /* check all redraw regions for mouse interference */
  525.     for (i=0; i<n_redraws; i++)
  526.     {
  527.         p = ®ion[i];
  528.         if ((p->x < mxmax) && ((p->x + p->w) > mxmin) &&
  529.             (p->y < mymax) && ((p->y + p->h) > mymin))
  530.         {    HIDE_MOUSE;
  531.             hidden = TRUE;
  532.             break;
  533.         }
  534.     }
  535.  
  536.     for (i=0; i<n_redraws; i++)
  537.     {
  538.         p = ®ion[i];
  539.         /* clip all regions to screen size */
  540.         if ((p->x+p->w) > wdesk) p->w = wdesk - p->x;
  541.         if ((p->y+p->h) > maxy) p->h =maxy - p->y;
  542.         if ((p->x+p->w) > (xwork+wwork)) p->w = (xwork+wwork) - p->x;
  543.         if ((p->y+p->h) > (ywork+hwork)) p->h = (ywork+hwork) - p->y;
  544.         if (p->w <=0 || p->h <= 0) continue;
  545.  
  546.         array[0] = p->x - xwork;
  547.         array[1] = p->y - ywork;
  548.         array[2] = p->x - xwork + p->w - 1;
  549.         array[3] = p->y - ywork + p->h - 1;
  550.         array[4] = p->x;
  551.         array[5] = p->y;
  552.         array[6] = p->x + p->w - 1;
  553.         array[7] = p->y + p->h - 1;
  554.  
  555.         vro_cpyfm(handle,3,array,&windsource,&screen_fdb);
  556.     }
  557.  
  558.     if (hidden)
  559.     {    hidden = FALSE;
  560.         SHOW_MOUSE;
  561.     }
  562.  
  563.     n_redraws = 0;
  564. }
  565.  
  566. /*******************************************************
  567. do_load() mallocs a buffer, reads in a degas pic, and
  568.     copies the contents to the picture buffer. This means
  569.     I only do 1 disk access, and I dont waste the space of
  570.     keeping a full width picture, which saves about 15K of
  571.     space. Note that if memory cannot be allocated nothing
  572.     bad happens, but no picture is loaded and no error
  573.     message is returned... This routine also closes the
  574.     file after the read.
  575. *********************************************************/
  576. do_load(fd)
  577. {
  578.     register char *tptr, *buffer;
  579.     register int x,y;
  580.     char *tptr2;
  581.  
  582.     tptr = (char *)Malloc(27520L);
  583.     if ((long)tptr <= 0L) goto end;
  584.  
  585.     tptr2 = tptr;
  586.     buffer = parray;
  587.  
  588.     Fseek(34L,fd,0);
  589.     Fread(fd,27520L,tptr);
  590.  
  591.  
  592.     if (planes == 2)
  593.     {
  594.         for (y = 0; y < 181; y++)
  595.         {
  596.             for (x = 0; x < 112; x++)
  597.                 *buffer++ = *tptr++;
  598.             tptr += 48;                /* to end of degas line */
  599.         }
  600.     }
  601.     else
  602.     {
  603.         for (y = 0; y < 362; y++)
  604.         {
  605.             for (x = 0; x < 56; x++)
  606.                 *buffer++ = *tptr++;
  607.             tptr += 24;                /* to end of degas line */
  608.         }
  609.     }
  610.  
  611.     Mfree(tptr2);
  612. end:
  613.     Fclose(fd);
  614. }
  615.  
  616. add_difficulty()
  617. {
  618.     if (level <= 17)
  619.     {
  620.         /* restrict upper paddle limit */
  621.         pad_y_top++;
  622.         if (planes == 1) pad_y_top++;
  623.     }
  624. }
  625.