fc1f49545db10c17778820dcc37d694407d22864
[neverball] / ball / st_level.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 "set.h"
18 #include "level.h"
19 #include "audio.h"
20 #include "config.h"
21
22 #include "st_level.h"
23 #include "st_play.h"
24 #include "st_over.h"
25
26 /*---------------------------------------------------------------------------*/
27
28 static int level_enter(void)
29 {
30     int id, jd, kd, ld;
31     const char * ln;
32
33     /* Load the level */
34     level_play_go();
35     
36     ln = _(level_number_name(curr_level()));
37             
38     if ((id = gui_vstack(0)))
39     {
40         if ((jd = gui_hstack(id)))
41         {
42             gui_filler(jd);
43             if ((kd = gui_vstack(jd)))
44             {
45                 if (level_extra_bonus(curr_level()))
46                     gui_label(kd, _("*** BONUS ***"),  GUI_MED, GUI_TOP, gui_wht, gui_grn);
47                 if ((ld = gui_hstack(kd)))
48                 {
49                     if (level_extra_bonus(curr_level()))
50                     {
51                         gui_label(ld, ln,          GUI_LRG, 0, gui_wht, gui_grn);
52                         gui_label(ld, _("Level "), GUI_LRG, 0, gui_wht, gui_grn);
53                     }
54                     else
55                     {
56                         gui_label(ld, ln,          GUI_LRG, GUI_NE, 0, 0);
57                         gui_label(ld, _("Level "), GUI_LRG, GUI_NW, 0, 0);
58                     }
59                 }
60                 gui_label(kd, _(set_name(set_curr())),  GUI_SML, GUI_BOT, gui_wht, gui_wht);
61             }
62             gui_filler(jd);
63         }
64         gui_space(id);
65         gui_multi(id, _(curr_intro()), GUI_SML, GUI_ALL, gui_wht, gui_wht);
66
67         gui_layout(id, 0, 0);
68     }
69
70     game_set_fly(1.f);
71
72     return id;
73 }
74
75 static void level_leave(int id)
76 {
77     gui_delete(id);
78 }
79
80 static void level_timer(int id, float dt)
81 {
82     game_step_fade(dt);
83     audio_timer(dt);
84 }
85
86 static void level_paint(int id, float st)
87 {
88     game_draw(0, st);
89     gui_paint(id);
90 }
91
92 static int level_click(int b, int d)
93 {
94     return (b < 0 && d == 1) ? goto_state(&st_play_ready) : 1;
95 }
96
97 static int level_keybd(int c, int d)
98 {
99     if (d && c == SDLK_F12)
100         return goto_state(&st_poser);
101     return 1;
102 }
103
104 static int level_buttn(int b, int d)
105 {
106     if (d)
107     {
108         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
109             return goto_state(&st_play_ready);
110         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
111             return goto_state(&st_over);
112     }
113     return 1;
114 }
115
116 /*---------------------------------------------------------------------------*/
117
118 static void poser_paint(int id, float st)
119 {
120     game_draw(1, st);
121 }
122
123 static int poser_buttn(int c, int d)
124 {
125     return (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, c)) ? goto_state(&st_level) : 1;
126 }
127
128 /*---------------------------------------------------------------------------*/
129
130 struct state st_level = {
131     level_enter,
132     level_leave,
133     level_paint,
134     level_timer,
135     NULL,
136     NULL,
137     level_click,
138     level_keybd,
139     level_buttn,
140     1, 0
141 };
142
143 struct state st_poser = {
144     NULL,
145     NULL,
146     poser_paint,
147     NULL,
148     NULL,
149     NULL,
150     NULL,
151     NULL,
152     poser_buttn,
153     1, 0
154 };