aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-02-21 18:50:36 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-02-21 18:50:36 +0000
commitc11c0383fc4609dd67012d9e3aa44b7fa58c999c (patch)
tree6152ba5d513b98b617d85b01d44068b8abf1d1ab
parent2416dc256e53c431c5226827d90cf504f190f9ec (diff)
downloadPenguinYippies-c11c0383fc4609dd67012d9e3aa44b7fa58c999c.tar.gz
PenguinYippies-c11c0383fc4609dd67012d9e3aa44b7fa58c999c.tar.bz2
PenguinYippies-c11c0383fc4609dd67012d9e3aa44b7fa58c999c.zip
Better animation and clicky stuff
-rw-r--r--src/animation.c17
-rw-r--r--src/animation.h4
-rw-r--r--src/clicky.c21
-rw-r--r--src/clicky.h2
-rw-r--r--src/mainMenu.h1
5 files changed, 40 insertions, 5 deletions
diff --git a/src/animation.c b/src/animation.c
index 1a2f612..95447b2 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -28,6 +28,7 @@ Animation createAnimation(AnimationAsset* asset, double delay)
animation.width = asset->image.width;
animation.height = asset->image.height;
+ animation.repeat = true;
animation.delay = delay;
animation.lastTime = -1.0; // -1.0 for no last time.
@@ -65,7 +66,14 @@ void runAnimation(Animation* animation)
if (newFrame >= animation->frameCount)
{
- newFrame = 0;
+ if (animation->repeat)
+ {
+ newFrame = 0;
+ }
+ else
+ {
+ newFrame = animation->frameCount - 1;
+ }
}
// Set the frame
@@ -81,6 +89,13 @@ void playAnimation(Animation* animation)
animation->lastTime = -1.0;
}
+void replayAnimation(Animation* animation)
+{
+ animation->playing = true;
+ animation->lastTime = -1.0;
+ setAnimationFrame(animation, 0);
+}
+
void pauseAnimation(Animation* animation)
{
animation->playing = false;
diff --git a/src/animation.h b/src/animation.h
index 693383b..241ca44 100644
--- a/src/animation.h
+++ b/src/animation.h
@@ -25,7 +25,8 @@ typedef struct Animation {
int width;
int height;
- // Timing the frames.
+ // Timing the frames and other stuff.
+ bool repeat;
double delay;
double lastTime;
@@ -42,6 +43,7 @@ void closeAnimation(Animation* animation);
void setAnimationFrame(Animation* animation, int frame);
void runAnimation(Animation* animation);
+void replayAnimation(Animation* animation);
void playAnimation(Animation* animation);
void pauseAnimation(Animation* animation);
void toggleAnimation(Animation* animation);
diff --git a/src/clicky.c b/src/clicky.c
index a1ab910..d8d64f9 100644
--- a/src/clicky.c
+++ b/src/clicky.c
@@ -1,10 +1,26 @@
#include "clicky.h"
#include "game.h"
#include "assets.h"
+#include <raylib.h>
+
+void updateClicky(Game* game, Clicky* clicky)
+{
+ clicky->updateCB(game, clicky);
+}
void updatePenguinLol(Game* game, Clicky* clicky)
{
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
+ {
+ replayAnimation(&clicky->animation);
+ }
+ // Run animation and update.
+ runAnimation(&clicky->animation);
+
+ Texture texture = clicky->animation.texture;
+ DrawTexturePro(texture, (Rectangle){0.0, 0.0, texture.width, texture.height},
+ clicky->rect, Vector2Zero(), 0.0, WHITE);
}
Clicky createPenguinLolClicky(Game* game)
@@ -12,14 +28,13 @@ Clicky createPenguinLolClicky(Game* game)
Clicky clicky;
clicky.animation = createAnimation(&game->assets.animations[PENGUIN_LOL_ANIMATION], ANIMATION_DEFAULT_DELAY);
- clicky.texture = &clicky.animation.texture;
+ clicky.animation.repeat = false;
+ clicky.texture = NULL;
clicky.rect = (Rectangle){0.0, 0.0, 128.0, 128.0};
clicky.data = NULL;
clicky.updateCB = updatePenguinLol;
- runAnimation(&clicky.animation);
-
return clicky;
}
diff --git a/src/clicky.h b/src/clicky.h
index 283b5c0..764df00 100644
--- a/src/clicky.h
+++ b/src/clicky.h
@@ -17,6 +17,8 @@ typedef struct Clicky {
ClickyUpdateCB updateCB;
} Clicky;
+void updateClicky(Game* game, Clicky* clicky);
+
// A silly silly penguin lol.
Clicky createPenguinLolClicky(Game* game);
void freePenginLolClicky(Clicky clicky);
diff --git a/src/mainMenu.h b/src/mainMenu.h
index 1396183..58f383e 100644
--- a/src/mainMenu.h
+++ b/src/mainMenu.h
@@ -1,6 +1,7 @@
#include "gameCommon.h"
#include "animation.h"
#include "ui.h"
+#include "clicky.h"
#ifndef MAIN_MENU_H
#define MAIN_MENU_H