Hi,
Decelerate is handled by the friction vector. You are explicitly setting the velocity to zero when no keys are pressed, and additionally doing some "strange" things which are not very melonJS-like, and also not very Sonic-like. Here's how I changed it:
In "init", I setup the physics constants:
this.setVelocity(0.046875 * 4, 15);
this.setMaxVelocity(6 * 2, 15);
this.setFriction(0.046875 * 2, 0);
Then in the "update" method, I totally rewrote the input handling code to only set the velocity vector (ignoring the algorithm described in the physics article, because melonJS already does ALL of that for you when you call this.updateMovement). What you are left with is a very, very simple input handler:
if (me.input.isKeyPressed('left'))
// flip the sprite on horizontal axis
(this.vel.x <= 0) ? this.accel.x : this.dec.x
else if (me.input.isKeyPressed('right'))
(this.vel.x >= 0) ? this.accel.x : this.dec.x
if (me.input.isKeyPressed('jump'))
And there you go! It acts a lot more like Sonic, now. It's not a perfect clone, for sure. But it's close. And with some tweaks, you can still get it closer.
You will notice I've done a few things different with the constants. Most importantly, the Genesis Sonic games run at 30fps, so I've doubled the constants for 60fps in melonJS. Second, I've doubled the acceleration constant *AGAIN* to counteract the friction (which is applied regardless of whether you are holding directions). But overall it is very similar.
The last bit of info to divulge is that setting the velocity in the input handlers will select either the acceleration constant or the deceleration constant, depending on the direction your Sonic is already moving. It does not handle the quirk regarding max deceleration when Sonic is moving too slow. And as mentioned, it may not be worth adding that.
Give it a try, and let us know what you think!