Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

97 строки
1.6 KiB

  1. define([
  2. 'js/rendering/effects',
  3. 'js/rendering/renderer'
  4. ], function(
  5. effects,
  6. renderer
  7. ) {
  8. var scale = 40;
  9. return {
  10. type: 'attackAnimation',
  11. frames: 4,
  12. frameDelay: 4,
  13. layer: 'attacks',
  14. spriteSheet: 'attacks',
  15. row: null,
  16. col: null,
  17. loop: 1,
  18. loopCounter: 0,
  19. frame: 0,
  20. frameDelayCd: 0,
  21. flipped: false,
  22. sprite: null,
  23. init: function(blueprint) {
  24. effects.register(this);
  25. this.flipped = (Math.random() < 0.5);
  26. this.frameDelayCd = this.frameDelay;
  27. var cell = (this.row * 8) + this.col + this.frame;
  28. this.sprite = renderer.buildObject({
  29. sheetName: this.spriteSheet,
  30. cell: cell,
  31. x: this.obj.x,
  32. y: this.obj.y,
  33. offsetX: this.obj.offsetX,
  34. offsetY: this.obj.offsetY,
  35. flipX: this.flipped
  36. });
  37. },
  38. renderManual: function() {
  39. if (this.frameDelayCd > 0)
  40. this.frameDelayCd--;
  41. else {
  42. this.frameDelayCd = this.frameDelay;
  43. this.frame++;
  44. if (this.frame == this.frames) {
  45. this.loopCounter++;
  46. if (this.loopCounter == this.loop) {
  47. if (this.destroyObject)
  48. this.obj.destroyed = true;
  49. else
  50. this.destroyed = true;
  51. return;
  52. }
  53. else
  54. this.frame = 0;
  55. }
  56. }
  57. this.sprite.x = this.obj.x * scale;
  58. this.sprite.y = this.obj.y * scale;
  59. var cell = (this.row * 8) + this.col + this.frame;
  60. renderer.setSprite({
  61. sheetName: this.spriteSheet,
  62. cell: cell,
  63. flipX: this.flipped,
  64. sprite: this.sprite
  65. });
  66. if (this.flipped)
  67. this.sprite.x += scale;
  68. },
  69. destroyManual: function() {
  70. renderer.destroyObject({
  71. layerName: this.spriteSheet,
  72. sprite: this.sprite
  73. });
  74. effects.unregister(this);
  75. }
  76. };
  77. });