home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume11 / blockbuster / part01 / blockbuster.h < prev    next >
C/C++ Source or Header  |  1990-08-10  |  6KB  |  232 lines

  1. /*
  2.  * File:       blockbuster.h
  3.  * Author:     Eric Van Gestel
  4.  *
  5.  * For:                blockbuster
  6.  *
  7.  * Compilation:
  8.  *     -lsuntool -lsunwindow -lpixrect
  9.  */
  10.  
  11. /* file paths are defined at the end of this file */
  12.  
  13. #include <stdio.h>
  14. #include <pwd.h>
  15. #include <suntool/sunview.h>
  16. #include <suntool/canvas.h>
  17. #include <sys/time.h>
  18. #include <sys/file.h>
  19. #include <ctype.h>
  20. #include <math.h>
  21. /*
  22.  * #define M_PI                3.14159265358979323846
  23.  * #define M_PI_2      1.57079632679489661923
  24.  * #define M_PI_4      0.78539816339744830962
  25.  */
  26. #define M_PI_3_4       2.35619449019234492885
  27. #define M_SQRT2_2      0.70710678118654752440
  28. #define NEAR_HORIZONTAL        0.7    /* < M_PI_4 */
  29.  
  30.  
  31. /*** windowing objects ***/
  32.  
  33. #define BORDER         50
  34. #define MSG_HEIGHT     FONT_HEIGHT + 10
  35.  
  36. #define MAX_ROW                42
  37. #define MAX_COL                11
  38.  
  39. /* upper left corner of brick in pixels */
  40. #define COL_X( col )   (col) ? (col) * 64 - 48 + BORDER : BORDER
  41. #define ROW_Y( row )   (row) * 16 + BORDER
  42.  
  43. /* brick coordinates */
  44. #define X_COL( x )     ( (int)(x) - BORDER + 48 ) / 64
  45. #define Y_ROW( y )     ( (int)(y) - BORDER ) / 16
  46.  
  47. #define STAGE_HEIGHT_IN_PIXELS ( ( MAX_ROW + 1 ) * 16 + 2 * BORDER )
  48. #define STAGE_WIDTH_IN_PIXELS  ( ( MAX_COL - 1 ) * 64 + 2 * ( BORDER + 16 ) )
  49.  
  50. #define PIX_XOR        (PIX_SRC^PIX_DST)
  51.  
  52. Frame           frame;
  53. Canvas          stage_cvs, msg_cvs;
  54. Pixwin         *stage_win, *msg_win;
  55. Pixfont        *font;
  56.  
  57.  
  58. /*** messages ***/
  59.  
  60. #define FONT_R16       "/usr/lib/fonts/fixedwidthfonts/serif.r.16"
  61. #define FONT_WIDTH     font->pf_defaultsize.x
  62. #define FONT_HEIGHT    ( font->pf_defaultsize.y + 10 )
  63.  
  64. #define OFFSET_BALLS   20
  65. #define OFFSET_SCORE   250
  66. #define OFFSET_SPEED   550
  67.  
  68. char            msg0_buf[55];
  69.  
  70. #define msg0( offset, format, value )  \
  71.     /* int offset;  char *format;  {arg} value; */ \
  72.     pw_text( msg_win, offset, FONT_HEIGHT, PIX_SRC, font, \
  73.         sprintf( msg0_buf, format, value ) )
  74.  
  75. #define msg1( offset, value )  \
  76.     /* int offset;  char *value; */ \
  77.     pw_text( stage_win, offset, FONT_HEIGHT, PIX_SRC, font, value )
  78.  
  79. #define msg( offset, message ) \
  80.     /* int offset;  char *message; */ \
  81.     pw_text( stage_win, \
  82.         ( STAGE_WIDTH_IN_PIXELS - strlen( message ) * FONT_WIDTH ) / 2, \
  83.         BORDER + ( 4 + offset ) * FONT_HEIGHT, \
  84.         PIX_SRC, font, message )
  85.  
  86.  
  87. /*** active objects ***/
  88.  
  89. #define NO_BALL        0
  90. #define NE     1
  91. #define NW     2
  92. #define SW     3
  93. #define SE     4
  94.  
  95. #ifndef FALSE
  96. #define FALSE  0
  97. #endif
  98. #ifndef TRUE
  99. #define TRUE   1
  100. #endif
  101.  
  102. #define HORIZONTAL     1
  103. #define VERTICAL       2
  104.  
  105. #define INIT_BALLS     3
  106. #define LOOP_MAX       100
  107.  
  108. #define INIT_SPEED     3.0
  109. #define MAX_SPEED      8.0
  110. #define SPEED_LIMIT    12.0
  111. #define SPEED_INCR     0.2
  112. #define SPEED_INCR_2   0.1    /* SPEED_INCR / 2 */
  113. #define SPEED_RESOLUTION       60    /* SPEED_LIMIT / SPEED_INCR */
  114. #define SPEED_RESOLUTION_FACTOR        5.0    /* SPEED_RESOLUTION /
  115.                          * SPEED_LIMI
  116.                          * 
  117.                         /* the stage is a two
  118.                          * dimensional array of
  119.                          * bricks */
  120. struct Brick {
  121.     char            code;    /* Q.V. map_codes */
  122.     short           nhits;
  123. }               stage[MAX_ROW + 1][MAX_COL + 1];
  124.  
  125. #define IS_HIT_BRICK( code )   code > '0' && code <= '9'
  126.  
  127. struct Ball {
  128.     int             quadrant;    /* enumeration { NO_BALL, NE, NW, SW,
  129.                      * SE } */
  130.     double          angle;    /* range -M_PI_4..NEAR_HORIZONTAL */
  131.     /*
  132.      * NW -P4|-P4 NE +NH | +NH >>>>>>+<<<<<<  (gap to avoid infinite
  133.      * horizontal bounce loops) +NH | +NH SW -P4|-P4 SE
  134.      */
  135.     int             row, col;    /* coordinates on the stage */
  136.     double          x, y;    /* coordinates in pixels */
  137.     double          speed, x_speed, y_speed;    /* motion per update in
  138.                              * pixels */
  139.     /*
  140.      * INVARIANT: x_speed == speed * cos( true_angle ) y_speed == speed *
  141.      * sin( true_angle )
  142.      */
  143. }               ball1, ball2, ball3;
  144.  
  145. int             launch_quadrant;/* enumeration { NE, NW } */
  146. int             launch_row, launch_col;
  147. double          launch_x, launch_y;
  148. int             emit_row, emit_col;
  149.  
  150. #define MIN_PALLET_LENGTH      12
  151. #define SHORT_PALLET_LENGTH    16
  152. #define LONG_PALLET_LENGTH     99
  153. #define MAX_PALLET_LENGTH      99
  154. #define MAX_PALLET_HEIGHT      999
  155. #define PALLET_INCR    100
  156. #define PALLET_DENOMINATOR     20000
  157. #define PALLET_MIN_Y   ROW_Y( MAX_ROW - 9 )
  158. #define PALLET_MAX_Y   ROW_Y( MAX_ROW - 1 )
  159.  
  160. int             pallet_lengthI;    /* range MIN_PALLET_LENGTH..MAX_PALLET_LENGTH */
  161. int             pallet_heightI;    /* range pallet_lengthI..MAX_PALLET_HEIGHT */
  162. int             pallet_xI;    /* range 0..STAGE_WIDTH_IN_PIXELS */
  163. int             pallet_yI;    /* range PALLET_MAX_Y+4..PALLET_MIN_Y-12 */
  164. int             pallet_row;    /* range MAX_ROW-1..MAX_ROW-9 */
  165. double          pallet_length, pallet_height, pallet_x, pallet_y;
  166.  
  167. /*
  168.  * INVARIANT:
  169.  *     pallet_* == (double) pallet_*I;
  170.  *     pallet_width == 2 * pallet_length
  171.  *     pallet_height >= pallet_length >= ABS( excentricity )
  172.  *       =>  atan2( excentricity, pallet_height ) range -M_PI_4..M_PI_4
  173.  */
  174. int             mouse_yI;    /* range 0..STAGE_HEIGHT_IN_PIXELS *//* <HC> */
  175.  
  176. int             nb_stages, stage_nb, balls_left, score, score_incr, nbricks, loop_nhits, pallet_modif;
  177. double          launch_speed;
  178.  
  179. #define NAME_LENGTH    20
  180. char            stage_name[NAME_LENGTH];
  181.  
  182. #define MAX_NB_STAGES  100
  183. int             stages[MAX_NB_STAGES];
  184.  
  185. struct Brick   *last_busted_brick;    /* NULL == none so far */
  186. char            last_busted_code;
  187. int             last_busted_row, last_busted_col;
  188.  
  189.  
  190. /*** notifier event handlers ***/
  191.  
  192. Notify_value    move_balls(  );    /* => timeout events */
  193. int             move_pallet(  );/* => LOC_MOVE events */
  194.  
  195.  
  196. /*** itimer ***/
  197.  
  198. struct itimerval timeout;
  199.  
  200. #define ITIMER_DELAY   5000
  201. #define ITIMER_NULL ((struct itimerval *) 0 )
  202. #define start_timer()  \
  203.     timeout.it_value.tv_usec = ITIMER_DELAY; \
  204.     (void) notify_set_itimer_func( frame, move_balls, \
  205.     ITIMER_REAL, &timeout, ITIMER_NULL )
  206. #define stop_timer()   \
  207.     (void) notify_set_itimer_func( frame, move_balls, \
  208.     ITIMER_REAL, ITIMER_NULL, ITIMER_NULL )
  209.  
  210.  
  211. /*** score and stages files ***/
  212.  
  213. #define PATH_LENGTH    64
  214.  
  215. char    *login;
  216. char    playground[PATH_LENGTH];
  217.  
  218. #ifndef STAGEDIR
  219. #define STAGEDIR    "/usr/games/lib/blockbuster"
  220. #endif
  221.  
  222. #define SCOREFILE      "%s/scores"
  223. #define NB_SCORES      12
  224. #define USER_SCORES    3
  225.  
  226. #define NB_STAGESFILE  "%s/nb_stages"
  227. #define STAGEFILE      "%s/stage%d"
  228. #define STAGEFILE_LENGTH       PATH_LENGTH
  229.  
  230. #define SAVEFILE       "%s/save/%s"
  231. #define SAVEFILE_LENGTH        PATH_LENGTH
  232.