With Drag

Notes

Use the arrow keys to move the player left and right.

The player now has a DRAG component. DRAG works by applying a velocity in the opposite direction of the player movement whenever the player is not accelerating. This causes the player to slow down gradually when no keys are pressed. Note that ACCELERATION is greater than DRAG. This allows the player to slow down and change direction faster by pressing the opposite arrow key; or to coast to a stop by releasing all of the keys.

Source