You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

109 lines
2.1 KiB

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