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