CNugget.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. function CNugget(iXPos,iYPos,iScale,oSprite){
  2. var _bActive;
  3. var _iValue;
  4. var _iWidth;
  5. var _iHeight;
  6. var _iScale;
  7. var _oNuggetSprite;
  8. this._init = function(iXPos,iYPos,iScale,oSprite){
  9. _bActive =true;
  10. var iRandRot = Math.floor(Math.random()*180);
  11. _oNuggetSprite = createBitmap(oSprite);
  12. _oNuggetSprite.x = iXPos;
  13. _oNuggetSprite.y = iYPos;
  14. _oNuggetSprite.rotation = iRandRot;
  15. _oNuggetSprite.regX = oSprite.width/2;
  16. _oNuggetSprite.regY = oSprite.height/2;
  17. _oNuggetSprite.scaleX = _oNuggetSprite.scaleY = iScale;
  18. s_oStage.addChild(_oNuggetSprite);
  19. _iValue = Math.floor(1000 * iScale);
  20. _iScale = iScale;
  21. _iWidth = oSprite.width;
  22. _iHeight = oSprite.height;
  23. };
  24. this.unload = function(){
  25. s_oStage.removeChild(_oNuggetSprite);
  26. _oNuggetSprite = null;
  27. };
  28. this.changePos = function(iXPos,iYPos,iScale){
  29. _oNuggetSprite.x = iXPos;
  30. _oNuggetSprite.y = iYPos;
  31. _oNuggetSprite.scaleX = _oNuggetSprite.scaleY = _iScale = iScale;
  32. _oNuggetSprite.visible = true;
  33. _bActive =true;
  34. };
  35. this.hide = function(){
  36. if(_oNuggetSprite !== null){
  37. _oNuggetSprite.visible = false;
  38. _bActive =false;
  39. }
  40. };
  41. this.getImage = function(){
  42. return _oNuggetSprite;
  43. };
  44. this.getRadius = function(){
  45. return ((_iWidth/2)*_iScale) * 1;
  46. };
  47. this.getPos = function(){
  48. return { x: _oNuggetSprite.x, y: _oNuggetSprite.y};
  49. };
  50. this.getX = function(){
  51. return _oNuggetSprite.x;
  52. };
  53. this.getY = function(){
  54. return _oNuggetSprite.y;
  55. };
  56. this.getWidth = function(){
  57. return _iWidth;
  58. };
  59. this.getValue = function(){
  60. return _iValue;
  61. };
  62. this.isActive = function(){
  63. return _bActive;
  64. };
  65. this.updateMoveBack = function(iHookSpeed,iDir){
  66. var iNewX = _oNuggetSprite.x - (iHookSpeed) * Math.cos(iDir);
  67. var iNewY = _oNuggetSprite.y - (iHookSpeed) * Math.sin(iDir);
  68. _oNuggetSprite.x = iNewX;
  69. _oNuggetSprite.y = iNewY;
  70. };
  71. this._init(iXPos,iYPos,iScale,oSprite);
  72. }