Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

66 řádky
1.1 KiB

  1. define([
  2. 'js/system/client',
  3. 'js/misc/physics',
  4. 'js/system/events'
  5. ], function (
  6. client,
  7. physics,
  8. events
  9. ) {
  10. return {
  11. type: 'touchMover',
  12. lastNode: null,
  13. nodes: [],
  14. minSqrDistance: 9,
  15. init: function () {
  16. ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'].forEach(e => this[e].bind(this));
  17. },
  18. onTouchStart: function (e) {
  19. this.lastNode = e;
  20. },
  21. onTouchMove: function (e) {
  22. const lastNode = this.lastNode;
  23. let sqrDistance = Math.pow(lastNode.x - e.x, 2) + Math.pow(lastNode.y - e.y, 2);
  24. if (sqrDistance < this.minSqrDistance)
  25. return;
  26. let dx = 1;
  27. let dy = 0;
  28. let newX = this.obj.pather.pathPos.x + dx;
  29. let newY = this.obj.pather.pathPos.y + dy;
  30. if (physics.isTileBlocking(~~newX, ~~newY)) {
  31. this.bump(dx, dy);
  32. return;
  33. }
  34. this.obj.pather.addQueue(newX, newY);
  35. },
  36. onTouchEnd: function () {
  37. this.lastNode = null;
  38. },
  39. onTouchCancel: function () {
  40. this.lastNode = null;
  41. },
  42. ump: function (dx, dy) {
  43. if (this.obj.pather.path.length > 0)
  44. return;
  45. this.obj.addComponent('bumpAnimation', {
  46. deltaX: dx,
  47. deltaY: dy
  48. });
  49. }
  50. };
  51. });