pop.bubble.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. POP.Bubble = function(speed) {
  2. this.x = POP.rnd(POP.W);
  3. this.xConstant = this.x;
  4. this.y = POP.rnd(50, POP.H);
  5. this.r = POP.rnd(15, 10);
  6. this.speed = speed || POP.rnd(5, 1) * -1;
  7. this.remove = false;
  8. this.counter = 0;
  9. this.waveSize = 5 + this.r;
  10. this.col = 'rgba(255,255,255,0.5)';
  11. this.move = function() {
  12. this.y = this.y + this.speed;
  13. this.x = this.waveSize * Math.sin(this.counter) + this.xConstant;
  14. if (this.y < 0) {
  15. POP.score.escapees += 1;
  16. POP.lives -= 1;
  17. this.remove = true;
  18. }
  19. this.counter += 0.05;
  20. return this;
  21. };
  22. this.render = function() {
  23. POP.draw.circle(this.x, this.y,
  24. this.r,
  25. this.col,
  26. '#fff');
  27. return this;
  28. };
  29. this.checkCollision = function() {
  30. if ( POP.m.click && POP.collision.circle(this, POP.m)) {
  31. this.burst();
  32. }
  33. return this;
  34. };
  35. this.burst = function() {
  36. POP.score.burst += 1;
  37. POP.explosions.push( new POP.Explosion(this.x, this.y, this.r));
  38. this.remove = true;
  39. };
  40. };