No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

98 líneas
1.5 KiB

  1. define([
  2. 'js/input',
  3. 'js/system/client',
  4. 'js/misc/physics'
  5. ], function(
  6. input,
  7. client,
  8. physics
  9. ) {
  10. return {
  11. type: 'keyboardMover',
  12. moveCd: 0,
  13. moveCdMax: 8,
  14. direction: {
  15. x: 0,
  16. y: 0
  17. },
  18. update: function() {
  19. if (this.obj.moveAnimation)
  20. this.obj.pather.clearPath();
  21. if (input.isKeyDown('esc')) {
  22. client.request({
  23. cpn: 'player',
  24. method: 'queueAction',
  25. data: {
  26. action: 'clearQueue',
  27. priority: true
  28. }
  29. });
  30. }
  31. if (this.moveCd > 0) {
  32. this.moveCd--;
  33. return;
  34. }
  35. this.keyMove();
  36. },
  37. bump: function(dx, dy) {
  38. if (this.obj.pather.path.length > 0)
  39. return;
  40. this.obj.addComponent('bumpAnimation', {
  41. deltaX: dx,
  42. deltaY: dy
  43. });
  44. },
  45. keyMove: function() {
  46. var delta = {
  47. x: input.getAxis('horizontal'),
  48. y: input.getAxis('vertical')
  49. };
  50. if ((!delta.x) && (!delta.y))
  51. return;
  52. this.direction.x = delta.x;
  53. this.direction.y = delta.y;
  54. var newX = this.obj.pather.pathPos.x + delta.x;
  55. var newY = this.obj.pather.pathPos.y + delta.y;
  56. if (physics.isTileBlocking(~~newX, ~~newY)) {
  57. this.bump(delta.x, delta.y)
  58. return;
  59. }
  60. this.moveCd = this.moveCdMax;
  61. this.addQueue(newX, newY);
  62. },
  63. addQueue: function(x, y) {
  64. if (this.obj.moveAnimation)
  65. return;
  66. this.obj.dirty = true;
  67. this.obj.pather.add(x, y);
  68. this.obj.pather.pathPos.x = x;
  69. this.obj.pather.pathPos.y = y;
  70. client.request({
  71. cpn: 'player',
  72. method: 'move',
  73. data: {
  74. x: x,
  75. y: y
  76. }
  77. });
  78. }
  79. };
  80. });