// no inertia: if (keyPressed[68]){ // key 'D' player.x = player.x + 10; // player moves 10px to the right(+10) each frame. } if (keyPressed[65]){ // key 'A' player.x = player.x - 10; // player moves 10px to the left(-10) each frame. } //----------------------------------- // inertia: if (keyPressed[68]){ // key 'D' player.vx = player.vx + 1; // move right: player accelerates when key pressed, speed(vx) increases. } if (keyPressed[65]){ // key 'A' player.vx = player.vx - 1; // move left: speed(vx) increases in the negative direction, e.g. -1,-2,-3. } player.x = player.x + player.vx; // player moves left or right depending on the speed(vx). player.vx = player.vx * 0.95 // friction: speed(vx) decreases every frame.