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.
 
 
 

106 lines
2.0 KiB

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