So I tried writing a collide function that is identical to code.org's collide() for sprites. I don't know how to implement this so I just made a function. Any ideas?
function collide(sprite, width, height) {
if (player.x + player.width >= sprite.x && player.x <= sprite.x + width) {
player.ld = true;
player.x--;
} else {
player.ld = false;
}
if (player.x <= sprite.x + sprite.width && player.x + player.width >= sprite.x) {
player.rd = true;
player.x--;
} else {
player.rd = false;
}
}
Note: the parameters width and height are for the scaled width and height of the sprite. rd and ld disable the player from moving furthr in and subtracts/adds to their position to prevent them from touching.