aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/clicky.c28
-rw-r--r--src/clicky.h7
-rw-r--r--src/shop.c4
3 files changed, 32 insertions, 7 deletions
diff --git a/src/clicky.c b/src/clicky.c
index f6787b8..f3201f6 100644
--- a/src/clicky.c
+++ b/src/clicky.c
@@ -2,7 +2,9 @@
#include "game.h"
#include "assets.h"
#include "util.h"
+#include <math.h>
#include <raylib.h>
+#include <raymath.h>
void initClickies(Clickies* clickies)
{
@@ -88,11 +90,12 @@ Clicky createPenguinLolClicky(Game* game)
{
Clicky clicky;
+ clicky.type = PENGUIN_LOL_TYPE;
clicky.animation = createAnimation(&game->assets.animations[PENGUIN_LOL_ANIMATION], ANIMATION_DEFAULT_DELAY);
setAnimationFrame(&clicky.animation, clicky.animation.frameCount - 1);
clicky.animation.repeat = false;
clicky.texture = NULL;
- clicky.rect = (Rectangle){0.0, 0.0, 512.0, 512.0};
+ clicky.rect = (Rectangle){0.0, 0.0, 400.0, 400.0};
clicky.data = NULL;
clicky.updateCB = updatePenguinLol;
@@ -127,23 +130,37 @@ void updateClicker(Game* game, Clicky* clicky)
{
Clickies* clickies = &game->clickies;
+ float cloestDistance = WINDOW_WIDTH * 2.0;
+ Clicky* closestClicky = NULL;
+
for (int i = 0; i < clickies->clickiesCount; ++i)
{
Clicky* testClicky = &clickies->clickies[i];
// Same clicky lmao.
- if (testClicky == clicky)
+ if (testClicky == clicky && testClicky->type == CLICKER_TYPE)
{
continue;
}
- if (CheckCollisionRecs(clicky->rect, testClicky->rect))
+ double distance = Vector2Distance(
+ (Vector2){clicky->rect.x, clicky->rect.y},
+ (Vector2){testClicky->rect.x, testClicky->rect.y}
+ );
+
+ if (CheckCollisionRecs(clicky->rect, testClicky->rect) && distance < cloestDistance)
{
- testClicky->wasClicked = true;
- break; // Clicker only clicks one clicky
+ closestClicky = testClicky;
+ cloestDistance = distance;
}
}
+ // Clicker click the clicky.
+ if (closestClicky != NULL)
+ {
+ closestClicky->wasClicked = true;
+ }
+
clicker->timeLastClicked = currentTime;
}
@@ -168,6 +185,7 @@ Clicky createClickerClicky(Game* game)
{
Clicky clicky;
+ clicky.type = CLICKER_TYPE;
clicky.animation = createAnimation(&game->assets.animations[CLICKER_ANIMATION], ANIMATION_DEFAULT_DELAY);
playAnimation(&clicky.animation);
clicky.animation.repeat = true;
diff --git a/src/clicky.h b/src/clicky.h
index e38ecdf..8fb339d 100644
--- a/src/clicky.h
+++ b/src/clicky.h
@@ -12,8 +12,15 @@ typedef struct Clicky Clicky;
typedef void (*ClickyUpdateCB)(Game* game, Clicky* clicky);
typedef void (*ClickyFreeCB)(Clicky clicky);
+typedef enum ClickyType {
+ PENGUIN_LOL_TYPE,
+ CLICKER_TYPE
+} ClickyType;
+
// A fixable clicky clicky. There shall be many clicky clickies.
typedef struct Clicky {
+ ClickyType type;
+
Animation animation;
Texture* texture;
Rectangle rect;
diff --git a/src/shop.c b/src/shop.c
index ea9b60c..98acb97 100644
--- a/src/shop.c
+++ b/src/shop.c
@@ -38,10 +38,10 @@ void initShop(Shop* shop, Game* game)
// Entries.
shop->penguinLol = LoadTextureFromImage(assets->animations[PENGUIN_LOL_ANIMATION].image);
- shop->entries[0] = (ShopEntry){&shop->penguinLol, 10, createPenguinLolCB};
+ shop->entries[0] = (ShopEntry){&shop->penguinLol, 50, createPenguinLolCB};
shop->clicker = LoadTextureFromImage(assets->animations[CLICKER_ANIMATION].image);
- shop->entries[1] = (ShopEntry){&shop->clicker, 20, createClicker};
+ shop->entries[1] = (ShopEntry){&shop->clicker, 70, createClicker};
}
void buyThingFromShop(Shop* shop, int id, Game* game)