diff --git a/assets_test.c b/assets_test.c index 24124c8..4ddfacf 100644 --- a/assets_test.c +++ b/assets_test.c @@ -32,6 +32,7 @@ int main(void) Font* fnt = get_font(&assets, "testfont"); int current_frame = 0; + int elapsed = 0; while(!WindowShouldClose()) { if (IsKeyReleased(KEY_C)) @@ -49,12 +50,12 @@ int main(void) EndDrawing(); // Update the animated Sprite - spr2->elapsed++; - if (spr2->elapsed == spr2->speed) + elapsed++; + if (elapsed == spr2->speed) { current_frame++; current_frame %= spr2->frame_count; - spr2->elapsed = 0; + elapsed = 0; } } term_assets(&assets); diff --git a/engine/EC.h b/engine/EC.h index 0c1c227..3339ee0 100644 --- a/engine/EC.h +++ b/engine/EC.h @@ -186,7 +186,6 @@ typedef struct Sprite { Vector2 origin; Vector2 anchor; int frame_count; - int elapsed; int speed; char* name; } Sprite_t; @@ -207,6 +206,11 @@ typedef struct _CSprite_t { bool pause; int current_frame; float fractional; + float rotation; // Degree + float rotation_speed; // Degree / s + int elapsed; + Vector2 offset; + Color colour; } CSprite_t; typedef struct _CMoveable_t { diff --git a/particle_test.c b/particle_test.c index 97a6993..d72a8b2 100644 --- a/particle_test.c +++ b/particle_test.c @@ -63,7 +63,6 @@ int main(void) .origin = (Vector2){0, 0}, .anchor = (Vector2){tex.width / 2, tex.height / 2}, .frame_count = 0, - .elapsed = 0, .speed = 0, .name = "test_spr" }; diff --git a/run.sh b/run.sh index 99fe604..9b79a76 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,3 @@ #!/bin/sh -LSAN_OPTIONS=suppressions=./lsan_supp.txt ./build/$1 +./build.sh && LSAN_OPTIONS=suppressions=./lsan_supp.txt ./build/$1 diff --git a/scenes/game_systems.c b/scenes/game_systems.c index 4b9bdc6..6b5dfd5 100644 --- a/scenes/game_systems.c +++ b/scenes/game_systems.c @@ -2002,7 +2002,6 @@ void sprite_animation_system(Scene_t* scene) { next_idx = p_cspr->transition_func(p_ent); } - if (p_cspr->pause) return; bool reset = p_cspr->current_idx != next_idx; p_cspr->current_idx = next_idx; @@ -2010,7 +2009,14 @@ void sprite_animation_system(Scene_t* scene) SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx]; if (spr.sprite == NULL) continue; - if (reset) p_cspr->current_frame = 0; + if (reset) + { + p_cspr->fractional = 0; + p_cspr->elapsed = 0; + p_cspr->current_frame = 0; + } + + if (spr.sprite->speed == 0) continue; // Animate it (handle frame count) p_cspr->fractional += scene->delta_time; @@ -2018,12 +2024,15 @@ void sprite_animation_system(Scene_t* scene) if (p_cspr->fractional > ANIM_FRAME_RATE) { p_cspr->fractional -= ANIM_FRAME_RATE; - spr.sprite->elapsed++; - if (spr.sprite->elapsed == spr.sprite->speed) + p_cspr->elapsed++; + if (p_cspr->elapsed == spr.sprite->speed) { - p_cspr->current_frame++; - p_cspr->current_frame %= spr.sprite->frame_count; - spr.sprite->elapsed = 0; + p_cspr->elapsed = 0; + if (!p_cspr->pause) + { + p_cspr->current_frame++; + p_cspr->current_frame %= spr.sprite->frame_count; + } } } }