update copyright info, also add a copiright template to add at the top of sourcefiles
[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 "level.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         if (level_mode() == MODE_CHALLENGE)
42             return goto_state(&st_over);
43         else
44             return goto_state(&st_start);
45             
46     case FAIL_OVER:
47         return goto_state(&st_over);
48
49     case FAIL_RETRY:
50         return goto_state(&st_level);
51
52     case FAIL_SAVE:
53         return goto_save(next, next);
54     }
55     return 1;
56 }
57
58 static int fail_buttn(int b, int d)
59 {
60     if (d)
61     {
62         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
63             return fail_action(gui_token(gui_click()));
64         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
65             return fail_action(FAIL_BACK);
66     }
67     return 1;
68 }
69
70 static int fall_out_enter(void)
71 {
72     int id, jd, kd;
73
74     if ((id = gui_vstack(0)))
75     {
76         kd = gui_label(id, _("Fall-out!"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
77     
78         if ((jd = gui_harray(id)))
79         {
80             gui_state(jd, _("Save Replay"),     GUI_SML, FAIL_SAVE,  0);
81
82             if (level_dead())
83                 gui_start(jd, _("Game Over"),   GUI_SML, FAIL_OVER,  0);
84             else
85                 gui_start(jd, _("Retry Level"), GUI_SML, FAIL_RETRY, 0);
86         }
87
88         gui_pulse(kd, 1.2f);
89         gui_layout(id, 0, 0);
90     }
91
92     audio_music_fade_out(2.0f);
93     audio_play(AUD_FALL, 1.0f);
94
95     config_clr_grab();
96
97     return id;
98 }
99
100 static void fall_out_timer(int id, float dt)
101 {
102     float g[3] = { 0.0f, -9.8f, 0.0f };
103
104     if (time_state() < 2.f)
105         game_step(g, dt, 0);
106
107     gui_timer(id, dt);
108     audio_timer(dt);
109 }
110
111
112 /*---------------------------------------------------------------------------*/
113
114 static int time_out_enter(void)
115 {
116     int id, jd, kd;
117
118     if ((id = gui_vstack(0)))
119     {
120         kd = gui_label(id, _("Time's Up!"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
121     
122         if ((jd = gui_harray(id)))
123         {
124             gui_state(jd, _("Save Replay"),     GUI_SML, FAIL_SAVE,  0);
125
126             if (level_dead())
127                 gui_start(jd, _("Game Over"),   GUI_SML, FAIL_OVER,  0);
128             else
129                 gui_start(jd, _("Retry Level"), GUI_SML, FAIL_RETRY, 0);
130         }
131
132         gui_pulse(kd, 1.2f);
133         gui_layout(id, 0, 0);
134     }
135
136     audio_music_fade_out(2.0f);
137     audio_play(AUD_TIME, 1.0f);
138
139     config_clr_grab();
140
141     return id;
142 }
143
144 /*---------------------------------------------------------------------------*/
145
146 struct state st_fall_out = {
147     fall_out_enter,
148     shared_leave,
149     shared_paint,
150     fall_out_timer,
151     shared_point,
152     shared_stick,
153     shared_click,
154     NULL,
155     fail_buttn,
156     1, 0
157 };
158
159 struct state st_time_out = {
160     time_out_enter,
161     shared_leave,
162     shared_paint,
163     shared_timer,
164     shared_point,
165     shared_stick,
166     shared_click,
167     NULL,
168     fail_buttn,
169     1, 0
170 };