Gravity and ground height.

This commit is contained in:
Mal
2020-01-25 13:11:25 +01:00
parent 388799c97e
commit 0cd532f45a
8 changed files with 316 additions and 27 deletions

View File

@@ -10,6 +10,7 @@ export default class Movable
};
this.position = new GeometryPoint();
this.speed = speed;
this.jumpHeight = 35;
this.fallSpeed = 0;
}
@@ -39,6 +40,39 @@ export default class Movable
return this.animations[this.currentAnimation].getRect();
}
getPositionFootLeft()
{
return new GeometryPoint(
this.position.x - this.animations[this.currentAnimation].getWidth() * 0.5, this.position.y
);
}
getPositionFootRight()
{
return new GeometryPoint(
this.position.x + this.animations[this.currentAnimation].getWidth() * 0.5, this.position.y
);
}
jump()
{
this.fallSpeed -= this.jumpHeight;
this.isJumping = true;
}
getFootHeight()
{
return new GeometryPoint(
this.position.x,
this.position.y + this.animations[this.currentAnimation].getHeight()
);
}
setFootHeight(height)
{
this.position.y = height - this.animations[this.currentAnimation].getHeight();
}
draw(context)
{
this.animations[this.currentAnimation].setFootPosition(this.position.x, this.position.y);