mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Basic implementations
This commit is contained in:
41
js/Movable.js
Normal file
41
js/Movable.js
Normal file
@@ -0,0 +1,41 @@
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
draw(context)
|
||||
{
|
||||
this.animations[this.currentAnimation].setFootPosition(this.position.x, this.position.y);
|
||||
this.animations[this.currentAnimation].draw(context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user