character: add support for repeating animation with successor

plus update README
This commit is contained in:
Sebastian Krzyszkowiak 2017-03-04 19:54:48 +01:00
parent c472bd861c
commit 31f173f2a8
3 changed files with 19 additions and 4 deletions

View file

@ -20,6 +20,7 @@ Used by such games as:
- [Jam Fighter](https://github.com/dos1/jamfighter)
- [WAAAA](https://github.com/dos1/waaaa)
- [Fajer](https://github.com/dos1/fajer)
- [Doctor von Wissenschäftler Strikes Again](https://github.com/dos1/dwsa)
WIP: The engine is being separated from its games and modularized right now. Stay tuned for documentation and examples soon!

View file

@ -42,6 +42,7 @@ SYMBOL_EXPORT void SelectSpritesheet(struct Game *game, struct Character *charac
} else {
character->successor = NULL;
}
character->repeat = tmp->repeat;
character->pos = 0;
if (character->bitmap) {
if ((al_get_bitmap_width(character->bitmap) != tmp->width / tmp->cols) || (al_get_bitmap_height(character->bitmap) != tmp->height / tmp->rows)) {
@ -110,6 +111,12 @@ SYMBOL_EXPORT void RegisterSpritesheet(struct Game *game, struct Character *char
s->rows = atoi(al_get_config_value(config, "", "rows"));
s->blanks = atoi(al_get_config_value(config, "", "blanks"));
s->delay = atof(al_get_config_value(config, "", "delay"));
char* val = al_get_config_value(config, "", "repeat");
if (val) {
s->repeat = atof(val);
} else {
s->repeat = 0;
}
s->kill = false;
const char *kill = al_get_config_value(config, "", "kill");
if (kill) s->kill = atoi(kill);
@ -138,6 +145,7 @@ SYMBOL_EXPORT struct Character* CreateCharacter(struct Game *game, char* name) {
character->spritesheets = NULL;
character->spritesheet = NULL;
character->successor = NULL;
character->repeat = 0;
character->shared = false;
character->dead = false;
return character;
@ -174,10 +182,14 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game *game, struct Character *charact
}
if (character->pos>=character->spritesheet->cols*character->spritesheet->rows-character->spritesheet->blanks) {
character->pos=0;
if (character->spritesheet->kill) {
character->dead = true;
} else if (character->successor) {
SelectSpritesheet(game, character, character->successor);
if (character->repeat) {
character->repeat--;
} else {
if (character->spritesheet->kill) {
character->dead = true;
} else if (character->successor) {
SelectSpritesheet(game, character, character->successor);
}
}
}
}

View file

@ -37,6 +37,7 @@ struct Spritesheet {
int height;
int delay;
bool kill;
int repeat;
float scale; /*!< Scale modifier of the frame. */
char* successor; /*!< Name of animation successor. If it's not blank, then animation will be played only once. */
struct Spritesheet* next; /*!< Next spritesheet in the queue. */
@ -55,6 +56,7 @@ struct Character {
float y; /*!< Vertical position of character. */
float angle; /*!< Characters display angle (radians). */
void* data; /*!< Additional, custom character data (HP etc.). */
int repeat;
bool shared;
bool dead;
};