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 int main( int argc
, char** argv
) {
42 int sdl_flags
= SDL_SWSURFACE
| SDL_DOUBLEBUF
;
43 char datadir
[MAXPATHLEN
];
45 char copyright_line
[100];
46 int copyright_line_width
;
48 Point elektrons
[ELEKTRONS
];
51 fprintf( stderr
, "Tennix %s\n%s\n%s\n\n", VERSION
, COPYRIGHT
, URL
);
53 sprintf( copyright_line
, "Tennix %s -- %s", VERSION
, COPYRIGHT
);
55 srand( (unsigned)time( NULL
));
57 for( el
=0; el
<ELEKTRONS
; el
++) {
58 elektrons
[el
].x
= elektrons
[el
].y
= 0;
59 elektrons
[el
].w
= 50+(rand()%120);
60 elektrons
[el
].h
= 10+(rand()%10);
61 elektrons
[el
].current_x
= WIDTH
/2;
62 elektrons
[el
].current_y
= HEIGHT
/2;
63 elektrons
[el
].new_x
= rand()%WIDTH
;
64 elektrons
[el
].new_y
= rand()%HEIGHT
;
65 elektrons
[el
].phase
= 4*2*PI
*((rand()%1000)/1000.0);
66 elektrons
[el
].r
= 100+rand()%155;
67 elektrons
[el
].g
= 100+rand()%155;
69 elektrons
[el
].size
= 0;
70 elektrons
[el
].new_size
= 5+rand()%10;
73 if( SDL_Init( SDL_INIT_VIDEO
) == -1) {
74 fprintf( stderr
, "Can't init SDL: %s\n", SDL_GetError());
80 vi
= (SDL_VideoInfo
*)SDL_GetVideoInfo();
82 if( (screen
= SDL_SetVideoMode( WIDTH
, HEIGHT
, vi
->vfmt
->BitsPerPixel
, sdl_flags
)) == NULL
) {
83 fprintf( stderr
, "Can't set video mode: %s\n", SDL_GetError());
87 SDL_WM_SetCaption( "Tennix! SDL", "Tennix");
88 SDL_ShowCursor( SDL_DISABLE
);
89 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY
, 1);
92 init_graphics( datadir
);
94 copyright_line_width
= font_get_string_width( GR_DKC2_FONT
, copyright_line
);
98 if( e
.type
== SDL_QUIT
) {
101 keys
= SDL_GetKeyState( NULL
);
102 mb
= SDL_GetMouseState( &mx
, &my
);
104 if( keys
[SDLK_ESCAPE
] || keys
['q']) {
109 SDL_WM_ToggleFullScreen( screen
);
114 for( el
=0; el
<ELEKTRONS
; el
++) {
115 elektrons
[el
].new_x
= WIDTH
/2 - ELEKTRONS_WIDTH
;
116 elektrons
[el
].new_y
= highlight_y
;
117 if( elektrons
[el
].new_size
>= 5) {
118 elektrons
[el
].new_size
= 1+rand()%4;
123 for( el
=0; el
<ELEKTRONS
; el
++) {
124 elektrons
[el
].current_x
+= (1.0*(elektrons
[el
].new_x
-elektrons
[el
].current_x
)/ELEKTRON_LAZYNESS
);
125 elektrons
[el
].current_y
+= (1.0*(elektrons
[el
].new_y
-elektrons
[el
].current_y
)/ELEKTRON_LAZYNESS
);
126 if( i
%4==0 && elektrons
[el
].size
< elektrons
[el
].new_size
) {
127 elektrons
[el
].size
++;
129 if( i
%4==0 && elektrons
[el
].size
> elektrons
[el
].new_size
) {
130 elektrons
[el
].size
--;
132 elektrons
[el
].phase
+= 0.02+(rand()%20/100.0);
133 elektrons
[el
].x
= elektrons
[el
].current_x
+ ELEKTRONS_WIDTH
+ elektrons
[el
].w
*cosf(elektrons
[el
].phase
/4);
134 elektrons
[el
].y
= elektrons
[el
].current_y
+ elektrons
[el
].h
*sinf(elektrons
[el
].phase
);
137 if( M_POS_START_GAME(mx
,my
)) {
138 highlight_y
= HIGHLIGHT_START_GAME
;
139 } else if( M_POS_START_MULTI(mx
,my
)) {
140 highlight_y
= HIGHLIGHT_START_MULTI
;
141 /*} else if( M_POS_CREDITS(mx,my)) {
142 highlight_y = HIGHLIGHT_CREDITS;
143 */} else if( M_POS_QUIT(mx
,my
)) {
144 highlight_y
= HIGHLIGHT_QUIT
;
145 } else if( highlight_y
== 0) {
147 for( el
=0; el
<ELEKTRONS
; el
++) {
148 elektrons
[el
].new_size
= 5+rand()%10;
152 for( el
=0; el
<ELEKTRONS
; el
++) {
153 elektrons
[el
].new_x
= rand()%(WIDTH
-ELEKTRONS_WIDTH
-elektrons
[el
].w
/2);
154 elektrons
[el
].new_y
= rand()%HEIGHT
;
155 elektrons
[el
].new_size
= 5+rand()%10;
160 for( el
=0; el
<ELEKTRONS
; el
++) {
161 if( elektrons
[el
].size
> 0) {
162 rectangle( elektrons
[el
].x
, elektrons
[el
].y
, elektrons
[el
].size
, elektrons
[el
].size
, elektrons
[el
].r
, elektrons
[el
].g
, elektrons
[el
].b
);
163 if( elektrons
[el
].size
> 4) {
164 if( highlight_y
!= 0 || rand()%10 == 0) {
165 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);
167 rectangle( elektrons
[el
].x
+2, elektrons
[el
].y
+2, elektrons
[el
].size
-4, elektrons
[el
].size
-4, 0, 0, 0);
172 show_image( GR_MENU
, WIDTH
/2-get_image_width( GR_MENU
)/2, 0, 255);
173 font_draw_string( GR_DKC2_FONT
, copyright_line
, (WIDTH
-copyright_line_width
)/2, HEIGHT
-35, i
, ((i
/150)%ANIMATION_COUNT
));
174 show_sprite( GR_RACKET
, (mb
&SDL_BUTTON( SDL_BUTTON_LEFT
)) > 0, 4, mx
, my
, 255);
177 if( mb
& SDL_BUTTON( SDL_BUTTON_LEFT
)) {
178 if( M_POS_START_GAME(mx
,my
)) {
183 while( SDL_PollEvent( &e
));
184 fade_out( CH_AUDIENCE
);
186 if( M_POS_START_MULTI(mx
,my
)) {
191 while( SDL_PollEvent( &e
));
192 fade_out( CH_AUDIENCE
);
194 if( M_POS_CREDITS(mx
,my
)) {
195 //introimage( "data/credits.bmp");
197 if( M_POS_QUIT(mx
,my
)) {
206 while( is_fading()) {