1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
4 * This file is part of Project 16.
6 * Project 16 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
19 * Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "src/lib/16_sprit.h"
24 char* get_curr_anim_name(struct sprite *spri)
26 // Retrive animation name list
27 struct vrs_header huge *vrs = spri->spritesheet->vrs_hdr;
28 uint32_t huge *anim_names_offsets = (uint32_t huge *)
30 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_NAME_LIST]);
32 return (char *)(vrs + anim_names_offsets[spri->curr_anim]);
35 void init_anim(struct sprite *spri, int anim_index)
37 struct vrs_header huge *vrs = spri->spritesheet->vrs_hdr;
38 uint32_t huge *anim_lists_offsets = (uint32_t huge *)
40 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_LIST]);
41 struct vrs_animation_list_entry_t *anim_list = (struct vrs_animation_list_entry_t huge *)
43 anim_lists_offsets[anim_index]);
45 // Upon new animation, start from the first sprite in it
46 spri->curr_anim = anim_index;
47 spri->curr_anim_spri = 0;
48 spri->curr_spri_id = anim_list[0].sprite_id;
49 spri->delay = anim_list[0].delay;
51 spri->curr_anim_list = anim_list;
55 int set_anim_by_id(struct sprite *spri, int anim_id)
57 int new_anim_index = 0;
59 struct vrs_header huge *vrs = spri->spritesheet->vrs_hdr;
60 // Retruve animation ids list
61 uint16_t huge *anim_ids = (uint16_t huge *)
63 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_ID_LIST]);
65 // Loop through animation id untill match or end of list
66 while(iter_id = anim_ids[new_anim_index])
68 // Return on successful match
69 if (iter_id == anim_id)
71 init_anim(spri, new_anim_index);
79 void print_anim_ids(struct sprite *spri)
81 int new_anim_index = 0;
83 struct vrs_header huge *vrs = spri->spritesheet->vrs_hdr;
84 // Retruve animation ids list
85 uint16_t huge *anim_ids = (uint16_t huge *)
87 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_ID_LIST]);
89 if(!anim_ids[new_anim_index])
91 // Loop through animation id untill match or end of list
92 while(iter_id = anim_ids[new_anim_index])
94 // Return on successful match
96 printf("%d, ", iter_id);
101 void animate_spri(struct sprite *spri)
106 get_vrl_by_id(spri->spritesheet, spri->curr_spri_id, spri->sprite_vrl_cont);
107 draw_vrl1_vgax_modex( spri->x, spri->y,
108 spri->sprite_vrl_cont->vrl_header, spri->sprite_vrl_cont->line_offsets,
109 spri->sprite_vrl_cont->buffer + sizeof(struct vrl1_vgax_header),
110 spri->sprite_vrl_cont->data_size);
112 // Depending on delay, update indices
114 // Delay = 0 means that sprite should loop. Nothing to change here
118 // Delay = 1 means that on next time unit sprite should be changed
120 spri->curr_anim_spri++;
122 // If we hit the end of an animation sequence, restart it
123 if(!(spri->curr_spri_id = spri->curr_anim_list[spri->curr_anim_spri].sprite_id)){
124 spri->curr_anim_spri = 0;
125 spri->curr_spri_id = spri->curr_anim_list[spri->curr_anim_spri].sprite_id;
127 spri->delay = spri->curr_anim_list[spri->curr_anim_spri].delay;
129 // Delay > 1 means that we should not change sprite yet. Decrease delay