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,
42 #include "animation.h"
44 #include "locations.h"
50 /* IDs from the resource file */
51 #define START_BUTTON 1
52 #define CHECKBOX_FULLSCREEN 2
55 BOOL CALLBACK
ConfigDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
57 static int checkbox_is_checked
;
61 EndDialog(hwndDlg
, IDCANCEL
);
66 EndDialog(hwndDlg
, (checkbox_is_checked
)?(IDYES
):(IDNO
));
69 EndDialog(hwndDlg
, IDCANCEL
);
71 case CHECKBOX_FULLSCREEN
:
72 checkbox_is_checked
^= 1;
84 int WINAPI
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
85 LPSTR lpCmdLine
, int nCmdShow
) {
87 int main( int argc
, char** argv
) {
89 int i
, slide
, slide_direction
;
93 unsigned int worldmap_xpos
, worldmap_ypos
;
97 int sdl_flags
= SDL_SWSURFACE
;
98 int btn_hovering
= 0, btn_hovering_old
= 0;
100 bool mouse_pressed
= false;
102 bool benchmark
= false;
103 unsigned int night_start
, night_end
;
104 GameState
*current_game
= NULL
, *prepared_game
= NULL
;
105 InputDevice
* input_devices
;
106 unsigned int input_device_count
, input_device_id
;
108 AnimationState
*intro_playback
;
110 TennixNet
* connection
= NULL
;
111 char* net_host
= NULL
;
112 bool net_master
= false;
113 TennixArchive
* tnxar
= NULL
;
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("--slave", "-s")) {
204 net_host
= OPTION_VALUE
;
205 assert(OPTION_VALUE
!= NULL
);
206 OPTION_VALUE_PROCESSED
;
209 else if (OPTION_SET("--master", "-m")) {
210 net_host
= OPTION_VALUE
;
211 assert(OPTION_VALUE
!= NULL
);
212 OPTION_VALUE_PROCESSED
;
216 fprintf(stderr
, "Ignoring unknown option: %s\n", argv
[i
]);
221 if (do_help
== true) {
222 fprintf(stderr
, "Usage: %s [--fullscreen|-f] [--help|-h]\n", argv
[0]);
230 srand((unsigned)time(NULL
));
233 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_JOYSTICK
) == -1) {
234 fprintf( stderr
, "Can't init SDL: %s\n", SDL_GetError());
238 vi
= SDL_GetVideoInfo();
239 if( (screen
= SDL_SetVideoMode( WIDTH
, HEIGHT
, vi
->vfmt
->BitsPerPixel
, sdl_flags
)) == NULL
) {
240 fprintf( stderr
, "Can't set video mode: %s\n", SDL_GetError());
244 SDL_WM_SetCaption( "Tennix 2009 World Tennis Championship Tour", "Tennix 2009");
245 SDL_ShowCursor( SDL_DISABLE
);
246 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY
, 1);
248 tnxar
= new TennixArchive(ARCHIVE_FILE
, ARCHIVE_FILE_INSTALLED
);
249 init_graphics(*tnxar
);
255 if (net_host
!= NULL
) {
256 connection
= network_connect(net_host
, net_master
);
259 menu_button_init(&btn_back
);
260 menu_button_init(&btn_start
);
261 menu_button_init(&btn_player1
);
262 menu_button_init(&btn_player2
);
264 input_devices
= find_input_devices(&input_device_count
);
266 current_game
= gamestate_load(GAMESTATE_FILE
);
267 if (current_game
!= NULL
) {
268 /* restore pointer to location */
269 current_game
->location
= &(locations
[current_game
->current_location
]);
271 for (i
=1; i
<=MAXPLAYERS
; i
++) {
272 if (PLAYER(current_game
, i
).type
== PLAYER_TYPE_HUMAN
) {
273 input_device_id
= PLAYER(current_game
, i
).input_device_index
;
274 if (input_device_id
< input_device_count
) {
275 /* ok, we still have that device around */
276 PLAYER(current_game
, i
).input
= &(input_devices
[input_device_id
]);
278 /* the device vanished - set to AI (FIXME: select new device) */
279 PLAYER(current_game
, i
).type
= PLAYER_TYPE_AI
;
280 PLAYER(current_game
, i
).input
= NULL
;
286 #ifdef ENABLE_FPS_LIMIT
292 GameState
* g
= gamestate_new();
293 PLAYER(g
, 1).type
= PLAYER_TYPE_AI
;
294 PLAYER(g
, 2).type
= PLAYER_TYPE_AI
;
295 g
->location
= &(locations
[0]);
296 gameloop(g
, connection
);
301 /*intro = create_intro();
302 intro_playback = animation_state_new(intro);
303 animation_state_run(intro_playback, 1);
304 animation_state_free(intro_playback);
305 animation_free(intro);
308 worldmap_xpos
= (WIDTH
-get_image_width(GR_WORLDMAP
))/2;
309 worldmap_ypos
= (HEIGHT
-get_image_height(GR_WORLDMAP
))/2;
312 /* Sliding initialization */
313 ticks
= SDL_GetTicks();
314 slide
= slide_start
= get_image_width(GR_SIDEBAR
);
317 /* State transitions */
319 case MENU_STATE_STARTED
:
320 state
= MENU_STATE_SLIDE_TO_MAINMENU
;
322 case MENU_STATE_SLIDE_TO_MAINMENU
:
324 rectangle(0, 0, WIDTH
, HEIGHT
, 80, 80, 80);
327 slide_direction
= -1;
328 state
= MENU_STATE_SLIDE_TO_MAINMENU_IN_PROGRESS
;
330 case MENU_STATE_SLIDE_TO_MAINMENU_IN_PROGRESS
:
333 state
= MENU_STATE_MAINMENU
;
336 case MENU_STATE_MAINMENU
:
338 prepared_game
= NULL
;
340 case MENU_STATE_SLIDE_TO_LOCATION
:
343 state
= MENU_STATE_SLIDE_TO_LOCATION_IN_PROGRESS
;
345 case MENU_STATE_SLIDE_TO_LOCATION_IN_PROGRESS
:
346 if (slide
== slide_start
) {
347 state
= MENU_STATE_FADE_TO_LOCATION
;
350 case MENU_STATE_FADE_TO_LOCATION
:
352 state
= MENU_STATE_LOCATION
;
355 rectangle(0, 0, WIDTH
, HEIGHT
, 80, 80, 80);
356 /* Draw and store the worldmap with day/night times */
357 show_image(GR_WORLDMAP
, WIDTH
/2-get_image_width(GR_WORLDMAP
)/2, HEIGHT
/2-get_image_height(GR_WORLDMAP
)/2, 255);
358 day_night(get_image_width(GR_WORLDMAP
), &night_start
, &night_end
);
359 if (night_start
> night_end
) {
360 rectangle_alpha(worldmap_xpos
, worldmap_ypos
, night_end
, get_image_height(GR_WORLDMAP
), 0, 0, 0, 150);
361 rectangle_alpha(worldmap_xpos
+night_start
, worldmap_ypos
, get_image_width(GR_WORLDMAP
)-night_start
, get_image_height(GR_WORLDMAP
), 0, 0, 0, 150);
363 rectangle_alpha(worldmap_xpos
+night_start
, worldmap_ypos
, night_end
-night_start
, get_image_height(GR_WORLDMAP
), 0, 0, 0, 150);
366 /* add misc items to screen */
367 font_draw_string(FONT_XLARGE
, "Pick a location", (WIDTH
-font_get_string_width(FONT_XLARGE
, "Pick a location"))/2, 20);
371 case MENU_STATE_FADE_TO_OPTIONS
:
374 rectangle(0, 0, WIDTH
, HEIGHT
, 80, 80, 80);
375 rectangle(CONTROLLER_SETUP_BORDER
, HEIGHT
/2-CONTROLLER_SETUP_SIZE
/2, CONTROLLER_SETUP_SIZE
, CONTROLLER_SETUP_SIZE
, 150, 150, 150);
376 rectangle(WIDTH
-CONTROLLER_SETUP_BORDER
-CONTROLLER_SETUP_SIZE
, (HEIGHT
-CONTROLLER_SETUP_SIZE
)/2, CONTROLLER_SETUP_SIZE
, CONTROLLER_SETUP_SIZE
, 150, 150, 150);
377 font_draw_string(FONT_XLARGE
, "Controller setup", (WIDTH
-font_get_string_width(FONT_XLARGE
, "Controller setup"))/2, 20);
378 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
));
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 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
));
383 state
= MENU_STATE_OPTIONS
;
385 case MENU_STATE_LOCATION
:
386 case MENU_STATE_OPTIONS
:
387 /* Prepare a new game */
388 if (prepared_game
== NULL
) {
389 prepared_game
= gamestate_new();
390 prepared_game
->location
= NULL
;
391 /* FIXME - this should not be written here, but taken from the input devices */
392 btn_player1
.text
= "Keyboard (arrows)";
393 btn_player2
.text
= "Carl Van Court";
395 PLAYER(prepared_game
, 1).input_device_index
= 0;
397 PLAYER(prepared_game
, 1).input_device_index
= 2;
399 PLAYER(prepared_game
, 1).type
= PLAYER_TYPE_HUMAN
;
400 PLAYER(prepared_game
, 1).input
= &(input_devices
[PLAYER(prepared_game
, 1).input_device_index
]);
401 location_info_visible
= false;
402 prepared_game
->current_location
= -1;
403 highlight_location
= -1;
406 case MENU_STATE_SLIDE_TO_GAME
:
409 state = MENU_STATE_SLIDE_TO_GAME_IN_PROGRESS;
411 case MENU_STATE_SLIDE_TO_GAME_IN_PROGRESS:
412 if (slide == slide_start) {
413 state = MENU_STATE_GAME;
415 state
= MENU_STATE_GAME
;
417 case MENU_STATE_SLIDE_TO_RESUME
:
420 state
= MENU_STATE_SLIDE_TO_RESUME_IN_PROGRESS
;
422 case MENU_STATE_SLIDE_TO_RESUME_IN_PROGRESS
:
423 if (slide
== slide_start
) {
424 state
= MENU_STATE_RESUME
;
427 case MENU_STATE_GAME
:
428 if (prepared_game
== NULL
) {
429 fprintf(stderr
, "Game not yet prepared!\n");
433 /* Cancel a possibly started game */
435 current_game
= prepared_game
;
436 prepared_game
= NULL
;
437 /* no break - we are continuing with "resume" */
438 case MENU_STATE_RESUME
:
439 if (current_game
== NULL
) {
440 fprintf(stderr
, "Cannot resume game!\n");
444 gameloop(current_game
, connection
);
446 while(SDL_PollEvent(&e
));
447 #ifdef ENABLE_FPS_LIMIT
452 state
= MENU_STATE_SLIDE_TO_MAINMENU
;
454 case MENU_STATE_SLIDE_TO_QUIT
:
457 state
= MENU_STATE_SLIDE_TO_QUIT_IN_PROGRESS
;
459 case MENU_STATE_SLIDE_TO_QUIT_IN_PROGRESS
:
460 if (slide
== slide_start
) {
461 state
= MENU_STATE_QUIT
;
464 case MENU_STATE_QUIT
:
468 fprintf(stderr
, "State error: %d\n", state
);
473 if (SDL_GetTicks() > ticks
+ 20) {
474 if (slide
>= 1 && slide
<= slide_start
) {
475 slide
+= slide_direction
+(slide_direction
*slide
/(sqrt(2*slide
)));
476 slide
= MAX(0, MIN(slide_start
, slide
));
477 } else if (slide_direction
!= 0) {
480 ticks
= SDL_GetTicks();
485 if (state
!= MENU_STATE_OPTIONS
) {
486 fill_image_offset(GR_FOG
, 0, 0, WIDTH
, HEIGHT
, -i
, 0);
489 show_image(GR_SIDEBAR
, WIDTH
-get_image_width(GR_SIDEBAR
)+slide
, 0, 255);
490 show_image(GR_TENNIXLOGO
, WIDTH
-get_image_width(GR_SIDEBAR
)-10, 20-slide
, 255);
491 if (state
!= MENU_STATE_OPTIONS
&& state
!= MENU_STATE_LOCATION
) {
493 show_image(GR_BTN_PLAY
, WIDTH
-get_image_width(GR_BTN_PLAY
)+slide
+(slide
/7)+3-(3*(btn_hovering
==MENU_START
)), 150, 255);
494 if (current_game
!= NULL
) {
495 show_image(GR_BTN_RESUME
, WIDTH
-get_image_width(GR_BTN_RESUME
)+slide
+(slide
/7)+3-(3*(btn_hovering
==MENU_RESUME
)), 230, 255);
496 font_draw_string(FONT_SMALL
, "match paused", 10, 10);
498 font_draw_string(FONT_MEDIUM
, "Tennix 2009 World Tennis Championship Tour", 10, 10);
500 font_draw_string_color(FONT_MEDIUM
, URL
, 10-1, HEIGHT
-10-1-font_get_height(FONT_MEDIUM
), 130, 130, 130);
501 font_draw_string_color(FONT_MEDIUM
, URL
, 10, HEIGHT
-10-font_get_height(FONT_MEDIUM
), 30, 30, 30);
502 show_image(GR_BTN_QUIT
, WIDTH
-get_image_width(GR_BTN_QUIT
)+slide
+(slide
/7)+3-(3*(btn_hovering
==MENU_QUIT
)), 350, 255);
503 } else if (state
== MENU_STATE_OPTIONS
) {
505 draw_button_object(&btn_back
, mx
, my
);
506 draw_button_object(&btn_start
, mx
, my
);
507 draw_button_object(&btn_player1
, mx
, my
);
508 draw_button_object(&btn_player2
, mx
, my
);
509 wiggle
= 15*sinf((float)ticks
/300.);
510 if (PLAYER(prepared_game
, 1).input_device_index
> -1) {
511 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);
513 show_image_rotozoom(GR_INPUT_AI
, CONTROLLER_SETUP_BORDER
+ CONTROLLER_SETUP_SIZE
/2, HEIGHT
/2, wiggle
, 1.0);
515 if (PLAYER(prepared_game
, 2).input_device_index
> -1) {
516 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);
518 show_image_rotozoom(GR_INPUT_AI
, WIDTH
-CONTROLLER_SETUP_BORDER
-CONTROLLER_SETUP_SIZE
/2, HEIGHT
/2, -wiggle
, 1.0);
520 } else if (state
== MENU_STATE_LOCATION
) {
521 /* Location selection screen */
522 for (x
=0; x
<location_count(); x
++) {
523 new_location_distance
= SQUARE_DISTANCE(mx
-worldmap_xpos
-locations
[x
].worldmap_x
,
524 my
-worldmap_ypos
-locations
[x
].worldmap_y
);
525 if (highlight_location
== -1) {
526 if (new_location_distance
< 20*20) {
527 highlight_location
= x
;
530 highlight_location_distance
= SQUARE_DISTANCE(mx
-worldmap_xpos
-locations
[highlight_location
].worldmap_x
,
531 my
-worldmap_ypos
-locations
[highlight_location
].worldmap_y
);
532 if (highlight_location_distance
> 20*20) {
533 highlight_location
= -1;
535 if (highlight_location_distance
> new_location_distance
&& new_location_distance
< 20*20) {
536 highlight_location
= x
;
540 if (prepared_game
!= NULL
) {
541 if (!location_info_visible
) {
542 for (x
=0; x
<location_count(); x
++) {
543 /* draw rectangle for location at "x"*/
544 if (highlight_location
!= -1 && (unsigned int)highlight_location
== x
) {
545 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));
548 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);
551 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);
552 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);
553 font_draw_string(FONT_SMALL
, prepared_game
->location
->name
, location_info_xpos
+MENU_OPTIONS_BORDER
, location_info_ypos
+MENU_OPTIONS_BORDER
+200);
554 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
));
555 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
));
556 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
));
558 if (prepared_game
->location
!= NULL
) {
559 draw_button_object(&btn_start
, mx
, my
);
562 draw_button_object(&btn_back
, mx
, my
);
566 if( e
.type
== SDL_QUIT
) {
567 state
= MENU_STATE_SLIDE_TO_QUIT
;
571 keys
= SDL_GetKeyState( NULL
);
572 mb
= SDL_GetMouseState( &mx
, &my
);
574 btn_hovering_old
= btn_hovering
;
575 if (state
== MENU_STATE_MAINMENU
) {
576 btn_hovering
= M_POS_DECODE(mx
, my
);
577 if (current_game
== NULL
) {
578 btn_hovering
&= ~MENU_RESUME
;
580 } else if (state
== MENU_STATE_LOCATION
) {
581 if (M_POS_BUTTON(btn_back
, mx
, my
)) {
582 btn_hovering
= MENU_QUIT
;
583 } else if (M_POS_BUTTON(btn_start
, mx
, my
)) {
584 btn_hovering
= MENU_START
;
588 } else if (state
== MENU_STATE_OPTIONS
) {
589 if (M_POS_BUTTON(btn_back
, mx
, my
)) {
590 btn_hovering
= MENU_QUIT
;
591 } else if (M_POS_BUTTON(btn_start
, mx
, my
)) {
592 btn_hovering
= MENU_START
;
593 } else if (M_POS_BUTTON(btn_player1
, mx
, my
)) {
594 btn_hovering
= MENU_PLAYER1
;
595 } else if (M_POS_BUTTON(btn_player2
, mx
, my
)) {
596 btn_hovering
= MENU_PLAYER2
;
601 /* No menu screen - no hovering. */
604 #ifndef MAEMO /* On Maemo, we cannot really "hover" (touchscreen!) */
605 if (btn_hovering_old
!= btn_hovering
&& btn_hovering
!= 0) {
606 #ifdef HAVE_VOICE_FILES
607 if (btn_hovering
== MENU_QUIT
) {
608 play_sample(VOICE_QUIT_IT
);
609 } else if (btn_hovering
== MENU_START
) {
610 play_sample(VOICE_NEW_GAME
);
612 play_sample(SOUND_MOUSEOVER
);
615 /*play_sample(SOUND_MOUSEOVER);*/
620 if( keys
[SDLK_ESCAPE
] || keys
['q']) {
621 /* FIXME: do the state thingie! */
626 SDL_WM_ToggleFullScreen( screen
);
629 #ifndef MAEMO /* No mouse cursor on Maemo (we have a touchscreen) */
630 if (state
== MENU_STATE_MAINMENU
|| state
== MENU_STATE_OPTIONS
|| state
== MENU_STATE_LOCATION
) {
631 show_image(GR_CURSOR
, mx
-2, my
-1, 255);
635 /* Draw the "real" mouse coordinates */
636 /*rectangle(mx-1, my-1, 2, 2, 255, 255, 255);*/
638 /* Store the screen, because we are fading after this screen update */
639 /*if (!(mb & SDL_BUTTON(SDL_BUTTON_LEFT)) && btn_hovering != MENU_NONE && mouse_pressed == true) store_screen();*/
643 if( mb
& SDL_BUTTON(SDL_BUTTON_LEFT
)) {
644 if (!mouse_pressed
) {
645 play_sample(SOUND_MOUSEOVER
);
647 mouse_pressed
= true;
648 } else if (mouse_pressed
== true) {
649 /* Mouse button released */
650 if (state
== MENU_STATE_MAINMENU
|| state
== MENU_STATE_OPTIONS
|| state
== MENU_STATE_LOCATION
) {
651 #ifdef HAVE_VOICE_FILES
652 if (btn_hovering
== MENU_START
) {
653 play_sample(VOICE_LETS_GO
);
655 play_sample(SOUND_MOUSECLICK
);
658 /*play_sample(SOUND_MOUSEOVER);*/
661 if (state
== MENU_STATE_MAINMENU
) {
662 switch (btn_hovering
) {
664 state
= MENU_STATE_SLIDE_TO_LOCATION
;
667 state
= MENU_STATE_SLIDE_TO_RESUME
;
670 state
= MENU_STATE_SLIDE_TO_QUIT
;
673 } else if (state
== MENU_STATE_LOCATION
) {
674 switch (btn_hovering
) {
676 if (prepared_game
->location
!= NULL
) {
677 state
= MENU_STATE_FADE_TO_OPTIONS
;
681 state
= MENU_STATE_SLIDE_TO_MAINMENU
;
684 if (!location_info_visible
&& highlight_location
!= -1) {
685 prepared_game
->current_location
= highlight_location
;
686 /* Set the day/night status */
687 if (night_start
< night_end
) {
688 locations
[prepared_game
->current_location
].night
= (locations
[prepared_game
->current_location
].worldmap_x
> night_start
&& locations
[prepared_game
->current_location
].worldmap_x
< night_end
);
690 locations
[prepared_game
->current_location
].night
= (locations
[prepared_game
->current_location
].worldmap_x
< night_end
|| locations
[prepared_game
->current_location
].worldmap_x
> night_start
);
692 prepared_game
->location
= &(locations
[prepared_game
->current_location
]);
693 location_info_xpos
= MAX(0, MIN(WIDTH
-320-50, mx
-320/2));
694 location_info_ypos
= MAX(0, MIN(HEIGHT
-200-160, my
-200/2));
695 location_info_visible
= true;
697 location_info_visible
= false;
698 highlight_location
= -1;
699 prepared_game
->current_location
= -1;
700 prepared_game
->location
= NULL
;
704 } else if (state
== MENU_STATE_OPTIONS
) {
705 switch (btn_hovering
) {
707 state
= MENU_STATE_SLIDE_TO_GAME
;
710 state
= MENU_STATE_FADE_TO_LOCATION
;
713 /* advance the input device index */
714 PLAYER(prepared_game
, 1).input_device_index
++;
715 if (PLAYER(prepared_game
, 1).input_device_index
== (signed int)input_device_count
) {
716 PLAYER(prepared_game
, 1).input_device_index
= -1;
719 if (input_devices
[PLAYER(prepared_game
, 1).input_device_index
].exclusive_to_player
== 2) {
720 PLAYER(prepared_game
, 1).input_device_index
++;
723 /* determine the selected input device */
724 if (PLAYER(prepared_game
, 1).input_device_index
== -1) {
725 PLAYER(prepared_game
, 1).type
= PLAYER_TYPE_AI
;
726 PLAYER(prepared_game
, 1).input
= NULL
;
727 btn_player1
.text
= "Carl Van Court";
729 PLAYER(prepared_game
, 1).type
= PLAYER_TYPE_HUMAN
;
730 PLAYER(prepared_game
, 1).input
= &(input_devices
[PLAYER(prepared_game
, 1).input_device_index
]);
731 btn_player1
.text
= input_device_get_name(PLAYER(prepared_game
, 1).input
);
735 /* advance the input device index */
736 PLAYER(prepared_game
, 2).input_device_index
++;
738 if (input_devices
[PLAYER(prepared_game
, 2).input_device_index
].exclusive_to_player
== 1) {
739 PLAYER(prepared_game
, 2).input_device_index
++;
742 if (PLAYER(prepared_game
, 2).input_device_index
== (signed int)input_device_count
) {
743 PLAYER(prepared_game
, 2).input_device_index
= -1;
746 /* determine the selected input device */
747 if (PLAYER(prepared_game
, 2).input_device_index
== -1) {
748 PLAYER(prepared_game
, 2).type
= PLAYER_TYPE_AI
;
749 PLAYER(prepared_game
, 2).input
= NULL
;
750 btn_player2
.text
= "Carl Van Court";
752 PLAYER(prepared_game
, 2).type
= PLAYER_TYPE_HUMAN
;
753 PLAYER(prepared_game
, 2).input
= &(input_devices
[PLAYER(prepared_game
, 2).input_device_index
]);
754 btn_player2
.text
= input_device_get_name(PLAYER(prepared_game
, 2).input
);
759 mouse_pressed
= false;
762 #ifdef ENABLE_FPS_LIMIT
763 while (frames
*1000.0/((float)(SDL_GetTicks()-ft
+1))>(float)(DEFAULT_FPS
)) {
770 if (current_game
!= NULL
) {
771 if (gamestate_save(current_game
, GAMESTATE_FILE
) != 0) {
772 fprintf(stderr
, "Warning: cannot save gamestate to %s\n", GAMESTATE_FILE
);
776 /* Play the credits */
777 /*intro = create_credits();
778 intro_playback = animation_state_new(intro);
779 animation_state_run(intro_playback, 1);
780 animation_state_free(intro_playback);
781 animation_free(intro);*/
792 void menu_button_init(MenuButton
* b
)
796 if (b
->image_id
!= GR_COUNT
) {
798 * If the button is an image, the "w" and "h" attributes of the
799 * MenuButton struct are simply factors with which the real width
800 * and height of the image (=button) should be multiplied and added
801 * to the "x" and "y" position and the "w" and "h" are replaced with
802 * the real size of the image for the collision detection
807 b
->w
= get_image_width(b
->image_id
);
808 b
->h
= get_image_height(b
->image_id
);