1 // $Id$
2
3 // Fish Supper
4 // Copyright 2006, 2007, 2009, 2010 Matthew Clarke <mafferyew@googlemail.com>
5 //
6 // This file is part of Fish Supper.
7 //
8 // Fish Supper is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // Fish Supper is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Fish Supper. If not, see <http://www.gnu.org/licenses/>.
20
21
22
23
24 #include "Get_ready_screen.h"
25 #include "SDL_image.h"
26 #include <cstdio>
27 #include <iostream>
28 #include <string>
29
30
31
32
33 // *******************
34 // *** CONSTRUCTOR ***
35 // *******************
Get_ready_screen()36 FS::Get_ready_screen::Get_ready_screen()
37 {
38 // nothing
39
40 } // FS::Get_ready_screen::Get_ready_screen()
41
42 // ******************
43 // *** DESTRUCTOR ***
44 // ******************
~Get_ready_screen()45 FS::Get_ready_screen::~Get_ready_screen()
46 {
47 // nothing
48
49 } // FS::Get_ready_screen::~Get_ready_screen()
50
51
52
53
54 // ************************
55 // *** MEMBER FUNCTIONS ***
56 // ************************
57
58 // **************************************************
59
init_level_select(int furthest_lev)60 void FS::Get_ready_screen::init_level_select(int furthest_lev)
61 {
62 current_start_level = furthest_level = furthest_lev;
63 draw_level_select();
64
65 } // FS::Get_ready_screen::init_level_select
66
67 // **************************************************
68
draw_level_select()69 void FS::Get_ready_screen::draw_level_select()
70 {
71 char lev_string[4];
72 sprintf(lev_string, "%d", current_start_level);
73
74 gfx_ptr->draw_background(FS_gfx::GET_READY);
75 gfx_ptr->draw_text( FS_gfx::SMALL_FONT, 0, 50, "Please select start level . . .",
76 true, FS::SCREEN_WIDTH );
77 gfx_ptr->draw_text( FS_gfx::SMALL_FONT, 0, 90, lev_string, true, FS::SCREEN_WIDTH );
78
79 FS_gfx::Image_name limit;
80 if ( current_start_level == 1 )
81 {
82 limit = FS_gfx::LOWER_LIMIT;
83 }
84 else if ( current_start_level == furthest_level )
85 {
86 limit = FS_gfx::UPPER_LIMIT;
87 }
88 else
89 {
90 limit = FS_gfx::MIDDLE;
91 } // if ... else
92 gfx_ptr->draw_texture( limit, 355, 90 );
93
94 SDL_GL_SwapBuffers();
95
96 } // FS::Get_ready_screen::draw_level_select
97
98 // **************************************************
99
update_level_select()100 int FS::Get_ready_screen::update_level_select()
101 {
102 bool changed = false;
103 int selection = 0;
104 User_input::Keyboard_Event ke;
105
106 while ( input_ptr->next_event(ke) )
107 {
108 if ( ke == User_input::JUMP_KEY_PRESSED )
109 {
110 selection = current_start_level;
111 break;
112 }
113 else if ( ke == User_input::LEFT_KEY_PRESSED )
114 {
115 if ( current_start_level > 1 )
116 {
117 --current_start_level;
118 changed = true;
119 } // if
120 }
121 else if ( ke == User_input::RIGHT_KEY_PRESSED )
122 {
123 if ( current_start_level < furthest_level )
124 {
125 ++current_start_level;
126 changed = true;
127 } // if
128 } // if ... else
129 } // while
130
131 if (changed)
132 {
133 draw_level_select();
134 } // if
135
136 return selection;
137
138 } // FS::Get_ready_screen::update_level_select
139
140 // **************************************************
141
init_countdown(int t,int lev)142 void FS::Get_ready_screen::init_countdown(int t, int lev)
143 {
144 start_time = t;
145 draw_countdown(10, lev);
146
147 } // FS::Get_ready_screen::init_countdown
148
149 // **************************************************
150
draw_countdown(int seconds,int lev)151 void FS::Get_ready_screen::draw_countdown(int seconds, int lev)
152 {
153 //std::cout << "draw_countdown1\n";
154 //std::cout << "seconds=" << seconds << "; lev=" << lev << "\n";
155
156 gfx_ptr->draw_background(FS_gfx::GET_READY);
157
158 // FIXME: create this string once then re-use?!
159 std::string message;
160 char level_digits[4];
161 char secs_digits[3];
162 sprintf(level_digits, "%d", lev);
163 sprintf(secs_digits, "%d", seconds);
164 message = "About to start level ";
165 message += level_digits;
166 message += " . . .";
167
168 gfx_ptr->draw_text( FS_gfx::SMALL_FONT, 0, 50, message, true, FS::SCREEN_WIDTH );
169 gfx_ptr->draw_text( FS_gfx::SMALL_FONT, 0, 90, "Get Ready!", true, FS::SCREEN_WIDTH );
170 gfx_ptr->draw_text( FS_gfx::SMALL_FONT, 0, 130, secs_digits, true, FS::SCREEN_WIDTH );
171
172 SDL_GL_SwapBuffers();
173
174 //std::cout << "draw_countdown2\n";
175
176 } // FS::Get_ready_screen::draw_countdown
177
178 // **************************************************
179
update_countdown(int t,int lev)180 bool FS::Get_ready_screen::update_countdown(int t, int lev)
181 {
182 int seconds_passed = (t - start_time) / 1000;
183 bool jump_pressed = false;
184 User_input::Keyboard_Event ke;
185
186 while ( input_ptr->next_event(ke) )
187 {
188 if ( ke == User_input::JUMP_KEY_PRESSED )
189 {
190 jump_pressed = true;
191 break;
192 } // if
193 } // while
194
195 if ( (seconds_passed == SECONDS_TO_WAIT) || jump_pressed )
196 {
197 return true;
198 } // if
199
200 draw_countdown( SECONDS_TO_WAIT - seconds_passed, lev );
201
202 return false;
203
204 } // FS::Get_ready_screen::update_countdown
205
206
207
208