Java game slopes tile collision

I'm trying to figure out how I can make my player move on sloped tiles. My tiles all represent RGB values, and this is how I currently handle collisions and whether the player can move there or not:

// Go through all pixels in the level and add all data related to the level
for (int y = 0; y < img.getHeight(); y++)
    for (int x = 0; x < img.getWidth(); x++) {
    Color color     = new Color(img.getRGB(x, y));
    int red     = color.getRed();
    levelData[y][x] = red;

int tileValue = level.getLevelData()[tileY][tileX];
return switch (tileValue) {
    case TRANSPARENT_TILE, SLOPED_TILE -> false;
    default -> true;
    };

And here I check if the tile is solid, and if so, the player can move to position and I update his hitbox.x (which is the top left position of the hitbox).

boolean isTopLeftSolid = isSolid(x, y, level);
boolean isTopRightSolid = isSolid(x + width, y, level);
boolean isBottomLeftSolid = isSolid(x, y+height, level);
boolean isBottomRightSolid = isSolid(x+width, y+height, level);

if (canMoveToPosition(hitbox.x + xDirection, hitbox.y, hitbox.width, hitbox.height, level))
    hitbox.x += xDirection;


My question is, how can I adjust the player hitbox y position based on what section of a sloped tile he is standing on? I have the section of the tile he is standing on but I don't know how to update the "solidity" of a sloped tile.

boolean isTileSloped(int tileX, int tileY, Level level) {
    int tileValue = level.getLevelData()[tileY][tileX];

    if (tileValue != SLOPED_TILE)
        return false;

    float bottomLeft = hitbox.x / TILES_SIZE;
    int bottomLeftFloor = (int) Math.floor(bottomLeft);
    float difference = bottomLeft - bottomLeftFloor;
    int section = (int) (difference * 4) + 1;

    if (tileX == bottomLeftFloor) {
        System.out.println("Section " + section);
        if (section == 1) {
        // Need help here with setting the hitbox y position
        }
    }
    return true;
}
Was this page helpful?