diff options
author | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-21 19:29:29 +0000 |
---|---|---|
committer | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-21 19:29:29 +0000 |
commit | 1ce1a705c61064e44f83c772b70ee9b208a4c289 (patch) | |
tree | f5e593fc4ea11a2a3dd3a186679421086af4a01e | |
parent | 1a677439d001e9ef481c6e932b6ca78c3733f531 (diff) | |
download | PenguinYippies-1ce1a705c61064e44f83c772b70ee9b208a4c289.tar.gz PenguinYippies-1ce1a705c61064e44f83c772b70ee9b208a4c289.tar.bz2 PenguinYippies-1ce1a705c61064e44f83c772b70ee9b208a4c289.zip |
Working on pixal collision thingy
-rw-r--r-- | src/animation.c | 4 | ||||
-rw-r--r-- | src/clicky.c | 13 | ||||
-rw-r--r-- | src/util.c | 23 | ||||
-rw-r--r-- | src/util.h | 4 |
4 files changed, 40 insertions, 4 deletions
diff --git a/src/animation.c b/src/animation.c index 95447b2..d2aeb70 100644 --- a/src/animation.c +++ b/src/animation.c @@ -45,9 +45,9 @@ void closeAnimation(Animation* animation) void setAnimationFrame(Animation* animation, int frame) { animation->currentFrame = frame; - unsigned int nextFrameDataOffset = animation->width * animation->height * 4 * frame; + unsigned int frameOffset = animation->width * animation->height * 4 * frame; - UpdateTexture(animation->texture, ((unsigned char*)animation->asset->image.data) + nextFrameDataOffset); + UpdateTexture(animation->texture, ((unsigned char*)animation->asset->image.data) + frameOffset); } void runAnimation(Animation* animation) diff --git a/src/clicky.c b/src/clicky.c index 4f901b0..88b23ce 100644 --- a/src/clicky.c +++ b/src/clicky.c @@ -1,7 +1,7 @@ #include "clicky.h" #include "game.h" #include "assets.h" -#include <raylib.h> +#include "util.h" void updateClicky(Game* game, Clicky* clicky) { @@ -12,7 +12,16 @@ void updatePenguinLol(Game* game, Clicky* clicky) { if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { - replayAnimation(&clicky->animation); + Rectangle clickRect = clicky->rect; + clickRect.width /= 2.0; + clickRect.height /= 2.0; + clickRect.x += clickRect.width / 2.0; + clickRect.y += clickRect.height / 2.0; + + if (CheckCollisionPointRec(getScaledMousePosition(), clickRect)) + { + replayAnimation(&clicky->animation); + } } // Run animation and update. @@ -9,3 +9,26 @@ Vector2 getScaledMousePosition() return mousePosition; } + +bool doesCollideWithAnimation(Rectangle rect, Animation* animation, Vector2 point) +{ + float xScale = (float)rect.width / animation->width; + float yScale = (float)rect.height / animation->height; + + unsigned int frameOffset = animation->width * animation->height * 4 * animation->currentFrame; + + // Check each pixal. + for (int row = 0; row < rect.height; ++row) + { + for (int col = 0; col < rect.width; ++col) + { + int scaledRow = row * yScale; + int scaledCol = col * xScale; + + int pixalPosition = frameOffset + (animation->width * scaledRow + scaledCol); + + } + } + + return false; +} @@ -1,4 +1,5 @@ #include "gameCommon.h" +#include "animation.h" #include <raylib.h> #ifndef UTIL_H @@ -7,4 +8,7 @@ // Scale from the window to render texture. Vector2 getScaledMousePosition(); +// Check pixals and that fun stuff. +bool doesCollideWithAnimation(Rectangle rect, Animation* animation, Vector2 point); + #endif |