1 /** 2 * @file controller_spheres.cc 3 * @brief Metallic spheres controller used in congratulations 4 * @created 2004-08-05 5 * @date 2007-10-21 6 * @copyright 1991-2014 TLK Games 7 * @author Bruno Ethvignot 8 * @version $Revision: 24 $ 9 */ 10 /* 11 * copyright (c) 1991-2014 TLK Games all rights reserved 12 * $Id: controller_spheres.cc 24 2014-09-28 15:30:04Z bruno.ethvignot@gmail.com $ 13 * 14 * TecnoballZ is free software; you can redistribute it and/or modify 15 * it under the terms of the GNU General Public License as published by 16 * the Free Software Foundation; either version 3 of the License, or 17 * (at your option) any later version. 18 * 19 * TecnoballZ is distributed in the hope that it will be useful, but 20 * WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License 25 * along with this program; if not, write to the Free Software 26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 27 * MA 02110-1301, USA. 28 */ 29 #include "../include/controller_spheres.h" 30 #include "../include/handler_audio.h" 31 #include "../include/handler_resources.h" 32 #include "../include/handler_high_score.h" 33 #include "../include/handler_resources.h" 34 35 /** 36 * Create the metallic spheres controller 37 */ controller_spheres()38controller_spheres::controller_spheres () 39 { 40 littleInit (); 41 /* 8 metallics spheres */ 42 max_of_sprites = 12; 43 sprites_have_shades = true; 44 sprite_type_id = sprite_object::METALLIC_SPHERE; 45 radius_horizontal_variation = 0; 46 radius_vertical_variation = 0; 47 radius_hinc_variation = 0; 48 radius_vinc_variation = 0; 49 radius_sphere_speed = 0; 50 } 51 52 /** 53 * Release the metallic spheres controller 54 */ ~controller_spheres()55controller_spheres::~controller_spheres () 56 { 57 release_sprites_list (); 58 } 59 60 /** 61 * Perform some initializations 62 */ 63 void initialize()64controller_spheres::initialize () 65 { 66 Sint32 offst = 360 / max_of_sprites; 67 Sint32 value = 0; 68 for (Uint32 i = 0; i < max_of_sprites; i++) 69 { 70 sprites_list[i]->enable (); 71 sprites_list[i]->x_maximum = value; 72 value += offst; 73 } 74 } 75 76 /** 77 * Animate the metal spheres 78 */ 79 void run()80controller_spheres::run () 81 { 82 const Sint16 *sin = handler_resources::zesinus360; 83 const Sint16 *cos = handler_resources::cosinus360; 84 Sint32 res = resolution; 85 Uint32 angle_max = 360; 86 Uint32 horizontal_radius = 80 * res; 87 Uint32 vertical_radius = 80 * res; 88 89 /* rotation speed variation */ 90 radius_sphere_speed = (radius_sphere_speed + (random_counter & 3)) % angle_max; 91 Sint32 h = (sin[radius_sphere_speed] * 2) >> 7; 92 Sint32 v = (cos[radius_sphere_speed] * 2) >> 7; 93 Sint32 sphere_speed = 4 + h + v; 94 if (0 == sphere_speed) 95 { 96 sphere_speed = 1; 97 } 98 99 /* radius increment variation */ 100 radius_hinc_variation = (radius_hinc_variation + (random_counter & 7)) % angle_max; 101 h = (sin[radius_hinc_variation] * 3) >> 7; 102 v = (cos[radius_hinc_variation] * 3) >> 7; 103 Sint32 radius_hinc = h + v + 6; 104 /* horizontal radius variation */ 105 radius_horizontal_variation = (radius_horizontal_variation + radius_hinc) % angle_max; 106 h = (sin[radius_horizontal_variation] * 30 * res) >> 7; 107 v = (cos[radius_horizontal_variation] * 30 * res) >> 7; 108 horizontal_radius = horizontal_radius + h + v; 109 110 /* radius increment variation */ 111 radius_vinc_variation = (radius_vinc_variation + (random_counter & 3)) % angle_max; 112 h = (sin[radius_vinc_variation] * 6) >> 7; 113 v = (cos[radius_vinc_variation] * 5) >> 7; 114 Sint32 radius_vinc = h + v + 7; 115 /* vertical radius variation */ 116 radius_vertical_variation = (radius_vertical_variation + radius_vinc) % angle_max; 117 h = (sin[radius_vertical_variation] * 15 * res) >> 7; 118 v = (cos[radius_vertical_variation] * 15 * res) >> 7; 119 vertical_radius = vertical_radius + h + v; 120 121 Sint32 x_center = (160 * res) - (sprites_list[0]->sprite_width / 2); 122 Sint32 y_center = (120 * res) - (sprites_list[0]->sprite_height / 2); 123 for (Uint32 i = 0; i < max_of_sprites; i++) 124 { 125 sprite_object *sphere = sprites_list[i]; 126 sphere->x_maximum = (sphere->x_maximum + sphere_speed) % angle_max; 127 Sint32 xcoord = (sin[sphere->x_maximum] * (Sint32)horizontal_radius) >> 7; 128 Sint32 ycoord = (cos[sphere->x_maximum] * (Sint32)vertical_radius) >> 7; 129 xcoord += x_center; 130 ycoord += y_center; 131 sphere->x_coord = xcoord; 132 sphere->y_coord = ycoord; 133 } 134 } 135