pop.starfish.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. POP.Starfish = function() {
  2. this.x = (Math.random() * (POP.W));
  3. this.y = POP.H + (Math.random() * 100) + 100;
  4. this.speed= -1;
  5. this.inner_r = 10;
  6. this.offset = (this.inner_r / 100) * 70;
  7. this.r = this.inner_r + this.offset; // for col detection
  8. this.points = 5;
  9. this.increase = Math.PI * 2 / this.points;
  10. this.angle = 0;
  11. this.types = {
  12. 'green': { inner: 'green', outer: 'limegreen', action: 'green' },
  13. 'red': { inner: '#600', 'outer': '#900', action: 'red'},
  14. 'black': { inner: '#111', 'outer': '#444', action: 'black' }
  15. };
  16. this.types_ref = ['green', 'red', 'black'];
  17. this.type = this.types[this.types_ref[Math.floor(Math.random() * this.types_ref.length)]];
  18. this.render = function() {
  19. if (this.y < 0) {
  20. this.reset();
  21. return;
  22. }
  23. var i, x, y;
  24. this.y += this.speed;
  25. POP.draw.circle(this.x, this.y, this.inner_r, this.type.inner);
  26. for (i = 0; i < this.points; i += 1) {
  27. x = this.offset * Math.cos(this.angle) + (this.x);
  28. y = this.offset * Math.sin(this.angle) + (this.y);
  29. POP.draw.circle(x, y, this.inner_r / 2, (this.type.outer));
  30. this.angle += this.increase;
  31. }
  32. this.angle += 0.01;
  33. };
  34. this.collides = function() {
  35. return POP.collision.circle(this, POP.m);
  36. };
  37. this.reset = function() {
  38. this.type = this.types[this.types_ref[Math.floor(Math.random() * this.types_ref.length)]];
  39. this.x = (Math.random() * (POP.W));
  40. this.y = POP.H + (Math.random() * 100) + 100;
  41. };
  42. };