Bugfix for ball not moving completely off-screen
[tennix.git] / game.h
blobd320bec9f163248585e606f1fd42b7f99afad51b
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 float dest1;
43 float dest2;
44 } Ball;
46 typedef struct {
47 float x;
48 float y;
49 unsigned char state;
50 unsigned int score;
51 unsigned char responsible; /* responsible for the next fault (if any) */
52 } Player;
54 typedef struct {
55 Ball ball;
56 Ball ground;
57 Player player1;
58 Player player2;
59 float phase;
60 unsigned int time;
61 bool was_stopped;
62 } GameState;
64 #define PI 3.1415
66 #define GAME_TICKS 15
68 #define GROUND_PHASE 0.4
69 #define PHASE_AMP 3.2
71 #define BALL_JUMP_MIN 4
72 #define BALL_JUMP_MAX 10
73 #define BALL_DEFAULT_SPEED 3.0
75 #define RACKET_X_MID 15
76 #define RACKET_Y_MID 24
78 #define BALL_X_MID 9
79 #define BALL_Y_MID 9
81 #define GAME_X_MIN 41.0*2
82 #define GAME_X_MAX 270.0*2
83 #define GAME_X_MID ((GAME_X_MIN+GAME_X_MAX)/2)
85 #define GAME_Y_MIN 155.0
86 #define GAME_Y_MAX 330.0
87 #define GAME_Y_MID ((GAME_Y_MIN+GAME_Y_MAX)/2)
89 #define PLAYER_Y_MIN 0.0
90 #define PLAYER_Y_MAX 1.0*HEIGHT
92 #define IS_OFFSCREEN_Y(y) (((y)<0-BALL_Y_MID*2) || ((y)>HEIGHT+BALL_Y_MID*2))
93 #define IS_OFFSCREEN_X(x) (((x)<0-BALL_X_MID*2) || ((x)>WIDTH+BALL_X_MID*2))
94 #define IS_OFFSCREEN(x,y) ((IS_OFFSCREEN_X(x)) || (IS_OFFSCREEN_Y(y)))
95 #define IS_OUT_Y(y) (y<GAME_Y_MIN || y>GAME_Y_MAX)
96 #define IS_OUT_X(x) (x<GAME_X_MIN || x>GAME_X_MAX)
98 #define PLAYER_AREA_Y RACKET_Y_MID
99 #define PLAYER_AREA_X RACKET_X_MID
100 #define IS_NEAR_Y(py,by) (fabsf(py-by)<PLAYER_AREA_Y)
101 #define IS_NEAR_X(px,bx) (fabsf(px-bx)<PLAYER_AREA_X)
103 #define PLAYER_STATE_MAX 5
104 #define PLAYER_POWERSHOT 6.2
106 void game();
107 void render( GameState*);
108 bool step( GameState*);
109 void limit_value( float*, float, float);
110 float get_phase( GameState*);
111 float get_move_y( GameState*, unsigned char);
113 #endif