1 /**
2 * @file controller_paddles.cc
3 * @brief Paddles controller
4 * @date 2007-11-18
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: controller_paddles.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/controller_paddles.h"
29 #include "../include/handler_resources.h"
30 #include "../include/handler_players.h"
31 #include "../include/controller_projectiles.h"
32 #include "../include/handler_keyboard.h"
33
34 /**
35 * Create the paddles controller in bricks levels
36 */
controller_paddles()37 controller_paddles::controller_paddles ()
38 {
39 littleInit ();
40 sprites_have_shades = true;
41 is_draw_pixel_by_pixel = false;
42 is_team_mode = false;
43
44 if (current_phase == GUARDS_LEVEL)
45 {
46 max_of_sprites = 1;
47 sprite_type_id = sprite_object::PADDLE_IN_GUARDIANS_LEVEL;
48 paddle_length = 32 * resolution;
49 reverse_counter = 0;
50
51 paddle_bottom = new sprite_paddle (false);
52 paddle_right = NULL;
53 paddle_top = NULL;
54 paddle_left = NULL;
55 paddle_robot = NULL;
56
57 width_maxi = 32 * resolution;
58 width_mini = 32 * resolution;
59 bottom_y_coord = (232 - 8) * resolution;
60 min_coordinate = 16 * resolution;
61 max_coordinate = 300 * resolution;
62 }
63 else
64 {
65 max_of_sprites = 5;
66 sprite_type_id = sprite_object::HORIZONTAL_PADDLE;
67 paddle_length = 64 * resolution;
68 paddle_bottom = new sprite_paddle ();
69 paddle_right = new sprite_paddle ();
70 paddle_top = new sprite_paddle ();
71 paddle_left = new sprite_paddle ();
72 paddle_robot = new sprite_paddle (false);
73
74 min_coordinate = 32 * resolution;
75 max_coordinate = 224 * resolution;
76 top_y_coord = (20 - 8) * resolution;
77 bottom_y_coord = (232 - 8) * resolution;
78 left_x_coord = 20 * resolution;
79 right_x_coord = 228 * resolution;
80 width_maxi = 64 * resolution;
81 width_mini = 16 * resolution;
82 reverse_counter = 0;
83 }
84 }
85
86 /**
87 * Release the paddles controller in guards levels
88 */
~controller_paddles()89 controller_paddles::~controller_paddles ()
90 {
91 release_sprites_list ();
92 }
93
94 /**
95 * Create and initializes the list of the projectiles for the 4 paddles
96 */
97 void
create_projectiles_list()98 controller_paddles::create_projectiles_list ()
99 {
100 paddle_bottom->create_projectiles_list ();
101 paddle_right->create_projectiles_list ();
102 paddle_top->create_projectiles_list ();
103 paddle_left->create_projectiles_list ();
104 }
105
106 /**
107 * Intialize the paddles
108 */
109 void
create_paddles_sprites()110 controller_paddles::create_paddles_sprites ()
111 {
112 alloc_sprites_list ();
113
114 /*
115 * Create one simple paddle in guards levels
116 */
117 if (max_of_sprites == 1)
118 {
119 paddle_bottom->set_object_pos (0);
120 paddle_bottom->create_sprite (sprite_type_id, sprites_bitmap, 1, 0);
121 sprites->add (paddle_bottom);
122 sprites_list[0] = paddle_bottom;
123 paddle_bottom->set_coordinates (keyboard->get_mouse_x (), bottom_y_coord);
124 /* width of the paddle in pixels */
125 paddle_bottom->collision_width = paddle_length;
126 paddle_bottom->paddle_number = 1;
127 paddle_bottom->is_vertical = 0;
128 /* ball rebounds table */
129 paddle_bottom->rebonds_Ga = midi1_left;
130 paddle_bottom->rebonds_Dr = midi1Right;
131 paddle_bottom->enable_counter = 1;
132 paddle_bottom->enable ();
133 paddle_bottom->direct_tab = ballePets1; // table direction balle collee
134 }
135 else
136 {
137 /**
138 * create 4 paddles sprites
139 */
140 Uint32 id;
141 if (current_player->get_area_number () > 2)
142 {
143 id = handler_resources::BITMAP_PADDLES_1;
144 }
145 else
146 {
147 id = handler_resources::BITMAP_PADDLES_2;
148 }
149 resources->load_sprites_bitmap (id);
150
151 /* create bottom paddle sprite */
152 paddle_bottom->set_object_pos (0);
153 paddle_bottom->create_sprite (sprite_object::HORIZONTAL_PADDLE,
154 sprites_bitmap, true, 0);
155 sprites->add (paddle_bottom);
156 sprites_list[0] = paddle_bottom;
157
158 /* create left paddle sprite */
159 paddle_right->set_object_pos (1);
160 paddle_right->create_sprite (sprite_object::VERTICAL_PADLLE,
161 sprites_bitmap, true, 0);
162 sprites->add (paddle_right);
163 sprites_list[1] = paddle_right;
164
165 /* create top paddle sprite */
166 paddle_top->set_object_pos (2);
167 paddle_bottom->duplicate_to (paddle_top);
168 sprites->add (paddle_top);
169 sprites_list[2] = paddle_top;
170
171 /* create right paddle sprite */
172 paddle_left->set_object_pos (3);
173 paddle_right->duplicate_to (paddle_left);
174 sprites->add (paddle_left);
175 sprites_list[3] = paddle_left;
176
177 /* release paddles graphic page */
178 resources->release_sprites_bitmap ();
179 }
180 }
181
182 /**
183 * Create and initialize the robot paddle sprite
184 */
185 void
initialize_robot()186 controller_paddles::initialize_robot ()
187 {
188 paddle_robot->set_object_pos (4);
189 paddle_robot->create_sprite (sprite_object::PADDLE_ROBOT,
190 sprites_bitmap, true, 0);
191 sprites->add (paddle_robot);
192 sprites_list[4] = paddle_robot;
193 }
194
195 /**
196 * Activate robot paddle in bricks level
197 */
198 void
enable_robot()199 controller_paddles::enable_robot ()
200 {
201 Sint32 center;
202 paddle_robot->enable ();
203 center = min_coordinate + (max_coordinate - min_coordinate) / 2 -
204 (paddle_robot->collision_width / 2);
205 paddle_robot->set_coordinates (center, 232 * resolution);
206 paddle_robot->enable_counter = 1;
207 }
208
209 /**
210 * Deactivate robot paddle in bricks level
211 */
212 void
disable_robot()213 controller_paddles::disable_robot ()
214 {
215 paddle_robot->disable ();
216 paddle_robot->enable_counter = 0;
217 }
218
219 /**
220 * Initialize the four paddles in the bricks levels
221 * @param blitz a pointer to the gigablitz controller
222 * @param ball a pointer to the balls controller
223 */
224 void
init_paddles(controller_gigablitz * blitz,controller_balls * ball)225 controller_paddles::init_paddles (controller_gigablitz * blitz, controller_balls * ball)
226 {
227 gigablitz = blitz;
228 balls = ball;
229
230 paddle_length = current_player->get_paddle_length ();
231 Sint32 center = (max_coordinate - min_coordinate) / 2 - (paddle_length / 2);
232
233 /* initialize bottom paddle */
234 paddle_bottom->set_coordinates (center, bottom_y_coord);
235 /* paddles width: 8, 16, 24, 32, 40, 48, 56 or 64 pixels */
236 paddle_bottom->collision_width = paddle_length;
237 paddle_bottom->paddle_number = BOTTOM_PADDLE;
238 paddle_bottom->is_vertical = false;
239 paddle_bottom->enable_if_ok (is_team_mode, paddle_length, 3);
240 paddle_bottom->projectile_xinc0 = 0;
241 paddle_bottom->projectile_yinc0 = -5 * resolution;
242 paddle_bottom->projectile_xinc1 = -1 * resolution;
243 paddle_bottom->projectile_yinc1 = -4 * resolution;
244 paddle_bottom->projectile_xinc2 = 1 * resolution;
245 paddle_bottom->projectile_yinc2 = -4 * resolution;
246 paddle_bottom->projectile_xcenter = 32 * resolution;
247 paddle_bottom->projectile_ycenter = -20 * resolution;
248 paddle_bottom->projectile_xoffset = 0;
249 paddle_bottom->projectile_yoffset = -10 * resolution;
250 paddle_bottom->rebonds_Ga = midi1_left; // rebonds raquette va a gauche
251 paddle_bottom->rebonds_Dr = midi1Right; // rebonds raquette va a droite
252 paddle_bottom->direct_tab = ballePets1; // table direction balle collee
253 paddle_bottom->width_mini = width_mini;
254 paddle_bottom->width_maxi = width_maxi;
255
256 /* initialize right paddle */
257 paddle_right->set_coordinates (right_x_coord, center);
258 paddle_right->collision_height = paddle_length;
259 paddle_right->paddle_number = RIGHT_PADDLE;
260 paddle_right->is_vertical = true;
261 paddle_right->enable_if_ok (is_team_mode, paddle_length,
262 current_player->get_paddle_alive_counter (RIGHT_PADDLE));
263 paddle_right->projectile_xinc0 = -5 * resolution;
264 paddle_right->projectile_yinc0 = 0;
265 paddle_right->projectile_xinc1 = -4 * resolution;
266 paddle_right->projectile_yinc1 = 1 * resolution;
267 paddle_right->projectile_xinc2 = -4 * resolution;
268 paddle_right->projectile_yinc2 = -1 * resolution;
269 paddle_right->projectile_xcenter = -20 * resolution;
270 paddle_right->projectile_ycenter = 32 * resolution;
271 paddle_right->projectile_xoffset = -10 * resolution;
272 paddle_right->projectile_yoffset = 0;
273 paddle_right->rebonds_Ga = midi2_left;
274 paddle_right->rebonds_Dr = midi2Right;
275 paddle_right->direct_tab = ballePets2;
276 paddle_right->width_mini = width_mini;
277 paddle_right->width_maxi = width_maxi;
278 current_player->set_paddle_alive_counter (RIGHT_PADDLE,
279 paddle_right->enable_counter);
280
281 /* initialize top paddle */
282 paddle_top->set_coordinates (center, top_y_coord);
283 paddle_top->collision_width = paddle_length;
284 paddle_top->paddle_number = TOP_PADDLE;
285 paddle_top->is_vertical = false;
286 paddle_top->enable_if_ok (is_team_mode, paddle_length,
287 current_player->get_paddle_alive_counter (TOP_PADDLE));
288 paddle_top->projectile_xinc0 = 0;
289 paddle_top->projectile_yinc0 = 5 * resolution;
290 paddle_top->projectile_xinc1 = 1 * resolution;
291 paddle_top->projectile_yinc1 = 4 * resolution;
292 paddle_top->projectile_xinc2 = -1 * resolution;
293 paddle_top->projectile_yinc2 = 4 * resolution;
294 paddle_top->projectile_xcenter = 32 * resolution - 5;
295 paddle_top->projectile_ycenter = 24 * resolution;
296 paddle_top->projectile_xoffset = 0;
297 paddle_top->projectile_yoffset = 10 * resolution;
298 paddle_top->rebonds_Ga = midi3_left;
299 paddle_top->rebonds_Dr = midi3Right;
300 paddle_top->direct_tab = ballePets3;
301 paddle_top->width_mini = width_mini;
302 paddle_top->width_maxi = width_maxi;
303 current_player->set_paddle_alive_counter (TOP_PADDLE,
304 paddle_top->enable_counter);
305
306 /* initialize left paddle */
307 paddle_left->set_coordinates (left_x_coord, center);
308 paddle_left->collision_height = paddle_length;
309 paddle_left->paddle_number = LEFT_PADDLE;
310 paddle_left->is_vertical = true;
311 paddle_left->enable_if_ok (is_team_mode, paddle_length,
312 current_player->get_paddle_alive_counter (LEFT_PADDLE));
313 paddle_left->projectile_xinc0 = 5 * resolution;
314 paddle_left->projectile_yinc0 = 0 * resolution;
315 paddle_left->projectile_xinc1 = 4 * resolution;
316 paddle_left->projectile_yinc1 = 1 * resolution;
317 paddle_left->projectile_xinc2 = 4 * resolution;
318 paddle_left->projectile_yinc2 = -1 * resolution;
319 paddle_left->projectile_xcenter = 24 * resolution;
320 paddle_left->projectile_ycenter = 32 * resolution - 5;
321 paddle_left->projectile_xoffset = 10 * resolution;
322 paddle_left->projectile_yoffset = 0;
323 paddle_left->rebonds_Ga = midi4_left;
324 paddle_left->rebonds_Dr = midi4Right;
325 paddle_left->direct_tab = ballePets4;
326 paddle_left->width_mini = width_mini;
327 paddle_left->width_maxi = width_maxi;
328 current_player->set_paddle_alive_counter (LEFT_PADDLE
329 , paddle_left->enable_counter);
330
331 /* initialize robot paddle */
332 paddle_robot->set_coordinates (center, bottom_y_coord);
333 /* paddle width always 128 pixels */
334 paddle_robot->collision_width = width_maxi;
335 paddle_robot->paddle_number = ROBOT_PADDLE;
336 paddle_robot->is_vertical = false;
337 paddle_robot->projectile_xinc0 = 0;
338 paddle_robot->projectile_yinc0 = -5 * resolution;
339 paddle_robot->projectile_xinc1 = -1 * resolution;
340 paddle_robot->projectile_yinc1 = -4 * resolution;
341 paddle_robot->projectile_xinc2 = 1 * resolution;
342 paddle_robot->projectile_yinc2 = -4 * resolution;
343 paddle_robot->projectile_xcenter = 32 * resolution;
344 paddle_robot->projectile_ycenter = -20 * resolution;
345 paddle_robot->projectile_xoffset = 0;
346 paddle_robot->projectile_yoffset = -10 * resolution;
347 paddle_robot->rebonds_Ga = midi1_left; // rebonds raquette va a gauche
348 paddle_robot->rebonds_Dr = midi1Right; // rebonds raquette va a droite
349 paddle_robot->direct_tab = ballePets1; // table direction balle collee
350 }
351
352 /**
353 * Fire the projectiles
354 */
355 void
fire_projectiles()356 controller_paddles::fire_projectiles ()
357 {
358
359 /* mode solo */
360 if (!is_team_mode)
361 {
362 if (keyboard->is_left_button ()
363 || keyboard->control_is_pressed(handler_keyboard::K_FIRE))
364 {
365 paddle_bottom->fire_projectiles ();
366 paddle_right->fire_projectiles ();
367 paddle_top->fire_projectiles ();
368 paddle_left->fire_projectiles ();
369 }
370 }
371 else
372 /* mode team no implemented */
373 {
374 }
375 paddle_bottom->move_projectiles ();
376 paddle_right->move_projectiles ();
377 paddle_top->move_projectiles ();
378 paddle_left->move_projectiles ();
379 }
380
381 /**
382 * Check if the player release all glued balls in the bricks levels
383 */
384 void
check_if_release_balls()385 controller_paddles::check_if_release_balls ()
386 {
387 /*
388 * mode solo
389 */
390 if (!is_team_mode)
391 {
392 if (keyboard->is_right_button () ||
393 keyboard->control_is_pressed (handler_keyboard::K_RELEASE_BALL))
394 {
395 tiles_background *tiles = tiles_background::get_instance ();
396 tiles->set_scroll_type(tiles_background::TILES_NO_SCROLL);
397 paddle_bottom->release_ball ();
398 paddle_right->release_ball ();
399 paddle_top->release_ball ();
400 paddle_left->release_ball ();
401 #ifndef SOUNDISOFF
402 audio->stop_lost_music ();
403 #endif
404 }
405 }
406 /*
407 * mode team not implemented
408 */
409 /* else
410 {
411
412 } */
413 }
414
415 /**
416 * Check if the player release all glued balls in the guards levels
417 */
418 void
check_if_release_ball()419 controller_paddles::check_if_release_ball ()
420 {
421 if (keyboard->is_right_button ()
422 || keyboard->control_is_pressed(handler_keyboard::K_RELEASE_BALL))
423 {
424 paddle_bottom->release_ball ();
425 }
426 }
427
428 /**
429 * Release all balls in bricks levels
430 */
431 void
release_all_balls()432 controller_paddles::release_all_balls ()
433 {
434 paddle_bottom->release_ball ();
435 paddle_right->release_ball ();
436 paddle_top->release_ball ();
437 paddle_left->release_ball ();
438 }
439
440
441
442 /**
443 * Calculate the speed of
444 */
445 Sint32
get_paddles_speed()446 controller_paddles::get_paddles_speed ()
447 {
448
449 Sint32 off_x = 0;
450 bool is_key_down = false;
451 if (keyboard->control_is_pressed(handler_keyboard::K_LEFT))
452 {
453 if ((Sint32)kb_paddle_speed > 0)
454 {
455 kb_paddle_speed = 0;
456 }
457 kb_paddle_speed -= 2;
458 if ((Sint32)kb_paddle_speed < 1)
459 {
460 kb_paddle_speed *= 0.9;
461 }
462 off_x = (Sint32)kb_paddle_speed;
463 is_key_down = true;
464 }
465 else if (keyboard->control_is_pressed(handler_keyboard::K_RIGHT))
466 {
467 if ((Sint32)kb_paddle_speed < 0)
468 {
469 kb_paddle_speed = 0;
470 }
471 kb_paddle_speed += 2;
472 if ((Sint32)kb_paddle_speed > 1)
473 {
474 kb_paddle_speed *= 0.9;
475 }
476 off_x = (Sint32)kb_paddle_speed;
477 is_key_down = true;
478 }
479
480 if (absolute_mouse_positioning)
481 {
482 if (!is_key_down)
483 {
484 kb_paddle_speed = 0;
485 off_x = keyboard->get_mouse_x () - paddle_bottom->x_coord;
486 }
487 else
488 {
489 SDL_WarpMouse (paddle_bottom->x_coord + off_x,
490 display->get_height() >> 1);
491 }
492 }
493
494 else
495 {
496 if (!is_key_down)
497 {
498 kb_paddle_speed = 0;
499 off_x = keyboard->get_mouse_x_offset ();
500 }
501 }
502
503 return off_x;
504 }
505
506 /**
507 * Control the movements of paddle(s) in the bricks levels
508 */
509 void
move_paddles()510 controller_paddles::move_paddles ()
511 {
512 Sint32 speed = 0;
513 const Sint32 **tabB1, **tabB2, **tabB3, **tabB4;
514 Sint32 x = paddle_bottom->x_coord;
515 Sint32 off_x = get_paddles_speed();
516
517
518 /* one player mode */
519 if (!is_team_mode)
520 {
521 rakVgauche = 0;
522 rakVdroite = 0;
523
524 /* if 2 mouse buttons are pressed or GigaBlitz run also no test */
525 if (!keyboard->is_gigablitz_or_tilt ()
526 && !gigablitz->is_enable ())
527 {
528 if (reverse_counter > 0)
529 {
530 off_x = -off_x;
531 }
532
533 x += off_x;
534 if (off_x < 0)
535 {
536 if (x <= min_coordinate)
537 {
538 x = min_coordinate;
539 }
540 rakVgauche = -off_x;
541 speed = rakVgauche;
542 tabB1 = paddle_bottom->rebonds_Ga;
543 tabB2 = paddle_right->rebonds_Ga;
544 tabB3 = paddle_top->rebonds_Ga;
545 tabB4 = paddle_left->rebonds_Ga;
546 }
547 else
548 {
549 Sint32 i = max_coordinate - paddle_length;
550 if (x >= i)
551 {
552 x = i;
553 }
554 rakVdroite = off_x;
555 speed = rakVdroite;
556 tabB1 = paddle_bottom->rebonds_Dr;
557 tabB2 = paddle_right->rebonds_Dr;
558 tabB3 = paddle_top->rebonds_Dr;
559 tabB4 = paddle_left->rebonds_Dr;
560 }
561
562 /* select a table of bounces's ball according to paddle's moving */
563 if (speed > 10)
564 {
565 speed = 10;
566 }
567 paddle_bottom->current_bounces = *(tabB1 + speed);
568 paddle_right->current_bounces = *(tabB2 + speed);
569 paddle_top->current_bounces = *(tabB3 + speed);
570 paddle_left->current_bounces = *(tabB4 + speed);
571
572 /** Update x or y coordinates of the paddles */
573 paddle_bottom->set_x_coord (x);
574 paddle_right->set_y_coord (x - 16);
575 paddle_top->set_x_coord (x);
576 paddle_left->set_y_coord (x - 16);
577 }
578
579
580 }
581
582 /* team mode (on Amiga I had two mice simultaneously) */
583 else
584 {
585
586 }
587 }
588
589 /**
590 * Control the movements of paddle in the guardians levels
591 */
592 void
move_paddle()593 controller_paddles::move_paddle ()
594 {
595 Sint32 speed = 0;
596 const Sint32 **tabB1;
597 Sint32 x = paddle_bottom->x_coord;
598 Sint32 off_x = get_paddles_speed();
599 /* mode solo */
600 if (!is_team_mode)
601 {
602 if (reverse_counter > 0)
603 {
604 off_x = -off_x;
605 }
606 x += off_x;
607 if (off_x < 0)
608 {
609 if (x <= min_coordinate)
610 {
611 x = min_coordinate;
612 }
613 speed = -off_x;
614 tabB1 = paddle_bottom->rebonds_Ga;
615 }
616 else
617 {
618 Sint32 i = max_coordinate - paddle_length;
619 if (x >= i)
620 x = i;
621 speed = off_x;
622 tabB1 = paddle_bottom->rebonds_Dr;
623 }
624
625 /* select a table of bounces's ball according to paddle's moving */
626 if (speed > 10)
627 {
628 speed = 10;
629 }
630 paddle_bottom->current_bounces = *(tabB1 + speed);
631 paddle_bottom->set_x_coord (x);
632 paddle_bottom->blink ();
633 }
634
635 /* team mode (on Amiga I had two mice simultaneously) */
636 else
637 {
638
639 }
640 }
641
642 /**
643 * Move the bottom robot paddle
644 */
645 void
move_robot()646 controller_paddles::move_robot ()
647 {
648 if (paddle_robot->enable_counter == 0)
649 {
650 return;
651 }
652
653 Sint32 t = balls->get_max_of_sprites ();
654 sprite_ball **balls_list = balls->get_sprites_list ();
655 Sint32 pos_y = 0;
656 sprite_ball *target_ball = NULL;
657 for (Sint32 i = 0; i < t; i++)
658 {
659 sprite_ball *ball = *(balls_list++);
660 if (!ball->is_enabled)
661 {
662 continue;
663 }
664 if (ball->direction >= 36 && ball->direction <= 60)
665 {
666 if (ball->y_coord > pos_y)
667 {
668 pos_y = ball->y_coord;
669 target_ball = ball;
670 }
671 }
672 }
673
674 if (pos_y <= 0)
675 {
676 return;
677 }
678 Sint32 x_paddle = paddle_robot->x_coord;
679 Sint32 x_ball = target_ball->x_coord + target_ball->collision_width / 2 - paddle_robot->collision_width / 2;
680 Sint32 offset = x_paddle - x_ball;
681 Sint32 max = 5 * resolution;
682 if (offset > max)
683 {
684 offset = max;
685 }
686 if (offset < -max)
687 {
688 offset = -max;
689 }
690 x_paddle = x_paddle - offset;
691
692 if (x_paddle < min_coordinate)
693 {
694 x_paddle = min_coordinate;
695 }
696 if (x_paddle > (Sint32)(max_coordinate - paddle_robot->collision_width))
697 {
698 x_paddle = max_coordinate - paddle_robot->collision_width;
699 }
700
701 offset = paddle_robot->x_coord;
702 paddle_robot->x_coord = x_paddle;
703 offset = x_paddle - offset;
704 const Sint32 **tabB1;
705 if (offset < 0)
706 {
707 offset = -offset;
708 tabB1 = paddle_robot->rebonds_Ga;
709 }
710 else
711 {
712 tabB1 = paddle_robot->rebonds_Dr;
713 }
714 paddle_robot->current_bounces = *(tabB1 + offset);
715 }
716
717 /**
718 * Return a pointer to a paddle sprite from a paddle identifier number
719 * @param id identifier number of the paddle
720 * @return pointer to a paddle sprite
721 */
722 sprite_paddle *
get_paddle(Uint32 id)723 controller_paddles::get_paddle (Uint32 id)
724 {
725 switch (id)
726 {
727 case BOTTOM_PADDLE:
728 return paddle_bottom;
729 case RIGHT_PADDLE:
730 return paddle_right;
731 case TOP_PADDLE:
732 return paddle_top;
733 case LEFT_PADDLE:
734 return paddle_left;
735 case ROBOT_PADDLE:
736 return paddle_robot;
737 }
738 return NULL;
739 }
740
741 /**
742 * Set the maximum paddles size in the bricks levels
743 */
744 void
set_maximum_paddles_size()745 controller_paddles::set_maximum_paddles_size ()
746 {
747 if (paddle_length >= 64 * resolution)
748 {
749 return;
750 }
751 paddle_length = 64 * resolution;
752 Sint32 x = paddle_bottom->get_x_coord ();
753 Sint32 i = max_coordinate - paddle_length;
754 if (x >= i)
755 {
756 x = i;
757 paddle_bottom->set_x_coord (x);
758 paddle_right->set_y_coord (x);
759 paddle_top->set_x_coord (x);
760 paddle_left->set_y_coord (x);
761 }
762 paddle_bottom->set_width (paddle_length);
763 paddle_right->set_height (paddle_length);
764 paddle_top->set_width (paddle_length);
765 paddle_left->set_height (paddle_length);
766 current_player->set_paddle_length (paddle_length);
767 }
768
769 /**
770 * Expand the size of the paddle(s) in the bricks levels
771 */
772 void
expand_paddles()773 controller_paddles::expand_paddles ()
774 {
775 if (paddle_length >= (64 * resolution))
776 {
777 return;
778 }
779 paddle_length += (8 * resolution);
780 Sint32 x = paddle_bottom->get_x_coord ();
781 Sint32 i = max_coordinate - paddle_length;
782 if (x >= i)
783 {
784 x = i;
785 paddle_bottom->set_x_coord (x);
786 paddle_right->set_y_coord (x);
787 paddle_top->set_x_coord (x);
788 paddle_left->set_y_coord (x);
789 }
790 paddle_bottom->set_width (paddle_length);
791 paddle_right->set_height (paddle_length);
792 paddle_top->set_width (paddle_length);
793 paddle_left->set_height (paddle_length);
794 current_player->set_paddle_length (paddle_length);
795 }
796
797 /**
798 * Shrink the size of the paddle(s) in the bricks levels
799 */
800 void
shrink_paddles()801 controller_paddles::shrink_paddles ()
802 {
803 if (paddle_length <= (16 * resolution))
804 {
805 return;
806 }
807 paddle_length -= (8 * resolution);
808 paddle_bottom->set_width (paddle_length);
809 paddle_right->set_height (paddle_length);
810 paddle_top->set_width (paddle_length);
811 paddle_left->set_height (paddle_length);
812 current_player->set_paddle_length (paddle_length);
813 }
814
815 /**
816 * Enable reverse movements of the paddle
817 * @param counter value of the reverse
818 */
819 void
set_reverse_counter(Uint32 counter)820 controller_paddles::set_reverse_counter (Uint32 counter)
821 {
822 reverse_counter = counter;
823 }
824
825 /**
826 * Return counter value of the reverse paddle
827 * @return counter value of the reverse
828 */
829 Uint32
get_reverse_counter()830 controller_paddles::get_reverse_counter ()
831 {
832 return reverse_counter;
833 }
834
835 /**
836 * Disable all paddles during the game over
837 */
838 void
disable_all_paddles()839 controller_paddles::disable_all_paddles ()
840 {
841 for (Uint32 i = 0; i < max_of_sprites; i++)
842 {
843 sprite_paddle * paddle= sprites_list[i];
844 paddle->disable ();
845 }
846 }
847
848 Sint32
849 controller_paddles::ballePets1[14] = { 4, 8, 12, 16, 20, 24, 28,
850 28, 24, 20, 16, 12, 8, 4
851 };
852 Sint32
853 controller_paddles::ballePets2[14] = { 20, 24, 28, 32, 36, 40, 44,
854 44, 40, 36, 32, 28, 24, 20
855 };
856 Sint32
857 controller_paddles::ballePets3[14] = { 60, 56, 52, 48, 44, 40, 36,
858 36, 40, 44, 48, 52, 56, 60
859 };
860 Sint32
861 controller_paddles::ballePets4[14] = { 12, 8, 4, 0, 60, 56, 52,
862 52, 56, 60, 0, 4, 8, 12
863 };
864
865 // table de rebonds de la balle raquette du bas
866 const Sint32
867 controller_paddles::rb09[16] =
868 { 4, 4, 8, 12, 16, 20, 24, 28, 28, 32, 32, 32, 32, 20, 24, 28 };
869 const Sint32
870 controller_paddles::rb10[16] =
871 { 4, 4, 8, 12, 16, 20, 24, 28, 28, 32, 32, 32, 28, 20, 20, 16 };
872 const Sint32
873 controller_paddles::rb11[16] =
874 { 4, 4, 8, 12, 16, 20, 24, 28, 28, 28, 28, 28, 24, 16, 16, 12 };
875 const Sint32
876 controller_paddles::rb12[16] =
877 { 4, 4, 8, 12, 16, 20, 24, 28, 28, 28, 28, 24, 20, 16, 12, 8 };
878 const Sint32
879 controller_paddles::rb13[16] =
880 { 4, 4, 8, 12, 16, 20, 24, 28, 28, 28, 24, 20, 16, 12, 8, 4 };
881 const Sint32
882 controller_paddles::rb14[16] =
883 { 4, 4, 8, 12, 16, 20, 24, 28, 28, 20, 20, 20, 12, 8, 4, 4 };
884 const Sint32
885 controller_paddles::rb15[16] =
886 { 4, 4, 8, 12, 16, 20, 24, 28, 28, 16, 16, 16, 8, 8, 4, 0 };
887 const Sint32
888 controller_paddles::rb16[16] =
889 { 4, 4, 8, 12, 16, 20, 24, 28, 28, 8, 12, 12, 4, 4, 0, 0 };
890 const Sint32
891 controller_paddles::rb17[16] =
892 { 4, 4, 8, 12, 16, 20, 24, 28, 28, 4, 8, 12, 0, 0, 0, 0 };
893 const Sint32 *
894 controller_paddles::midi1_left[] =
895 { rb13, rb14, rb14, rb15, rb15, rb16, rb16, rb16, rb16, rb16, rb17 };
896 const Sint32 *
897 controller_paddles::midi1Right[] =
898 { rb13, rb12, rb12, rb11, rb11, rb10, rb10, rb10, rb10, rb10, rb09 };
899
900 // table de rebonds de la balle raquette de droite
901 const Sint32
902 controller_paddles::rb18[] =
903 { 32 + 16, 20 + 16, 24 + 16, 28 + 16, 4 + 16, 4 + 16, 8 + 16, 12 + 16,
904 16 + 16, 20 + 16, 24 + 16, 28 + 16, 28 + 16, 32 + 16, 32 + 16, 32 + 16
905 };
906 const Sint32
907 controller_paddles::rb19[] =
908 { 28 + 16, 20 + 16, 20 + 16, 16 + 16, 4 + 16, 04 + 16, 8 + 16, 12 + 16,
909 16 + 16, 20 + 16, 24 + 16, 28 + 16, 28 + 16, 32 + 16, 32 + 16, 32 + 16
910 };
911 const Sint32
912 controller_paddles::rb20[] =
913 { 24 + 16, 16 + 16, 16 + 16, 12 + 16, 4 + 16, 4 + 16, 8 + 16, 12 + 16,
914 16 + 16, 20 + 16, 24 + 16, 28 + 16, 28 + 16, 28 + 16, 28 + 16, 28 + 16
915 };
916 const Sint32
917 controller_paddles::rb21[] =
918 { 20 + 16, 16 + 16, 12 + 16, 8 + 16, 4 + 16, 04 + 16, 8 + 16, 12 + 16,
919 16 + 16, 20 + 16, 24 + 16, 28 + 16, 28 + 16, 28 + 16, 28 + 16, 24 + 16
920 };
921 const Sint32
922 controller_paddles::rb22[] =
923 { 16 + 16, 12 + 16, 8 + 16, 4 + 16, 4 + 16, 4 + 16, 8 + 16, 12 + 16,
924 16 + 16, 20 + 16, 24 + 16, 28 + 16, 28 + 16, 28 + 16, 24 + 16, 20 + 16
925 };
926 const Sint32
927 controller_paddles::rb23[] =
928 { 12 + 16, 8 + 16, 4 + 16, 4 + 16, 4 + 16, 4 + 16, 8 + 16, 12 + 16,
929 16 + 16, 20 + 16, 24 + 16, 28 + 16, 28 + 16, 20 + 16, 20 + 16, 20 + 16
930 };
931 const Sint32
932 controller_paddles::rb24[] =
933 { 8 + 16, 8 + 16, 4 + 16, 0 + 16, 4 + 16, 4 + 16, 8 + 16, 12 + 16,
934 16 + 16, 20 + 16, 24 + 16, 28 + 16, 28 + 16, 16 + 16, 16 + 16, 16 + 16
935 };
936 const Sint32
937 controller_paddles::rb25[] =
938 { 4 + 16, 4 + 16, 0 + 16, 0 + 16, 4 + 16, 4 + 16, 8 + 16, 12 + 16,
939 16 + 16, 20 + 16, 24 + 16, 28 + 16, 28 + 16, 8 + 16, 12 + 16, 12 + 16
940 };
941 const Sint32
942 controller_paddles::rb26[] =
943 { 0 + 16, 0 + 16, 0 + 16, 0 + 16, 4 + 16, 4 + 16, 8 + 16, 12 + 16,
944 16 + 16, 20 + 16, 24 + 16, 28 + 16, 28 + 16, 4 + 16, 8 + 16, 12 + 16
945 };
946 const Sint32 *
947 controller_paddles::midi2_left[] =
948 { rb22, rb21, rb21, rb20, rb20, rb19, rb19, rb19, rb19, rb19, rb18 };
949 const Sint32 *
950 controller_paddles::midi2Right[] =
951 { rb22, rb23, rb23, rb24, rb24, rb25, rb25, rb25, rb25, rb25, rb26 };
952
953
954 // table de rebonds de la balle raquette du haut
955 const Sint32
956 controller_paddles::rb27[] = { 60, 0, 0, 0, 0, 52, 56, 60,
957 4 + 32, 4 + 32, 8 + 32, 12 + 32, 16 + 32, 20 + 32, 24 + 32, 28 + 32
958 };
959 const Sint32
960 controller_paddles::rb28[] = { 60, 0, 0, 0, 60, 52, 52, 48,
961 4 + 32, 4 + 32, 8 + 32, 12 + 32, 16 + 32, 20 + 32, 24 + 32, 28 + 32
962 };
963 const Sint32
964 controller_paddles::rb29[] = { 60, 60, 60, 60, 56, 48, 48, 44,
965 4 + 32, 4 + 32, 8 + 32, 12 + 32, 16 + 32, 20 + 32, 24 + 32, 28 + 32
966 };
967 const Sint32
968 controller_paddles::rb30[] = { 60, 60, 60, 56, 52, 48, 48, 40,
969 4 + 32, 4 + 32, 8 + 32, 12 + 32, 16 + 32, 20 + 32, 24 + 32, 28 + 32
970 };
971 const Sint32
972 controller_paddles::rb31[] = { 60, 60, 56, 52, 48, 44, 40, 36,
973 4 + 32, 4 + 32, 8 + 32, 12 + 32, 16 + 32, 20 + 32, 24 + 32, 28 + 32
974 };
975 const Sint32
976 controller_paddles::rb32[] = { 60, 52, 52, 48, 44, 40, 36, 36,
977 4 + 32, 4 + 32, 8 + 32, 12 + 32, 16 + 32, 20 + 32, 24 + 32, 28 + 32
978 };
979 const Sint32
980 controller_paddles::rb33[] = { 60, 48, 48, 16 + 32, 40, 40, 32, 32,
981 4 + 32, 4 + 32, 8 + 32, 12 + 32, 16 + 32, 20 + 32, 24 + 32, 28 + 32
982 };
983 const Sint32
984 controller_paddles::rb34[] = { 60, 40, 44, 12 + 32, 36, 36, 32, 32,
985 4 + 32, 4 + 32, 8 + 32, 12 + 32, 16 + 32, 20 + 32, 24 + 32, 28 + 32
986 };
987 const Sint32
988 controller_paddles::rb35[] = { 60, 36, 40, 12 + 32, 32, 32, 32, 32,
989 4 + 32, 4 + 32, 8 + 32, 12 + 32, 16 + 32, 20 + 32, 24 + 32, 28 + 32
990 };
991 const Sint32 *
992 controller_paddles::midi3_left[] =
993 { rb31, rb30, rb30, rb29, rb29, rb28, rb28, rb28, rb28, rb28, rb27 };
994 const Sint32 *
995 controller_paddles::midi3Right[] =
996 { rb31, rb32, rb32, rb33, rb33, rb34, rb34, rb34, rb34, rb34, rb35 };
997
998
999 // table de rebonds de la balle raquette de gauche
1000 const Sint32
1001 controller_paddles::rb36[] =
1002 { 16 - 16, 20 - 16, 24 - 16, 28 - 16, 28 - 16, 32 - 16, 32 - 16, 32 - 16,
1003 32 - 16, 20 - 16, 24 - 16, 28 - 16, 4 + 48, 4 + 48, 8 + 48, 12 + 48
1004 };
1005 const Sint32
1006 controller_paddles::rb37[] =
1007 { 16 - 16, 20 - 16, 24 - 16, 28 - 16, 28 - 16, 32 - 16, 32 - 16, 32 - 16,
1008 28 - 16, 20 - 16, 20 - 16, 16 - 16, 4 + 48, 4 + 48, 8 + 48, 12 + 48
1009 };
1010 const Sint32
1011 controller_paddles::rb38[] =
1012 { 16 - 16, 20 - 16, 24 - 16, 28 - 16, 28 - 16, 28 - 16, 28 - 16, 28 - 16,
1013 24 - 16, 16 - 16, 16 - 16, 12 + 48, 4 + 48, 4 + 48, 8 + 48, 12 + 48
1014 };
1015 const Sint32
1016 controller_paddles::rb39[] =
1017 { 16 - 16, 20 - 16, 24 - 16, 28 - 16, 28 - 16, 28 - 16, 28 - 16, 24 - 16,
1018 20 - 16, 16 - 16, 12 + 48, 8 + 48, 4 + 48, 4 + 48, 8 + 48, 12 + 48
1019 };
1020 const Sint32
1021 controller_paddles::rb40[] =
1022 { 16 - 16, 20 - 16, 24 - 16, 28 - 16, 28 - 16, 28 - 16, 24 - 16, 20 - 16,
1023 16 - 16, 12 + 48, 8 + 48, 4 + 48, 4 + 48, 4 + 48, 8 + 48, 12 + 48
1024 };
1025 const Sint32
1026 controller_paddles::rb41[] =
1027 { 16 - 16, 20 - 16, 24 - 16, 28 - 16, 28 - 16, 20 - 16, 20 - 16, 20 - 16,
1028 12 + 48, 8 + 48, 4 + 48, 4 + 48, 4 + 48, 4 + 48, 8 + 48, 12 + 48
1029 };
1030 const Sint32
1031 controller_paddles::rb42[] =
1032 { 16 - 16, 20 - 16, 24 - 16, 28 - 16, 28 - 16, 16 - 16, 16 - 16, 16 - 16,
1033 8 + 48, 8 + 48, 4 + 48, 0 + 48, 4 + 48, 4 + 48, 8 + 48, 12 + 48
1034 };
1035 const Sint32
1036 controller_paddles::rb43[] =
1037 { 16 - 16, 20 - 16, 24 - 16, 28 - 16, 28 - 16, 8 + 48, 12 + 48, 12 + 48,
1038 4 + 48, 4 + 48, 0 + 48, 0 + 48, 4 + 48, 4 + 48, 8 + 48, 12 + 48
1039 };
1040 const Sint32
1041 controller_paddles::rb44[] =
1042 { 16 - 16, 20 - 16, 24 - 16, 28 - 16, 28 - 16, 4 + 48, 8 + 48, 12 + 48,
1043 0 + 48, 0 + 48, 0 + 48, 0 + 48, 4 + 48, 4 + 48, 8 + 48, 12 + 48
1044 };
1045 const Sint32 *
1046 controller_paddles::midi4_left[] =
1047 { rb40, rb41, rb41, rb42, rb42, rb43, rb43, rb43, rb43, rb43, rb44 };
1048 const Sint32 *
1049 controller_paddles::midi4Right[] =
1050 { rb40, rb39, rb39, rb38, rb38, rb37, rb37, rb37, rb37, rb37, rb36 };
1051