Split SOL data structures into base, varying and rendering parts
[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 "progress.h"
18 #include "audio.h"
19 #include "config.h"
20 #include "video.h"
21 #include "demo.h"
22
23 #include "game_common.h"
24
25 #include "st_over.h"
26 #include "st_level.h"
27 #include "st_shared.h"
28
29 /*---------------------------------------------------------------------------*/
30
31 static int over_gui(void)
32 {
33     int id;
34
35     if ((id = gui_label(0, _("GAME OVER"), GUI_LRG, GUI_ALL, gui_gry, gui_red)))
36     {
37         gui_layout(id, 0, 0);
38         gui_pulse(id, 1.2f);
39     }
40
41     return id;
42 }
43
44 static int over_enter(struct state *st, struct state *prev)
45 {
46     audio_music_fade_out(2.0f);
47     audio_play(AUD_OVER, 1.f);
48
49     video_clr_grab();
50
51     return over_gui();
52 }
53
54 static void over_timer(int id, float dt)
55 {
56     if (time_state() > 3.f)
57         goto_state(&st_exit);
58
59     gui_timer(id, dt);
60 }
61
62 static int over_click(int b, int d)
63 {
64     return (b == SDL_BUTTON_LEFT && d == 1) ? goto_state(&st_exit) : 1;
65 }
66
67 static int over_buttn(int b, int d)
68 {
69     if (d)
70     {
71         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) ||
72             config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
73             return goto_state(&st_exit);
74     }
75     return 1;
76 }
77
78 /*---------------------------------------------------------------------------*/
79
80 struct state st_over = {
81     over_enter,
82     shared_leave,
83     shared_paint,
84     over_timer,
85     NULL,
86     NULL,
87     NULL,
88     over_click,
89     NULL,
90     over_buttn
91 };