Object-oriented code for the player
There are many reasons you may want to use object-oriented (OO) code in your game. First, it's a very good way to organize your code. Second, it provides some useful ways to reuse and extend your code.
If you are not familiar with OO programming, JavaScript is probably not the best language to learn. We won't go into the theory of OO; even without it, you should be able to see the logic behind the code we will be writing and what it brings to the table.
As we need only one player, we will create an anonymous class and instantiate it right away. This is quite unusual and only makes sense in this particular situation. Here is the skeleton of our class with all methods, but without their implementation. We will look at each of them later.
var player = new (function(){ var acceleration = 9; var speed = 20; var status = "stand"; var horizontalMove = 0; this.update = function (delta) { //... ...