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.
 
 
 

122 lines
1.9 KiB

  1. define([
  2. 'js/rendering/renderer'
  3. ], function (
  4. renderer
  5. ) {
  6. return {
  7. type: 'moveAnimation',
  8. targetX: 0,
  9. targetY: 0,
  10. x: 0,
  11. y: 0,
  12. ttl: 50,
  13. endTime: 0,
  14. particles: null,
  15. init: function (blueprint) {
  16. this.particles = this.obj.addComponent('particles', {
  17. blueprint: {
  18. scale: {
  19. start: {
  20. min: 6,
  21. max: 16
  22. },
  23. end: {
  24. min: 0,
  25. max: 10
  26. }
  27. },
  28. opacity: {
  29. start: 0.05,
  30. end: 0
  31. },
  32. lifetime: {
  33. min: 1,
  34. max: 2
  35. },
  36. speed: {
  37. start: {
  38. min: 2,
  39. max: 20
  40. },
  41. end: {
  42. min: 0,
  43. max: 8
  44. }
  45. },
  46. color: {
  47. start: 'fcfcfc',
  48. end: 'c0c3cf'
  49. },
  50. randomScale: true,
  51. randomSpeed: true,
  52. chance: 0.4
  53. }
  54. });
  55. this.endTime = +new Date() + this.ttl;
  56. let obj = this.obj;
  57. this.x = obj.x;
  58. this.y = obj.y;
  59. if (this.targetX > this.x)
  60. this.obj.flipX = false;
  61. else if (this.targetX < this.x)
  62. this.obj.flipX = true;
  63. this.obj.setSpritePosition();
  64. },
  65. update: function () {
  66. let source = this.obj;
  67. let target = this.target;
  68. let dx = this.targetX - this.x;
  69. let dy = this.targetY - this.y;
  70. let ticksLeft = ~~((this.endTime - (+new Date())) / 16);
  71. if (ticksLeft <= 0) {
  72. this.obj.x = this.targetX;
  73. this.obj.y = this.targetY;
  74. this.obj.setSpritePosition();
  75. this.destroyed = true;
  76. this.particles.destroyed = true;
  77. //Sometimes we just move to a point without exploding
  78. if (target) {
  79. target.addComponent('explosion', {
  80. new: true,
  81. blueprint: {
  82. r: 242,
  83. g: 245,
  84. b: 245
  85. }
  86. }).explode();
  87. }
  88. } else {
  89. dx /= ticksLeft;
  90. dy /= ticksLeft;
  91. this.x += dx;
  92. this.y += dy;
  93. this.obj.x = (~~((this.x * 32) / 8) * 8) / 32;
  94. this.obj.y = (~~((this.y * 32) / 8) * 8) / 32;
  95. this.obj.setSpritePosition();
  96. }
  97. renderer.updateSprites();
  98. }
  99. };
  100. });