Don't allow racket hit on "out"; non-permanent racket swing
[tennix.git] / game.h
blob5db226c7ffa8004b440b5cbf5f283384f6613413
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 enum {
37 REFEREE_NORMAL,
38 REFEREE_PLAYER1,
39 REFEREE_OUT,
40 REFEREE_PLAYER2
43 typedef struct {
44 float x;
45 float y;
46 float move_x;
47 float move_y;
48 float jump;
49 } Ball;
51 typedef struct {
52 float x;
53 float y;
54 unsigned char state;
55 unsigned int score;
56 bool responsible; /* responsible for the next fault (if any) */
57 unsigned char desire; /* what the player aims to do (0=normal, 1=upper edge, 2=lower edge)*/
58 bool type; /* is this player ai-controlled or human? */
59 float ball_dest; /* prospective y-position of ball */
60 bool state_locked; /* enabled when user keeps pressing the "hit" key */
61 } Player;
63 enum {
64 PLAYER_TYPE_HUMAN,
65 PLAYER_TYPE_AI,
68 enum {
69 DESIRE_NORMAL,
70 DESIRE_MAX
73 typedef struct {
74 Ball ball;
75 Ball ground;
76 Player player1;
77 Player player2;
78 float phase;
79 unsigned int time;
80 bool was_stopped;
81 bool player1_serves;
82 char* status;
83 char score_str[10];
84 unsigned char referee;
85 } GameState;
87 #define PI 3.1415
89 #define GAME_TICKS 15
91 #define GROUND_PHASE 0.4
92 #define PHASE_AMP 3.2
94 #define BALL_JUMP_MIN 4
95 #define BALL_JUMP_MAX 10
96 #define BALL_DEFAULT_SPEED 3.0
98 #define RACKET_X_MID 15
99 #define RACKET_Y_MID 24
101 #define BALL_X_MID 9
102 #define BALL_Y_MID 9
104 #define GAME_X_MIN 41.0*2
105 #define GAME_X_MAX 270.0*2
106 #define GAME_X_MID ((GAME_X_MIN+GAME_X_MAX)/2)
108 #define GAME_Y_MIN 155.0
109 #define GAME_Y_MAX 330.0
110 #define GAME_Y_MID ((GAME_Y_MIN+GAME_Y_MAX)/2)
112 #define GAME_EDGE_AREA 20.0
113 #define GAME_EDGE_UPPER GAME_Y_MIN+GAME_EDGE_AREA
114 #define GAME_EDGE_LOWER GAME_Y_MAX-GAME_EDGE_AREA
116 #define PLAYER_Y_MIN 0.0
117 #define PLAYER_Y_MAX 1.0*HEIGHT
119 #define IS_OFFSCREEN_Y(y) (((y)<0-BALL_Y_MID*2) || ((y)>HEIGHT+BALL_Y_MID*2))
120 #define IS_OFFSCREEN_X(x) (((x)<0-BALL_X_MID*2) || ((x)>WIDTH+BALL_X_MID*2))
121 #define IS_OFFSCREEN(x,y) ((IS_OFFSCREEN_X(x)) || (IS_OFFSCREEN_Y(y)))
122 #define IS_OUT_Y(y) (y<GAME_Y_MIN || y>GAME_Y_MAX)
123 #define IS_OUT_X(x) (x<GAME_X_MIN || x>GAME_X_MAX)
125 #define PLAYER_AREA_Y RACKET_Y_MID
126 #define PLAYER_AREA_X RACKET_X_MID
127 #define IS_NEAR_Y(py,by) (fabsf(py-by)<PLAYER_AREA_Y)
128 #define IS_NEAR_Y_AI(py,by) (fabsf(py-by)<PLAYER_AREA_Y/2.5)
129 #define IS_NEAR_X(px,bx) (fabsf(px-bx)<PLAYER_AREA_X)
130 #define IS_NEAR_X_AI(px,bx) (fabsf(px-bx)<PLAYER_AREA_X*2)
132 #define PLAYER_STATE_MAX 7
133 #define PLAYER_POWERSHOT 6.2
135 #define MOVE_Y_SEED 3
137 void game( bool);
138 void render( GameState*);
139 bool step( GameState*);
140 void limit_value( float*, float, float);
141 float get_phase( GameState*);
142 float get_move_y( GameState*, unsigned char);
143 void input_human( Player*, bool, bool, bool);
144 void input_ai( Player*, Ball*, Player*);
145 void game_setup_serve( GameState*);
147 #endif