gameStar.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. function GameStar(x, y) {
  2. GameStar.superclass.constructor.apply(this);
  3. this.addAnimationFromCache("GameStar");
  4. this.orign.x = this.width / 2;
  5. this.orign.y = this.height / 2;
  6. this.reset( ProductItem.prototype.fieldOffset.x + ProductItem.prototype.cellSize.x / 2 + ProductItem.prototype.cellSize.x * x,
  7. ProductItem.prototype.fieldOffset.y + ProductItem.prototype.cellSize.y / 2 + ProductItem.prototype.cellSize.y * y);
  8. this.state = this.STATE_PASSIVE;
  9. this.looped = false;
  10. this.blinkTimer = Math.random() * 90 + 90;
  11. }
  12. extend(GameStar, TrinSprite);
  13. GameStar.prototype.update = function() {
  14. GameStar.superclass.update.apply(this);
  15. switch (this.state) {
  16. case this.STATE_PASSIVE:
  17. break;
  18. case this.STATE_PICKED:
  19. this.scale.x = this.scale.y = this.scale.x + 0.1;
  20. this.alpha = Math.max(this.alpha - 0.05, 0);
  21. if (this.alpha === 0) {
  22. this.kill();
  23. }
  24. break;
  25. }
  26. if (this.blinkTimer-- < 0) {
  27. this.blinkTimer = Math.random() * 90 + 90;
  28. this.play();
  29. }
  30. };
  31. GameStar.prototype.pick = function() {
  32. PlayState.prototype.stars++;
  33. this.state= this.STATE_PICKED;
  34. };
  35. GameStar.prototype.isPickable = function() {
  36. return this.state === this.STATE_PASSIVE;
  37. };
  38. GameStar.prototype.STATE_PASSIVE = 0;
  39. GameStar.prototype.STATE_PICKED = 1;