25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

92 lines
1.4 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 (input.isKeyDown('esc')) {
  20. client.request({
  21. cpn: 'player',
  22. method: 'queueAction',
  23. data: {
  24. action: 'clearQueue',
  25. priority: true
  26. }
  27. });
  28. }
  29. if (this.moveCd > 0) {
  30. this.moveCd--;
  31. return;
  32. }
  33. this.keyMove();
  34. },
  35. bump: function(dx, dy) {
  36. if (this.obj.pather.path.length > 0)
  37. return;
  38. this.obj.addComponent('bumpAnimation', {
  39. deltaX: dx,
  40. deltaY: dy
  41. });
  42. },
  43. keyMove: function() {
  44. var delta = {
  45. x: input.getAxis('horizontal'),
  46. y: input.getAxis('vertical')
  47. };
  48. if ((!delta.x) && (!delta.y))
  49. return;
  50. this.direction.x = delta.x;
  51. this.direction.y = delta.y;
  52. var newX = this.obj.pather.pathPos.x + delta.x;
  53. var newY = this.obj.pather.pathPos.y + delta.y;
  54. if (physics.isTileBlocking(~~newX, ~~newY)) {
  55. this.bump(delta.x, delta.y)
  56. return;
  57. }
  58. this.moveCd = this.moveCdMax;
  59. this.addQueue(newX, newY);
  60. },
  61. addQueue: function(x, y) {
  62. this.obj.dirty = true;
  63. this.obj.pather.add(x, y);
  64. this.obj.pather.pathPos.x = x;
  65. this.obj.pather.pathPos.y = y;
  66. client.request({
  67. cpn: 'player',
  68. method: 'move',
  69. data: {
  70. x: x,
  71. y: y
  72. }
  73. });
  74. }
  75. };
  76. });