LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_sprites.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2024
3  * All rights reserved
4  */
5 
6 #ifndef LG_SPRITES_H
7 #define LG_SPRITES_H
8 
9 #define LG_SPRITE_MIN_SIZE 4
10 #define LG_SPRITE_N_DRAWS_MAX 1024
11 
12 typedef struct {
13  int id; /* (So far) 0 -> OK, -1 -> invalid sprite */
14  /* === Setup at init - all images must be square and have same dims === */
15  /* === Private - don't modify === */
16  LG_Texture *atlas_texture; /* Texture atlas */
17  int atlas_side; /* = width = height (square) */
18  int image_side; /* = width = height (square) */
19  int atlas_side_for_n_images;
20  zboolean overflow;
21  /* === Public but don't modify === */
22  int n_frames;
23  int w;
24  int h;
25  zboolean was_cloned; /* Cloned objects_2d use same texture atlas as the original object */
26  /* === Modifiable members === */
27  int current_frame;
28  int x;
29  int y;
30  int motion_x;
31  int motion_y;
32  /* === Use but don't modify, set by lg_sprite_draw(LG_ON) */
33  int previous_frame;
34  int prev_x; /* Set to x after draw(LG_ON), to be used by draw(LG_OFF) */
35  int prev_y; /* Set to y after draw(LG_ON), to be used by draw(LG_OFF) */
36  int last_motion_x;
37  int last_motion_y;
38  /* Used only by lg_save/restore_sprite_position() */
39  int x_bak;
40  int y_bak;
41  /*
42  * To test ***objects collision*** if one object real size and position is
43  * very different from the object squared image
44  * Default value should be 0
45  */
46  int real_obj_diff_x;
47  int real_obj_diff_y;
48  int real_obj_diff_w;
49  int real_obj_diff_h;
50  /* === Used only in BASP === */
51  int life_counter;
52  int down_counter;
53  int teleport_counter;
54  int random_motion_counter;
55  int timer[4];
56 } LG_Sprite;
57 
58 /*
59  * Rq_SDraw_Array stands for Requested Sprite Draw Array
60  * Array of sprites to be drawed in batch - use linked list instead ?
61  */
62 typedef struct {
63  LG_Sprite *sprite[LG_SPRITE_N_DRAWS_MAX];
65 
66 /* SDL coord sys */
67 #define LG_UP (-1)
68 #define LG_DOWN (1)
69 #define LG_LEFT (-1)
70 #define LG_RIGHT (1)
71 
72 LG_Sprite lg_sprite(const char *[], LG_Color_u, int, int);
73 
75 
77 
79 
81 
83 
85 
87 
89 
91 
93 
95 
97 
98 /*void lg_move_sprite_inside_rectangle(LG_Sprite *, int, int, Rec2Di *);*/
99 
101 
103 
104 void lg_sprite_info(LG_Sprite *);
105 
107 
109 
110 #endif /* LG_SPRITES_H */
lg_sprite_is_inside_rectangle
int lg_sprite_is_inside_rectangle(LG_Sprite *sprite, Rec2Di *rect)
Definition: lg_sprites.c:414
lg_sprite_get_cur_frame
int lg_sprite_get_cur_frame(LG_Sprite *sprite)
Definition: lg_sprites.c:340
lg_sprite_set_cur_frame
void lg_sprite_set_cur_frame(LG_Sprite *sprite, int frame)
Definition: lg_sprites.c:330
Rq_SDraw_Array
Definition: lg_sprites.h:62
lg_save_sprite_position
void lg_save_sprite_position(LG_Sprite *sprite)
Definition: lg_sprites.c:671
lg_sprite_centers_collide_by_x_y
int lg_sprite_centers_collide_by_x_y(LG_Sprite *sprite1, LG_Sprite *sprite2, int x, int y)
Definition: lg_sprites.c:582
lg_sprite_draw
int lg_sprite_draw(LG_Sprite *sprite)
Definition: lg_sprites.c:254
lg_rqdraw_init
void lg_rqdraw_init(Rq_SDraw_Array *draw_list)
Definition: lg_sprites.c:753
lg_sprite_is_outside_rectangle
int lg_sprite_is_outside_rectangle(LG_Sprite *sprite, Rec2Di *rect)
Definition: lg_sprites.c:475
LG_Sprite
Definition: lg_sprites.h:12
lg_sprite_info
void lg_sprite_info(LG_Sprite *sprite)
Definition: lg_sprites.c:693
LG_Color_u
Definition: lg_vertex.h:91
lg_rqdraw_add_sprite
int lg_rqdraw_add_sprite(LG_Sprite *sprite, Rq_SDraw_Array *draw_list)
Definition: lg_sprites.c:785
lg_restore_sprite_position
void lg_restore_sprite_position(LG_Sprite *sprite)
Definition: lg_sprites.c:682
lg_clone_sprite
LG_Sprite lg_clone_sprite(LG_Sprite *sprite)
Definition: lg_sprites.c:359
lg_sprite_free_tex
void lg_sprite_free_tex(LG_Sprite *sprite)
Definition: lg_sprites.c:318
lg_sprite
LG_Sprite lg_sprite(const char *file_name[], LG_Color_u lg_color_u_key, int w, int h)
Definition: lg_sprites.c:43
lg_sprite_centers_collide_by_k
int lg_sprite_centers_collide_by_k(LG_Sprite *sprite1, LG_Sprite *sprite2, int k)
Definition: lg_sprites.c:611
lg_sprites_collide
int lg_sprites_collide(LG_Sprite *sprite1, LG_Sprite *sprite2)
Definition: lg_sprites.c:540
LG_Texture
Definition: lg_textures.h:42
lg_sprite_is_inside_rectangle_set
int lg_sprite_is_inside_rectangle_set(LG_Sprite *sprite, Rec2Di **rect)
Definition: lg_sprites.c:447
Rec2Di
Definition: lg_gr_func.h:47
lg_sprite_is_outside_rectangle_set
int lg_sprite_is_outside_rectangle_set(LG_Sprite *sprite, Rec2Di **rect)
Definition: lg_sprites.c:507