character: fix stopping of non-repeating reversed spritesheets

This commit is contained in:
Sebastian Krzyszkowiak 2019-10-06 08:03:30 +02:00
parent 1d6dc5e0d0
commit 11267cd3b1
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 19 additions and 1 deletions

View file

@ -531,7 +531,7 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
} else {
if (character->repeats == 0) {
if (character->reversed) {
character->pos = 1;
character->pos = 0;
} else {
character->pos = character->spritesheet->frame_count - 1;
}

View file

@ -68,9 +68,27 @@ static void character_spritesheet_stops(void** state) {
assert_int_equal(character->pos, 2);
}
static void character_spritesheet_reversed_stops(void** state) {
struct Game* game = *state;
struct Character* character = CreateCharacter(game, "test");
RegisterSpritesheet(game, character, "animation");
SelectSpritesheet(game, character, "-animation");
assert_int_equal(character->pos, 2);
AnimateCharacter(game, character, 0.1, 1.0);
assert_int_equal(character->pos, 1);
AnimateCharacter(game, character, 0.1, 1.0);
assert_int_equal(character->pos, 0);
AnimateCharacter(game, character, 0.1, 1.0);
assert_int_equal(character->pos, 0);
AnimateCharacter(game, character, 0.1, 1.0);
assert_int_equal(character->pos, 0);
}
int test_character(void) {
const struct CMUnitTest character_tests[] = {
cmocka_unit_test(character_spritesheet_stops),
cmocka_unit_test(character_spritesheet_reversed_stops),
};
return cmocka_run_group_tests(character_tests, character_setup, character_teardown);
}