1 /**
2  * @file controller_moneys.cc
3  * @brief Moneys controller
4  * @date 2014-08-16
5  * @copyright 1991-2014 TLK Games
6  * @author Bruno Ethvignot
7  * @version $Revision: 22 $
8  */
9 /*
10  * copyright (c) 1991-2014 TLK Games all rights reserved
11  * $Id: controller_moneys.cc 22 2014-08-16 11:28:58Z 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 
29 #include "../include/controller_moneys.h"
30 
31 /**
32  * Create the moneys controller
33  */
controller_moneys()34 controller_moneys::controller_moneys ()
35 {
36   littleInit ();
37   max_of_sprites = 6;
38   sprites_have_shades = true;
39   sprite_type_id = sprite_object::MONEY;
40   delay_count = 0;
41 }
42 
43 /**
44  * Release the moneys controller
45  */
~controller_moneys()46 controller_moneys::~controller_moneys ()
47 {
48   release_sprites_list ();
49 }
50 
51 /**
52  * Initialize the moneys sprites in the bricks levels
53  * @param delay time delay before sending a new money capsule
54  * @param score
55  * @param money
56  */
57 void
initialize(Uint32 delay,right_panel_score * score,controller_indicators * money)58 controller_moneys::initialize (Uint32 delay, right_panel_score * score,
59                                controller_indicators * money)
60 {
61   send_delay = delay;
62   ptbarreScr = score;
63   ptPrntmney = money;
64   for (Uint32 i = 0; i < max_of_sprites; i++)
65     {
66       sprite_money *money = sprites_list[i];
67       money->init_members ();
68     }
69 }
70 
71 /**
72  * Send a money capsule from a brick
73  * @param briPT a pointer to the brick which touched by a ball
74  */
75 void
send_money_from_brick(brick_redraw * briPT)76 controller_moneys::send_money_from_brick (brick_redraw * briPT)
77 {
78   if (++delay_count <= send_delay)
79     {
80       return;
81     }
82   delay_count = 0;
83   for (Uint32 i = 0; i < max_of_sprites; i++)
84     {
85       sprite_money *money = sprites_list[i];
86       if (money->enable_if_available (briPT))
87         {
88           return;
89         }
90     }
91 }
92 
93 /**
94  * Send a money capsule from a destroyed flying enemy ship
95  * @param ball a pointer to the ball sprite which destroyed the enemy ship
96  */
97 void
send_money(sprite_ball * ball)98 controller_moneys::send_money (sprite_ball * ball)
99 {
100   for (Uint32 i = 0; i < max_of_sprites; i++)
101     {
102       sprite_money *money = sprites_list[i];
103       if (money->enable_if_available (ball))
104         {
105           return;
106         }
107     }
108 }
109 
110 /**
111  * Send a money capsule from a destroyed flying enemy ship
112  * @param blast a pointer to the projectile sprite which
113  *        destroyed the enemy ship
114  */
115 void
send_money(sprite_projectile * blast)116 controller_moneys::send_money (sprite_projectile * blast)
117 {
118   for (Uint32 i = 0; i < max_of_sprites; i++)
119     {
120       sprite_money *money = sprites_list[i];
121       if (money->enable_if_available (blast))
122         {
123           return;
124         }
125     }
126 }
127 
128 /**
129  * Move money capsules and check collision with the paddles
130  * in bricks levels
131  */
132 void
move()133 controller_moneys::move ()
134 {
135   for (Uint32 i = 0; i < max_of_sprites; i++)
136     {
137       sprite_money *money = sprites_list[i];
138       money->play_animation_loop ();
139       Uint32 amount = money->move ();
140       if (amount > 0)
141         {
142           current_player->add_score (20);
143           ptPrntmney->increase_money_amount (amount);
144         }
145     }
146 }
147 
148 /**
149  * Initialize the moneys sprites in the guardians levels
150  * @param delay time delay before sending a new money capsule
151  */
152 void
initialize(Uint32 delay,controller_indicators * money)153 controller_moneys::initialize (Uint32 delay, controller_indicators * money)
154 {
155   send_delay = delay;
156   ptPrntmney = money;
157   for (Uint32 i = 0; i < max_of_sprites; i++)
158     {
159       sprite_money *money = sprites_list[i];
160       money->init_members ();
161     }
162 }
163 
164 /**
165  * Send a money capsule from a guardian
166  * @param ball a pointer to the ball sprite which touched the guardian
167  */
168 void
send_money_from_guardian(sprite_ball * ball)169 controller_moneys::send_money_from_guardian (sprite_ball * ball)
170 {
171   if (++delay_count <= send_delay)
172     {
173       return;
174     }
175   delay_count = 0;
176   for (Uint32 i = 0; i < max_of_sprites; i++)
177     {
178       sprite_money *money = sprites_list[i];
179       if (money->enable_if_available (ball))
180         {
181           return;
182         }
183     }
184 }
185 
186 /**
187  * Move money capsules and check collision with the paddle
188  * in guardians levels
189  */
190 void
move_bottom()191 controller_moneys::move_bottom ()
192 {
193   for (Uint32 i = 0; i < max_of_sprites; i++)
194     {
195       sprite_money *money = sprites_list[i];
196       money->play_animation_loop ();
197       Uint32 amount = money->move_bottom ();
198       if (amount > 0)
199         {
200           ptPrntmney->increase_money_amount (amount);
201           current_player->add_score (20);
202         }
203     }
204 }
205