1 #include "src/lib/16_sprit.h"
3 char* get_curr_anim_name(struct sprite *spri)
5 // Retrive animation name list
6 struct vrs_header huge *vrs = spri->spritesheet->vrs_hdr;
7 uint32_t huge *anim_names_offsets = (uint32_t huge *)
9 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_NAME_LIST]);
11 return (char *)(vrs + anim_names_offsets[spri->curr_anim]);
14 void init_anim(struct sprite *spri, int anim_index)
16 struct vrs_header huge *vrs = spri->spritesheet->vrs_hdr;
17 uint32_t huge *anim_lists_offsets = (uint32_t huge *)
19 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_LIST]);
20 struct vrs_animation_list_entry_t huge *anim_list = (struct vrs_animation_list_entry_t huge *)
22 anim_lists_offsets[anim_index]);
24 // Upon new animation, start from the first sprite in it
25 spri->curr_anim = anim_index;
26 spri->curr_anim_spri = 0;
27 spri->curr_spri_id = anim_list[0].sprite_id;
28 spri->delay = anim_list[0].delay;
30 spri->curr_anim_list = anim_list;
34 int set_anim_by_id(struct sprite *spri, int anim_id)
36 int new_anim_index = 0;
38 struct vrs_header huge *vrs = spri->spritesheet->vrs_hdr;
39 // Retruve animation ids list
40 uint16_t huge *anim_ids = (uint16_t huge *)
42 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_ID_LIST]);
44 // Loop through animation id untill match or end of list
45 while(iter_id = anim_ids[new_anim_index])
47 // Return on successful match
48 if (iter_id == anim_id)
50 init_anim(spri, new_anim_index);
58 void print_anim_ids(struct sprite *spri)
60 int new_anim_index = 0;
62 struct vrs_header huge *vrs = spri->spritesheet->vrs_hdr;
63 // Retruve animation ids list
64 uint16_t huge *anim_ids = (uint16_t huge *)
66 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_ID_LIST]);
68 if(!anim_ids[new_anim_index])
70 // Loop through animation id untill match or end of list
71 while(iter_id = anim_ids[new_anim_index])
73 // Return on successful match
79 void animate_spri(struct sprite *spri)
85 i = get_vrl_by_id(spri->spritesheet, spri->curr_spri_id, spri->sprite_vrl_cont);
88 printf("Error retriving required sprite");
91 draw_vrl1_vgax_modex( spri->x, spri->y,
92 spri->sprite_vrl_cont->vrl_header, spri->sprite_vrl_cont->line_offsets,
93 spri->sprite_vrl_cont->buffer + sizeof(struct vrl1_vgax_header),
94 spri->sprite_vrl_cont->data_size);
96 // Depending on delay, update indices
98 // Delay = 0 means that sprite should loop. Nothing to change here
102 // Delay = 1 means that on next time unit sprite should be changed
104 spri->curr_anim_spri++;
106 // If we hit the end of an animation sequence, restart it
107 if(!(spri->curr_spri_id = spri->curr_anim_list[spri->curr_anim_spri].sprite_id)){
108 spri->curr_anim_spri = 0;
109 spri->curr_spri_id = spri->curr_anim_list[spri->curr_anim_spri].sprite_id;
111 spri->delay = spri->curr_anim_list[spri->curr_anim_spri].delay;
113 // Delay > 1 means that we should not change sprite yet. Decrease delay