//
// This implementation imparts acceleration (change in velocity) every update, meaning the longer a key is pressed the faster the character will move.
//
update(engine, delta) {
let seconds = delta/1000; // convert from milliseconds to seconds
let accel = 2; // 2 pixels/sec/sec
ex.Actor.prototype.update.call(this, engine, delta);
if (engine.input.keyboard.isHeld(ex.Input.Keys.W)) {
this.velY = this.velY - accel * seconds;
}
if (engine.input.keyboard.isHeld(ex.Input.Keys.A)) {
this.velX = this.velX - accel * seconds;
}
if (engine.input.keyboard.isHeld(ex.Input.Keys.S)) {
this.velY = this.velY + accel * seconds;
}
if (engine.input.keyboard.isHeld(ex.Input.Keys.D)) {
this.velX = this.velX + accel * seconds;
}
this.x = this.x + this.velX;
this.y = this.y + this.velY;
}