669f5cad91366bde7afce82793b29c8cb0274a07
[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 "level.h"
18 #include "audio.h"
19 #include "config.h"
20
21 #include "st_level.h"
22 #include "st_play.h"
23 #include "st_over.h"
24
25 /*---------------------------------------------------------------------------*/
26
27 static int level_enter(void)
28 {
29     int id, jd;
30
31     if ((id = gui_vstack(0)))
32     {
33         if ((jd = gui_hstack(id)))
34         {
35             gui_filler(jd);
36             gui_count(jd, curr_level(), GUI_LRG, GUI_NE | GUI_SE);
37             gui_label(jd, "Level ",     GUI_LRG, GUI_NW | GUI_SW, 0, 0);
38             gui_filler(jd);
39         }
40         gui_space(id);
41         gui_multi(id, curr_intro(), GUI_SML, GUI_ALL, gui_wht, gui_wht);
42
43         gui_layout(id, 0, 0);
44     }
45
46     game_set_fly(1.f);
47
48     return id;
49 }
50
51 static void level_leave(int id)
52 {
53     gui_delete(id);
54 }
55
56 static void level_timer(int id, float dt)
57 {
58     game_step_fade(dt);
59     audio_timer(dt);
60 }
61
62 static void level_paint(int id, float st)
63 {
64     game_draw(0, st);
65     gui_paint(id);
66 }
67
68 static int level_click(int b, int d)
69 {
70     return (b < 0 && d == 1) ? goto_state(&st_play_ready) : 1;
71 }
72
73 static int level_keybd(int c, int d)
74 {
75     if (d && c == SDLK_ESCAPE)
76         goto_state(&st_over);
77     if (d && c == SDLK_F12)
78         goto_state(&st_poser);
79     return 1;
80 }
81
82 static int level_buttn(int b, int d)
83 {
84     if (d)
85     {
86         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
87             return goto_state(&st_play_ready);
88         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
89             return goto_state(&st_over);
90     }
91     return 1;
92 }
93
94 /*---------------------------------------------------------------------------*/
95
96 static void poser_paint(int id, float st)
97 {
98     game_draw(1, st);
99 }
100
101 static int poser_keybd(int c, int d)
102 {
103     return (d && c == SDLK_ESCAPE) ? goto_state(&st_level) : 1;
104 }
105
106 /*---------------------------------------------------------------------------*/
107
108 struct state st_level = {
109     level_enter,
110     level_leave,
111     level_paint,
112     level_timer,
113     NULL,
114     NULL,
115     level_click,
116     level_keybd,
117     level_buttn,
118     1, 0
119 };
120
121 struct state st_poser = {
122     NULL,
123     NULL,
124     poser_paint,
125     NULL,
126     NULL,
127     NULL,
128     NULL,
129     poser_keybd,
130     NULL,
131     1, 0
132 };