Keep track of changed resource files in makefile
[tennix.git] / game.h
blob49303061d30668649a1acc98e4216c7c93033c0f
2 /**
4 * Tennix! SDL Port
5 * Copyright (C) 2003, 2007 Thomas Perl <thp@perli.net>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
22 **/
24 #ifndef __GAME_H
25 #define __GAME_H
27 #include <math.h>
28 #include "tennix.h"
30 typedef unsigned char bool;
31 enum {
32 false,
33 true
36 typedef struct {
37 float x;
38 float y;
39 float move_x;
40 float move_y;
41 float jump;
42 } Ball;
44 typedef struct {
45 float x;
46 float y;
47 unsigned char state;
48 unsigned int score;
49 bool responsible; /* responsible for the next fault (if any) */
50 unsigned char desire; /* what the player aims to do (0=normal, 1=upper edge, 2=lower edge)*/
51 bool type; /* is this player ai-controlled or human? */
52 float ball_dest; /* prospective y-position of ball */
53 } Player;
55 enum {
56 PLAYER_TYPE_HUMAN,
57 PLAYER_TYPE_AI,
60 enum {
61 DESIRE_NORMAL,
62 DESIRE_MAX
65 typedef struct {
66 Ball ball;
67 Ball ground;
68 Player player1;
69 Player player2;
70 float phase;
71 unsigned int time;
72 bool was_stopped;
73 bool player1_serves;
74 char* status;
75 char score_str[10];
76 } GameState;
78 #define PI 3.1415
80 #define GAME_TICKS 15
82 #define GROUND_PHASE 0.4
83 #define PHASE_AMP 3.2
85 #define BALL_JUMP_MIN 4
86 #define BALL_JUMP_MAX 10
87 #define BALL_DEFAULT_SPEED 3.0
89 #define RACKET_X_MID 15
90 #define RACKET_Y_MID 24
92 #define BALL_X_MID 9
93 #define BALL_Y_MID 9
95 #define GAME_X_MIN 41.0*2
96 #define GAME_X_MAX 270.0*2
97 #define GAME_X_MID ((GAME_X_MIN+GAME_X_MAX)/2)
99 #define GAME_Y_MIN 155.0
100 #define GAME_Y_MAX 330.0
101 #define GAME_Y_MID ((GAME_Y_MIN+GAME_Y_MAX)/2)
103 #define GAME_EDGE_AREA 20.0
104 #define GAME_EDGE_UPPER GAME_Y_MIN+GAME_EDGE_AREA
105 #define GAME_EDGE_LOWER GAME_Y_MAX-GAME_EDGE_AREA
107 #define PLAYER_Y_MIN 0.0
108 #define PLAYER_Y_MAX 1.0*HEIGHT
110 #define IS_OFFSCREEN_Y(y) (((y)<0-BALL_Y_MID*2) || ((y)>HEIGHT+BALL_Y_MID*2))
111 #define IS_OFFSCREEN_X(x) (((x)<0-BALL_X_MID*2) || ((x)>WIDTH+BALL_X_MID*2))
112 #define IS_OFFSCREEN(x,y) ((IS_OFFSCREEN_X(x)) || (IS_OFFSCREEN_Y(y)))
113 #define IS_OUT_Y(y) (y<GAME_Y_MIN || y>GAME_Y_MAX)
114 #define IS_OUT_X(x) (x<GAME_X_MIN || x>GAME_X_MAX)
116 #define PLAYER_AREA_Y RACKET_Y_MID
117 #define PLAYER_AREA_X RACKET_X_MID
118 #define IS_NEAR_Y(py,by) (fabsf(py-by)<PLAYER_AREA_Y)
119 #define IS_NEAR_Y_AI(py,by) (fabsf(py-by)<PLAYER_AREA_Y/2.5)
120 #define IS_NEAR_X(px,bx) (fabsf(px-bx)<PLAYER_AREA_X)
121 #define IS_NEAR_X_AI(px,bx) (fabsf(px-bx)<PLAYER_AREA_X*2)
123 #define PLAYER_STATE_MAX 5
124 #define PLAYER_POWERSHOT 6.2
126 #define MOVE_Y_SEED 3
128 void game( bool);
129 void render( GameState*);
130 bool step( GameState*);
131 void limit_value( float*, float, float);
132 float get_phase( GameState*);
133 float get_move_y( GameState*, unsigned char);
134 void input_human( Player*, bool, bool, bool);
135 void input_ai( Player*, Ball*, Player*);
136 void game_setup_serve( GameState*);
138 #endif