5 * Copyright (C) 2003, 2007 Thomas Perl <thp@perli.net>
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,
35 static const char* help_text
[] = {
37 "player 1 moves with <w>, <s> and <d>",
38 "player 2 moves with <o>, <l> and <k>",
39 "switch court in game with <c>, pause with <p>",
42 /* Number of lines in help_text */
44 /* Height (in pixels) of the help text scroller */
47 int main( int argc
, char** argv
) {
54 int sdl_flags
= SDL_SWSURFACE
| SDL_DOUBLEBUF
;
55 char datadir
[MAXPATHLEN
];
57 char copyright_line
[100];
58 int copyright_line_width
;
59 int help
, help_line_widths
[HELP_LINES
], help_line_height
, help_offset
;
61 Point elektrons
[ELEKTRONS
];
64 fprintf( stderr
, "Tennix %s\n%s\n%s\n\n", VERSION
, COPYRIGHT
, URL
);
66 sprintf( copyright_line
, "Tennix %s -- %s", VERSION
, COPYRIGHT
);
68 srand( (unsigned)time( NULL
));
70 for( el
=0; el
<ELEKTRONS
; el
++) {
71 elektrons
[el
].x
= elektrons
[el
].y
= 0;
72 elektrons
[el
].w
= 50+(rand()%120);
73 elektrons
[el
].h
= 10+(rand()%10);
74 elektrons
[el
].current_x
= WIDTH
/2;
75 elektrons
[el
].current_y
= HEIGHT
/2;
76 elektrons
[el
].new_x
= rand()%WIDTH
;
77 elektrons
[el
].new_y
= rand()%HEIGHT
;
78 elektrons
[el
].phase
= 4*2*PI
*((rand()%1000)/1000.0);
79 elektrons
[el
].r
= 100+rand()%155;
80 elektrons
[el
].g
= 100+rand()%155;
82 elektrons
[el
].size
= 0;
83 elektrons
[el
].new_size
= 5+rand()%10;
86 if( SDL_Init( SDL_INIT_VIDEO
) == -1) {
87 fprintf( stderr
, "Can't init SDL: %s\n", SDL_GetError());
93 vi
= (SDL_VideoInfo
*)SDL_GetVideoInfo();
95 if( (screen
= SDL_SetVideoMode( WIDTH
, HEIGHT
, vi
->vfmt
->BitsPerPixel
, sdl_flags
)) == NULL
) {
96 fprintf( stderr
, "Can't set video mode: %s\n", SDL_GetError());
100 SDL_WM_SetCaption( "Tennix! SDL", "Tennix");
101 SDL_ShowCursor( SDL_DISABLE
);
102 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY
, 1);
104 init_sound( datadir
);
105 init_graphics( datadir
);
107 copyright_line_width
= font_get_string_width( GR_DKC2_FONT
, copyright_line
);
108 for( help
=0; help
<HELP_LINES
; help
++) {
109 help_line_widths
[help
] = font_get_string_width( GR_SMALLISH_FONT
, help_text
[help
]);
111 help_line_height
= get_image_height( GR_SMALLISH_FONT
);
115 if( e
.type
== SDL_QUIT
) {
118 keys
= SDL_GetKeyState( NULL
);
119 mb
= SDL_GetMouseState( &mx
, &my
);
121 if( keys
[SDLK_ESCAPE
] || keys
['q']) {
126 SDL_WM_ToggleFullScreen( screen
);
131 for( el
=0; el
<ELEKTRONS
; el
++) {
132 elektrons
[el
].new_x
= WIDTH
/2 - ELEKTRONS_WIDTH
;
133 elektrons
[el
].new_y
= highlight_y
;
134 if( elektrons
[el
].new_size
>= 5) {
135 elektrons
[el
].new_size
= 1+rand()%4;
140 for( el
=0; el
<ELEKTRONS
; el
++) {
141 elektrons
[el
].current_x
+= (1.0*(elektrons
[el
].new_x
-elektrons
[el
].current_x
)/ELEKTRON_LAZYNESS
);
142 elektrons
[el
].current_y
+= (1.0*(elektrons
[el
].new_y
-elektrons
[el
].current_y
)/ELEKTRON_LAZYNESS
);
143 if( i
%4==0 && elektrons
[el
].size
< elektrons
[el
].new_size
) {
144 elektrons
[el
].size
++;
146 if( i
%4==0 && elektrons
[el
].size
> elektrons
[el
].new_size
) {
147 elektrons
[el
].size
--;
149 elektrons
[el
].phase
+= 0.02+(rand()%20/100.0);
150 elektrons
[el
].x
= elektrons
[el
].current_x
+ ELEKTRONS_WIDTH
+ elektrons
[el
].w
*cosf(elektrons
[el
].phase
/4);
151 elektrons
[el
].y
= elektrons
[el
].current_y
+ elektrons
[el
].h
*sinf(elektrons
[el
].phase
);
154 if( M_POS_START_GAME(mx
,my
)) {
155 highlight_y
= HIGHLIGHT_START_GAME
;
156 } else if( M_POS_START_MULTI(mx
,my
)) {
157 highlight_y
= HIGHLIGHT_START_MULTI
;
158 /*} else if( M_POS_CREDITS(mx,my)) {
159 highlight_y = HIGHLIGHT_CREDITS;
160 */} else if( M_POS_QUIT(mx
,my
)) {
161 highlight_y
= HIGHLIGHT_QUIT
;
162 } else if( highlight_y
== 0) {
164 for( el
=0; el
<ELEKTRONS
; el
++) {
165 elektrons
[el
].new_size
= 5+rand()%10;
169 for( el
=0; el
<ELEKTRONS
; el
++) {
170 elektrons
[el
].new_x
= rand()%(WIDTH
-ELEKTRONS_WIDTH
-elektrons
[el
].w
/2);
171 elektrons
[el
].new_y
= rand()%HEIGHT
;
172 elektrons
[el
].new_size
= 5+rand()%10;
177 for( el
=0; el
<ELEKTRONS
; el
++) {
178 if( elektrons
[el
].size
> 0) {
179 rectangle( elektrons
[el
].x
, elektrons
[el
].y
, elektrons
[el
].size
, elektrons
[el
].size
, elektrons
[el
].r
, elektrons
[el
].g
, elektrons
[el
].b
);
180 if( elektrons
[el
].size
> 4) {
181 if( highlight_y
!= 0 || rand()%10 == 0) {
182 draw_line_faded( elektrons
[el
].x
+elektrons
[el
].size
/2, elektrons
[el
].y
+elektrons
[el
].size
/2, mx
+15, my
+24, elektrons
[el
].r
/3, elektrons
[el
].g
/3, 0, 0 ,0 ,0);
184 rectangle( elektrons
[el
].x
+2, elektrons
[el
].y
+2, elektrons
[el
].size
-4, elektrons
[el
].size
-4, 0, 0, 0);
189 show_image( GR_MENU
, WIDTH
/2-get_image_width( GR_MENU
)/2, 0, 255);
190 font_draw_string( GR_DKC2_FONT
, copyright_line
, (WIDTH
-copyright_line_width
)/2, HEIGHT
-35, i
, ((i
/150)%ANIMATION_COUNT
));
191 for( help
=0; help
<HELP_LINES
; help
++) {
192 help_offset
= (help_line_height
*(HELP_LINES
-help
)+i
/2)%HELP_PHASE
;
193 font_draw_string_alpha( GR_SMALLISH_FONT
, help_text
[help
],
194 (WIDTH
-help_line_widths
[help
])/2,
195 HEIGHT
/2+30-help_offset
,
197 255.0*fabsf( sinf( help_offset
/((float)HELP_PHASE
)*M_PI
))
200 show_sprite( GR_RACKET
, ((mb
&SDL_BUTTON( SDL_BUTTON_LEFT
))>0)+(((mb
&SDL_BUTTON( SDL_BUTTON_RIGHT
))>0)*2), 4, mx
, my
, 255);
203 if( mb
& SDL_BUTTON( SDL_BUTTON_LEFT
)) {
204 if( M_POS_START_GAME(mx
,my
)) {
209 while( SDL_PollEvent( &e
));
210 fade_out( CH_AUDIENCE
);
212 if( M_POS_START_MULTI(mx
,my
)) {
217 while( SDL_PollEvent( &e
));
218 fade_out( CH_AUDIENCE
);
220 if( M_POS_CREDITS(mx
,my
)) {
221 //introimage( "data/credits.bmp");
223 if( M_POS_QUIT(mx
,my
)) {
232 while( is_fading()) {