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.
 
 
 

66 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.some(c => c.type === this.type))
  20. return true;
  21. },
  22. update: function () {
  23. let deltaX = this.deltaX;
  24. if (deltaX < 0)
  25. this.obj.flipX = true;
  26. else if (deltaX > 0)
  27. this.obj.flipX = false;
  28. if (this.updateCd > 0)
  29. this.updateCd--;
  30. else {
  31. this.obj.offsetX += (this.deltaX * this.direction * this.speed);
  32. this.obj.offsetY += (this.deltaY * this.direction * this.speed);
  33. this.updateCd = this.updateCdMax;
  34. this.durationCounter++;
  35. if (this.durationCounter === this.duration) {
  36. this.durationCounter = 0;
  37. this.direction *= -1;
  38. if ((this.direction === 1) && (!this.infinite))
  39. this.destroyed = true;
  40. }
  41. }
  42. this.obj.setSpritePosition();
  43. },
  44. destroy: function () {
  45. this.obj.offsetX = 0;
  46. this.obj.offsetY = 0;
  47. this.obj.setSpritePosition();
  48. effects.unregister(this);
  49. }
  50. };
  51. });