javascript – Problem with the detection of collisions on canvas platforms

To have many problems with my collision detection in my platform game. If you go straight to the right the block will float. Also the corners allow the block to sink and the walls are sticky. It is a bit of a disaster. I know that because of buoyancy, my gravity is a big problem. If someone could help me, I would be so happy.

Here is the collision code:


  
  
  
  const calculatedTileSize = 1.0 / mapTileSize;
const nextX = guy.x + guy.velX;
const nextY = guy.y + guy.velY;


const currentMinX = (guy.x * calculatedTileSize) | 0;
const currentMaxX = ((guy.x + guy.width) * calculatedTileSize) | 0;
const currentMinY = (guy.y * calculatedTileSize) | 0;
const currentMaxY = ((guy.y + guy.height) * calculatedTileSize) | 0;

const nextMinX = (nextX * calculatedTileSize) | 0;
const nextMaxX = ((nextX + guy.width) * calculatedTileSize) | 0;
const nextMinY = (nextY * calculatedTileSize) | 0;
const nextMaxY = ((nextY + guy.height) * calculatedTileSize) | 0;


// Collision of the X axis
yes (guy.velX! == 0.0) {
for (be i = nextMinX; i <= nextMaxX; i ++) {
for (be j = currentMinY; j <= currentMaxY; j ++) {
yes (map)[j][i]) {
guy.velX = 0.0;
break;
}
}
}
}

// Collision of the Y axis
if (guy.velY! == 0.0) {
for (be j = nextMinY; j <= nextMaxY; j ++) {
for (be i = currentMinX; i <= currentMaxX; i ++) {
yes (map)[j][i]) {
guy.velY = 0.0;
physics.gravity = 0;
} else {
physical value = 0.4;
}
}
}
}

The complete game is in this codepen:

https://codepen.io/charlie1172/pen/OeGdvJ