fix del key on mac
[neverball] / ball / st_fail.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 "game.h"
17 #include "levels.h"
18 #include "audio.h"
19 #include "config.h"
20 #include "st_shared.h"
21
22 #include "st_fail.h"
23 #include "st_over.h"
24 #include "st_save.h"
25 #include "st_level.h"
26 #include "st_start.h"
27
28 /*---------------------------------------------------------------------------*/
29
30 #define FAIL_BACK  0
31 #define FAIL_OVER  1
32 #define FAIL_RETRY 2
33 #define FAIL_SAVE  3
34
35 static int fail_action(int i)
36 {
37     struct state * next = level_dead() ? &st_over : &st_level;
38     switch (i)
39     {
40     case FAIL_BACK:
41         return goto_end_level();
42             
43     case FAIL_OVER:
44         return goto_state(&st_over);
45
46     case FAIL_RETRY:
47         return goto_state(&st_level);
48
49     case FAIL_SAVE:
50         return goto_save(next, next);
51     }
52     return 1;
53 }
54
55 static int fail_buttn(int b, int d)
56 {
57     if (d)
58     {
59         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
60             return fail_action(gui_token(gui_click()));
61         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
62             return fail_action(FAIL_BACK);
63     }
64     return 1;
65 }
66
67 static int fall_out_enter(void)
68 {
69     int id, jd, kd;
70
71     if ((id = gui_vstack(0)))
72     {
73         kd = gui_label(id, _("Fall-out!"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
74     
75         if ((jd = gui_harray(id)))
76         {
77             gui_state(jd, _("Save Replay"),     GUI_SML, FAIL_SAVE,  0);
78
79             if (level_dead())
80                 gui_start(jd, _("Game Over"),   GUI_SML, FAIL_OVER,  0);
81             else
82                 gui_start(jd, _("Retry Level"), GUI_SML, FAIL_RETRY, 0);
83         }
84
85         gui_pulse(kd, 1.2f);
86         gui_layout(id, 0, 0);
87     }
88
89     audio_music_fade_out(2.0f);
90     audio_play(AUD_FALL, 1.0f);
91
92     config_clr_grab();
93
94     return id;
95 }
96
97 static void fall_out_timer(int id, float dt)
98 {
99     float g[3] = { 0.0f, -9.8f, 0.0f };
100
101     if (time_state() < 2.f)
102         game_step(g, dt, 0);
103
104     gui_timer(id, dt);
105     audio_timer(dt);
106 }
107
108
109 /*---------------------------------------------------------------------------*/
110
111 static int time_out_enter(void)
112 {
113     int id, jd, kd;
114
115     if ((id = gui_vstack(0)))
116     {
117         kd = gui_label(id, _("Time's Up!"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
118     
119         if ((jd = gui_harray(id)))
120         {
121             gui_state(jd, _("Save Replay"),     GUI_SML, FAIL_SAVE,  0);
122
123             if (level_dead())
124                 gui_start(jd, _("Game Over"),   GUI_SML, FAIL_OVER,  0);
125             else
126                 gui_start(jd, _("Retry Level"), GUI_SML, FAIL_RETRY, 0);
127         }
128
129         gui_pulse(kd, 1.2f);
130         gui_layout(id, 0, 0);
131     }
132
133     audio_music_fade_out(2.0f);
134     audio_play(AUD_TIME, 1.0f);
135
136     config_clr_grab();
137
138     return id;
139 }
140
141 /*---------------------------------------------------------------------------*/
142
143 struct state st_fall_out = {
144     fall_out_enter,
145     shared_leave,
146     shared_paint,
147     fall_out_timer,
148     shared_point,
149     shared_stick,
150     shared_click,
151     NULL,
152     fail_buttn,
153     1, 0
154 };
155
156 struct state st_time_out = {
157     time_out_enter,
158     shared_leave,
159     shared_paint,
160     shared_timer,
161     shared_point,
162     shared_stick,
163     shared_click,
164     NULL,
165     fail_buttn,
166     1, 0
167 };