1 /**
2 * @file right_panel_score.cc
3 * @brief The right panel score in the bricks levels
4 * @date 2012-10-07
5 * @copyright 1991-2014 TLK Games
6 * @author Bruno Ethvignot
7 * @version $Revision: 24 $
8 */
9 /*
10 * copyright (c) 1991-2014 TLK Games all rights reserved
11 * $Id: right_panel_score.cc 24 2014-09-28 15:30:04Z bruno.ethvignot@gmail.com $
12 *
13 * TecnoballZ is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * TecnoballZ is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 * MA 02110-1301, USA.
27 */
28 #include "../include/right_panel_score.h"
29 #include "../include/handler_resources.h"
30 #include "../include/handler_high_score.h"
31
32 right_panel_score * right_panel_score::panel_score_singleton = NULL;
33
34 /**
35 * Create the right panel score
36 */
right_panel_score()37 right_panel_score::right_panel_score ()
38 {
39 initial_me ();
40 gauge_height = GAUGE_HEIGHT * resolution;
41 gigablitz_countdown = gauge_height;
42 delay_gigablitz_countdown = 0;
43 flip_white = false;
44 gauge_height = 0;
45 panel_width = 0;
46 }
47
48 /**
49 * Release the right panel score
50 */
~right_panel_score()51 right_panel_score::~right_panel_score ()
52 {
53 destroy_me ();
54 panel_score_singleton = NULL;
55 }
56
57 /**
58 * Get the object instance
59 * right_panel_score is a singleton
60 * @return the right_panel_score object
61 */
62 right_panel_score *
get_instance()63 right_panel_score::get_instance ()
64 {
65 if (NULL == panel_score_singleton)
66 {
67 panel_score_singleton = new right_panel_score ();
68 }
69 return panel_score_singleton;
70 }
71
72 /**
73 * First initialization
74 * @param balls
75 */
76 void
first_init()77 right_panel_score::first_init ()
78 {
79 initialize ();
80 gauge_pixel = game_screen->get_pixel_data
81 (GAUGE_XCOORD * resolution, GAUGE_YCOORD * resolution);
82 draw_background ();
83 }
84
85 /**
86 * Draw the background of the panel score
87 */
88 void
draw_background()89 right_panel_score::draw_background ()
90 {
91 bitmap_data *bmp = new bitmap_data ();
92 bmp->load (handler_resources::BITMAP_RIGHT_PANEL);
93
94 /* drawn panel score */
95 offscreen_surface* screen;
96 if (has_background)
97 {
98 screen = background_screen;
99 }
100 else
101 {
102 screen = game_screen;
103 }
104 panel_width = bmp->get_width ();
105 screen->blit_surface (bmp, 0, 0, 256 * resolution, 0,
106 bmp->get_width (), 240 * resolution);
107 delete bmp;
108 bmp = (bitmap_data *) NULL;
109 draw (screen, AREA_NUM_XCOORD * resolution,
110 AREA_NUM_YCOORD * resolution, current_player->area_number, 2);
111 draw (screen, LEVEL_NUM_XCOORD * resolution,
112 LEVEL_NUM_YCOORD * resolution, current_player->level_number, 2);
113 draw (screen, PLAYERNAME_XCOORD * resolution,
114 PLAYERNAME_YCOORD * resolution, current_player->player_name);
115 draw (screen, BEST_SCORE_XCOORD * resolution,
116 BEST_SCORE_YCOORD * resolution, high_score->get_best_score (), 6);
117 draw (screen, BEST_PLAYER_XCOORD * resolution,
118 BEST_PLAYER_YCOORD * resolution, high_score->get_best_playername (), 0);
119 }
120
121 /**
122 * Display score, number of lifes and number of bricks
123 */
124 void
text_refresh()125 right_panel_score::text_refresh ()
126 {
127 draw (game_screen, SCORE_XCOORD * resolution,
128 SCORE_YCOORD * resolution, current_player->score_value, 6);
129 draw (game_screen, LIFES_XCOORD * resolution,
130 LIFES_YCOORD * resolution, bricks_counter, 3);
131 draw (game_screen, BRICKS_XCOORD * resolution,
132 BRICKS_YCOORD * resolution, current_player->number_of_lifes, 2);
133 }
134
135 /**
136 * Decrease the number of bricks
137 * @param dec number to substract
138 */
139 void
decrease_bricks_counter(Uint32 dec)140 right_panel_score::decrease_bricks_counter (Uint32 dec)
141 {
142 if (dec >= bricks_counter)
143 {
144 bricks_counter = 0;
145 }
146 else
147 {
148 bricks_counter -= dec;
149 }
150 }
151
152 /**
153 * Return the number of bricks
154 * @return the number of bricks
155 */
156 Uint32
get_bricks_counter()157 right_panel_score::get_bricks_counter ()
158 {
159 return bricks_counter;
160 }
161
162 /**
163 * Intialize the bricks counter
164 * @param counter the number of bricks
165 */
166 void
set_bricks_counter(Uint32 counter)167 right_panel_score::set_bricks_counter (Uint32 counter)
168 {
169 bricks_counter = counter;
170 }
171
172 /**
173 * Draw the gauge of the Gigablitz
174 */
175 void
draw_gigablizt_gauge()176 right_panel_score::draw_gigablizt_gauge ()
177 {
178 controller_gigablitz *gigablitz = controller_gigablitz::get_instance ();
179 controller_balls *balls = controller_balls::get_instance ();
180 if (keyboard->is_gigablitz_or_tilt ()
181 && !gigablitz->is_enable () && !balls->is_sticky_balls_remains ())
182 {
183 if (++delay_gigablitz_countdown >= DELAY_GIGABLITZ_COUNTDOWN)
184 {
185 if (gigablitz_countdown > 0)
186 {
187 delay_gigablitz_countdown = 0;
188 gigablitz_countdown = gigablitz_countdown - resolution;
189 /* gauge maximum height reached? */
190 if (gigablitz_countdown == 0)
191 {
192 /* yes, launch the gigablitz!*/
193 gigablitz->shoot_paddle ();
194 }
195 }
196 }
197 }
198 else
199 {
200 if (gigablitz_countdown < gauge_height)
201 {
202 delay_gigablitz_countdown = 0;
203 gigablitz_countdown = gigablitz_countdown + resolution;
204 }
205 }
206
207 /* draw the vertical gauge */
208 unsigned char *dest = (unsigned char *)gauge_pixel;
209 Sint32 next = game_screen->get_width ();
210 unsigned char pixel = 0;
211 if (resolution == 1)
212 {
213 for (Uint32 i = 0; i < gigablitz_countdown; i++)
214 {
215 dest[0] = pixel;
216 dest[1] = pixel;
217 dest[2] = pixel;
218 dest[3] = pixel;
219 dest[4] = pixel;
220 dest += next;
221 }
222 }
223 else
224 {
225 for (Uint32 i = 0; i < gigablitz_countdown; i++)
226 {
227 dest[0] = pixel;
228 dest[1] = pixel;
229 dest[2] = pixel;
230 dest[3] = pixel;
231 dest[4] = pixel;
232 dest[5] = pixel;
233 dest[6] = pixel;
234 dest[7] = pixel;
235 dest[8] = pixel;
236 dest[9] = pixel;
237 dest += next;
238 }
239 }
240
241 Sint32 h = (gauge_height) - gigablitz_countdown;
242 flip_white = flip_white ? false : true;
243 if (flip_white)
244 {
245 unsigned char pixel = 130;
246 if (resolution == 1)
247 {
248 for (Sint32 i = 0; i < h; i++)
249 {
250 dest[0] = pixel;
251 dest[1] = pixel;
252 dest[2] = pixel;
253 dest[3] = pixel;
254 dest[4] = pixel;
255 dest += next;
256 }
257 }
258 else
259 {
260 for (Sint32 i = 0; i < h; i++)
261 {
262 dest[0] = pixel;
263 dest[1] = pixel;
264 dest[2] = pixel;
265 dest[3] = pixel;
266 dest[4] = pixel;
267 dest[5] = pixel;
268 dest[6] = pixel;
269 dest[7] = pixel;
270 dest[8] = pixel;
271 dest[9] = pixel;
272 dest += next;
273 }
274 }
275 }
276 else
277 {
278 if (resolution == 1)
279 {
280 unsigned char *e = temoinCol1;
281 for (Sint32 i = 0; i < h; i++)
282 {
283 char pixel = (char) e[i];
284 dest[0] = pixel;
285 dest[1] = pixel;
286 dest[2] = pixel;
287 dest[3] = pixel;
288 dest[4] = pixel;
289 dest += next;
290 }
291 }
292 else
293 {
294 unsigned char *e = temoinCol2;
295 for (Sint32 i = 0; i < h; i++)
296 {
297 unsigned char pixel = e[i];
298 dest[0] = pixel;
299 dest[1] = pixel;
300 dest[2] = pixel;
301 dest[3] = pixel;
302 dest[4] = pixel;
303 dest[5] = pixel;
304 dest[6] = pixel;
305 dest[7] = pixel;
306 dest[8] = pixel;
307 dest[9] = pixel;
308 dest += next;
309 }
310 }
311 }
312 }
313
314 /**
315 * Reset the countdown of the Gigablitz
316 */
317 void
reset_gigablitz_countdown()318 right_panel_score::reset_gigablitz_countdown ()
319 {
320 gigablitz_countdown = gauge_height;
321 }
322
323 /**
324 * Return the width of the panel
325 * @return Width panel scores in pixels
326 */
327 Uint32
get_width()328 right_panel_score::get_width ()
329 {
330 return panel_width;
331 }
332
333 /** List of 54 couleurs from gigablitz */
334 unsigned char right_panel_score::temoinCol1[GAUGE_HEIGHT] =
335 {
336 255,
337 255,
338 254,
339 254,
340 253,
341 253,
342 252,
343 252,
344 251,
345 250,
346 250,
347 249,
348 248,
349 248,
350 247,
351 246,
352 246,
353 245,
354 244,
355 244,
356 243,
357 242,
358 242,
359 241,
360 240,
361 240,
362 239
363 };
364
365 unsigned char right_panel_score::temoinCol2[GAUGE_HEIGHT * 2] =
366 { 255,
367 255,
368 255,
369 255,
370 254,
371 254,
372 254,
373 254,
374 253,
375 253,
376 253,
377 253,
378 252,
379 252,
380 252,
381 251,
382 251,
383 251,
384 250,
385 250,
386 250,
387 249,
388 249,
389 249,
390 248,
391 248,
392 248,
393 247,
394 247,
395 247,
396 246,
397 246,
398 246,
399 245,
400 245,
401 245,
402 244,
403 244,
404 244,
405 243,
406 243,
407 243,
408 242,
409 242,
410 242,
411 241,
412 241,
413 241,
414 240,
415 240,
416 240,
417 239,
418 239,
419 239
420 };
421