home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of Select: Games 9
/
CD_1.iso
/
kids
/
apool
/
apool.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-23
|
8KB
|
195 lines
/* This is "apool.h", part of the pool (billiards)-program
"ANOTHER POOL" (V 0.97).
"apool.h" includes the constants, prototype and global variables.
Copyright (C) 1995 by Gerrit Jahn (email: ub1g@rz.uni-karlsruhe.de)
"ANOTHER POOL" (V 0.97) is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* ------------------------------ apool.h ------------------------------ */
#include <stdlib.h>
#include <stdio.h>
/*#define BANDEN 9 Anz. der "Banden", Zeile weg -> Proc. "unkompiliert" */
#define LEFT 20 /* Bildschirmgrenze links, rechts, oben, unten */
#define RIGHT 620
#define UP 70
#define DOWN 370
#define BALLS 16 /* Anzahl der Bälle */
#define DIFFX (double)(RIGHT-LEFT) /* "Länge u. 2* Breite in Pixeln */
#define RADIUS 8.0 /* Radius der Kugeln in Pixel */
#define MSG printf("\n\n ANOTHER POOL (V 0.97)\n\n")
/* #define RADIUSL 39 */ /* Radius der 6 Löcher */
#define SPINPOSX 600 /* Position der Kugel für Spineinstellung (x, y) */
#define SPINPOSY 430
#define ROLL (5.0/7.0) /* Anteil Transl.- zu Ges.energ. bei vollst. Rollen */
/*#define ALPHA 0.005*/ /* Umwandlungsfaktor von Transl. zu Rot.-geschw */
/*#define BETA 0.00008*/ /* "Bohr-Reibung" */
/*#define DELTA 0.00000005*/ /* Roll-Reibung (viel zu groß !!! ) */
/*#define ETA 0.0000001*/ /* Gleit-Reibung */
/*#define CETA 0.001*/ /* Umwandlung von Spin in Geschwindigkeit */
/*#define THETA 0.001*/ /* (Extra)-Dämpfung des Spins */
/*#define BANDES 0.3 */ /* Faktor, der WW Effet-Bande "verfeinert" */
/*#define BANDEREF 0.95*/ /* 1-Geschw.verlust b. Band.koll. (v_trans) */
/*#define SPINC 0.3*/ /*(1-max.Abnahme) des Spins bei Koll. zweier Kugeln */
#define RND ((int)(2.0*rand()/RAND_MAX+0.5)-1)
#define XAB (sqrt(4*RADIUS*RADIUS-(RADIUS+1)*(RADIUS+1))+1.5)
/*#define MASSE_WEISS 1.05*/ /* weiße Kugel schwerer als die bunten .... */
#define MSG2 msg(\
"left button: cue, middle button: set spin, right button: set power")
#define SKALP( a,b ) ((a).x*(b).x+(a).y*(b).y) /* Skalarprodukt */
#define BETR( a ) sqrt( SKALP( a, a ) ) /* Betrag */
#define COS( a ) cos( a* M_PI / 180.0 ) /* cos mit Winkeln in ° */
#define COSV( a, b ) (((a.x || a.y)) ?\
(SKALP( a, b)/(BETR( a ) * BETR( b ))) : 0 ) /* cos aus Skalaprod. */
#define DIFF(a, b) ((a)*(a) + (b)*(b)) /* DIFF, DIFF2: Abst.quadrate */
#define DIFF2(a, b) (((a)*(a) + (b)*(b)) * DIFFX*DIFFX)
#define BLACK 4 /* 'Farbe' der schwarzen Kugel */
#define WHITE (BALLS-1)
#define COL_WHITE 0
#define COL_YELLOW 2
#define COL_RED 1
#define COL_BLACK 3
#define NEW_COL_NEW (1<<3)
#define NEW_COL_DOUBLE (1<<5)
#define FOUL_BLACK_ILLEGALY_POCKETED (1<<12)
#define FOUL_WHITE_POCKETED (1<<11)
#define FOUL_NO_TOUCH (1<<10)
#define FOUL_WRONG_COLOR_POCKETED (1<<9)
#define FOUL_WRONG_COLOR_TOUCHED (1<<8)
#define FOUL_CORRECT_POT (1<<5)
#define FOUL_NO_FOUL 0
#define FOUL_ANY_FOUL ( FOUL_BLACK_ILLEGALY_POCKETED | FOUL_WHITE_POCKETED\
|FOUL_NO_TOUCH | FOUL_WRONG_COLOR_POCKETED| FOUL_WRONG_COLOR_TOUCHED )
/* Definition der benötigten Strukturen */
struct vect { double x, y; };
struct ball { struct vect v, vr, ve, e, p; double ez, m; int stat, col; };
/* v: normale Translationsgeschw.; vr: normale Rotationsgeschw.;
p: Koordinaten (0<=x<=1, 0<=y<=0.5); e,ez: ("eingegebener" Effet, Spin;
ve: normale End-Tanslationgeschw.; m: Masse
stat: "Status" der Kugel; col: Farbe (rot, gelb, schwarz) */
struct hole { struct vect p, m; };
/* p: Pos. des Mittelpunktes des Kreises, der das jeweilige Loch darstellt,
m: Pos. des Punktes auf den der Computer zielen muß, damit er ins
Loch trifft, wird bei plot_table() oder so berechnet */
struct player { int stat, wait, points, col, hole_black; double speed;};
/* stat: für Fouls, Treffer, etc.; col: welche Farbe darf angespielt werden;
speed: letzter Powerfaktor */
struct bande { struct vect p0, p1, n; };
/* p0,p1: Die zwei Punkte, die die Position der Bande festlegen,
n: 'Normalen-Vektor' der Bande */
struct target { struct vect pos; int kno, ord; struct target *next;
double abst, angle; struct target *test; };
/* f. computer.c: pos: Position des Punktes, auf den der Computer zielt,
kno, zugehörige Kugel, ord, wieviele Kugeln liegen zwischen Weißer und
Loch; abst: noch nicht benötigt, angle: unter welchem (Gesamt)-Winkel
werden die Kugeln versenkt (wichtig für setzen der Gesch.) */
struct foul { int wrongct, wrongcp, whited, notouch; };
struct statistic { struct foul fouls; int wins, losses, pots, nopots,
slosses; };
/* jetzt kommen die globalen Variablen */
extern double ALPHA, BETA, DELTA, ETA, CETA, THETA, BANDES, BANDEREF,
SPINC, MASSE_WEISS; /* eigentlich Konstanten, werden es später wieder !!! */
extern double oldalph, alph, spd, RADIUSL, e_winkel, old_min;
extern int counter, oldx[BALLS], oldy[BALLS], olds[2];
extern int first_hit, bande_hit, act, col_in, last_foul, freeball,
extra_shot,ende, c_player, anstoss, demo, last_pocketed_balls;
extern int BREMSE, PAINT, CLEV, new_col, old_ball, old_hole;
extern struct ball k[BALLS];
extern struct hole posl[6];
extern struct bande ban[18];
extern struct player ply[2];
extern struct statistic stats[2];
extern FILE *datei;
/* functions in billard.c */
void test_for_play_on_black( void );
int test_if_game_is_over( void );
void rules( void );
void init_table( void );
void undo( void );
void save_actual_position( void );
void stop_it( void );
void calc_e_winkel( void );
/* functions in graphics.c */
void init_graphics( int x_auflsg, int y_auflsg, int anz_colors);
void msg( char *ausgabestring );
void plot_table( void );
void speed( double geschwindigkeit ); /* 0<= geschw. <= 1 */
void plot_balls( void );
void test_spin( int maus_x_pos, int maus_y_pos );
void set_spin( double spin_x, double spin_y , double spin_z);
void wink( double winkel_alpha ); /* 0 <= alpha <= 85° */
void plot_one_ball( int which_one );
void err( char *ausgabe_string );
void err2( char *ausgabe_string, int color );
void debug( char *out_string );
void make_mouse_cursor( void );
int menu( void );
void wait_for_click( void );
void close_graphics( void );
void mouse_on( void );
void mouse_off( void );
void plot_act_player( int actual_player );
void set_white_ball( void );
void calc_player_v( void );
void set_player_power( void );
void set_player_spin( void );
void set_test_power( void );
int set_test_power2( void );
void ctrl_break_off( void );
void plot_statistics( double time, int graphics_on_off );
void delete_ball( int ballnr );
void help( void );
void credits( void );
/* functions in physics.c */
void translate_spin( void );
void refl_kk( int kugelnr, struct vect kbande );
void coll( int kugel_a, int kugel_b );
void reflection( int kugelnr, int bandennr );
int in_line( int kugelnr, int bandennr );
void banden_test( void );
int move_balls( void );
void calc_v_end( int no_of_ball );
int move_balls( void );
void stoss( void );
void wait_user_time( double time );
/* functions in computer.c */
int in_line_c( int ball_no_1, int ball_no_2, struct vect point_0,
struct vect point_1, int color, int graphics_on_off );
struct vect calc_tp( struct vect act_ball, struct vect target );
void set_c_speed( double abs, struct vect speed );
void computer_stoss( void );
int banden_stoss( void );
void calc_hot_spot( void );
/* function in creatabl.c */
void create_table( double widt