5 * Copyright (C) 2003, 2007, 2008 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,
42 /* IDs from the resource file */
43 #define START_BUTTON 1
44 #define CHECKBOX_FULLSCREEN 2
47 BOOL CALLBACK
ConfigDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
49 static int checkbox_is_checked
;
53 EndDialog(hwndDlg
, IDCANCEL
);
58 EndDialog(hwndDlg
, (checkbox_is_checked
)?(IDYES
):(IDNO
));
61 EndDialog(hwndDlg
, IDCANCEL
);
63 case CHECKBOX_FULLSCREEN
:
64 checkbox_is_checked
^= 1;
76 int WINAPI
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
77 LPSTR lpCmdLine
, int nCmdShow
) {
79 int main( int argc
, char** argv
) {
81 int i
, slide
, slide_direction
= -1;
87 int sdl_flags
= SDL_SWSURFACE
;
88 int copyright_line_width
;
92 bool is_clicked
= false;
95 sdl_flags
|= SDL_FULLSCREEN
;
100 mb_result
= DialogBox(hInstance
, "CONFIG", 0, (DLGPROC
)ConfigDialogProc
);
104 sdl_flags
|= SDL_FULLSCREEN
;
113 fprintf( stderr
, "Tennix %s\n%s\n%s\n\n", VERSION
, COPYRIGHT
, URL
);
115 bool do_help
= false;
118 /* A poor/lazy man's getopt */
119 #define OPTION_SET(longopt,shortopt) \
120 (strcmp(argv[i], longopt)==0 || strcmp(argv[i], shortopt)==0)
121 #define OPTION_VALUE \
122 ((i+1 < argc)?(argv[i+1]):(NULL))
123 #define OPTION_VALUE_PROCESSED \
125 if (OPTION_SET("--fullscreen", "-f")) {
126 sdl_flags
|= SDL_FULLSCREEN
;
128 else if (OPTION_SET("--help", "-h")) {
131 else if (OPTION_SET("--list-joysticks", "-J")) {
132 SDL_Init(SDL_INIT_JOYSTICK
);
136 else if (OPTION_SET("--joystick", "-j")) {
137 SDL_Init(SDL_INIT_JOYSTICK
);
138 if (OPTION_VALUE
== NULL
) {
139 fprintf(stderr
, "Error: You need to specify the name of the joystick as parameter.\n");
143 if (joystick_open(OPTION_VALUE
)==0) {
144 fprintf(stderr
, "Warning: Cannot find joystick \"%s\" - Ignored.\n", OPTION_VALUE
);
147 OPTION_VALUE_PROCESSED
;
150 fprintf(stderr
, "Ignoring unknown option: %s\n", argv
[i
]);
155 if (do_help
== true) {
156 fprintf(stderr
, "Usage: %s [--fullscreen|-f] [--help|-h] [--list-joysticks|-J] [--joystick|-j] [joystick name]\n", argv
[0]);
161 srand( (unsigned)time( NULL
));
163 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_JOYSTICK
) == -1) {
164 fprintf( stderr
, "Can't init SDL: %s\n", SDL_GetError());
168 SDL_VideoInfo
* vi
= (SDL_VideoInfo
*)SDL_GetVideoInfo();
169 if( (screen
= SDL_SetVideoMode( WIDTH
, HEIGHT
, vi
->vfmt
->BitsPerPixel
, sdl_flags
)) == NULL
) {
170 fprintf( stderr
, "Can't set video mode: %s\n", SDL_GetError());
174 SDL_WM_SetCaption( "Tennix " VERSION
, "Tennix");
175 SDL_ShowCursor( SDL_DISABLE
);
176 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY
, 1);
182 /*play_sample_background(SOUND_BACKGROUND);*/
184 copyright_line_width
= font_get_string_width( GR_DKC2_FONT
, COPYRIGHT
);
187 ticks
= SDL_GetTicks();
188 slide_start
= get_image_width(GR_SIDEBAR
);
191 if (SDL_GetTicks() > ticks
+ 20) {
192 if (slide
> 0 && slide
<= slide_start
) {
193 slide
+= slide_direction
*(1+slide
/25);
194 } else if (slide
>= slide_start
) {
201 ticks
= SDL_GetTicks();
203 btn_offset
= slide
/7;
204 show_image(GR_SIDEBAR
, WIDTH
-get_image_width(GR_SIDEBAR
)+slide
, 0, 255);
205 show_image(GR_TENNIXLOGO
, WIDTH
-get_image_width(GR_SIDEBAR
)-10+slide
/2, 20, 255);
206 show_image(GR_BTN_PLAY
, WIDTH
-get_image_width(GR_BTN_PLAY
)+slide
+btn_offset
+3-(3*(btn_hovering
==1)), 150, 255);
207 show_image(GR_BTN_OPTIONS
, WIDTH
-get_image_width(GR_BTN_OPTIONS
)+slide
+btn_offset
+3-(3*(btn_hovering
==2)), 230, 255);
208 show_image(GR_BTN_QUIT
, WIDTH
-get_image_width(GR_BTN_QUIT
)+slide
+btn_offset
+3-(3*(btn_hovering
==3)), 350, 255);
211 if( e
.type
== SDL_QUIT
) {
214 keys
= SDL_GetKeyState( NULL
);
215 mb
= SDL_GetMouseState( &mx
, &my
);
217 if( keys
[SDLK_ESCAPE
] || keys
['q']) {
222 SDL_WM_ToggleFullScreen( screen
);
225 if( M_POS_START_GAME(mx
,my
)) {
226 if (btn_hovering
!= 1) play_sample(SOUND_MOUSEOVER
);
228 } else if( M_POS_START_MULTI(mx
,my
)) {
229 if (btn_hovering
!= 2) play_sample(SOUND_MOUSEOVER
);
231 } else if( M_POS_QUIT(mx
,my
)) {
232 if (btn_hovering
!= 3) play_sample(SOUND_MOUSEOVER
);
238 /*font_draw_string( GR_SMALLISH_FONT, COPYRIGHT, (WIDTH-copyright_line_width)/2-80, HEIGHT-35, i*3, (((i*3)/150)%ANIMATION_COUNT));*/
239 #ifndef MAEMO /* No mouse cursor on Maemo (we have a touchscreen) */
240 show_sprite( GR_RACKET
, ((mb
&SDL_BUTTON( SDL_BUTTON_LEFT
))>0)+(((mb
&SDL_BUTTON( SDL_BUTTON_RIGHT
))>0)*2), 4, mx
, my
, 255);
242 /*font_draw_string( GR_SMALLISH_FONT, "FYI: Currently, the options menu is the two-player mode :)", 10, 10, 0, 0);*/
245 /* Draw the "real" mouse coordinates */
246 rectangle(mx
-1, my
-1, 2, 2, 255, 255, 255);
248 if (mb
& SDL_BUTTON(SDL_BUTTON_LEFT
) && M_POS_QUIT(mx
,my
) && is_clicked
== false) store_screen();
251 if( mb
& SDL_BUTTON( SDL_BUTTON_LEFT
)) {
253 } else if (is_clicked
== true) {
254 play_sample(SOUND_MOUSECLICK
);
255 if( M_POS_START_GAME(mx
,my
) || M_POS_START_MULTI(mx
, my
)) {
256 stop_sample(SOUND_BACKGROUND
);
258 game(M_POS_START_GAME(mx
, my
));
261 while( SDL_PollEvent( &e
));
262 /*play_sample_background(SOUND_BACKGROUND);*/
264 slide_direction
= -1;
265 } else if( M_POS_QUIT(mx
,my
)) {
266 stop_sample(SOUND_BACKGROUND
);
277 while( is_fading()) {