CBullet.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. function CBullet(iXPos, iYPos, oSprite) {
  2. var _oBullet;
  3. var _iCnt;
  4. var _iOffsetWallUp;
  5. var _iID;
  6. this._init = function () {
  7. var iHeight = oSprite.height / 2;
  8. _oBullet = createBitmap(oSprite);
  9. _oBullet.x = iXPos;
  10. _oBullet.y = iYPos;
  11. _oBullet.regX = oSprite.width / 2;
  12. _oBullet.regY = iHeight;
  13. s_oStage.addChild(_oBullet);
  14. _iCnt = 0;
  15. var iEdgeUpWidth = 30 + iHeight;
  16. _iOffsetWallUp = iEdgeUpWidth + iHeight;
  17. };
  18. this.getX = function () {
  19. return _oBullet.x;
  20. };
  21. this.getY = function () {
  22. return _oBullet.y;
  23. };
  24. this.setPosition = function (iXPos, iYPos) {
  25. if (iXPos === null) {
  26. } else {
  27. _oBullet.x = iXPos;
  28. }
  29. if (iYPos === null) {
  30. } else {
  31. _oBullet.y = iYPos;
  32. }
  33. };
  34. this.unload = function () {
  35. s_oStage.removeChild(_oBullet);
  36. s_oBullet = null;
  37. };
  38. this.setIndex = function (iID) {
  39. _iID = iID;
  40. };
  41. this.getIndex = function () {
  42. return _iID;
  43. };
  44. this.update = function () {
  45. _oBullet.y -= BULLET_SPEED;
  46. if (_oBullet.y < _iOffsetWallUp) {
  47. s_oGame.unloadBullet(_iID);
  48. playSound("brick_metal", 1, false);
  49. }
  50. };
  51. s_oBullet = this;
  52. this._init();
  53. };
  54. var s_oBullet;