home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume11
/
blockbuster
/
part01
/
blockbuster.h
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-10
|
6KB
|
232 lines
/*
* File: blockbuster.h
* Author: Eric Van Gestel
*
* For: blockbuster
*
* Compilation:
* -lsuntool -lsunwindow -lpixrect
*/
/* file paths are defined at the end of this file */
#include <stdio.h>
#include <pwd.h>
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <sys/time.h>
#include <sys/file.h>
#include <ctype.h>
#include <math.h>
/*
* #define M_PI 3.14159265358979323846
* #define M_PI_2 1.57079632679489661923
* #define M_PI_4 0.78539816339744830962
*/
#define M_PI_3_4 2.35619449019234492885
#define M_SQRT2_2 0.70710678118654752440
#define NEAR_HORIZONTAL 0.7 /* < M_PI_4 */
/*** windowing objects ***/
#define BORDER 50
#define MSG_HEIGHT FONT_HEIGHT + 10
#define MAX_ROW 42
#define MAX_COL 11
/* upper left corner of brick in pixels */
#define COL_X( col ) (col) ? (col) * 64 - 48 + BORDER : BORDER
#define ROW_Y( row ) (row) * 16 + BORDER
/* brick coordinates */
#define X_COL( x ) ( (int)(x) - BORDER + 48 ) / 64
#define Y_ROW( y ) ( (int)(y) - BORDER ) / 16
#define STAGE_HEIGHT_IN_PIXELS ( ( MAX_ROW + 1 ) * 16 + 2 * BORDER )
#define STAGE_WIDTH_IN_PIXELS ( ( MAX_COL - 1 ) * 64 + 2 * ( BORDER + 16 ) )
#define PIX_XOR (PIX_SRC^PIX_DST)
Frame frame;
Canvas stage_cvs, msg_cvs;
Pixwin *stage_win, *msg_win;
Pixfont *font;
/*** messages ***/
#define FONT_R16 "/usr/lib/fonts/fixedwidthfonts/serif.r.16"
#define FONT_WIDTH font->pf_defaultsize.x
#define FONT_HEIGHT ( font->pf_defaultsize.y + 10 )
#define OFFSET_BALLS 20
#define OFFSET_SCORE 250
#define OFFSET_SPEED 550
char msg0_buf[55];
#define msg0( offset, format, value ) \
/* int offset; char *format; {arg} value; */ \
pw_text( msg_win, offset, FONT_HEIGHT, PIX_SRC, font, \
sprintf( msg0_buf, format, value ) )
#define msg1( offset, value ) \
/* int offset; char *value; */ \
pw_text( stage_win, offset, FONT_HEIGHT, PIX_SRC, font, value )
#define msg( offset, message ) \
/* int offset; char *message; */ \
pw_text( stage_win, \
( STAGE_WIDTH_IN_PIXELS - strlen( message ) * FONT_WIDTH ) / 2, \
BORDER + ( 4 + offset ) * FONT_HEIGHT, \
PIX_SRC, font, message )
/*** active objects ***/
#define NO_BALL 0
#define NE 1
#define NW 2
#define SW 3
#define SE 4
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define HORIZONTAL 1
#define VERTICAL 2
#define INIT_BALLS 3
#define LOOP_MAX 100
#define INIT_SPEED 3.0
#define MAX_SPEED 8.0
#define SPEED_LIMIT 12.0
#define SPEED_INCR 0.2
#define SPEED_INCR_2 0.1 /* SPEED_INCR / 2 */
#define SPEED_RESOLUTION 60 /* SPEED_LIMIT / SPEED_INCR */
#define SPEED_RESOLUTION_FACTOR 5.0 /* SPEED_RESOLUTION /
* SPEED_LIMI
*
/* the stage is a two
* dimensional array of
* bricks */
struct Brick {
char code; /* Q.V. map_codes */
short nhits;
} stage[MAX_ROW + 1][MAX_COL + 1];
#define IS_HIT_BRICK( code ) code > '0' && code <= '9'
struct Ball {
int quadrant; /* enumeration { NO_BALL, NE, NW, SW,
* SE } */
double angle; /* range -M_PI_4..NEAR_HORIZONTAL */
/*
* NW -P4|-P4 NE +NH | +NH >>>>>>+<<<<<< (gap to avoid infinite
* horizontal bounce loops) +NH | +NH SW -P4|-P4 SE
*/
int row, col; /* coordinates on the stage */
double x, y; /* coordinates in pixels */
double speed, x_speed, y_speed; /* motion per update in
* pixels */
/*
* INVARIANT: x_speed == speed * cos( true_angle ) y_speed == speed *
* sin( true_angle )
*/
} ball1, ball2, ball3;
int launch_quadrant;/* enumeration { NE, NW } */
int launch_row, launch_col;
double launch_x, launch_y;
int emit_row, emit_col;
#define MIN_PALLET_LENGTH 12
#define SHORT_PALLET_LENGTH 16
#define LONG_PALLET_LENGTH 99
#define MAX_PALLET_LENGTH 99
#define MAX_PALLET_HEIGHT 999
#define PALLET_INCR 100
#define PALLET_DENOMINATOR 20000
#define PALLET_MIN_Y ROW_Y( MAX_ROW - 9 )
#define PALLET_MAX_Y ROW_Y( MAX_ROW - 1 )
int pallet_lengthI; /* range MIN_PALLET_LENGTH..MAX_PALLET_LENGTH */
int pallet_heightI; /* range pallet_lengthI..MAX_PALLET_HEIGHT */
int pallet_xI; /* range 0..STAGE_WIDTH_IN_PIXELS */
int pallet_yI; /* range PALLET_MAX_Y+4..PALLET_MIN_Y-12 */
int pallet_row; /* range MAX_ROW-1..MAX_ROW-9 */
double pallet_length, pallet_height, pallet_x, pallet_y;
/*
* INVARIANT:
* pallet_* == (double) pallet_*I;
* pallet_width == 2 * pallet_length
* pallet_height >= pallet_length >= ABS( excentricity )
* => atan2( excentricity, pallet_height ) range -M_PI_4..M_PI_4
*/
int mouse_yI; /* range 0..STAGE_HEIGHT_IN_PIXELS *//* <HC> */
int nb_stages, stage_nb, balls_left, score, score_incr, nbricks, loop_nhits, pallet_modif;
double launch_speed;
#define NAME_LENGTH 20
char stage_name[NAME_LENGTH];
#define MAX_NB_STAGES 100
int stages[MAX_NB_STAGES];
struct Brick *last_busted_brick; /* NULL == none so far */
char last_busted_code;
int last_busted_row, last_busted_col;
/*** notifier event handlers ***/
Notify_value move_balls( ); /* => timeout events */
int move_pallet( );/* => LOC_MOVE events */
/*** itimer ***/
struct itimerval timeout;
#define ITIMER_DELAY 5000
#define ITIMER_NULL ((struct itimerval *) 0 )
#define start_timer() \
timeout.it_value.tv_usec = ITIMER_DELAY; \
(void) notify_set_itimer_func( frame, move_balls, \
ITIMER_REAL, &timeout, ITIMER_NULL )
#define stop_timer() \
(void) notify_set_itimer_func( frame, move_balls, \
ITIMER_REAL, ITIMER_NULL, ITIMER_NULL )
/*** score and stages files ***/
#define PATH_LENGTH 64
char *login;
char playground[PATH_LENGTH];
#ifndef STAGEDIR
#define STAGEDIR "/usr/games/lib/blockbuster"
#endif
#define SCOREFILE "%s/scores"
#define NB_SCORES 12
#define USER_SCORES 3
#define NB_STAGESFILE "%s/nb_stages"
#define STAGEFILE "%s/stage%d"
#define STAGEFILE_LENGTH PATH_LENGTH
#define SAVEFILE "%s/save/%s"
#define SAVEFILE_LENGTH PATH_LENGTH