Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

121 linhas
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. var 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. }
  62. else if (this.targetX < this.x)
  63. this.obj.flipX = true;
  64. this.obj.setSpritePosition();
  65. },
  66. update: function() {
  67. var source = this.obj;
  68. var target = this.target;
  69. var dx = this.targetX - this.x;
  70. var dy = this.targetY - this.y;
  71. var ticksLeft = ~~((this.endTime - (+new Date)) / 16);
  72. if (ticksLeft <= 0) {
  73. this.obj.x = this.targetX;
  74. this.obj.y = this.targetY;
  75. this.obj.setSpritePosition();
  76. this.destroyed = true;
  77. this.particles.destroyed = true;
  78. //Sometimes we just move to a point without exploding
  79. if (target) {
  80. target.addComponent('explosion', {
  81. new: true,
  82. blueprint: {
  83. r: 242,
  84. g: 245,
  85. b: 245
  86. }
  87. }).explode();
  88. }
  89. } else {
  90. dx /= ticksLeft;
  91. dy /= ticksLeft;
  92. this.x += dx;
  93. this.y += dy;
  94. this.obj.x = (~~((this.x * 32) / 8) * 8) / 32;
  95. this.obj.y = (~~((this.y * 32) / 8) * 8) / 32;
  96. this.obj.setSpritePosition();
  97. }
  98. renderer.updateSprites();
  99. }
  100. };
  101. });