on the top, left side of your canvas the x and y values are 0. So the width and height doesn't matter. You need to detect if the player is less than 10 as once you go left or above the canvas you get into the negatives.
If you want to make that look fancier I would base it off your key press instead.
Code: Select all
if (player.isDownKey && player.y < canvas.width - 5)
{
move player down
}
This way if the player is on the edge of the canvas and tries to push down it wont move but they can push up. It keeps the jumping out of the animation when they hit a wall.