mr-crocs-adventures/js/Movable.js

47 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-01-22 22:50:45 +01:00
import GeometryPoint from "./geometry/GeometryPoint.js";
export default class Movable
{
constructor(defaultAnimation, speed = 1)
{
this.currentAnimation = 'DEFAULT';
this.animations = {
DEFAULT: defaultAnimation,
};
this.position = new GeometryPoint();
this.speed = speed;
2020-01-23 23:09:03 +01:00
this.fallSpeed = 0;
2020-01-22 22:50:45 +01:00
}
playAnimation(animation, timestamp)
{
this.currentAnimation = animation;
this.animations[animation].play(timestamp);
}
addAnimation(name, animation)
{
this.animations[name] = animation;
}
moveLeft(delta = 1)
{
this.position.x -= this.speed * delta;
}
moveRight(delta = 1)
{
this.position.x += this.speed * delta;
}
2020-01-23 23:09:03 +01:00
getRect()
{
return this.animations[this.currentAnimation].getRect();
}
2020-01-22 22:50:45 +01:00
draw(context)
{
this.animations[this.currentAnimation].setFootPosition(this.position.x, this.position.y);
this.animations[this.currentAnimation].draw(context);
}
}