Why the collisions in this p5library game don’t ajust to the sprite?

I’m starting to use this library and I’m not quite sure how things work. I got the base from a YouTube video and then tried adding things myself. The problem is that the frog sprite sinks into the platforms, so I suppose the problem is that either the frog image is too big for the sprite or it’s wrong. It could also be that the collisions with the platforms are off or lower than normal, making it look like the frog is sinking instead of staying on top of the platform.

This is the full code:


let groundFloor;
let player;
let floors;
let score = 0;
let score_max = 0; 
let music;
let rana;
let sea; 
let seaLevel = 0; 
let gameOver = false; 
let restartButton; 
let seaSpeed = 0.5; 
let seaAccelerationInterval; 

// Precargar la imagen y el sonido
function preload() {
  rana = loadImage('../img/rana_salta.png');
  music = loadSound('../sonido/SonidoJuego.mp3');
}

function setup() {
  // Tamaño pantalla
  let canvas = createCanvas(400, 600);
  // Asegurar que el canvas está en el centro
  canvas.parent('gameContainer'); 
  // Gravedad
  world.gravity.y = 10;

  // Piso del suelo (a una altura y estático)
  groundFloor = new Sprite(0, height - 20, width * 2, 20, 's');

  // Pared izquierda en el extremo del groundFloor
  leftWall = new Sprite(-groundFloor.w / 2 + 10, height / 2, 20, height * 100, 's');
  // Pared derecha en el extremo del groundFloor
  rightWall = new Sprite(groundFloor.w / 2 - 10, height / 2, 20, height * 100, 's');

  // Jugador
  player = new Sprite(width / 2, height - 100, 40, 40, 'd');
  player.rotationLock = true;
  player.image = rana;
  player.scale = 0.05;

  // Mar
  // Iniciar el mar más abajo
  sea = new Sprite(0, height + 300, width * 2, 200, 's'); 
  sea.color = 'blue'; 

  floors = new Group();

  // Pisos
  for (let i = 0; i < 100; i++) {
    let f = new floors.Sprite();
    f.w = random(20, 100);
    f.h = 20;
    f.collider = 's';
    f.x = random(leftWall.x + leftWall.w / 2, rightWall.x - rightWall.w / 2); // Generar pisos entre las paredes
    f.y = player.y - (i * 50);
  }
  
  music.loop();

  // Configurar intervalo para acelerar el mar
  startSeaAcceleration();
}

function draw() {
  clear();
  background(0);

  if (!gameOver) {
    // Actualizar la posición del mar
    sea.y -= seaSpeed; 

    // Actualizar el nivel del mar
    seaLevel = floor((height + 300 - sea.y) * 0.5);

    // Verificar colisión con el mar
    if (player.colliding(sea)) {
      endGame(); 
    }

    // Score
    // Para que no sea menor a 0
    if (player.y > 0) {
      score = 0;
    } else {
      // Redondea la posición y del jugador hacia abajo
      score = floor((player.y * -1));
    }

    // Actualizar score_max
    if (score > score_max) {
      score_max = score;
    }

    camera.off();

    //Textos
    textSize(20); 
    fill(255);
    text(`Score: ${score}`, 10, 30); 
    text(`Max Score: ${score_max}`, 10, 60); 
    text(`Sea Level: ${seaLevel}`, 10, 90); 
    camera.on();

    // Fijar la cámara en el jugador
    camera.x = player.x;
    camera.y = player.y;
    camera.zoom = 2;

    // Controles
    // Moverse
    if (kb.pressing('a')) {
      player.x -= 2; 
    } else if (kb.pressing('d')) {
      player.x += 2; 
    }
    // Saltar solo si estás tocando superficies
    if (kb.presses('space') && (player.colliding(floors) || player.colliding(groundFloor))) {
      player.vel.y = -10; 
    }

    spawnFloors();
  } else {
    showGameOverScreen();
  }
}

// Función para configurar el intervalo de aceleración del mar
function startSeaAcceleration() {
  seaAccelerationInterval = setInterval(() => {
    seaSpeed *= 1.05; // Aumentar la velocidad del mar en un 5%
  }, 10000); // Cada 10 segundos
}

// Función para terminar el juego y mostrar la pantalla de "Has perdido"
function endGame() {
  gameOver = true;
  noLoop(); // Detener el bucle de dibujo de p5.js
  clearInterval(seaAccelerationInterval); // Detener la aceleración del mar

  // Crear botón de reiniciar
  restartButton = createButton('Reiniciar');
  restartButton.position((windowWidth / 2) - 50, (windowHeight / 2));
  restartButton.mousePressed(resetGame);
}

// Función para reiniciar el juego
function resetGame() {
  gameOver = false;
  player.x = width / 2;
  player.y = height - 100;
  score = 0;
  sea.y = height + 300; 
  seaSpeed = 0.5; 
  floors.removeAll();

  // Recrear los pisos iniciales
  for (let i = 0; i < 100; i++) {
    let f = new floors.Sprite();
    f.w = random(20, 100);
    f.h = 20;
    f.collider = 's';
    // Generar pisos entre las paredes
    f.x = random(leftWall.x + leftWall.w / 2, rightWall.x - rightWall.w / 2); 
    f.y = player.y - (i * 50);
  }

  // Eliminar botón de reiniciar
  restartButton.remove();
  loop(); // Reiniciar el bucle de dibujo

  // Reiniciar la aceleración del mar
  startSeaAcceleration();
}

// Función para mostrar la pantalla de "Has perdido"
function showGameOverScreen() {
  camera.off();
  textSize(50);
  fill(255);
  textAlign(CENTER, CENTER);
  text('Has perdido', width / 2, height / 2 - 100);
  camera.on();
}

function spawnFloors() {
  if (player.y < floors[floors.length - 1].y) {
    let f = new floors.Sprite();
    f.w = random(20, 100);
    f.h = 20;
    f.collider = 's';
    f.x = random(leftWall.x + leftWall.w / 2, rightWall.x - rightWall.w / 2); // Generar pisos entre las paredes
    f.y = player.y - random(50, 100);
  }
}

As i said i think the problem is in this specifics parts:

player = new Sprite(width / 2, height - 100, 40, 40, 'd');
 player.rotationLock = true;
 player.image = rana;
 player.scale = 0.05;

/ Pisos
 for (let i = 0; i < 100; i++) {
   let f = new floors.Sprite();
   f.w = random(20, 100);
   f.h = 20;
   f.collider = 's';
   f.x = random(leftWall.x + leftWall.w / 2, rightWall.x - rightWall.w / 2); // Generar pisos entre las paredes
   f.y = player.y - (i * 50);
 }

I have tried making the sprite smaller and even adjusting the player’s scale up and down, but I’m not sure how to fix the collisions with the platforms.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật