diff options
author | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-22 19:19:43 +0000 |
---|---|---|
committer | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-22 19:19:43 +0000 |
commit | d6c58243b7b9d90e5e23af2f3c866ddf316cb0fa (patch) | |
tree | 0ee4b8533b28eb3e3d4be034c0eb356d83b98734 /src/util.c | |
parent | 1ce1a705c61064e44f83c772b70ee9b208a4c289 (diff) | |
download | PenguinYippies-d6c58243b7b9d90e5e23af2f3c866ddf316cb0fa.tar.gz PenguinYippies-d6c58243b7b9d90e5e23af2f3c866ddf316cb0fa.tar.bz2 PenguinYippies-d6c58243b7b9d90e5e23af2f3c866ddf316cb0fa.zip |
Can now use pixel data for collision
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 31 |
1 files changed, 18 insertions, 13 deletions
@@ -10,24 +10,29 @@ Vector2 getScaledMousePosition() return mousePosition; } -bool doesCollideWithAnimation(Rectangle rect, Animation* animation, Vector2 point) +bool doesCollideWithAnimationData(Rectangle rect, void* data, int width, int height, int frame, Vector2 point) { - float xScale = (float)rect.width / animation->width; - float yScale = (float)rect.height / animation->height; + // Doesn't collide with rect. + if (!CheckCollisionPointRec(point, rect)) + { + return false; + } - unsigned int frameOffset = animation->width * animation->height * 4 * animation->currentFrame; + float xScale = (float)width / rect.width; + float yScale = (float)height / rect.height; - // 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 row = (point.y - rect.y) * yScale; + int col = (point.x - rect.x) * xScale; - int pixalPosition = frameOffset + (animation->width * scaledRow + scaledCol); + unsigned int frameOffset = width * height * frame; - } + // Position of the apha byte in the color. + unsigned int position = (frameOffset + (width * row + col)) * 4 + 3; + + // Check apha at position. + if (*(((unsigned char*)data) + position) != 0x00) + { + return true; } return false; |