Version 1.2.0 with new build/configure system
[tennix.git] / src / tennix.h
bloba547aee2d573bfb15ea9dd4c9d2dfbfda82bb38e
2 /**
4 * Tennix! SDL Port
5 * Copyright (C) 2003, 2007, 2008, 2009 Thomas Perl <thp@thpinfo.com>
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 __TENNIX_H
25 #define __TENNIX_H
27 #include "config.h"
29 #define tnx_assert(x) do { \
30 if (!(x)) { \
31 fprintf(stderr, "Assertion fail: %s\n", #x); \
32 exit(1); \
33 } \
34 } while(0)
36 #include <sys/param.h>
38 #include <SDL/SDL.h>
40 #ifdef HAVE_SDL_NET
41 #include <SDL/SDL_net.h>
42 #endif
44 typedef struct {
45 unsigned char x;
46 unsigned char y;
47 unsigned char keys; /* bitfield (0 = key pressed, 1 = not pressed) */
48 } NetworkInputData;
50 #ifdef HAVE_SDL_NET
51 typedef struct {
52 UDPsocket send_socket;
53 UDPsocket recv_input_socket;
54 UDPsocket recv_state_socket;
56 UDPpacket* input_packet;
57 UDPpacket* state_packet;
59 IPaddress peer;
61 bool input_available;
62 bool state_available;
64 Uint16 base_port_local;
65 Uint16 base_port_remote;
67 NetworkInputData input_data;
69 bool master;
70 } TennixNet;
71 #else
72 typedef void TennixNet;
73 #endif /* HAVE_SDL_NET */
75 #define ARCHIVE_FILE "tennix.tnx"
76 #define ARCHIVE_FILE_INSTALLED "/" PREFIX "/share/tennix/" ARCHIVE_FILE
78 #define GAMESTATE_FILE ".tennix-current_match-" VERSION
80 #define COPYRIGHT "Copyright 2003, 2007-2011, 2013 Thomas Perl"
81 #define URL "http://icculus.org/tennix/"
83 #define WIDTH 640
84 #define HEIGHT 480
86 #define MENU_BUTTON_HEIGHT 62
87 #define MENU_BUTTON_WIDTH 185
89 #define MENU_START_YPOS 150
90 #define MENU_RESUME_YPOS 230
91 #define MENU_QUIT_YPOS 350
93 #define M_POS_XPOS(x) (x>WIDTH-MENU_BUTTON_WIDTH)
94 #define M_POS_START(y) (y>MENU_START_YPOS && y<MENU_START_YPOS+MENU_BUTTON_HEIGHT)
95 #define M_POS_RESUME(y) (y>MENU_RESUME_YPOS && y<MENU_RESUME_YPOS+MENU_BUTTON_HEIGHT)
96 #define M_POS_QUIT(y) (y>MENU_QUIT_YPOS && y<MENU_QUIT_YPOS+MENU_BUTTON_HEIGHT)
98 #define MENU_OPTIONS_BORDER 20
99 #define MENU_OPTIONS_BUTTON_HEIGHT 25
100 #define MENU_OPTIONS_BUTTON_WIDTH 150
102 /* Menu items */
103 enum {
104 MENU_NONE = 0,
105 MENU_START = 1,
106 MENU_RESUME = 2,
107 MENU_COURT_CHANGE = 4,
108 MENU_PLAYER1 = 8,
109 MENU_PLAYER2 = 16,
110 MENU_QUIT = 32
113 #define M_POS_DECODE(x,y) (M_POS_XPOS(x)?((M_POS_START(y))?(MENU_START):((M_POS_QUIT(y))?(MENU_QUIT):((M_POS_RESUME(y))?(MENU_RESUME):(MENU_NONE)))):(MENU_NONE))
115 /* Menu states */
116 enum {
117 MENU_STATE_STARTED = 0,
118 MENU_STATE_SLIDE_TO_MAINMENU,
119 MENU_STATE_SLIDE_TO_MAINMENU_IN_PROGRESS,
120 MENU_STATE_MAINMENU,
121 MENU_STATE_SLIDE_TO_LOCATION,
122 MENU_STATE_SLIDE_TO_LOCATION_IN_PROGRESS,
123 MENU_STATE_FADE_TO_LOCATION,
124 MENU_STATE_LOCATION,
125 MENU_STATE_FADE_TO_OPTIONS,
126 MENU_STATE_OPTIONS,
127 MENU_STATE_SLIDE_TO_GAME,
128 MENU_STATE_SLIDE_TO_GAME_IN_PROGRESS,
129 MENU_STATE_GAME,
130 MENU_STATE_SLIDE_TO_RESUME,
131 MENU_STATE_SLIDE_TO_RESUME_IN_PROGRESS,
132 MENU_STATE_RESUME,
133 MENU_STATE_SLIDE_TO_QUIT,
134 MENU_STATE_SLIDE_TO_QUIT_IN_PROGRESS,
135 MENU_STATE_QUIT
138 #define DEFAULT_FPS 33
141 extern SDL_Surface *screen;
143 typedef struct {
144 const char *text;
145 int x;
146 int y;
147 int w;
148 int h;
149 Uint8 r;
150 Uint8 g;
151 Uint8 b;
152 unsigned int image_id;
153 } MenuButton;
155 void menu_button_init(MenuButton*);
157 #define CONTROLLER_SETUP_BORDER 50
158 #define CONTROLLER_SETUP_SIZE 200
160 #define M_POS_BUTTON(button,mx,my) (mx>=(button).x && mx<=(button).x+(button).w && my>=(button).y && my<=(button).y+(button).h)
162 #define SQUARE_DISTANCE(xdiff, ydiff) (((xdiff)*(xdiff)) + ((ydiff)*(ydiff)))
164 #endif