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,
41 #include "animation.h"
43 #include "locations.h"
49 /* IDs from the resource file */
50 #define START_BUTTON 1
51 #define CHECKBOX_FULLSCREEN 2
54 BOOL CALLBACK
ConfigDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
56 static int checkbox_is_checked
;
60 EndDialog(hwndDlg
, IDCANCEL
);
65 EndDialog(hwndDlg
, (checkbox_is_checked
)?(IDYES
):(IDNO
));
68 EndDialog(hwndDlg
, IDCANCEL
);
70 case CHECKBOX_FULLSCREEN
:
71 checkbox_is_checked
^= 1;
83 int WINAPI
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
84 LPSTR lpCmdLine
, int nCmdShow
) {
86 int main( int argc
, char** argv
) {
88 int i
, slide
, slide_direction
;
92 unsigned int worldmap_xpos
, worldmap_ypos
;
96 int sdl_flags
= SDL_SWSURFACE
;
97 int btn_hovering
= 0, btn_hovering_old
= 0;
99 bool mouse_pressed
= false;
101 bool benchmark
= false;
102 unsigned int night_start
, night_end
;
103 GameState
*current_game
= NULL
, *prepared_game
= NULL
;
104 InputDevice
* input_devices
;
105 unsigned int input_device_count
, input_device_id
;
107 AnimationState
*intro_playback
;
109 TennixNet
* connection
= NULL
;
110 char* net_host
= NULL
;
113 bool net_master
= false;
115 MenuButton btn_back
= {
116 NULL
, /* not needed for image-based button */
118 HEIGHT
-MENU_OPTIONS_BORDER
,
119 0, -1, /* width and height will be set by menu_button_init */
123 MenuButton btn_start
= {
124 NULL
, /* not needed for image-based button */
125 WIDTH
-MENU_OPTIONS_BORDER
,
126 HEIGHT
-MENU_OPTIONS_BORDER
,
127 -1, -1, /* width and height will be set by menu_button_init */
131 MenuButton btn_player1
= {
133 CONTROLLER_SETUP_BORDER
,
134 HEIGHT
/2 + CONTROLLER_SETUP_SIZE
/2 + 10,
135 CONTROLLER_SETUP_SIZE
, MENU_OPTIONS_BUTTON_HEIGHT
,
139 MenuButton btn_player2
= {
141 WIDTH
-CONTROLLER_SETUP_SIZE
-CONTROLLER_SETUP_BORDER
,
142 HEIGHT
/2 + CONTROLLER_SETUP_SIZE
/2 + 10,
143 CONTROLLER_SETUP_SIZE
, MENU_OPTIONS_BUTTON_HEIGHT
,
148 int highlight_location
= -1;
149 float highlight_location_distance
= 0.0;
150 float new_location_distance
= 0.0;
151 bool location_info_visible
= false;
152 unsigned int location_info_xpos
= 0, location_info_ypos
= 0;
154 const SDL_VideoInfo
* vi
= NULL
;
156 bool do_help
= false;
158 int state
= MENU_STATE_STARTED
;
160 #ifdef ENABLE_FPS_LIMIT
161 Uint32 ft
, frames
; /* frame timer and frames */
164 #if defined(MAEMO) || defined(MACOSX)
165 sdl_flags
|= SDL_FULLSCREEN
;
170 mb_result
= DialogBox(hInstance
, "CONFIG", 0, (DLGPROC
)ConfigDialogProc
);
174 sdl_flags
|= SDL_FULLSCREEN
;
183 fprintf(stderr
, "Tennix 2009 World Tennis Championship Tour (v" VERSION
")\n" COPYRIGHT
"\n" URL
"\n\n");
187 /* A poor/lazy man's getopt */
188 #define OPTION_SET(longopt,shortopt) \
189 (strcmp(argv[i], longopt)==0 || strcmp(argv[i], shortopt)==0)
190 #define OPTION_VALUE \
191 ((i+1 < argc)?(argv[i+1]):(NULL))
192 #define OPTION_VALUE_PROCESSED \
194 if (OPTION_SET("--fullscreen", "-f")) {
195 sdl_flags
|= SDL_FULLSCREEN
;
197 else if (OPTION_SET("--help", "-h")) {
200 else if (OPTION_SET("--benchmark", "-b")) {
203 else if (OPTION_SET("--network", "-n")) {
204 net_host
= OPTION_VALUE
;
205 assert(OPTION_VALUE
!= NULL
);
206 OPTION_VALUE_PROCESSED
;
207 net_port_local
= atoi(OPTION_VALUE
);
208 assert(OPTION_VALUE
!= NULL
);
209 OPTION_VALUE_PROCESSED
;
210 net_port_remote
= atoi(OPTION_VALUE
);
211 assert(OPTION_VALUE
!= NULL
);
212 OPTION_VALUE_PROCESSED
;
214 else if (OPTION_SET("--master", "-m")) {
218 fprintf(stderr
, "Ignoring unknown option: %s\n", argv
[i
]);
223 if (do_help
== true) {
224 fprintf(stderr
, "Usage: %s [--fullscreen|-f] [--help|-h]\n", argv
[0]);
232 srand((unsigned)time(NULL
));
235 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_JOYSTICK
) == -1) {
236 fprintf( stderr
, "Can't init SDL: %s\n", SDL_GetError());
240 vi
= SDL_GetVideoInfo();
241 if( (screen
= SDL_SetVideoMode( WIDTH
, HEIGHT
, vi
->vfmt
->BitsPerPixel
, sdl_flags
)) == NULL
) {
242 fprintf( stderr
, "Can't set video mode: %s\n", SDL_GetError());
246 SDL_WM_SetCaption( "Tennix 2009 World Tennis Championship Tour", "Tennix 2009");
247 SDL_ShowCursor( SDL_DISABLE
);
248 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY
, 1);
255 if (net_host
!= NULL
) {
256 connection
= network_connect(net_host
, net_port_local
, net_port_remote
);
257 network_set_master(connection
, net_master
);
260 menu_button_init(&btn_back
);
261 menu_button_init(&btn_start
);
262 menu_button_init(&btn_player1
);
263 menu_button_init(&btn_player2
);
265 input_devices
= find_input_devices(&input_device_count
);
267 current_game
= gamestate_load(GAMESTATE_FILE
);
268 if (current_game
!= NULL
) {
269 /* restore pointer to location */
270 current_game
->location
= &(locations
[current_game
->current_location
]);
272 for (i
=1; i
<=MAXPLAYERS
; i
++) {
273 if (PLAYER(current_game
, i
).type
== PLAYER_TYPE_HUMAN
) {
274 input_device_id
= PLAYER(current_game
, i
).input_device_index
;
275 if (input_device_id
< input_device_count
) {
276 /* ok, we still have that device around */
277 PLAYER(current_game
, i
).input
= &(input_devices
[input_device_id
]);
279 /* the device vanished - set to AI (FIXME: select new device) */
280 PLAYER(current_game
, i
).type
= PLAYER_TYPE_AI
;
281 PLAYER(current_game
, i
).input
= NULL
;
287 #ifdef ENABLE_FPS_LIMIT
293 GameState
* g
= gamestate_new();
294 PLAYER(g
, 1).type
= PLAYER_TYPE_AI
;
295 PLAYER(g
, 2).type
= PLAYER_TYPE_AI
;
296 g
->location
= &(locations
[0]);
297 gameloop(g
, connection
);
302 /*intro = create_intro();
303 intro_playback = animation_state_new(intro);
304 animation_state_run(intro_playback, 1);
305 animation_state_free(intro_playback);
306 animation_free(intro);
309 worldmap_xpos
= (WIDTH
-get_image_width(GR_WORLDMAP
))/2;
310 worldmap_ypos
= (HEIGHT
-get_image_height(GR_WORLDMAP
))/2;
313 /* Sliding initialization */
314 ticks
= SDL_GetTicks();
315 slide
= slide_start
= get_image_width(GR_SIDEBAR
);
318 /* State transitions */
320 case MENU_STATE_STARTED
:
321 state
= MENU_STATE_SLIDE_TO_MAINMENU
;
323 case MENU_STATE_SLIDE_TO_MAINMENU
:
325 rectangle(0, 0, WIDTH
, HEIGHT
, 80, 80, 80);
328 slide_direction
= -1;
329 state
= MENU_STATE_SLIDE_TO_MAINMENU_IN_PROGRESS
;
331 case MENU_STATE_SLIDE_TO_MAINMENU_IN_PROGRESS
:
334 state
= MENU_STATE_MAINMENU
;
337 case MENU_STATE_MAINMENU
:
339 prepared_game
= NULL
;
341 case MENU_STATE_SLIDE_TO_LOCATION
:
344 state
= MENU_STATE_SLIDE_TO_LOCATION_IN_PROGRESS
;
346 case MENU_STATE_SLIDE_TO_LOCATION_IN_PROGRESS
:
347 if (slide
== slide_start
) {
348 state
= MENU_STATE_FADE_TO_LOCATION
;
351 case MENU_STATE_FADE_TO_LOCATION
:
353 state
= MENU_STATE_LOCATION
;
356 rectangle(0, 0, WIDTH
, HEIGHT
, 80, 80, 80);
357 /* Draw and store the worldmap with day/night times */
358 show_image(GR_WORLDMAP
, WIDTH
/2-get_image_width(GR_WORLDMAP
)/2, HEIGHT
/2-get_image_height(GR_WORLDMAP
)/2, 255);
359 day_night(get_image_width(GR_WORLDMAP
), &night_start
, &night_end
);
360 if (night_start
> night_end
) {
361 rectangle_alpha(worldmap_xpos
, worldmap_ypos
, night_end
, get_image_height(GR_WORLDMAP
), 0, 0, 0, 150);
362 rectangle_alpha(worldmap_xpos
+night_start
, worldmap_ypos
, get_image_width(GR_WORLDMAP
)-night_start
, get_image_height(GR_WORLDMAP
), 0, 0, 0, 150);
364 rectangle_alpha(worldmap_xpos
+night_start
, worldmap_ypos
, night_end
-night_start
, get_image_height(GR_WORLDMAP
), 0, 0, 0, 150);
367 /* add misc items to screen */
368 font_draw_string(FONT_XLARGE
, "Pick a location", (WIDTH
-font_get_string_width(FONT_XLARGE
, "Pick a location"))/2, 20);
372 case MENU_STATE_FADE_TO_OPTIONS
:
375 rectangle(0, 0, WIDTH
, HEIGHT
, 80, 80, 80);
376 rectangle(CONTROLLER_SETUP_BORDER
, HEIGHT
/2-CONTROLLER_SETUP_SIZE
/2, CONTROLLER_SETUP_SIZE
, CONTROLLER_SETUP_SIZE
, 150, 150, 150);
377 rectangle(WIDTH
-CONTROLLER_SETUP_BORDER
-CONTROLLER_SETUP_SIZE
, (HEIGHT
-CONTROLLER_SETUP_SIZE
)/2, CONTROLLER_SETUP_SIZE
, CONTROLLER_SETUP_SIZE
, 150, 150, 150);
378 font_draw_string(FONT_XLARGE
, "Controller setup", (WIDTH
-font_get_string_width(FONT_XLARGE
, "Controller setup"))/2, 20);
379 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
));
380 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
));
381 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
));
384 state
= MENU_STATE_OPTIONS
;
386 case MENU_STATE_LOCATION
:
387 case MENU_STATE_OPTIONS
:
388 /* Prepare a new game */
389 if (prepared_game
== NULL
) {
390 prepared_game
= gamestate_new();
391 prepared_game
->location
= NULL
;
392 /* FIXME - this should not be written here, but taken from the input devices */
393 btn_player1
.text
= "Keyboard (arrows)";
394 btn_player2
.text
= "Carl Van Court";
396 PLAYER(prepared_game
, 1).input_device_index
= 0;
398 PLAYER(prepared_game
, 1).input_device_index
= 2;
400 PLAYER(prepared_game
, 1).type
= PLAYER_TYPE_HUMAN
;
401 PLAYER(prepared_game
, 1).input
= &(input_devices
[PLAYER(prepared_game
, 1).input_device_index
]);
402 location_info_visible
= false;
403 prepared_game
->current_location
= -1;
404 highlight_location
= -1;
407 case MENU_STATE_SLIDE_TO_GAME
:
410 state = MENU_STATE_SLIDE_TO_GAME_IN_PROGRESS;
412 case MENU_STATE_SLIDE_TO_GAME_IN_PROGRESS:
413 if (slide == slide_start) {
414 state = MENU_STATE_GAME;
416 state
= MENU_STATE_GAME
;
418 case MENU_STATE_SLIDE_TO_RESUME
:
421 state
= MENU_STATE_SLIDE_TO_RESUME_IN_PROGRESS
;
423 case MENU_STATE_SLIDE_TO_RESUME_IN_PROGRESS
:
424 if (slide
== slide_start
) {
425 state
= MENU_STATE_RESUME
;
428 case MENU_STATE_GAME
:
429 if (prepared_game
== NULL
) {
430 fprintf(stderr
, "Game not yet prepared!\n");
434 /* Cancel a possibly started game */
436 current_game
= prepared_game
;
437 prepared_game
= NULL
;
438 /* no break - we are continuing with "resume" */
439 case MENU_STATE_RESUME
:
440 if (current_game
== NULL
) {
441 fprintf(stderr
, "Cannot resume game!\n");
445 gameloop(current_game
, connection
);
447 while(SDL_PollEvent(&e
));
448 #ifdef ENABLE_FPS_LIMIT
453 state
= MENU_STATE_SLIDE_TO_MAINMENU
;
455 case MENU_STATE_SLIDE_TO_QUIT
:
458 state
= MENU_STATE_SLIDE_TO_QUIT_IN_PROGRESS
;
460 case MENU_STATE_SLIDE_TO_QUIT_IN_PROGRESS
:
461 if (slide
== slide_start
) {
462 state
= MENU_STATE_QUIT
;
465 case MENU_STATE_QUIT
:
469 fprintf(stderr
, "State error: %d\n", state
);
474 if (SDL_GetTicks() > ticks
+ 20) {
475 if (slide
>= 1 && slide
<= slide_start
) {
476 slide
+= slide_direction
+(slide_direction
*slide
/(sqrt(2*slide
)));
477 slide
= MAX(0, MIN(slide_start
, slide
));
478 } else if (slide_direction
!= 0) {
481 ticks
= SDL_GetTicks();
486 if (state
!= MENU_STATE_OPTIONS
) {
487 fill_image_offset(GR_FOG
, 0, 0, WIDTH
, HEIGHT
, -i
, 0);
490 show_image(GR_SIDEBAR
, WIDTH
-get_image_width(GR_SIDEBAR
)+slide
, 0, 255);
491 show_image(GR_TENNIXLOGO
, WIDTH
-get_image_width(GR_SIDEBAR
)-10, 20-slide
, 255);
492 if (state
!= MENU_STATE_OPTIONS
&& state
!= MENU_STATE_LOCATION
) {
494 show_image(GR_BTN_PLAY
, WIDTH
-get_image_width(GR_BTN_PLAY
)+slide
+(slide
/7)+3-(3*(btn_hovering
==MENU_START
)), 150, 255);
495 if (current_game
!= NULL
) {
496 show_image(GR_BTN_RESUME
, WIDTH
-get_image_width(GR_BTN_RESUME
)+slide
+(slide
/7)+3-(3*(btn_hovering
==MENU_RESUME
)), 230, 255);
497 font_draw_string(FONT_SMALL
, "match paused", 10, 10);
499 font_draw_string(FONT_MEDIUM
, "Tennix 2009 World Tennis Championship Tour", 10, 10);
501 font_draw_string_color(FONT_MEDIUM
, URL
, 10-1, HEIGHT
-10-1-font_get_height(FONT_MEDIUM
), 130, 130, 130);
502 font_draw_string_color(FONT_MEDIUM
, URL
, 10, HEIGHT
-10-font_get_height(FONT_MEDIUM
), 30, 30, 30);
503 show_image(GR_BTN_QUIT
, WIDTH
-get_image_width(GR_BTN_QUIT
)+slide
+(slide
/7)+3-(3*(btn_hovering
==MENU_QUIT
)), 350, 255);
504 } else if (state
== MENU_STATE_OPTIONS
) {
506 draw_button_object(&btn_back
, mx
, my
);
507 draw_button_object(&btn_start
, mx
, my
);
508 draw_button_object(&btn_player1
, mx
, my
);
509 draw_button_object(&btn_player2
, mx
, my
);
510 wiggle
= 15*sinf((float)ticks
/300.);
511 if (PLAYER(prepared_game
, 1).input_device_index
> -1) {
512 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);
514 show_image_rotozoom(GR_INPUT_AI
, CONTROLLER_SETUP_BORDER
+ CONTROLLER_SETUP_SIZE
/2, HEIGHT
/2, wiggle
, 1.0);
516 if (PLAYER(prepared_game
, 2).input_device_index
> -1) {
517 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);
519 show_image_rotozoom(GR_INPUT_AI
, WIDTH
-CONTROLLER_SETUP_BORDER
-CONTROLLER_SETUP_SIZE
/2, HEIGHT
/2, -wiggle
, 1.0);
521 } else if (state
== MENU_STATE_LOCATION
) {
522 /* Location selection screen */
523 for (x
=0; x
<location_count(); x
++) {
524 new_location_distance
= SQUARE_DISTANCE(mx
-worldmap_xpos
-locations
[x
].worldmap_x
,
525 my
-worldmap_ypos
-locations
[x
].worldmap_y
);
526 if (highlight_location
== -1) {
527 if (new_location_distance
< 20*20) {
528 highlight_location
= x
;
531 highlight_location_distance
= SQUARE_DISTANCE(mx
-worldmap_xpos
-locations
[highlight_location
].worldmap_x
,
532 my
-worldmap_ypos
-locations
[highlight_location
].worldmap_y
);
533 if (highlight_location_distance
> 20*20) {
534 highlight_location
= -1;
536 if (highlight_location_distance
> new_location_distance
&& new_location_distance
< 20*20) {
537 highlight_location
= x
;
541 if (prepared_game
!= NULL
) {
542 if (!location_info_visible
) {
543 for (x
=0; x
<location_count(); x
++) {
544 /* draw rectangle for location at "x"*/
545 if (highlight_location
!= -1 && (unsigned int)highlight_location
== x
) {
546 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));
549 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);
552 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);
553 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);
554 font_draw_string(FONT_SMALL
, prepared_game
->location
->name
, location_info_xpos
+MENU_OPTIONS_BORDER
, location_info_ypos
+MENU_OPTIONS_BORDER
+200);
555 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
));
556 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
));
557 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
));
559 if (prepared_game
->location
!= NULL
) {
560 draw_button_object(&btn_start
, mx
, my
);
563 draw_button_object(&btn_back
, mx
, my
);
567 if( e
.type
== SDL_QUIT
) {
568 state
= MENU_STATE_SLIDE_TO_QUIT
;
572 keys
= SDL_GetKeyState( NULL
);
573 mb
= SDL_GetMouseState( &mx
, &my
);
575 btn_hovering_old
= btn_hovering
;
576 if (state
== MENU_STATE_MAINMENU
) {
577 btn_hovering
= M_POS_DECODE(mx
, my
);
578 if (current_game
== NULL
) {
579 btn_hovering
&= ~MENU_RESUME
;
581 } else if (state
== MENU_STATE_LOCATION
) {
582 if (M_POS_BUTTON(btn_back
, mx
, my
)) {
583 btn_hovering
= MENU_QUIT
;
584 } else if (M_POS_BUTTON(btn_start
, mx
, my
)) {
585 btn_hovering
= MENU_START
;
589 } else if (state
== MENU_STATE_OPTIONS
) {
590 if (M_POS_BUTTON(btn_back
, mx
, my
)) {
591 btn_hovering
= MENU_QUIT
;
592 } else if (M_POS_BUTTON(btn_start
, mx
, my
)) {
593 btn_hovering
= MENU_START
;
594 } else if (M_POS_BUTTON(btn_player1
, mx
, my
)) {
595 btn_hovering
= MENU_PLAYER1
;
596 } else if (M_POS_BUTTON(btn_player2
, mx
, my
)) {
597 btn_hovering
= MENU_PLAYER2
;
602 /* No menu screen - no hovering. */
605 #ifndef MAEMO /* On Maemo, we cannot really "hover" (touchscreen!) */
606 if (btn_hovering_old
!= btn_hovering
&& btn_hovering
!= 0) {
607 #ifdef HAVE_VOICE_FILES
608 if (btn_hovering
== MENU_QUIT
) {
609 play_sample(VOICE_QUIT_IT
);
610 } else if (btn_hovering
== MENU_START
) {
611 play_sample(VOICE_NEW_GAME
);
613 play_sample(SOUND_MOUSEOVER
);
616 /*play_sample(SOUND_MOUSEOVER);*/
621 if( keys
[SDLK_ESCAPE
] || keys
['q']) {
622 /* FIXME: do the state thingie! */
627 SDL_WM_ToggleFullScreen( screen
);
630 #ifndef MAEMO /* No mouse cursor on Maemo (we have a touchscreen) */
631 if (state
== MENU_STATE_MAINMENU
|| state
== MENU_STATE_OPTIONS
|| state
== MENU_STATE_LOCATION
) {
632 show_image(GR_CURSOR
, mx
-2, my
-1, 255);
636 /* Draw the "real" mouse coordinates */
637 /*rectangle(mx-1, my-1, 2, 2, 255, 255, 255);*/
639 /* Store the screen, because we are fading after this screen update */
640 /*if (!(mb & SDL_BUTTON(SDL_BUTTON_LEFT)) && btn_hovering != MENU_NONE && mouse_pressed == true) store_screen();*/
644 if( mb
& SDL_BUTTON(SDL_BUTTON_LEFT
)) {
645 if (!mouse_pressed
) {
646 play_sample(SOUND_MOUSEOVER
);
648 mouse_pressed
= true;
649 } else if (mouse_pressed
== true) {
650 /* Mouse button released */
651 if (state
== MENU_STATE_MAINMENU
|| state
== MENU_STATE_OPTIONS
|| state
== MENU_STATE_LOCATION
) {
652 #ifdef HAVE_VOICE_FILES
653 if (btn_hovering
== MENU_START
) {
654 play_sample(VOICE_LETS_GO
);
656 play_sample(SOUND_MOUSECLICK
);
659 /*play_sample(SOUND_MOUSEOVER);*/
662 if (state
== MENU_STATE_MAINMENU
) {
663 switch (btn_hovering
) {
665 state
= MENU_STATE_SLIDE_TO_LOCATION
;
668 state
= MENU_STATE_SLIDE_TO_RESUME
;
671 state
= MENU_STATE_SLIDE_TO_QUIT
;
674 } else if (state
== MENU_STATE_LOCATION
) {
675 switch (btn_hovering
) {
677 if (prepared_game
->location
!= NULL
) {
678 state
= MENU_STATE_FADE_TO_OPTIONS
;
682 state
= MENU_STATE_SLIDE_TO_MAINMENU
;
685 if (!location_info_visible
&& highlight_location
!= -1) {
686 prepared_game
->current_location
= highlight_location
;
687 /* Set the day/night status */
688 if (night_start
< night_end
) {
689 locations
[prepared_game
->current_location
].night
= (locations
[prepared_game
->current_location
].worldmap_x
> night_start
&& locations
[prepared_game
->current_location
].worldmap_x
< night_end
);
691 locations
[prepared_game
->current_location
].night
= (locations
[prepared_game
->current_location
].worldmap_x
< night_end
|| locations
[prepared_game
->current_location
].worldmap_x
> night_start
);
693 prepared_game
->location
= &(locations
[prepared_game
->current_location
]);
694 location_info_xpos
= MAX(0, MIN(WIDTH
-320-50, mx
-320/2));
695 location_info_ypos
= MAX(0, MIN(HEIGHT
-200-160, my
-200/2));
696 location_info_visible
= true;
698 location_info_visible
= false;
699 highlight_location
= -1;
700 prepared_game
->current_location
= -1;
701 prepared_game
->location
= NULL
;
705 } else if (state
== MENU_STATE_OPTIONS
) {
706 switch (btn_hovering
) {
708 state
= MENU_STATE_SLIDE_TO_GAME
;
711 state
= MENU_STATE_FADE_TO_LOCATION
;
714 /* advance the input device index */
715 PLAYER(prepared_game
, 1).input_device_index
++;
716 if (PLAYER(prepared_game
, 1).input_device_index
== (signed int)input_device_count
) {
717 PLAYER(prepared_game
, 1).input_device_index
= -1;
720 if (input_devices
[PLAYER(prepared_game
, 1).input_device_index
].exclusive_to_player
== 2) {
721 PLAYER(prepared_game
, 1).input_device_index
++;
724 /* determine the selected input device */
725 if (PLAYER(prepared_game
, 1).input_device_index
== -1) {
726 PLAYER(prepared_game
, 1).type
= PLAYER_TYPE_AI
;
727 PLAYER(prepared_game
, 1).input
= NULL
;
728 btn_player1
.text
= "Carl Van Court";
730 PLAYER(prepared_game
, 1).type
= PLAYER_TYPE_HUMAN
;
731 PLAYER(prepared_game
, 1).input
= &(input_devices
[PLAYER(prepared_game
, 1).input_device_index
]);
732 btn_player1
.text
= input_device_get_name(PLAYER(prepared_game
, 1).input
);
736 /* advance the input device index */
737 PLAYER(prepared_game
, 2).input_device_index
++;
739 if (input_devices
[PLAYER(prepared_game
, 2).input_device_index
].exclusive_to_player
== 1) {
740 PLAYER(prepared_game
, 2).input_device_index
++;
743 if (PLAYER(prepared_game
, 2).input_device_index
== (signed int)input_device_count
) {
744 PLAYER(prepared_game
, 2).input_device_index
= -1;
747 /* determine the selected input device */
748 if (PLAYER(prepared_game
, 2).input_device_index
== -1) {
749 PLAYER(prepared_game
, 2).type
= PLAYER_TYPE_AI
;
750 PLAYER(prepared_game
, 2).input
= NULL
;
751 btn_player2
.text
= "Carl Van Court";
753 PLAYER(prepared_game
, 2).type
= PLAYER_TYPE_HUMAN
;
754 PLAYER(prepared_game
, 2).input
= &(input_devices
[PLAYER(prepared_game
, 2).input_device_index
]);
755 btn_player2
.text
= input_device_get_name(PLAYER(prepared_game
, 2).input
);
760 mouse_pressed
= false;
763 #ifdef ENABLE_FPS_LIMIT
764 while (frames
*1000.0/((float)(SDL_GetTicks()-ft
+1))>(float)(DEFAULT_FPS
)) {
771 if (current_game
!= NULL
) {
772 if (gamestate_save(current_game
, GAMESTATE_FILE
) != 0) {
773 fprintf(stderr
, "Warning: cannot save gamestate to %s\n", GAMESTATE_FILE
);
777 /* Play the credits */
778 /*intro = create_credits();
779 intro_playback = animation_state_new(intro);
780 animation_state_run(intro_playback, 1);
781 animation_state_free(intro_playback);
782 animation_free(intro);*/
793 void menu_button_init(MenuButton
* b
)
797 if (b
->image_id
!= GR_COUNT
) {
799 * If the button is an image, the "w" and "h" attributes of the
800 * MenuButton struct are simply factors with which the real width
801 * and height of the image (=button) should be multiplied and added
802 * to the "x" and "y" position and the "w" and "h" are replaced with
803 * the real size of the image for the collision detection
808 b
->w
= get_image_width(b
->image_id
);
809 b
->h
= get_image_height(b
->image_id
);