aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-02-22 22:37:18 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-02-22 22:37:18 +0000
commit8409c0fef6be37b3b5081402c1669207a1dc9ca3 (patch)
tree74a35a59860450e4915d01c8313545a242d87747 /src
parent23707911599413826ee20044cf4eeecbb8e3bdb7 (diff)
downloadPenguinYippies-8409c0fef6be37b3b5081402c1669207a1dc9ca3.tar.gz
PenguinYippies-8409c0fef6be37b3b5081402c1669207a1dc9ca3.tar.bz2
PenguinYippies-8409c0fef6be37b3b5081402c1669207a1dc9ca3.zip
Working on clicky list
Diffstat (limited to 'src')
-rw-r--r--src/animation.c1
-rw-r--r--src/clicky.c40
-rw-r--r--src/clicky.h20
-rw-r--r--src/gameScreen.c9
-rw-r--r--src/gameScreen.h2
5 files changed, 45 insertions, 27 deletions
diff --git a/src/animation.c b/src/animation.c
index d2aeb70..22bef8d 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -73,6 +73,7 @@ void runAnimation(Animation* animation)
else
{
newFrame = animation->frameCount - 1;
+ animation->playing = false;
}
}
diff --git a/src/clicky.c b/src/clicky.c
index 691aa85..3afb515 100644
--- a/src/clicky.c
+++ b/src/clicky.c
@@ -3,9 +3,27 @@
#include "assets.h"
#include "util.h"
-void updateClicky(Game* game, Clicky* clicky)
+void initClickies(Clickies* clickies)
{
- clicky->updateCB(game, clicky);
+ clickies->clickiesCount = 0;
+}
+
+void closeClickies(Clickies* clickies)
+{
+ for (int i = 0; i < clickies->clickiesCount; ++i)
+ {
+ // Yes, we shall free it using a callback it stores.
+ // Just wish I could free myself like this ):
+ clickies->clickies[i].freeCB(clickies->clickies[i]);
+ }
+}
+
+void updateClickies(Game* game, Clickies* clickies)
+{
+ for (int i = 0; i < clickies->clickiesCount; ++i)
+ {
+ clickies->clickies[i].updateCB(game, &clickies->clickies[i]);
+ }
}
void updatePenguinLol(Game* game, Clicky* clicky)
@@ -39,26 +57,26 @@ void updatePenguinLol(Game* game, Clicky* clicky)
clicky->rect, Vector2Zero(), 0.0, WHITE);
}
+void freePenginLolClicky(Clicky clicky)
+{
+ closeAnimation(&clicky.animation);
+}
+
Clicky createPenguinLolClicky(Game* game)
{
Clicky clicky;
clicky.animation = createAnimation(&game->assets.animations[PENGUIN_LOL_ANIMATION], ANIMATION_DEFAULT_DELAY);
- setAnimationFrame(&clicky.animation, 0);
+ setAnimationFrame(&clicky.animation, clicky.animation.frameCount - 1);
clicky.animation.repeat = false;
clicky.texture = NULL;
clicky.rect = (Rectangle){0.0, 0.0, 512, 512};
- clicky.colors = LoadImageColors(game->assets.animations[PENGUIN_LOL_ANIMATION].image);
-
clicky.data = NULL;
clicky.updateCB = updatePenguinLol;
+ clicky.freeCB = freePenginLolClicky;
- return clicky;
-}
+ clicky.wasClicked = false;
-void freePenginLolClicky(Clicky clicky)
-{
- closeAnimation(&clicky.animation);
- UnloadImageColors(clicky.colors);
+ return clicky;
}
diff --git a/src/clicky.h b/src/clicky.h
index 12b3b12..8a91c68 100644
--- a/src/clicky.h
+++ b/src/clicky.h
@@ -1,11 +1,14 @@
#include "gameCommon.h"
#include "animation.h"
+#define MAX_CLICKIES 256
+
#ifndef CLICKY_H
#define CLICKY_H
typedef struct Clicky Clicky;
typedef void (*ClickyUpdateCB)(Game* game, Clicky* clicky);
+typedef void (*ClickyFreeCB)(Clicky clicky);
// A fixable clicky clicky. There shall be many clicky clickies.
typedef struct Clicky {
@@ -13,18 +16,25 @@ typedef struct Clicky {
Texture* texture;
Rectangle rect;
- // Used for color collision stuff.
- Color* colors;
-
void* data;
ClickyUpdateCB updateCB;
+ ClickyFreeCB freeCB;
+
+ // Used for reacting to clicks.
+ bool wasClicked;
} Clicky;
-void updateClicky(Game* game, Clicky* clicky);
+typedef struct Clickies {
+ Clicky clickies[MAX_CLICKIES];
+ size_t clickiesCount;
+} Clickies;
+
+void initClickies(Clickies* clickies);
+void closeClickies(Clickies* clickies);
+void updateClickies(Game* game, Clickies* clickies);
// A silly silly penguin lol.
Clicky createPenguinLolClicky(Game* game);
-void freePenginLolClicky(Clicky clicky);
#endif
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 7331a22..e15a7e5 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -67,11 +67,6 @@ void initGameScreen(GameScreen* gameScreen, Game* game)
WHITE,
BLACK
);
-
- // Clickies.
- gameScreen->penguinLol = createPenguinLolClicky(game);
- gameScreen->penguinLol.rect.x = WINDOW_WIDTH / 2.0 - 256.0;
- gameScreen->penguinLol.rect.y = WINDOW_HEIGHT / 2.0 - 256.0;
}
void updateGameScreen(GameScreen* gameScreen, Game* game)
@@ -99,15 +94,11 @@ void updateGameScreen(GameScreen* gameScreen, Game* game)
updateTexturedButton(&gameScreen->rebirthButton);
updateTexturedButton(&gameScreen->statisticsButton);
- // update clickies.
- updateClicky(game, &gameScreen->penguinLol);
-
DrawFPS(0, 0);
}
void closeGameScreen(GameScreen* gameScreen)
{
closeAnimation(&gameScreen->buttonPanelSharedAnimation);
- freePenginLolClicky(gameScreen->penguinLol);
}
diff --git a/src/gameScreen.h b/src/gameScreen.h
index 0acf650..58e534c 100644
--- a/src/gameScreen.h
+++ b/src/gameScreen.h
@@ -16,8 +16,6 @@ typedef struct GameScreen {
TexturedButton achievementsButton;
TexturedButton rebirthButton;
TexturedButton statisticsButton;
-
- Clicky penguinLol;
} GameScreen;
void initGameScreen(GameScreen* gameScreen, Game* game);