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.
 
 
 

76 rivejä
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. if (isMobile)
  21. obj.addComponent('touchMover');
  22. else {
  23. obj.addComponent('keyboardMover');
  24. obj.addComponent('mouseMover');
  25. }
  26. obj.addComponent('serverActions');
  27. obj.addComponent('pather');
  28. events.on('onRespawn', this.onRespawn.bind(this));
  29. events.emit('onGetPortrait', obj.portrait);
  30. },
  31. extend: function (blueprint) {
  32. let collisionChanges = blueprint.collisionChanges;
  33. delete blueprint.collisionChanges;
  34. if (collisionChanges)
  35. collisionChanges.forEach(c => physics.setCollision(c));
  36. },
  37. update: function () {
  38. const obj = this.obj;
  39. const x = obj.x;
  40. const y = obj.y;
  41. let oldPos = this.oldPos;
  42. if ((oldPos.x === x) && (oldPos.y === y))
  43. return;
  44. oldPos.x = x;
  45. oldPos.y = y;
  46. sound.update(x, y);
  47. this.positionCamera(x, y);
  48. },
  49. positionCamera: function (x, y, instant) {
  50. renderer.setPosition({
  51. x: (x - (renderer.width / (scale * 2))) * scale,
  52. y: (y - (renderer.height / (scale * 2))) * scale
  53. }, instant);
  54. },
  55. onRespawn: function (position) {
  56. this.positionCamera(position.x, position.y, true);
  57. }
  58. };
  59. });