this.width = 30
this.height = 30
this.image = spriteRight
this.frames = 0
this.sprites = {
right: spriteRight,
left: spriteLeft
};
this.currentSprite = this.sprites.right;
this.frameDelay = 0;
This makes it so the default animation is facing to the right, but it also defines right as spriteRight image and left as spriteLeft.
It also adds a frameDelay and sets the default image to spriteRight.
case 65:
console.log("left")
keys.left.pressed = true
player.currentSprite = player.sprites.left
break
...
case 68:
console.log("right")
keys.right.pressed = true
player.currentSprite = player.sprites.right
break
This makes it so when you press the d key you go right and it sets the player.currentSprite to the right image. WHen you click the a key it sets player.currentSprite to the left image.