Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

99 Zeilen
1.8 KiB

  1. define([
  2. 'js/input',
  3. 'js/system/client',
  4. 'js/misc/physics',
  5. 'js/system/events'
  6. ], function (
  7. input,
  8. client,
  9. physics,
  10. events
  11. ) {
  12. return {
  13. type: 'keyboardMover',
  14. moveCd: 0,
  15. moveCdMax: 8,
  16. init: function () {
  17. this.hookEvent('onCanvasKeyDown', this.onCanvasKeyDown.bind(this));
  18. this.hookEvent('onMoveSpeedChange', this.onMoveSpeedChange.bind(this));
  19. },
  20. update: function () {
  21. if (this.obj.dead)
  22. return;
  23. if (this.moveCd > 0) {
  24. this.moveCd--;
  25. return;
  26. }
  27. this.keyMove();
  28. },
  29. //Changes the moveCdMax variable
  30. // moveSpeed is affected when mounting and unmounting
  31. // moveSpeed: 0 | moveCdMax: 8
  32. // moveSpeed: 200 | moveCdMax: 4
  33. onMoveSpeedChange: function (moveSpeed) {
  34. this.moveCdMax = Math.ceil(4 + (((200 - moveSpeed) / 200) * 4));
  35. },
  36. onCanvasKeyDown: function (keyEvent) {
  37. if (keyEvent.key === 'esc') {
  38. client.request({
  39. cpn: 'player',
  40. method: 'performAction',
  41. data: {
  42. cpn: 'player',
  43. method: 'clearQueue',
  44. data: {}
  45. }
  46. });
  47. }
  48. },
  49. bump: function (dx, dy) {
  50. if (this.obj.pather.path.length > 0)
  51. return;
  52. if (this.obj.bumpAnimation)
  53. return;
  54. events.emit('onObjCollideBump', this.obj);
  55. this.obj.addComponent('bumpAnimation', {
  56. deltaX: dx,
  57. deltaY: dy
  58. });
  59. },
  60. keyMove: function () {
  61. let delta = {
  62. x: input.getAxis('horizontal'),
  63. y: input.getAxis('vertical')
  64. };
  65. if ((!delta.x) && (!delta.y))
  66. return;
  67. let newX = this.obj.pather.pathPos.x + delta.x;
  68. let newY = this.obj.pather.pathPos.y + delta.y;
  69. if (physics.isTileBlocking(~~newX, ~~newY)) {
  70. this.bump(delta.x, delta.y);
  71. return;
  72. }
  73. this.moveCd = this.moveCdMax;
  74. this.obj.pather.add(newX, newY);
  75. },
  76. destroy: function () {
  77. this.unhookEvents();
  78. }
  79. };
  80. });