50404508-7d63-4c76-be84-451908542d71.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. "use strict";
  2. cc._RF.push(module, '50404UIfWNMdr6ERRkIVC1x', 'bullet');
  3. // scripts/Game/bullet.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var CocosZ_1 = require("../Framework/CocosZ");
  26. var Constant_1 = require("../Framework/Constant");
  27. var gameMgr_1 = require("./gameMgr");
  28. var person_1 = require("./person");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. var Bullet = /** @class */ (function (_super) {
  31. __extends(Bullet, _super);
  32. function Bullet() {
  33. var _this = _super !== null && _super.apply(this, arguments) || this;
  34. _this.bulletId = 0;
  35. _this.id = 1;
  36. _this.atk = 10;
  37. _this.atker = null;
  38. _this.canMove = true;
  39. _this.canBreak = true;
  40. _this.canPenetrate = false;
  41. _this.canWall = false;
  42. _this.boomEffect = null;
  43. _this.hitEffect = null;
  44. _this.hitAudio = "";
  45. _this.isHartMusic = true;
  46. _this.hitEffectType = 0;
  47. // LIFE-CYCLE CALLBACKS:
  48. _this.hartInterval = 0;
  49. _this.isHitEffectAngle = false;
  50. _this.isAngle = false;
  51. _this.isBoom = false;
  52. _this.isRecord = true;
  53. // 方向
  54. _this.dir = null;
  55. _this._lastPos = null;
  56. // 已攻击对象
  57. _this.atkedArr = [];
  58. return _this;
  59. }
  60. Bullet_1 = Bullet;
  61. Bullet.prototype.start = function () {
  62. gameMgr_1.gameMgr && gameMgr_1.gameMgr.setMapTs.checkNode(this.node, true);
  63. if (this.node.zIndex == 0) {
  64. if (this.isBoom) {
  65. this.node.zIndex = Constant_1.ZindexLayer.zindex_bomb;
  66. }
  67. else if ("liewen" === this.node.name) {
  68. this.node.zIndex = Constant_1.ZindexLayer.zinedx_floorLiewen;
  69. }
  70. else {
  71. this.node.zIndex = Constant_1.ZindexLayer.zindex_bullet + this.bulletId;
  72. }
  73. }
  74. // gameMgr
  75. if (this.node.name == "bullet_sd" || this.node.name == "bullet_hdl") {
  76. var box = this.node.getComponent(cc.BoxCollider);
  77. if (box) {
  78. cc.tween(box.size).to(0.3, { height: 550 }).start();
  79. cc.tween(box.offset).to(0.3, { x: 700 }).start();
  80. }
  81. }
  82. };
  83. Bullet.prototype.onDisable = function () {
  84. this._lastPos = null;
  85. };
  86. Bullet.prototype.lateUpdate = function (dt) {
  87. // 每帧设置角度
  88. if (this.isAngle) {
  89. if (this._lastPos) {
  90. var div = this.node.getPosition().subSelf(this._lastPos);
  91. if (false == div.equals(cc.Vec2.ZERO)) {
  92. this.node.angle = -cc.v2(div).signAngle(cc.v2(1, 0)) / Math.PI * 180;
  93. this._lastPos = this.node.getPosition();
  94. }
  95. }
  96. else {
  97. this._lastPos = this.node.getPosition();
  98. }
  99. }
  100. };
  101. Bullet.prototype.onCollisionEnter = function (other, self) {
  102. var _this = this;
  103. if (other.tag == 1) {
  104. var ts_1 = other.getComponent(person_1.default);
  105. if (ts_1.id == this.id) {
  106. return;
  107. }
  108. // 能倍阻断并且不能穿透玩家
  109. if (this.canBreak && !this.canPenetrate) {
  110. this.node.destroy();
  111. }
  112. else {
  113. if (this.atkedArr.includes(other.node)) {
  114. return;
  115. }
  116. else if (this.isRecord) {
  117. this.atkedArr.push(other.node);
  118. }
  119. }
  120. // 击中效果
  121. if (this.hitEffect && !CocosZ_1.cocosz.isPause) {
  122. var node = cc.instantiate(this.hitEffect);
  123. node.zIndex = Constant_1.ZindexLayer.zindex_effect_hit;
  124. if (this.hitEffectType == 1) {
  125. node.parent = other.node;
  126. // 击中特效方向
  127. if (this.isHitEffectAngle) {
  128. node.angle = -cc.v2(this.dir).signAngle(cc.v2(1, 0)) / Math.PI * 180;
  129. }
  130. }
  131. else {
  132. var pos = this.node.getPosition();
  133. var dt = this.node.width;
  134. if (dt < 5) {
  135. var box = this.node.getComponent(cc.BoxCollider);
  136. if (box) {
  137. dt += box.offset.x;
  138. }
  139. }
  140. pos = pos.add(cc.v2(dt, 0).rotate(this.node.angle / 180 * Math.PI));
  141. node.parent = this.node.parent;
  142. node.setPosition(pos);
  143. }
  144. if (this.hitAudio) {
  145. gameMgr_1.gameMgr.playEffect(this.hitAudio, this.node);
  146. }
  147. }
  148. // 爆炸效果
  149. if (this.boomEffect) {
  150. var boom = cc.instantiate(this.boomEffect);
  151. boom.parent = this.node.parent;
  152. boom.setPosition(this.node.getPosition());
  153. boom.zIndex = Constant_1.ZindexLayer.zindex_bomb;
  154. gameMgr_1.gameMgr.playEffect("explo", boom);
  155. var bullet = boom.getComponent(Bullet_1);
  156. bullet.atk = this.atk;
  157. bullet.atker = this.atker;
  158. bullet.id = this.id;
  159. bullet.dir = this.dir;
  160. return;
  161. }
  162. // 血液效果
  163. if (gameMgr_1.gameMgr.blood && self.world && self.world.points && self.world.points[0]) {
  164. var blood = null;
  165. blood = cc.instantiate(gameMgr_1.gameMgr.blood);
  166. blood.parent = gameMgr_1.gameMgr.map;
  167. blood.zIndex = Constant_1.ZindexLayer.zindex_blood;
  168. ;
  169. var pos = blood.parent.convertToNodeSpaceAR(cc.v2(self.world.points[0].x, self.world.points[0].y));
  170. if (this.dir) {
  171. var angle = -cc.v2(this.dir).signAngle(cc.v2(0, 1)) / Math.PI * 180;
  172. blood.angle = angle;
  173. }
  174. blood.setPosition(pos);
  175. }
  176. // 击退
  177. if (this.isBoom) {
  178. var dir = other.node.getPosition().subSelf(this.node.getPosition()).normalizeSelf();
  179. // 方向为0,随机方向
  180. if (dir.equals(cc.Vec2.ZERO)) {
  181. dir = cc.v2(1, 0).rotateSelf(2 * Math.PI * Math.random());
  182. }
  183. this.dir = dir.mulSelf(3);
  184. }
  185. else if (!this.canMove && this.dir && this.dir.mag() < 2) {
  186. this.dir.normalizeSelf().mulSelf(2);
  187. }
  188. // 敌人受伤
  189. ts_1.hart(this.atk, this.atker, this.dir, this.isHartMusic);
  190. if (this.hartInterval) {
  191. this.schedule(function () {
  192. if (ts_1 && ts_1.isValid && _this.atkedArr.includes(ts_1.node)) {
  193. ts_1.hart(_this.atk, _this.atker, _this.dir, _this.isHartMusic);
  194. }
  195. }, this.hartInterval);
  196. }
  197. }
  198. // 障碍物
  199. else if (other.tag == 5) {
  200. // 爆炸效果
  201. if (this.boomEffect) {
  202. var boom = cc.instantiate(this.boomEffect);
  203. boom.parent = this.node.parent;
  204. boom.setPosition(this.node.getPosition());
  205. var bullet = boom.getComponent(Bullet_1);
  206. bullet.atk = this.atk;
  207. bullet.atker = this.atker;
  208. bullet.id = this.id;
  209. gameMgr_1.gameMgr.playEffect("explo", boom);
  210. }
  211. // 销毁子弹
  212. if (this.canBreak && !this.canWall) {
  213. var pos = this.node.getPosition();
  214. var dt = this.node.width;
  215. if (dt < 5) {
  216. var box = this.node.getComponent(cc.BoxCollider);
  217. if (box) {
  218. dt += box.offset.x;
  219. }
  220. }
  221. pos = pos.add(cc.v2(dt, 0).rotate(this.node.angle / 180 * Math.PI));
  222. if (this.hitEffect && this.hitEffectType != 1) {
  223. var node = cc.instantiate(this.hitEffect);
  224. node.parent = this.node.parent;
  225. node.setPosition(pos);
  226. node.zIndex = Constant_1.ZindexLayer.zindex_effect_hit;
  227. }
  228. else {
  229. var node = cc.instantiate(gameMgr_1.gameMgr.spark);
  230. node.parent = this.node.parent;
  231. node.setPosition(pos);
  232. node.zIndex = Constant_1.ZindexLayer.zindex_effect_spark;
  233. }
  234. this.node.destroy();
  235. }
  236. }
  237. };
  238. var Bullet_1;
  239. __decorate([
  240. property()
  241. ], Bullet.prototype, "bulletId", void 0);
  242. __decorate([
  243. property()
  244. ], Bullet.prototype, "canMove", void 0);
  245. __decorate([
  246. property({ tooltip: "能否阻断" })
  247. ], Bullet.prototype, "canBreak", void 0);
  248. __decorate([
  249. property({ tooltip: "能否穿透敌人" })
  250. ], Bullet.prototype, "canPenetrate", void 0);
  251. __decorate([
  252. property({ tooltip: "能否穿透墙壁" })
  253. ], Bullet.prototype, "canWall", void 0);
  254. __decorate([
  255. property(cc.Prefab)
  256. ], Bullet.prototype, "boomEffect", void 0);
  257. __decorate([
  258. property(cc.Prefab)
  259. ], Bullet.prototype, "hitEffect", void 0);
  260. __decorate([
  261. property({ type: cc.String, tooltip: "子弹音效" })
  262. ], Bullet.prototype, "hitAudio", void 0);
  263. __decorate([
  264. property({ tooltip: "敌人受伤是否发出音效" })
  265. ], Bullet.prototype, "isHartMusic", void 0);
  266. __decorate([
  267. property()
  268. ], Bullet.prototype, "hitEffectType", void 0);
  269. __decorate([
  270. property()
  271. ], Bullet.prototype, "hartInterval", void 0);
  272. __decorate([
  273. property({ tooltip: "击中效果设置角度" })
  274. ], Bullet.prototype, "isHitEffectAngle", void 0);
  275. __decorate([
  276. property({ tooltip: "每帧设置角度" })
  277. ], Bullet.prototype, "isAngle", void 0);
  278. __decorate([
  279. property({ tooltip: "是否爆炸子弹" })
  280. ], Bullet.prototype, "isBoom", void 0);
  281. __decorate([
  282. property({ tooltip: "是否记录受伤者" })
  283. ], Bullet.prototype, "isRecord", void 0);
  284. Bullet = Bullet_1 = __decorate([
  285. ccclass
  286. ], Bullet);
  287. return Bullet;
  288. }(cc.Component));
  289. exports.default = Bullet;
  290. cc._RF.pop();