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.
 
 
 

71 lines
1.3 KiB

  1. define([
  2. 'js/rendering/renderer',
  3. 'js/system/events',
  4. 'js/misc/physics',
  5. 'js/sound/sound'
  6. ], function (
  7. renderer,
  8. events,
  9. physics,
  10. sound
  11. ) {
  12. return {
  13. type: 'player',
  14. oldPos: {
  15. x: 0,
  16. y: 0
  17. },
  18. init: function () {
  19. const obj = this.obj;
  20. obj.addComponent('keyboardMover');
  21. obj.addComponent('mouseMover');
  22. obj.addComponent('serverActions');
  23. obj.addComponent('pather');
  24. events.on('onRespawn', this.onRespawn.bind(this));
  25. events.emit('onGetPortrait', obj.portrait);
  26. },
  27. extend: function (blueprint) {
  28. let collisionChanges = blueprint.collisionChanges;
  29. delete blueprint.collisionChanges;
  30. if (collisionChanges)
  31. collisionChanges.forEach(c => physics.setCollision(c));
  32. },
  33. update: function () {
  34. const obj = this.obj;
  35. const x = obj.x;
  36. const y = obj.y;
  37. let oldPos = this.oldPos;
  38. if ((oldPos.x === x) && (oldPos.y === y))
  39. return;
  40. oldPos.x = x;
  41. oldPos.y = y;
  42. sound.update(x, y);
  43. this.positionCamera(x, y);
  44. },
  45. positionCamera: function (x, y, instant) {
  46. renderer.setPosition({
  47. x: (x - (renderer.width / (scale * 2))) * scale,
  48. y: (y - (renderer.height / (scale * 2))) * scale
  49. }, instant);
  50. },
  51. onRespawn: function (position) {
  52. this.positionCamera(position.x, position.y, true);
  53. }
  54. };
  55. });