diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-12-15 18:11:02 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-12-15 18:11:02 +0100 |
commit | d1ea04251bf5f77a0eeda2ce1247a17c19556a6c (patch) | |
tree | c17bf8eb9a821dd2fd7c4e20344edee0ea0b04c6 | |
parent | 4dd7ac29fe0132b9f5896a84ccfe8d05363dfa74 (diff) |
Explicit phase control for animated textures.
-rw-r--r-- | src/common.hpp | 4 | ||||
-rw-r--r-- | src/game/effects.cpp | 5 | ||||
-rw-r--r-- | src/game/units.cpp | 16 | ||||
-rw-r--r-- | src/render.cpp | 8 |
4 files changed, 18 insertions, 15 deletions
diff --git a/src/common.hpp b/src/common.hpp index c946b80..34c7b60 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -318,8 +318,8 @@ namespace render { void end_frame(void); void render(game::state_t *game); - void render(animated_texture_t *anim, rectf_t bounds, bool mirror = false); - void render(oriented_sprite_t *sprite, rectf_t bounds, float angle); + void render(double phase, animated_texture_t *anim, rectf_t bounds, bool mirror = false); + void render(double phase, oriented_sprite_t *sprite, rectf_t bounds, float angle); void render_text(v2f_t x, float height, std::string str, text_align_t align, sf::Color color); void render_rect(rectf_t rect, sf::Color color); diff --git a/src/game/effects.cpp b/src/game/effects.cpp index e80623e..306405f 100644 --- a/src/game/effects.cpp +++ b/src/game/effects.cpp @@ -51,7 +51,10 @@ fx_blood_t::fx_blood_t(state_t *game_, v2f_t x_, bool alien_) : effect_t(game_) void fx_blood_t::render_to(render::state_t *render) { - render->render(&assets::fx.blood, render_bounds); + double phase; + + phase = (game->now - ttl) + 1; + render->render(phase, &assets::fx.blood, render_bounds); } } // namespace game diff --git a/src/game/units.cpp b/src/game/units.cpp index 65f0a2c..d03ce76 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -357,11 +357,11 @@ void human_t::render_to(render::state_t *render) body_angle = move.angle; } - render->render(legs, render_bounds, move.angle); - render->render(body, render_bounds, body_angle); - render->render(&assets::human.head_idle, render_bounds, body_angle); + render->render(game->now * 10, legs, render_bounds, move.angle); + render->render(game->now * 10, body, render_bounds, body_angle); + render->render(game->now * 10, &assets::human.head_idle, render_bounds, body_angle); } else - render->render(&assets::human.dead, render_bounds); + render->render(game->now * 10, &assets::human.dead, render_bounds); unit_t::render_to(render); } @@ -370,8 +370,8 @@ alien_t::alien_t(game::state_t *game) : unit_t(game, UNIT_ALIEN) { cflags = CF_BODY_SMALL; health = max_health = 4; - size[0] = v2f_t(-0.2f, -0.2f); - size[1] = v2f_t(+0.2f, +0.2f); + size[0] = v2f_t(-0.2f, -0.3f); + size[1] = v2f_t(+0.2f, +0.3f); render_size[0] = v2f_t(-0.3f, -0.3f); render_size[1] = v2f_t(+0.3f, +0.3f); name = text::get(text::UNIT_ALIEN); @@ -432,10 +432,10 @@ void alien_t::render_to(render::state_t *render) moving = move.moving && !move.blocked; if (!dead) - render->render((moving ? &assets::alien.walking : + render->render(game->now * 20, (moving ? &assets::alien.walking : &assets::alien.idle), render_bounds, move.angle); else - render->render(&assets::alien.dead, render_bounds); + render->render(game->now * 20, &assets::alien.dead, render_bounds); unit_t::render_to(render); } diff --git a/src/render.cpp b/src/render.cpp index a7c6ba6..0e04aab 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -144,7 +144,7 @@ void state_t::render(game::state_t *game) } } -void state_t::render(animated_texture_t *anim, rectf_t bounds, bool mirror){ +void state_t::render(double phase, animated_texture_t *anim, rectf_t bounds, bool mirror){ size_t frame; if (!anim) @@ -153,7 +153,7 @@ void state_t::render(animated_texture_t *anim, rectf_t bounds, bool mirror){ if (!anim->frame_count) return; - frame = floor(fmod(now * 20.0, anim->frame_count)); + frame = floor(fmod(phase, 1.0) * anim->frame_count); wot_rect.setTexture(anim->frames + frame, true); wot_rect.setFillColor(sf::Color::White); @@ -173,13 +173,13 @@ void state_t::render(animated_texture_t *anim, rectf_t bounds, bool mirror){ wot_rect.setScale(v2f_t(1, 1)); } -void state_t::render(oriented_sprite_t *sprite, rectf_t bounds, float angle) +void state_t::render(double phase, oriented_sprite_t *sprite, rectf_t bounds, float angle) { size_t index; bool mirror; index = sprite->select_index(angle, &mirror); - render(sprite->textures + index, bounds, mirror); + render(phase, sprite->textures + index, bounds, mirror); } void state_t::render_text(v2f_t x, float height, std::string str, |