5 * Copyright (C) 2003, 2007, 2008, 2009 Thomas Perl <thp@thpinfo.com>
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,
40 #include "animation.h"
42 #include "locations.h"
48 /* IDs from the resource file */
49 #define START_BUTTON 1
50 #define CHECKBOX_FULLSCREEN 2
53 BOOL CALLBACK
ConfigDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
55 static int checkbox_is_checked
;
59 EndDialog(hwndDlg
, IDCANCEL
);
64 EndDialog(hwndDlg
, (checkbox_is_checked
)?(IDYES
):(IDNO
));
67 EndDialog(hwndDlg
, IDCANCEL
);
69 case CHECKBOX_FULLSCREEN
:
70 checkbox_is_checked
^= 1;
82 int WINAPI
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
83 LPSTR lpCmdLine
, int nCmdShow
) {
85 int main( int argc
, char** argv
) {
87 int i
, slide
, slide_direction
;
91 unsigned int worldmap_xpos
, worldmap_ypos
;
95 int sdl_flags
= SDL_SWSURFACE
;
96 int btn_hovering
= 0, btn_hovering_old
= 0;
98 bool mouse_pressed
= false;
100 bool benchmark
= false;
101 unsigned int night_start
, night_end
;
102 GameState
*current_game
= NULL
, *prepared_game
= NULL
;
103 InputDevice
* input_devices
;
104 unsigned int input_device_count
, input_device_id
;
106 AnimationState
*intro_playback
;
109 MenuButton btn_back
= {
112 HEIGHT
-(MENU_OPTIONS_BORDER
+MENU_OPTIONS_BUTTON_HEIGHT
),
113 MENU_OPTIONS_BUTTON_WIDTH
, MENU_OPTIONS_BUTTON_HEIGHT
,
116 MenuButton btn_start
= {
118 WIDTH
-(MENU_OPTIONS_BORDER
+MENU_OPTIONS_BUTTON_WIDTH
),
119 HEIGHT
-(MENU_OPTIONS_BORDER
+MENU_OPTIONS_BUTTON_HEIGHT
),
120 MENU_OPTIONS_BUTTON_WIDTH
, MENU_OPTIONS_BUTTON_HEIGHT
,
123 MenuButton btn_player1
= {
125 CONTROLLER_SETUP_BORDER
,
126 HEIGHT
/2 + CONTROLLER_SETUP_SIZE
/2 + 10,
127 CONTROLLER_SETUP_SIZE
, MENU_OPTIONS_BUTTON_HEIGHT
,
130 MenuButton btn_player2
= {
132 WIDTH
-CONTROLLER_SETUP_SIZE
-CONTROLLER_SETUP_BORDER
,
133 HEIGHT
/2 + CONTROLLER_SETUP_SIZE
/2 + 10,
134 CONTROLLER_SETUP_SIZE
, MENU_OPTIONS_BUTTON_HEIGHT
,
138 int highlight_location
= -1;
139 float highlight_location_distance
= 0.0;
140 float new_location_distance
= 0.0;
141 bool location_info_visible
= false;
142 unsigned int location_info_xpos
= 0, location_info_ypos
= 0;
144 const SDL_VideoInfo
* vi
= NULL
;
146 bool do_help
= false;
148 int state
= MENU_STATE_STARTED
;
150 #ifdef ENABLE_FPS_LIMIT
151 Uint32 ft
, frames
; /* frame timer and frames */
155 sdl_flags
|= SDL_FULLSCREEN
;
160 mb_result
= DialogBox(hInstance
, "CONFIG", 0, (DLGPROC
)ConfigDialogProc
);
164 sdl_flags
|= SDL_FULLSCREEN
;
173 fprintf(stderr
, "Tennix 2009 World Tennis Championship Tour (v" VERSION
")\n" COPYRIGHT
"\n" URL
"\n\n");
177 /* A poor/lazy man's getopt */
178 #define OPTION_SET(longopt,shortopt) \
179 (strcmp(argv[i], longopt)==0 || strcmp(argv[i], shortopt)==0)
180 #define OPTION_VALUE \
181 ((i+1 < argc)?(argv[i+1]):(NULL))
182 #define OPTION_VALUE_PROCESSED \
184 if (OPTION_SET("--fullscreen", "-f")) {
185 sdl_flags
|= SDL_FULLSCREEN
;
187 else if (OPTION_SET("--help", "-h")) {
190 else if (OPTION_SET("--benchmark", "-b")) {
194 fprintf(stderr
, "Ignoring unknown option: %s\n", argv
[i
]);
199 if (do_help
== true) {
200 fprintf(stderr
, "Usage: %s [--fullscreen|-f] [--help|-h]\n", argv
[0]);
208 srand((unsigned)time(NULL
));
211 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_JOYSTICK
) == -1) {
212 fprintf( stderr
, "Can't init SDL: %s\n", SDL_GetError());
216 vi
= SDL_GetVideoInfo();
217 if( (screen
= SDL_SetVideoMode( WIDTH
, HEIGHT
, vi
->vfmt
->BitsPerPixel
, sdl_flags
)) == NULL
) {
218 fprintf( stderr
, "Can't set video mode: %s\n", SDL_GetError());
222 SDL_WM_SetCaption( "Tennix 2009 World Tennis Championship Tour", "Tennix 2009");
223 SDL_ShowCursor( SDL_DISABLE
);
224 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY
, 1);
230 input_devices
= find_input_devices(&input_device_count
);
232 current_game
= gamestate_load(GAMESTATE_FILE
);
233 if (current_game
!= NULL
) {
234 /* restore pointer to location */
235 current_game
->location
= &(locations
[current_game
->current_location
]);
237 for (i
=1; i
<=MAXPLAYERS
; i
++) {
238 if (PLAYER(current_game
, i
).type
== PLAYER_TYPE_HUMAN
) {
239 input_device_id
= PLAYER(current_game
, i
).input_device_index
;
240 if (input_device_id
< input_device_count
) {
241 /* ok, we still have that device around */
242 PLAYER(current_game
, i
).input
= &(input_devices
[input_device_id
]);
244 /* the device vanished - set to AI (FIXME: select new device) */
245 PLAYER(current_game
, i
).type
= PLAYER_TYPE_AI
;
246 PLAYER(current_game
, i
).input
= NULL
;
252 #ifdef ENABLE_FPS_LIMIT
258 GameState
* g
= gamestate_new();
259 PLAYER(g
, 1).type
= PLAYER_TYPE_AI
;
260 PLAYER(g
, 2).type
= PLAYER_TYPE_AI
;
261 g
->timelimit
= BENCHMARK_TIMELIMIT
*1000;
262 g
->location
= &(locations
[0]);
268 intro
= create_intro();
269 intro_playback
= animation_state_new(intro
);
270 animation_state_run(intro_playback
, 1);
271 animation_state_free(intro_playback
);
272 animation_free(intro
);
275 worldmap_xpos
= (WIDTH
-get_image_width(GR_WORLDMAP
))/2;
276 worldmap_ypos
= (HEIGHT
-get_image_height(GR_WORLDMAP
))/2;
279 /* Sliding initialization */
280 ticks
= SDL_GetTicks();
281 slide
= slide_start
= get_image_width(GR_SIDEBAR
);
284 /* State transitions */
286 case MENU_STATE_STARTED
:
287 state
= MENU_STATE_SLIDE_TO_MAINMENU
;
289 case MENU_STATE_SLIDE_TO_MAINMENU
:
291 rectangle(0, 0, WIDTH
, HEIGHT
, 80, 80, 80);
294 slide_direction
= -1;
295 state
= MENU_STATE_SLIDE_TO_MAINMENU_IN_PROGRESS
;
297 case MENU_STATE_SLIDE_TO_MAINMENU_IN_PROGRESS
:
300 state
= MENU_STATE_MAINMENU
;
303 case MENU_STATE_MAINMENU
:
305 prepared_game
= NULL
;
307 case MENU_STATE_SLIDE_TO_LOCATION
:
310 state
= MENU_STATE_SLIDE_TO_LOCATION_IN_PROGRESS
;
312 case MENU_STATE_SLIDE_TO_LOCATION_IN_PROGRESS
:
313 if (slide
== slide_start
) {
314 state
= MENU_STATE_FADE_TO_LOCATION
;
317 case MENU_STATE_FADE_TO_LOCATION
:
319 state
= MENU_STATE_LOCATION
;
322 rectangle(0, 0, WIDTH
, HEIGHT
, 80, 80, 80);
323 /* Draw and store the worldmap with day/night times */
324 show_image(GR_WORLDMAP
, WIDTH
/2-get_image_width(GR_WORLDMAP
)/2, HEIGHT
/2-get_image_height(GR_WORLDMAP
)/2, 255);
325 day_night(get_image_width(GR_WORLDMAP
), &night_start
, &night_end
);
326 if (night_start
> night_end
) {
327 rectangle_alpha(worldmap_xpos
, worldmap_ypos
, night_end
, get_image_height(GR_WORLDMAP
), 0, 0, 0, 150);
328 rectangle_alpha(worldmap_xpos
+night_start
, worldmap_ypos
, get_image_width(GR_WORLDMAP
)-night_start
, get_image_height(GR_WORLDMAP
), 0, 0, 0, 150);
330 rectangle_alpha(worldmap_xpos
+night_start
, worldmap_ypos
, night_end
-night_start
, get_image_height(GR_WORLDMAP
), 0, 0, 0, 150);
333 /* add misc items to screen */
334 font_draw_string(FONT_XLARGE
, "Pick a location", (WIDTH
-font_get_string_width(FONT_XLARGE
, "Pick a location"))/2, 20);
338 case MENU_STATE_FADE_TO_OPTIONS
:
341 rectangle(0, 0, WIDTH
, HEIGHT
, 80, 80, 80);
342 rectangle(CONTROLLER_SETUP_BORDER
, HEIGHT
/2-CONTROLLER_SETUP_SIZE
/2, CONTROLLER_SETUP_SIZE
, CONTROLLER_SETUP_SIZE
, 150, 150, 150);
343 rectangle(WIDTH
-CONTROLLER_SETUP_BORDER
-CONTROLLER_SETUP_SIZE
, (HEIGHT
-CONTROLLER_SETUP_SIZE
)/2, CONTROLLER_SETUP_SIZE
, CONTROLLER_SETUP_SIZE
, 150, 150, 150);
344 font_draw_string(FONT_XLARGE
, "Controller setup", (WIDTH
-font_get_string_width(FONT_XLARGE
, "Controller setup"))/2, 20);
345 font_draw_string(FONT_MEDIUM
, "Player 1", 130 - font_get_string_width(FONT_MEDIUM
, "Player 1")/2, (HEIGHT
-CONTROLLER_SETUP_SIZE
)/2 - 10 - font_get_height(FONT_MEDIUM
));
346 font_draw_string(FONT_MEDIUM
, "Player 1", 130 - font_get_string_width(FONT_MEDIUM
, "Player 1")/2, (HEIGHT
-CONTROLLER_SETUP_SIZE
)/2 - 10 - font_get_height(FONT_MEDIUM
));
347 font_draw_string(FONT_MEDIUM
, "Player 2", WIDTH
- CONTROLLER_SETUP_SIZE
/2 - CONTROLLER_SETUP_BORDER
- font_get_string_width(FONT_MEDIUM
, "Player 2")/2, (HEIGHT
-CONTROLLER_SETUP_SIZE
)/2 - 10 - font_get_height(FONT_MEDIUM
));
350 state
= MENU_STATE_OPTIONS
;
352 case MENU_STATE_LOCATION
:
353 case MENU_STATE_OPTIONS
:
354 /* Prepare a new game */
355 if (prepared_game
== NULL
) {
356 prepared_game
= gamestate_new();
357 prepared_game
->location
= NULL
;
358 btn_player1
.text
= "default";
359 btn_player2
.text
= "computer (AI)";
361 PLAYER(prepared_game
, 1).input_device_index
= 0;
363 PLAYER(prepared_game
, 1).input_device_index
= 2;
365 PLAYER(prepared_game
, 1).type
= PLAYER_TYPE_HUMAN
;
366 PLAYER(prepared_game
, 1).input
= &(input_devices
[PLAYER(prepared_game
, 1).input_device_index
]);
367 location_info_visible
= false;
368 prepared_game
->current_location
= -1;
369 highlight_location
= -1;
372 case MENU_STATE_SLIDE_TO_GAME
:
375 state = MENU_STATE_SLIDE_TO_GAME_IN_PROGRESS;
377 case MENU_STATE_SLIDE_TO_GAME_IN_PROGRESS:
378 if (slide == slide_start) {
379 state = MENU_STATE_GAME;
381 state
= MENU_STATE_GAME
;
383 case MENU_STATE_SLIDE_TO_RESUME
:
386 state
= MENU_STATE_SLIDE_TO_RESUME_IN_PROGRESS
;
388 case MENU_STATE_SLIDE_TO_RESUME_IN_PROGRESS
:
389 if (slide
== slide_start
) {
390 state
= MENU_STATE_RESUME
;
393 case MENU_STATE_GAME
:
394 if (prepared_game
== NULL
) {
395 fprintf(stderr
, "Game not yet prepared!\n");
398 /* Set the day/night status */
399 if (night_start
< night_end
) {
400 prepared_game
->night
= (prepared_game
->location
->worldmap_x
> night_start
&& prepared_game
->location
->worldmap_x
< night_end
);
402 prepared_game
->night
= (prepared_game
->location
->worldmap_x
< night_end
|| prepared_game
->location
->worldmap_x
> night_start
);
405 /* Cancel a possibly started game */
407 current_game
= prepared_game
;
408 prepared_game
= NULL
;
409 /* no break - we are continuing with "resume" */
410 case MENU_STATE_RESUME
:
411 if (current_game
== NULL
) {
412 fprintf(stderr
, "Cannot resume game!\n");
416 gameloop(current_game
);
418 while(SDL_PollEvent(&e
));
419 #ifdef ENABLE_FPS_LIMIT
424 state
= MENU_STATE_SLIDE_TO_MAINMENU
;
426 case MENU_STATE_SLIDE_TO_QUIT
:
429 state
= MENU_STATE_SLIDE_TO_QUIT_IN_PROGRESS
;
431 case MENU_STATE_SLIDE_TO_QUIT_IN_PROGRESS
:
432 if (slide
== slide_start
) {
433 state
= MENU_STATE_QUIT
;
436 case MENU_STATE_QUIT
:
440 fprintf(stderr
, "State error: %d\n", state
);
445 if (SDL_GetTicks() > ticks
+ 20) {
446 if (slide
>= 1 && slide
<= slide_start
) {
447 slide
+= slide_direction
+(slide_direction
*slide
/(sqrt(2*slide
)));
448 slide
= MAX(0, MIN(slide_start
, slide
));
449 } else if (slide_direction
!= 0) {
452 ticks
= SDL_GetTicks();
457 if (state
!= MENU_STATE_OPTIONS
) {
458 fill_image_offset(GR_FOG
, 0, 0, WIDTH
, HEIGHT
, -i
, 0);
461 show_image(GR_SIDEBAR
, WIDTH
-get_image_width(GR_SIDEBAR
)+slide
, 0, 255);
462 show_image(GR_TENNIXLOGO
, WIDTH
-get_image_width(GR_SIDEBAR
)-10, 20-slide
, 255);
463 if (state
!= MENU_STATE_OPTIONS
&& state
!= MENU_STATE_LOCATION
) {
465 show_image(GR_BTN_PLAY
, WIDTH
-get_image_width(GR_BTN_PLAY
)+slide
+(slide
/7)+3-(3*(btn_hovering
==MENU_START
)), 150, 255);
466 if (current_game
!= NULL
) {
467 show_image(GR_BTN_RESUME
, WIDTH
-get_image_width(GR_BTN_RESUME
)+slide
+(slide
/7)+3-(3*(btn_hovering
==MENU_RESUME
)), 230, 255);
468 font_draw_string(FONT_SMALL
, "current match:", 10, 10);
469 font_draw_string(FONT_SMALL
, current_game
->sets_score_str
, 10, 40);
471 font_draw_string(FONT_MEDIUM
, "Tennix 2009 World Tennis Championship Tour", 10, 10);
473 font_draw_string_color(FONT_MEDIUM
, URL
, 10-1, HEIGHT
-10-1-font_get_height(FONT_MEDIUM
), 130, 130, 130);
474 font_draw_string_color(FONT_MEDIUM
, URL
, 10, HEIGHT
-10-font_get_height(FONT_MEDIUM
), 30, 30, 30);
475 show_image(GR_BTN_QUIT
, WIDTH
-get_image_width(GR_BTN_QUIT
)+slide
+(slide
/7)+3-(3*(btn_hovering
==MENU_QUIT
)), 350, 255);
476 } else if (state
== MENU_STATE_OPTIONS
) {
478 draw_button_object(btn_back
, mx
, my
);
479 draw_button_object(btn_start
, mx
, my
);
480 draw_button_object(btn_player1
, mx
, my
);
481 draw_button_object(btn_player2
, mx
, my
);
482 wiggle
= 15*sinf((float)ticks
/300.);
483 if (PLAYER(prepared_game
, 1).input_device_index
> -1) {
484 show_image_rotozoom(input_devices
[PLAYER(prepared_game
, 1).input_device_index
].icon
, CONTROLLER_SETUP_BORDER
+ CONTROLLER_SETUP_SIZE
/2, HEIGHT
/2, wiggle
, 1.0);
486 show_image_rotozoom(GR_INPUT_AI
, CONTROLLER_SETUP_BORDER
+ CONTROLLER_SETUP_SIZE
/2, HEIGHT
/2, wiggle
, 1.0);
488 if (PLAYER(prepared_game
, 2).input_device_index
> -1) {
489 show_image_rotozoom(input_devices
[PLAYER(prepared_game
, 2).input_device_index
].icon
, WIDTH
-CONTROLLER_SETUP_BORDER
-CONTROLLER_SETUP_SIZE
/2, HEIGHT
/2, -wiggle
, 1.0);
491 show_image_rotozoom(GR_INPUT_AI
, WIDTH
-CONTROLLER_SETUP_BORDER
-CONTROLLER_SETUP_SIZE
/2, HEIGHT
/2, -wiggle
, 1.0);
493 } else if (state
== MENU_STATE_LOCATION
) {
494 /* Location selection screen */
495 for (x
=0; x
<location_count(); x
++) {
496 new_location_distance
= SQUARE_DISTANCE(mx
-worldmap_xpos
-locations
[x
].worldmap_x
,
497 my
-worldmap_ypos
-locations
[x
].worldmap_y
);
498 if (highlight_location
== -1) {
499 if (new_location_distance
< 20*20) {
500 highlight_location
= x
;
503 highlight_location_distance
= SQUARE_DISTANCE(mx
-worldmap_xpos
-locations
[highlight_location
].worldmap_x
,
504 my
-worldmap_ypos
-locations
[highlight_location
].worldmap_y
);
505 if (highlight_location_distance
> 20*20) {
506 highlight_location
= -1;
508 if (highlight_location_distance
> new_location_distance
&& new_location_distance
< 20*20) {
509 highlight_location
= x
;
513 if (prepared_game
!= NULL
) {
514 if (!location_info_visible
) {
515 for (x
=0; x
<location_count(); x
++) {
516 /* draw rectangle for location at "x"*/
517 if (highlight_location
!= -1 && (unsigned int)highlight_location
== x
) {
518 rectangle(worldmap_xpos
+ locations
[x
].worldmap_x
-3, worldmap_ypos
+ locations
[x
].worldmap_y
-3, 7, 7, 255*((i
/10)%2), 0, 255*((i
/10)%2));
521 rectangle(worldmap_xpos
+ locations
[x
].worldmap_x
-2, worldmap_ypos
+ locations
[x
].worldmap_y
-2, 5, 5, 255, 255*(prepared_game
->current_location
!= -1 && x
==(unsigned int)(prepared_game
->current_location
)), 0);
524 rectangle_alpha(location_info_xpos
-5, location_info_ypos
-5, 10+get_image_width(prepared_game
->location
->photo
), get_image_height(prepared_game
->location
->photo
)+100, 30, 30, 30, 200);
525 show_sprite(prepared_game
->location
->photo
, (i
/1000)%(prepared_game
->location
->photo_frames
), prepared_game
->location
->photo_frames
, location_info_xpos
, location_info_ypos
, 255);
526 font_draw_string(FONT_SMALL
, prepared_game
->location
->name
, location_info_xpos
+MENU_OPTIONS_BORDER
, location_info_ypos
+MENU_OPTIONS_BORDER
+200);
527 font_draw_string(FONT_SMALL
, prepared_game
->location
->area
, location_info_xpos
+MENU_OPTIONS_BORDER
, location_info_ypos
+MENU_OPTIONS_BORDER
+200+font_get_height(FONT_SMALL
));
528 font_draw_string(FONT_SMALL
, prepared_game
->location
->city
, location_info_xpos
+MENU_OPTIONS_BORDER
, location_info_ypos
+MENU_OPTIONS_BORDER
+200+2*font_get_height(FONT_SMALL
));
529 font_draw_string(FONT_SMALL
, prepared_game
->location
->court_type_name
, location_info_xpos
+MENU_OPTIONS_BORDER
, location_info_ypos
+MENU_OPTIONS_BORDER
+200+3*font_get_height(FONT_SMALL
));
531 if (prepared_game
->location
!= NULL
) {
532 draw_button_object(btn_start
, mx
, my
);
535 draw_button_object(btn_back
, mx
, my
);
539 if( e
.type
== SDL_QUIT
) {
540 state
= MENU_STATE_SLIDE_TO_QUIT
;
544 keys
= SDL_GetKeyState( NULL
);
545 mb
= SDL_GetMouseState( &mx
, &my
);
547 btn_hovering_old
= btn_hovering
;
548 if (state
== MENU_STATE_MAINMENU
) {
549 btn_hovering
= M_POS_DECODE(mx
, my
);
550 if (current_game
== NULL
) {
551 btn_hovering
&= ~MENU_RESUME
;
553 } else if (state
== MENU_STATE_LOCATION
) {
554 if (M_POS_BUTTON(btn_back
, mx
, my
)) {
555 btn_hovering
= MENU_QUIT
;
556 } else if (M_POS_BUTTON(btn_start
, mx
, my
)) {
557 btn_hovering
= MENU_START
;
561 } else if (state
== MENU_STATE_OPTIONS
) {
562 if (M_POS_BUTTON(btn_back
, mx
, my
)) {
563 btn_hovering
= MENU_QUIT
;
564 } else if (M_POS_BUTTON(btn_start
, mx
, my
)) {
565 btn_hovering
= MENU_START
;
566 } else if (M_POS_BUTTON(btn_player1
, mx
, my
)) {
567 btn_hovering
= MENU_PLAYER1
;
568 } else if (M_POS_BUTTON(btn_player2
, mx
, my
)) {
569 btn_hovering
= MENU_PLAYER2
;
574 /* No menu screen - no hovering. */
577 #ifndef MAEMO /* On Maemo, we cannot really "hover" (touchscreen!) */
578 if (btn_hovering_old
!= btn_hovering
&& btn_hovering
!= 0) {
579 #ifdef HAVE_VOICE_FILES
580 if (btn_hovering
== MENU_QUIT
) {
581 play_sample(VOICE_QUIT_IT
);
582 } else if (btn_hovering
== MENU_START
) {
583 play_sample(VOICE_NEW_GAME
);
585 play_sample(SOUND_MOUSEOVER
);
588 /*play_sample(SOUND_MOUSEOVER);*/
593 if( keys
[SDLK_ESCAPE
] || keys
['q']) {
594 /* FIXME: do the state thingie! */
599 SDL_WM_ToggleFullScreen( screen
);
602 #ifndef MAEMO /* No mouse cursor on Maemo (we have a touchscreen) */
603 if (state
== MENU_STATE_MAINMENU
|| state
== MENU_STATE_OPTIONS
|| state
== MENU_STATE_LOCATION
) {
604 show_image(GR_CURSOR
, mx
-2, my
-1, 255);
608 /* Draw the "real" mouse coordinates */
609 /*rectangle(mx-1, my-1, 2, 2, 255, 255, 255);*/
611 /* Store the screen, because we are fading after this screen update */
612 /*if (!(mb & SDL_BUTTON(SDL_BUTTON_LEFT)) && btn_hovering != MENU_NONE && mouse_pressed == true) store_screen();*/
616 if( mb
& SDL_BUTTON(SDL_BUTTON_LEFT
)) {
617 if (!mouse_pressed
) {
618 play_sample(SOUND_MOUSEOVER
);
620 mouse_pressed
= true;
621 } else if (mouse_pressed
== true) {
622 /* Mouse button released */
623 if (state
== MENU_STATE_MAINMENU
|| state
== MENU_STATE_OPTIONS
|| state
== MENU_STATE_LOCATION
) {
624 #ifdef HAVE_VOICE_FILES
625 if (btn_hovering
== MENU_START
) {
626 play_sample(VOICE_LETS_GO
);
628 play_sample(SOUND_MOUSECLICK
);
631 /*play_sample(SOUND_MOUSEOVER);*/
634 if (state
== MENU_STATE_MAINMENU
) {
635 switch (btn_hovering
) {
637 state
= MENU_STATE_SLIDE_TO_LOCATION
;
640 state
= MENU_STATE_SLIDE_TO_RESUME
;
643 state
= MENU_STATE_SLIDE_TO_QUIT
;
646 } else if (state
== MENU_STATE_LOCATION
) {
647 switch (btn_hovering
) {
649 if (prepared_game
->location
!= NULL
) {
650 state
= MENU_STATE_FADE_TO_OPTIONS
;
654 state
= MENU_STATE_SLIDE_TO_MAINMENU
;
657 if (!location_info_visible
&& highlight_location
!= -1) {
658 prepared_game
->current_location
= highlight_location
;
659 prepared_game
->location
= &(locations
[prepared_game
->current_location
]);
660 location_info_xpos
= MAX(0, MIN(WIDTH
-320-50, mx
-320/2));
661 location_info_ypos
= MAX(0, MIN(HEIGHT
-200-160, my
-200/2));
662 location_info_visible
= true;
664 location_info_visible
= false;
665 highlight_location
= -1;
666 prepared_game
->current_location
= -1;
667 prepared_game
->location
= NULL
;
671 } else if (state
== MENU_STATE_OPTIONS
) {
672 switch (btn_hovering
) {
674 state
= MENU_STATE_SLIDE_TO_GAME
;
677 state
= MENU_STATE_FADE_TO_LOCATION
;
680 /* advance the input device index */
681 PLAYER(prepared_game
, 1).input_device_index
++;
682 if (PLAYER(prepared_game
, 1).input_device_index
== (signed int)input_device_count
) {
683 PLAYER(prepared_game
, 1).input_device_index
= -1;
686 if (input_devices
[PLAYER(prepared_game
, 1).input_device_index
].exclusive_to_player
== 2) {
687 PLAYER(prepared_game
, 1).input_device_index
++;
690 /* determine the selected input device */
691 if (PLAYER(prepared_game
, 1).input_device_index
== -1) {
692 PLAYER(prepared_game
, 1).type
= PLAYER_TYPE_AI
;
693 PLAYER(prepared_game
, 1).input
= NULL
;
694 btn_player1
.text
= "Computer (AI)";
696 PLAYER(prepared_game
, 1).type
= PLAYER_TYPE_HUMAN
;
697 PLAYER(prepared_game
, 1).input
= &(input_devices
[PLAYER(prepared_game
, 1).input_device_index
]);
698 btn_player1
.text
= input_device_get_name(PLAYER(prepared_game
, 1).input
);
702 /* advance the input device index */
703 PLAYER(prepared_game
, 2).input_device_index
++;
705 if (input_devices
[PLAYER(prepared_game
, 2).input_device_index
].exclusive_to_player
== 1) {
706 PLAYER(prepared_game
, 2).input_device_index
++;
709 if (PLAYER(prepared_game
, 2).input_device_index
== (signed int)input_device_count
) {
710 PLAYER(prepared_game
, 2).input_device_index
= -1;
713 /* determine the selected input device */
714 if (PLAYER(prepared_game
, 2).input_device_index
== -1) {
715 PLAYER(prepared_game
, 2).type
= PLAYER_TYPE_AI
;
716 PLAYER(prepared_game
, 2).input
= NULL
;
717 btn_player2
.text
= "Computer (AI)";
719 PLAYER(prepared_game
, 2).type
= PLAYER_TYPE_HUMAN
;
720 PLAYER(prepared_game
, 2).input
= &(input_devices
[PLAYER(prepared_game
, 2).input_device_index
]);
721 btn_player2
.text
= input_device_get_name(PLAYER(prepared_game
, 2).input
);
726 mouse_pressed
= false;
729 #ifdef ENABLE_FPS_LIMIT
730 while (frames
*1000.0/((float)(SDL_GetTicks()-ft
+1))>(float)(DEFAULT_FPS
)) {
737 if (current_game
!= NULL
) {
738 if (gamestate_save(current_game
, GAMESTATE_FILE
) != 0) {
739 fprintf(stderr
, "Warning: cannot save gamestate to %s\n", GAMESTATE_FILE
);