1 /**
2  * @file sprite_ball.h
3  * @brief The ball sprite
4  * @date 2014-07-27
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: sprite_ball.h 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 #ifndef __SPRITE_BALL__
29 #define __SPRITE_BALL__
30 class sprite_ball;
31 #include "../include/sprite_object.h"
32 
33 /** Coordinates of the ball on the ejectors */
34 typedef struct
35   {
36     Sint32 x_coord;
37     Sint32 y_coord;
38   }
39 ball_ejector_coords;
40 
41 
42 #include "../include/sprite_paddle.h"
43 #include "../include/controller_bricks.h"
44 #include "../include/controller_viewfinders.h"
45 #include "../include/controller_ejectors.h"
46 
47 class sprite_ball:public sprite_object
48   {
49     friend class controller_balls;
50     friend class controller_viewfinders;
51     friend class controller_paddles;
52     friend class sprite_money;
53     friend class sprite_gem;
54     friend class controller_guardians;
55     friend class direction;
56 
57   public:
58     /** Different types of ball */
59     typedef enum
60     {
61       NORMAL,
62       POWER_1,
63       POWER_2
64     }
65     TYPES_OF_BALL;
66     /** Different sizes of ball */
67     typedef enum
68     {
69       SIZE_1 = 0,
70       SIZE_2 = 3,
71       SIZE_3 = 6
72     }
73     SIZES_OF_BALL;
74     /** Width and height of collision of the ball size 1 in low-res */
75     static const Sint32 WIDTH_1 = 5;
76     /** Width and height of collision of the ball size 2 in low-res */
77     static const Sint32 WIDTH_2 = 7;
78     /** Width and height of collision of the ball size 3 in low-res */
79     static const Sint32 WIDTH_3 = 9;
80     /** Left limit of ball in low-res */
81     static const Sint32 X_MINIMUM = 5;
82     /** Right limit of ball in low-res */
83     static const Sint32 X_MAXIMUM = 256;
84     /** Top limit of ball in low-res */
85     static const Sint32 Y_MINIMUM = 0;
86     /** Bottom limit of ball low-res */
87     static const Sint32 Y_MAXIMUM = 232;
88 
89     /** Previous X coordinate */
90     Sint32 previous_x_coord;
91     /** Previous Y coordinate */
92     Sint32 previous_y_coord;
93 
94   private:
95     /** Ball direction from 0 to 64 step 4
96      * 64 = immobile ball */
97     Sint32 direction;
98     /** Previous ball direction */
99     Sint32 previous_direction;
100     /** Delay counter before change ball direction
101      * Avoid the horizontal blockings */
102     Sint32 change_direction_count;
103     /** The last paddle touched by the ball */
104     sprite_paddle *paddle_touched;
105     /** Padlle on witch is stuck the ball */
106     sprite_paddle *stick_paddle;
107     /** Paddle number on which the ball is stuck */
108     Uint32 sticky_paddle_num;
109     /** Pointer to the current velocities table */
110     Sint16 *velocities;
111     /** Pointer to the current velocities table */
112     Sint16 *initial_velocities;
113     /** Pointer to the current points of collision with a brick */
114     Sint32 *brick_collision_points;
115     /* Strength of ball 1, 2 or 3 to decrease brick strength */
116     Sint32 strength1;
117     /* Strength of ball 32, 64 or 96 to decrease brick address */
118     Sint32 strength2;
119     /** Time delay before ejection of the ball */
120     Sint32 ejector_delay;
121     /** Table of directions possible that a ball can
122      * set when it leave a ejector */
123     Sint32 *ejector_table;
124     /** Counter before a tilt is possible */
125     Sint32 tilt_delay_counter;
126     /** Counter delay before accelerating the ball */
127     Sint32 accelerate_delay_counter;
128     /** Time delay before accelerating the ball */
129     Sint32 accelerate_delay;
130     /** Delay counter before the ball leaves the paddle */
131     Sint32 start_delay_counter;
132     /** Initial delay before the ball leaves the paddle */
133     Sint32 start_delay;
134     /** Direction of the viewfinder when the ball is sticked
135      * on a paddle: from 0 to 13 */
136     Sint32 viewfinder_direction;
137     /** Counter delay before change direction of the viewfinder */
138     Sint32 viewfinder_delay;
139     /** Size identfier SIZE_1, SIZE_2 or SIZE_3 */
140     Sint32 size_id;
141     /** Type of ball NORMAL, POWER_1 or POWER_2 */
142     Sint32 type;
143     /** Brick's width in pixels 16 or 32 */
144     Sint32 brick_width;
145     /** Previous hited wall RIGHT_WALL, LEFT_WALL, TOP_WALL or 0 if not */
146     Sint32 last_hited_wall;
147     /** True if collision point of ball with bricks were corrected */
148     static bool is_collisions_point_initialized;
149     /** Collision points of the ballz size 1 with a brick */
150     static Sint32 brick_collision_points_1[8];
151     /** Collision points of the ballz size 2 with a brick */
152     static Sint32 brick_collision_points_2[8];
153     /** Collision points of the ballz size 3 with a brick */
154     static Sint32 brick_collision_points_3[8];
155     /** Displacement offsets of speed 1 */
156     static Sint16 velocities_speed_1[];
157     /** Displacement offsets of speed 2 */
158     static Sint16 velocities_speed_2[];
159     /** Displacement offsets of speed 3 */
160     static Sint16 velocities_speed_3[];
161     /** Displacement offsets of speed 1 */
162     static Sint16 velocities_speed_4[];
163     /** Coordinates of the balls on the ejectors */
164     static ball_ejector_coords ejector_coords[];
165     /** Possible directions of a ball when
166      * a player activates the tilt */
167     static const Sint32 tilt_directions[16][16];
168     /** Directions possible that a ball can set when it leave
169      * the top-left ejector */
170     static Sint32 ball_ejector_1[];
171     /** Directions possible that a ball can set when it leave
172      * the bottom-left ejector */
173     static Sint32 ball_ejector_2[];
174     /** Directions possible that a ball can set when it leave
175      * the bottom-right ejector */
176     static Sint32 ball_ejector_3[];
177     /** Directions possible that a ball can set when it leave
178      * the top-right ejector */
179     static Sint32 ball_ejector_4[];
180     static Sint32 *ball_ejectors[];
181 
182   public:
183     sprite_ball ();
184     ~sprite_ball ();
185     static void init_collisions_points ();
186     void once_init (Sint32 start, Sint32 speed,
187                     sprite_paddle * paddle, Sint16 * table, Sint32 w);
188     void starts_again (sprite_paddle * paddle);
189     void remove (sprite_paddle * paddle);
190     void init_first_ball (Sint32 h);
191     void duplicate_from (sprite_ball * ball, Uint32 angle);
192     static Sint16 *get_velocities (Sint32 speed);
193     sprite_paddle *get_last_paddle_touched ();
194     void set_power_1 ();
195     void set_power_2 ();
196     void set_size_2 ();
197     void set_size_3 ();
198     void set_maximum_speed ();
199     void enbale_on_ejector (Uint32 eject_id, Uint32 otime);
200     void set_on_ejector (Uint32 eject_id, Uint32 otime = 1);
201     void disable_stick ();
202     void accelerate ();
203     virtual bool collision (sprite_object * sprite);
204 
205   private:
206     void set_initial_values (sprite_paddle * paddle);
207     void select_image ();
208   };
209 #endif
210