load_surface: flip image vertically before creating surface
[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 <string.h>
16
17 #include "gui.h"
18 #include "game.h"
19 #include "set.h"
20 #include "progress.h"
21 #include "audio.h"
22 #include "config.h"
23 #include "st_shared.h"
24
25 #include "st_level.h"
26 #include "st_play.h"
27 #include "st_start.h"
28 #include "st_over.h"
29
30 /*---------------------------------------------------------------------------*/
31
32 static int level_enter(void)
33 {
34     int id, jd, kd, ld;
35     const char *ln;
36     int b;
37     const float *textcol1, *textcol2;
38
39     if ((id = gui_vstack(0)))
40     {
41         if ((jd = gui_hstack(id)))
42         {
43             ln = level_repr (curr_level());
44             b  = level_bonus(curr_level());
45
46             textcol1 = b ? gui_wht : 0;
47             textcol2 = b ? gui_grn : 0;
48
49             gui_filler(jd);
50
51             if ((kd = gui_vstack(jd)))
52             {
53                 gui_label(kd, set_name(curr_set()), GUI_SML, GUI_ALL,
54                           gui_wht, gui_wht);
55
56                 gui_space(kd);
57
58                 if ((ld = gui_hstack(kd)))
59                 {
60                     if (b == 0)
61                     {
62                         gui_label(ld, ln,          GUI_LRG, GUI_NE,
63                                   textcol1, textcol2);
64                         gui_label(ld, _("Level "), GUI_LRG, GUI_NW,
65                                   textcol1, textcol2);
66                     }
67                     else
68                     {
69                         gui_label(ld, ln,                GUI_MED, GUI_NE,
70                                   textcol1, textcol2);
71                         gui_label(ld, _("Bonus Level "), GUI_MED, GUI_NW,
72                                   textcol1, textcol2);
73                     }
74                 }
75
76                 gui_label(kd, mode_to_str(curr_mode(), 1), GUI_SML, GUI_BOT,
77                           gui_wht, gui_wht);
78
79             }
80             gui_filler(jd);
81         }
82         gui_space(id);
83
84         gui_multi(id, level_msg(curr_level()),
85                   GUI_SML, GUI_ALL,
86                   gui_wht, gui_wht);
87
88         gui_layout(id, 0, 0);
89     }
90
91     game_set_fly(1.f);
92
93     return id;
94 }
95
96 static void level_timer(int id, float dt)
97 {
98     game_step_fade(dt);
99 }
100
101 static int level_click(int b, int d)
102 {
103     return (b < 0 && d == 1) ? goto_state(&st_play_ready) : 1;
104 }
105
106 static int level_keybd(int c, int d)
107 {
108     if (d && c == SDLK_F12)
109         return goto_state(&st_poser);
110     return 1;
111 }
112
113 static int level_buttn(int b, int d)
114 {
115     if (d)
116     {
117         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
118         {
119             return goto_state(&st_play_ready);
120         }
121         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
122         {
123             progress_stop();
124             return goto_state(&st_over);
125         }
126     }
127     return 1;
128 }
129
130 /*---------------------------------------------------------------------------*/
131
132 static void poser_paint(int id, float t)
133 {
134     game_draw(1, t);
135 }
136
137 static int poser_buttn(int c, int d)
138 {
139     if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, c))
140         return goto_state(&st_level);
141
142     return 1;
143 }
144
145 /*---------------------------------------------------------------------------*/
146
147 struct state st_level = {
148     level_enter,
149     shared_leave,
150     shared_paint,
151     level_timer,
152     NULL,
153     NULL,
154     NULL,
155     level_click,
156     level_keybd,
157     level_buttn,
158     1, 0
159 };
160
161 struct state st_poser = {
162     NULL,
163     NULL,
164     poser_paint,
165     NULL,
166     NULL,
167     NULL,
168     NULL,
169     NULL,
170     NULL,
171     poser_buttn,
172     1, 0
173 };