1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\r
6 * Project 16 is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Project 16 is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
\r
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
\r
19 * Fifth Floor, Boston, MA 02110-1301 USA.
\r
23 #include "src/lib/16_sprit.h"
\r
25 char* get_curr_anim_name(struct sprite *spri)
\r
27 // Retrive animation name list
\r
28 struct vrs_header far *vrs = spri->spritesheet->vrs_hdr;
\r
29 uint32_t far *anim_names_offsets = (uint32_t far *)
\r
31 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_NAME_LIST]);
\r
33 return (char *)(vrs + anim_names_offsets[spri->curr_anim]);
\r
36 void init_anim(struct sprite *spri, int anim_index)
\r
38 struct vrs_header far *vrs = spri->spritesheet->vrs_hdr;
\r
39 uint32_t far *anim_lists_offsets = (uint32_t far *)
\r
41 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_LIST]);
\r
42 struct vrs_animation_list_entry_t far *anim_list = (struct vrs_animation_list_entry_t far *)
\r
44 anim_lists_offsets[anim_index]);
\r
46 // Upon new animation, start from the first sprite in it
\r
47 spri->curr_anim = anim_index;
\r
48 spri->curr_anim_spri = 0;
\r
49 spri->curr_spri_id = anim_list[0].sprite_id;
\r
50 spri->delay = anim_list[0].delay;
\r
52 spri->curr_anim_list = anim_list;
\r
56 int set_anim_by_id(struct sprite *spri, int anim_id)
\r
58 int new_anim_index = 0;
\r
60 struct vrs_header far *vrs = spri->spritesheet->vrs_hdr;
\r
61 // Retruve animation ids list
\r
62 uint16_t far *anim_ids = (uint16_t far *)
\r
64 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_ID_LIST]);
\r
66 // Loop through animation id untill match or end of list
\r
67 while(iter_id = anim_ids[new_anim_index])
\r
69 // Return on successful match
\r
70 if (iter_id == anim_id)
\r
72 init_anim(spri, new_anim_index);
\r
80 void print_anim_ids(struct sprite *spri)
\r
82 int new_anim_index = 0;
\r
84 struct vrs_header far *vrs = spri->spritesheet->vrs_hdr;
\r
85 // Retruve animation ids list
\r
86 uint16_t far *anim_ids = (uint16_t far *)
\r
88 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_ID_LIST]);
\r
90 if(!anim_ids[new_anim_index])
\r
92 // Loop through animation id untill match or end of list
\r
93 while(iter_id = anim_ids[new_anim_index])
\r
95 printf("s%d ", iter_id);
\r
101 void animate_spri(struct sprite *spri, global_game_variables_t *gvar)
\r
107 i = get_vrl_by_id(spri->spritesheet, spri->curr_spri_id, spri->sprite_vrl_cont);
\r
110 Quit (gvar, "Error retriving required sprite");
\r
112 draw_vrl1_vgax_modex( spri->x, spri->y,
\r
113 spri->sprite_vrl_cont->vrl_header, spri->sprite_vrl_cont->line_offsets,
\r
114 spri->sprite_vrl_cont->buffer + sizeof(struct vrl1_vgax_header),
\r
115 spri->sprite_vrl_cont->data_size);
\r
117 // Depending on delay, update indices
\r
118 switch(spri->delay){
\r
119 // Delay = 0 means that sprite should loop. Nothing to change here
\r
123 // Delay = 1 means that on next time unit sprite should be changed
\r
125 spri->curr_anim_spri++;
\r
127 // If we hit the end of an animation sequence, restart it
\r
128 if(!(spri->curr_spri_id = spri->curr_anim_list[spri->curr_anim_spri].sprite_id)){
\r
129 spri->curr_anim_spri = 0;
\r
130 spri->curr_spri_id = spri->curr_anim_list[spri->curr_anim_spri].sprite_id;
\r
132 spri->delay = spri->curr_anim_list[spri->curr_anim_spri].delay;
\r
134 // Delay > 1 means that we should not change sprite yet. Decrease delay
\r