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