9494c7fab8ac472147d1aedf9c80adf08c0ab102
[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 "level.h"
19 #include "audio.h"
20 #include "config.h"
21 #include "demo.h"
22
23 #include "st_over.h"
24 #include "st_start.h"
25
26 /*---------------------------------------------------------------------------*/
27
28 static int over_enter(void)
29 {
30     int id;
31
32     if ((id = gui_label(0, _("GAME OVER"), GUI_LRG, GUI_ALL, gui_gry, gui_red)))
33     {
34         gui_layout(id, 0, 0);
35         gui_pulse(id, 1.2f);
36     }
37
38     audio_music_fade_out(2.0f);
39     audio_play(AUD_OVER, 1.f);
40
41     config_clr_grab();
42
43     return id;
44 }
45
46 static void over_leave(int id)
47 {
48     /* Save replay in all case */
49     demo_play_stop(NULL);
50     gui_delete(id);
51 }
52
53 static void over_paint(int id, float st)
54 {
55     game_draw(0, st);
56     gui_paint(id);
57 }
58
59 static void over_timer(int id, float dt)
60 {
61     if (dt > 0.f && time_state() > 3.f)
62         goto_state(&st_start);
63
64     gui_timer(id, dt);
65     audio_timer(dt);
66 }
67
68 static int over_keybd(int c, int d)
69 {
70     return (d && c == SDLK_ESCAPE) ? goto_state(&st_start) : 1;
71 }
72
73 static int over_click(int b, int d)
74 {
75     return (b < 0 && d == 1) ? goto_state(&st_start) : 1;
76 }
77
78 static int over_buttn(int b, int d)
79 {
80     if (d)
81     {
82         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) ||
83             config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b) ||
84             config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
85             return goto_state(&st_start);
86     }
87     return 1;
88 }
89
90 /*---------------------------------------------------------------------------*/
91
92 struct state st_over = {
93     over_enter,
94     over_leave,
95     over_paint,
96     over_timer,
97     NULL,
98     NULL,
99     over_click,
100     over_keybd,
101     over_buttn,
102     1, 0
103 };