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.
 
 
 

70 lines
1.2 KiB

  1. define([
  2. 'js/rendering/effects'
  3. ], function (
  4. effects
  5. ) {
  6. return {
  7. type: 'bumpAnimation',
  8. deltaX: 0,
  9. deltaY: 0,
  10. updateCd: 0,
  11. updateCdMax: 1,
  12. direction: 1,
  13. speed: 2,
  14. duration: 3,
  15. durationCounter: 0,
  16. infinite: false,
  17. init: function (blueprint) {
  18. //Only allow one bumper at a time
  19. if (this.obj.components.filter(function (c) {
  20. c.type == this.type;
  21. }) > 1)
  22. return true;
  23. },
  24. update: function () {
  25. let deltaX = this.deltaX;
  26. if (deltaX < 0)
  27. this.obj.flipX = true;
  28. else if (deltaX > 0)
  29. this.obj.flipX = false;
  30. if (this.updateCd > 0)
  31. this.updateCd--;
  32. else {
  33. this.obj.offsetX += (this.deltaX * this.direction * this.speed);
  34. this.obj.offsetY += (this.deltaY * this.direction * this.speed);
  35. this.updateCd = this.updateCdMax;
  36. this.durationCounter++;
  37. if (this.durationCounter == this.duration) {
  38. this.durationCounter = 0;
  39. this.direction *= -1;
  40. if ((this.direction == 1) && (!this.infinite))
  41. this.destroyed = true;
  42. else
  43. this.obj.dirty = true;
  44. }
  45. }
  46. this.obj.setSpritePosition();
  47. },
  48. destroy: function () {
  49. this.obj.offsetX = 0;
  50. this.obj.offsetY = 0;
  51. this.obj.setSpritePosition();
  52. effects.unregister(this);
  53. }
  54. };
  55. });