1 /**
2  * @file sprite_object.h
3  * @brief Draw sprites on the screen
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_object.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_OBJECT__
29 #define __SPRITE_OBJECT__
30 class sprite_object;
31 #include "../include/handler_display.h"
32 #include "../include/bitmap_data.h"
33 #include "../include/tecnoballz.h"
34 #include "../include/display_text_bitmap.h"
35 
36 /*
37  * sprite's ID
38  */
39 /*
40 typedef enum
41 {
42   BOB_ATOMES,
43   BOB_EJECT1,
44   BOB_EJECT2,
45   BOB_EJECT3,
46   BOB_EJECT4,
47   BOB_BRICKV,
48   BOB_BRICKH,
49   BOB_BRICKS,
50   BOB_BUMPHR,
51   BOB_BUMPVT,
52   BOB_BALLES,
53   BOB_FIREBP,
54   BOB_MONEYS,
55   BOB_GADGET,
56   BOB_LETTRE,
57   BOB_LEDSHP,
58   BOB_GAMEOV,
59   BOB_DEFILE,
60   BOB_LOGOTB,
61   BOB_MOUSE1,
62   BOB_MOUSE2,
63   BOB_GIGAB1,
64   BOB_GIGAB2,
65   BOB_GIGAB3,
66   BOB_GIGAB4,
67   BOB_GIGAB5,
68   BOB_GIGAB6,
69   BOB_GIGAB7,
70   BOB_MONEY0,
71   BOB_ROBOT0,
72   FINAL_GUARDIAN_AREA_1,
73   FINAL_GUARDIAN_AREA_2,
74   FINAL_GUARDIAN_AREA_3,
75   FINAL_GUARDIAN_AREA_4,
76   FINAL_GUARDIAN_AREA_5,
77   FINAL_GUARDIAN_AREA_6,
78   MEDIUM_GUARDIAN_AREA_1A,
79   MEDIUM_GUARDIAN_AREA_1B,
80   MEDIUM_GUARDIAN_AREA_2A,
81   MEDIUM_GUARDIAN_AREA_2B,
82   MEDIUM_GUARDIAN_AREA_3A,
83   MEDIUM_GUARDIAN_AREA_3B,
84   MEDIUM_GUARDIAN_AREA_4A,
85   MEDIUM_GUARDIAN_AREA_4B,
86   MEDIUM_GUARDIAN_AREA_5A,
87   MEDIUM_GUARDIAN_AREA_5B,
88   PADDLE_IN_GUARDIANS_LEVEL,
89   BOB_MISSIL,
90   BOB_EXPLO1,
91   BOB_EXPLO2,
92   BOB_ARGENT,
93   BOB_GRDNRJ,
94   BOB_GEMSTO,
95   BOB_WALLBO,
96   BOB_DIRECT,
97   BOB_ESCMEN,
98   BOB_MAGEYE,
99   BOB_LEDSH2,
100   BOB_BRICK1
101 }
102 BOB_ENUM;
103 */
104 
105 
106 /**
107  * Structure used to store x and y coordinates in the png image source
108  */
109 typedef struct
110   {
111     /** X-coordinate: real x = xcoord * 16 */
112     Sint16 xcoord;
113     /** Y-coordinate: real y = ycoord * 2 */
114     Sint16 ycoord;
115   }
116 sprite_coordinates;
117 
118 /**
119  * Structure used to store caracteristics of the sprite in the png image
120  * source width, height, coordinates in the png image source
121  */
122 typedef struct
123   {
124     /* real width = width * resolution */
125     Uint16 width;
126     /* real height = height * resolution */
127     Uint16 height;
128     /* number of animation(s) */
129     Uint16 number_of_images;
130     sprite_coordinates *coordinates;
131   }
132 sprite_description;
133 
134 typedef struct
135   {
136     Sint32 COUNTERTAB;            // size of table offsets / loops
137     Sint32 OFFSETLEFT;
138     Sint16 *TABAFFICH1;           // table of offsets and loops counters
139     char *TABAFFICH2;             // table of pixels
140   }
141 bb_afligne;
142 
143 class sprite_object:public virtual tecnoballz
144   {
145     friend class controller_game_over;
146     friend class controller_explosions;
147     friend class controller_guardians;
148     friend class controller_gems;
149     friend class controller_bullets;
150     friend class controller_spheres;
151     friend class display_text_bitmap;
152 
153   public:
154 
155     typedef enum
156     {
157       SHIPS,
158       EJECTOR_1,
159       EJECTOR_2,
160       EJECTOR_3,
161       EJECTOR_4,
162       VERTICAL_SIDE_BRICK,
163       HORIZONTAL_SIDE_BRICK,
164       BOB_BRICKS,
165       HORIZONTAL_PADDLE,
166       VERTICAL_PADLLE,
167       BALLS,
168       PROJECTILES,
169       MONEY,
170       CAPSULES,
171       FONT_GAME,
172       SHOP_LED_INDICATOR_320,
173       GAME_OVER_LETTERS,
174       FONT_MENU,
175       TECNOBALLZ_LOGO,
176       MOUSE_POINTER_1,
177       MOUSE_POINTER_2,
178       GIGABLITZ_1,
179       GIGABLITZ_2,
180       GIGABLITZ_3,
181       GIGABLITZ_4,
182       GIGABLITZ_5,
183       GIGABLITZ_6,
184       GIGABLITZ_7,
185       FONT_MONEY,
186       PADDLE_ROBOT,
187       FINAL_GUARDIAN_AREA_1,
188       FINAL_GUARDIAN_AREA_2,
189       FINAL_GUARDIAN_AREA_3,
190       FINAL_GUARDIAN_AREA_4,
191       FINAL_GUARDIAN_AREA_5,
192       FINAL_GUARDIAN_AREA_6,
193       MEDIUM_GUARDIAN_AREA_1A,
194       MEDIUM_GUARDIAN_AREA_1B,
195       MEDIUM_GUARDIAN_AREA_2A,
196       MEDIUM_GUARDIAN_AREA_2B,
197       MEDIUM_GUARDIAN_AREA_3A,
198       MEDIUM_GUARDIAN_AREA_3B,
199       MEDIUM_GUARDIAN_AREA_4A,
200       MEDIUM_GUARDIAN_AREA_4B,
201       MEDIUM_GUARDIAN_AREA_5A,
202       MEDIUM_GUARDIAN_AREA_5B,
203       PADDLE_IN_GUARDIANS_LEVEL,
204       BULLET,
205       EXPLOSION_1,
206       EXPLOSION_2,
207       METALLIC_SPHERE,
208       LIFE_GAUGE,
209       GEM,
210       BOTTOM_WALL,
211       VIEWFINDER,
212       POPUP_MENU,
213       MAGNETIC_EYE,
214       SHOP_LED_INDICATOR_640,
215       BRICKS,
216       NUMOF_SPRITE_TYPES
217     }
218     SPRITES_ENUM;
219 
220     typedef enum {
221       DRAW_WITH_TABLES,
222       COPY_FROM_BITMAP,
223       DRAW_LINE_BY_LINE,
224       DRAW_REPEAT_SPRITE,
225       DRAW_COLOR_CYCLING_MASK,
226       DRAW_CAPSULE,
227       DRAW_BRICK
228     }
229     DRAW_METHOD_ENUM;
230 
231   private:
232     /** List of tables of the drawing pixels data. Used for drawing sprite
233      * pixel by pixel, with color cycling.
234      * Only used for the chance capsule sprite */
235     Sint16 **drawing_pixels;
236     /** List of pointers of all images of the sprite
237      * in the source bitmap page */
238     char **images_pixel_data;
239     /** Pointer to sprite shadow in game offscreen for sprite */
240     char *shadow_screen_ptr;
241     /** Pointer to the background in restore offscreen for shadow */
242     char *shadow_restore_ptr;
243     Sint32 offsetSrce;            // offset source
244     Sint32 offsetDest;            // offset destination
245 
246     /*
247      * Drawing tables
248      */
249     /** List of tables of the drawing offsets and repeats values */
250     Sint16 **drawing_values;
251     /** Table of drawing offsets and repeats values for
252      * current sprite image frame */
253     Sint16 *current_drawing_values;
254     /** List of tables of the drawing pixels data */
255     char **drawing_data;
256     /** Data structure of drawing sprite line by line.
257      * Only used for the Gigablitz sprite */
258     bb_afligne **drawing_peer_line;
259 
260     static Sint32 ombredecax;
261     static Sint32 ombredecay;
262     static Sint32 ombrepixe4;
263     static char ombrepixel;
264 
265 
266   protected:
267     /** Table of drawing pixels data for current sprite image frame */
268     char *current_drawing_data;
269     /** Table of drawing data for current sprite image frame */
270     Sint16 *current_drawing_pixels;
271     /** Pointer to sprite in game offscreen */
272     char *screen_ptr;
273     /** Pointer to the background in restore offscreen */
274     char *restore_ptr;
275     /** The pixel data of the sprite */
276     char *pixel_data;
277     /** Width in bytes of bitmap in which is the sprite */
278     Uint32 row_size;
279     /** Width in bytes of offscreen */
280     Uint32 offscreen_pitch;
281     /** True if the sprite is enabled and drawn */
282     bool is_enabled;
283     /** True if the sprite has a shadow */
284     bool sprite_has_shadow;
285     /** X coordinate */
286     Sint32 x_coord;
287     /** Y coordinate */
288     Sint32 y_coord;
289     /** Width of the sprite in pixels */
290     Uint32 sprite_width;
291     /** Height of the sprite in pixels */
292     Uint32 sprite_height;
293     /** Time delay before next image of the animation */
294     Sint32 frame_period;
295     /** Counter time delay before next image */
296     Sint32 frame_delay;
297     /** Maximum number of images in the animation */
298     Sint32 max_of_images;
299     /** Index of the current image */
300     Sint32 frame_index;
301     Sint32 frame_index_max;
302     Sint32 frame_index_min;
303     /** Position of sprite in global list of all sprites */
304     Sint32 display_pos;
305     /** Width of the game screen in pixels */
306     Sint32 screen_width;
307     /** Height of the game screen in pixels */
308     Sint32 screen_height;
309     /** X coordinate minimum */
310     Sint32 x_minimum;
311     /** Y coordinate minimum */
312     Sint32 y_minimum;
313     /** X coordinate maximum */
314     Sint32 x_maximum;
315     /** Y coordinate maximum */
316     Sint32 y_maximum;
317     /** Type identifier of the sprite, integer from 0 to n */
318     Uint32 sprite_type_id;
319     Sint32 affligFrSv;            // premiere ligne a afficher (si afflignesF=1)
320     Sint32 affligLaSv;            // derniere ligne a afficher (si afflignesF=1)
321     /** If true, object has allocated memory for pixels of sprite */
322     bool has_allocated_memory;
323     /** Position of sprite in its list from 0 to n */
324     Sint32 object_pos;
325     /** true if the object must release
326      * the pixel data memory at its destruction */
327     bool is_release_pixel_data;
328     /** If true generate additional table to drawing pixel by pixel.
329      * Used with for color cycling */
330     bool is_draw_pixel_by_pixel;
331 
332   public:
333     /** Width used for the collisions */
334     Uint32 collision_width;
335     /** Height used for the collisions */
336     Uint32 collision_height;
337     Sint32 affligFrst;            // premiere ligne a afficher (si afflignesF=1)
338     Sint32 affligLast;            // derniere ligne a afficher (si afflignesF=1)
339     /** If true then mirror lines vertically in the initialization
340      * of the sprite */
341     bool is_mirrored_vertically;
342     Sint32 num_of_repeats;            // > 1 repeat
343     /** Current draw method used to display sprite */
344     Uint32 draw_method;
345     /** Current cycling color table index */
346     Sint32 cycling_index;
347     /** Current cycling color table used for projectiles */
348     const Sint32 *current_cycling;
349 
350   public:
351     sprite_object ();
352     virtual ~sprite_object ();
353     void clear_sprite_members ();
354     void release_sprite ();
355     void enable ();
356     void disable ();
357     bool is_enable ();
358     Uint32 get_sprite_type_id ();
359     void set_display_pos (Sint32 num);
360     void set_object_pos (Sint32 num);
361     void duplicate_to (sprite_object * sprite_dest);
362     void set_coordinates (Sint32 xcoord, Sint32 ycoord);
363     void create_sprite (Sint32 type_id, surface_sdl * bitmap, bool shadow,
364                         bool by_pixel = false);
365     void make_sprite (surface_sdl * image, bool shadow = false);
366     void init_coords_max_min(Uint32 width_less = 0);
367     void set_x_coord (Sint32 xcoord);
368     void set_y_coord (Sint32 ycoord);
369     void move_x (Sint32 x_offset);
370     void move_y (Sint32 y_offset);
371     bool has_shadow ();
372     void set_shadow (bool shadow = true);
373     Sint32 get_x_coord ();
374     Sint32 get_y_coord ();
375     void set_image ();
376     void set_image (Sint32 index);
377     Sint32 get_frame_index ();
378     void restore_background_under_sprite ();
379     void restore_line_by_line ();
380     virtual void draw ();
381     void restore_background_under_shadow ();
382     void draw_shadow ();
383     void draw_to_brackground ();
384     void draw_capsule ();
385     void draw_shadow_to_brackground ();
386     void draw_copy_from_bitmap ();
387     void copy_to_game_screen ();
388     void restore_rectangle_background ();
389     void pull (sprite_object * sprite, Sint32 xoffset = 0, Sint32 yoffset = 0);
390     void attract (sprite_object * sprite, Sint32 xoffset = 0, Sint32 yoffset = 0);
391     virtual bool collision (sprite_object * sprite);
392     virtual bool collision (Sint32 x1, Sint32 y1, Sint32 x2, Sint32 y2);
393     void set_frame_delay (Sint32 delay);
394     void set_frame_period (Sint32 period);
395     bool play_animation_once ();
396     void play_animation_loop ();
397     void new_offset (Sint32 nume);
398     void clip_coordinates ();
399     Uint32 get_sprite_width ();
400     Uint32 get_sprite_height ();
401     Uint32 get_collision_width ();
402     void enable_vertical_repeat (Uint32 numof_repeats);
403     void set_draw_method (Uint32 method);
404     void set_pixel_data (char *pixel, bool is_release = false);
405 
406   public:
407     static const Sint32 cycling_01[8];
408     static const Sint32 cycling_02[8];
409     static const sprite_description *zelistBOB[];
410 
411     void draw_with_tables ();
412   private:
413     void init_common (surface_sdl * image, bool shadow);
414     void alloc_drawing_tables (Sint32 num_images);
415     void draw_line_by_line ();
416     void draw_vertically_repeated ();
417     void draw_cycling_color ();
418     void draw_brick ();
419 
420   };
421 #endif
422