Preview:
void movePlayer(float player[], float bullet[], float shroom[][2], int maxShrooms) {
    float movementSpeed = 5.0f;
    int bottomLimit = resolutionY - (6 * boxPixelsY); // Calculate the bottom limit

    bool collisionUp = false;
    bool collisionDown = false;
    bool collisionLeft = false;
    bool collisionRight = false;

    // Check for collision with mushrooms in each direction
    for (int i = 0; i < maxShrooms; i++) {
        if (shroom[i][exists]) {
            // Check collision with each mushroom
            // Define collision range around the mushrooms
            float collisionRange = 16.0f; // Adjust this value as needed

            // Check collision in each direction
            if (player[x] + boxPixelsX > shroom[i][x] - collisionRange &&
                player[x] < shroom[i][x] + boxPixelsX + collisionRange &&
                player[y] + boxPixelsY > shroom[i][y] - collisionRange &&
                player[y] < shroom[i][y] + boxPixelsY + collisionRange) {
                // Collision occurred, set collision flags based on direction
                if (player[y] > shroom[i][y]) {
                    collisionUp = true;
                }
                if (player[y] < shroom[i][y]) {
                    collisionDown = true;
                }
                if (player[x] > shroom[i][x]) {
                    collisionLeft = true;
                }
                if (player[x] < shroom[i][x]) {
                    collisionRight = true;
                }
            }
        }
    }
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter