Fixed the problem that in a rare case, a set is downloaded and the neverballrc is...
[neverball] / ball / st_over.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #include "gui.h"
16 #include "set.h"
17 #include "game.h"
18 #include "levels.h"
19 #include "audio.h"
20 #include "config.h"
21 #include "demo.h"
22 #include "st_shared.h"
23
24 #include "st_over.h"
25 #include "st_start.h"
26
27 /*---------------------------------------------------------------------------*/
28
29 static int over_enter(void)
30 {
31     int id;
32
33     if (curr_lg()->mode != MODE_CHALLENGE)
34         return 0;
35
36     if ((id = gui_label(0, _("GAME OVER"), GUI_LRG, GUI_ALL, gui_gry, gui_red)))
37     {
38         gui_layout(id, 0, 0);
39         gui_pulse(id, 1.2f);
40     }
41
42     audio_music_fade_out(2.0f);
43     audio_play(AUD_OVER, 1.f);
44
45     config_clr_grab();
46
47     return id;
48 }
49
50 static void over_timer(int id, float dt)
51 {
52     if (curr_lg()->mode != MODE_CHALLENGE || time_state() > 3.f)
53         goto_state(&st_start);
54
55     gui_timer(id, dt);
56 }
57
58 static int over_click(int b, int d)
59 {
60     return (b < 0 && d == 1) ? goto_state(&st_start) : 1;
61 }
62
63 static int over_buttn(int b, int d)
64 {
65     if (d)
66     {
67         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) ||
68             config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
69             return goto_state(&st_start);
70     }
71     return 1;
72 }
73
74 /*---------------------------------------------------------------------------*/
75
76 struct state st_over = {
77     over_enter,
78     shared_leave,
79     shared_paint,
80     over_timer,
81     NULL,
82     NULL,
83     NULL,
84     over_click,
85     NULL,
86     over_buttn,
87     1, 0
88 };