You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Player.js 818B

1234567891011121314151617181920212223242526272829303132
  1. import Entity from "../Entity.js";
  2. import Texture from "../Texture.js";
  3. import Tile from "../Tile.js";
  4. import assets from "../assets.js";
  5. import TKeyboardController from "../traits/TKeyboardController.js";
  6. import TPhysics from "../traits/TPhysics.js";
  7. import TCollider from "../traits/TCollider.js";
  8. export default class Player extends Entity {
  9. constructor(level) {
  10. super(level, "player");
  11. this.bounds.size.set(0.5, 2);
  12. this.addTrait(new TCollider(this));
  13. this.addTrait(new TKeyboardController(this));
  14. this.addTrait(new TPhysics(this));
  15. this.texture = new Texture(assets.entities, [
  16. new Tile(0, 0, "player-head"),
  17. ]);
  18. }
  19. draw(ctx) {
  20. let x =
  21. this.bounds.pos.pixelX -
  22. assets.entities.scale * 1.5 -
  23. this.bounds.size.pixelX / 2
  24. this.texture.draw(ctx, x, this.bounds.pos.pixelY);
  25. }
  26. }