diff options
author | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-16 17:38:55 +0000 |
---|---|---|
committer | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-16 17:38:55 +0000 |
commit | 3631e9c1888d2d2e43e85af654fc0544594795f2 (patch) | |
tree | b74484a01b59971c0c60a96ac637ca3113e50e4c | |
parent | 2a3b0c6057d913d931d5db361b004c89e78d0385 (diff) | |
download | PenguinYippies-3631e9c1888d2d2e43e85af654fc0544594795f2.tar.gz PenguinYippies-3631e9c1888d2d2e43e85af654fc0544594795f2.tar.bz2 PenguinYippies-3631e9c1888d2d2e43e85af654fc0544594795f2.zip |
Animation play and pause working
-rw-r--r-- | src/animation.c | 19 | ||||
-rw-r--r-- | src/animation.h | 4 | ||||
-rw-r--r-- | src/mainMenu.c | 10 |
3 files changed, 30 insertions, 3 deletions
diff --git a/src/animation.c b/src/animation.c index 52210ae..1a2f612 100644 --- a/src/animation.c +++ b/src/animation.c @@ -31,6 +31,8 @@ Animation createAnimation(AnimationAsset* asset, double delay) animation.delay = delay; animation.lastTime = -1.0; // -1.0 for no last time. + animation.playing = false; + return animation; } @@ -49,6 +51,11 @@ void setAnimationFrame(Animation* animation, int frame) void runAnimation(Animation* animation) { + if (!animation->playing) + { + return; + } + double currentTime = GetTime(); if (animation->lastTime == -1.0 || currentTime - animation->lastTime >= animation->delay) @@ -68,7 +75,19 @@ void runAnimation(Animation* animation) } } +void playAnimation(Animation* animation) +{ + animation->playing = true; + animation->lastTime = -1.0; +} + void pauseAnimation(Animation* animation) { + animation->playing = false; +} + +void toggleAnimation(Animation* animation) +{ + animation->playing = !animation->playing; animation->lastTime = -1.0; } diff --git a/src/animation.h b/src/animation.h index 6a632eb..693383b 100644 --- a/src/animation.h +++ b/src/animation.h @@ -28,6 +28,8 @@ typedef struct Animation { // Timing the frames. double delay; double lastTime; + + bool playing; } Animation; AnimationAsset loadAnimationAssetFromFile(const char* fileName); @@ -40,6 +42,8 @@ void closeAnimation(Animation* animation); void setAnimationFrame(Animation* animation, int frame); void runAnimation(Animation* animation); +void playAnimation(Animation* animation); void pauseAnimation(Animation* animation); +void toggleAnimation(Animation* animation); #endif diff --git a/src/mainMenu.c b/src/mainMenu.c index e5d3b60..370b71f 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -1,12 +1,11 @@ #include "mainMenu.h" #include "game.h" #include "assets.h" -#include <raylib.h> void initMainMenu(MainMenu* mainMenu, Game* game) { mainMenu->startButtonAnimation = createAnimation( - &game->assets.animations[BUTTON_BOX_ANIMATION], + &game->assets.animations[PENGUIN_LOL_ANIMATION], ANIMATION_DEFAULT_DELAY ); } @@ -15,9 +14,14 @@ void updateMainMenu(MainMenu* mainMenu, Game* game) { ClearBackground(RAYWHITE); - DrawTextureEx(mainMenu->startButtonAnimation.texture, (Vector2){100.0, 100.0}, 0.0, 1.0, WHITE); + DrawTextureEx(mainMenu->startButtonAnimation.texture, (Vector2){100.0, 100.0}, 0.0, 0.1, WHITE); runAnimation(&mainMenu->startButtonAnimation); + if (IsKeyPressed(KEY_SPACE)) + { + toggleAnimation(&mainMenu->startButtonAnimation); + } + DrawFPS(0, 0); } |