Plot1.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. import CMath from "../../../../util/CMath";
  2. import BObject from "../../bullet/BObject";
  3. import FF from "../../FF";
  4. import FSprite, { SpriteActionType } from "../../object/FSprite";
  5. import PSprite from "../../object/PSprite";
  6. import FMapDialog from "../dialog/FMapDialog";
  7. import WOneByone from "../map1/WOneByone";
  8. /**
  9. * 剧情
  10. */
  11. const {ccclass, property} = cc._decorator;
  12. @ccclass
  13. export default class Plot1 extends cc.Component {
  14. @property(sp.Skeleton)
  15. myspine: sp.Skeleton = null;
  16. @property(cc.Prefab)
  17. mBullet: cc.Prefab = null;//子弹
  18. @property(cc.Prefab)
  19. mMapDialog: cc.Prefab = null;
  20. @property(cc.Prefab)
  21. mEffect: cc.Prefab = null;//爆炸效果
  22. @property({
  23. type:[cc.Prefab],
  24. displayName: '解救的对象'
  25. })
  26. mMonster: Array<cc.Prefab> = [];
  27. @property([cc.Node])
  28. mDx: Array<cc.Node> = [];
  29. @property(cc.SpriteFrame)
  30. mAppleIcon: cc.SpriteFrame = null;//苹果图标
  31. private ff:FF;
  32. onLoad () {
  33. }
  34. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  35. if(other.node.group == 'A'){
  36. let obj = other.node.getComponent(FSprite);
  37. if(obj.hp > 0){
  38. this.ff = obj.ff;
  39. this.node.removeComponent(cc.PhysicsBoxCollider);
  40. this.run();
  41. }
  42. }
  43. }
  44. private run(){
  45. this.ff.pauseSprite(true);
  46. this.ff.mBlockInputEvents.active = true;
  47. let map = this.ff.mMap;
  48. let winSize = cc.winSize
  49. let camera = map.mCamera;
  50. let cx = this.node.x - winSize.width/2;
  51. let cy = this.node.y - winSize.height/2;
  52. cc.tween(camera.node).sequence(
  53. cc.moveTo(0.7,cc.v2(cx,cy)),
  54. cc.callFunc(()=>{
  55. this.d1();
  56. })
  57. ).start()
  58. }
  59. private d1(){
  60. let dialogs = [
  61. '解决她',
  62. ];
  63. let mapDialog = new FMapDialog(this.ff,this.mMapDialog);
  64. let pos = cc.v2();
  65. pos.x = this.node.x + this.mDx[0].x;
  66. pos.y = this.node.y + this.mDx[0].y + this.mDx[0].height;
  67. mapDialog.showDialog(dialogs,
  68. pos,
  69. null,
  70. ()=>{
  71. this.playAni1();
  72. }
  73. );
  74. }
  75. /**
  76. * 怪物死亡
  77. * @param node
  78. */
  79. private mDead(node:cc.Node){
  80. let spine = node.getComponent(sp.Skeleton);
  81. spine.setCompleteListener(() => {
  82. node.destroy();
  83. });
  84. spine.setEventListener(null);
  85. spine.setAnimation(0, SpriteActionType.dead, false);
  86. }
  87. private playAni1(){
  88. let node = cc.instantiate(this.mBullet);
  89. let bObject = node.getComponent(BObject);
  90. let mHitEffect = bObject.mHitEffect;
  91. bObject.destroy();
  92. let p1 = this.myspine.node.getPosition();
  93. p1.y += this.myspine.node.height/2;
  94. let p2 = this.mDx[0].getPosition();
  95. p2.y += this.mDx[0].height/2;
  96. node.parent = this.node;
  97. let angle = CMath.getAngle(p1,p2)*180/Math.PI;
  98. node.angle = angle
  99. cc.tween(node).sequence(
  100. cc.moveTo(0.5,p2),
  101. cc.callFunc(()=>{
  102. node.destroy();
  103. let xnode = cc.instantiate(mHitEffect);
  104. xnode.x = this.mDx[0].x;
  105. xnode.y = this.mDx[0].y;
  106. xnode.parent = this.node;
  107. this.playAni2()
  108. this.mDead(this.mDx[0]);
  109. })
  110. ).start()
  111. }
  112. private playAni2(){
  113. let node = cc.instantiate(this.mBullet);
  114. let bObject = node.getComponent(BObject);
  115. let mHitEffect = bObject.mHitEffect;
  116. bObject.destroy();
  117. let p1 = this.myspine.node.getPosition();
  118. p1.y += this.myspine.node.height/2;
  119. let p2 = this.mDx[1].getPosition();
  120. p2.y += this.mDx[1].height/2;
  121. node.parent = this.node;
  122. let angle = CMath.getAngle(p1,p2)*180/Math.PI;
  123. node.angle = angle
  124. cc.tween(node).sequence(
  125. cc.moveTo(0.5,p2),
  126. cc.callFunc(()=>{
  127. node.destroy();
  128. let xnode = cc.instantiate(mHitEffect);
  129. xnode.x = this.mDx[1].x;
  130. xnode.y = this.mDx[1].y;
  131. xnode.parent = this.node;
  132. this.mDead(this.mDx[1]);
  133. this.d2()
  134. })
  135. ).start()
  136. }
  137. private d2(){
  138. this.myspine.node.scaleX = 1;
  139. let dialogs = [
  140. '妖...妖怪',
  141. ];
  142. let mapDialog = new FMapDialog(this.ff,this.mMapDialog);
  143. let pos = cc.v2();
  144. pos.x = this.node.x + this.mDx[2].x;
  145. pos.y = this.node.y + this.mDx[2].y + this.mDx[2].height;
  146. mapDialog.showDialog(dialogs,
  147. pos,
  148. null,
  149. ()=>{
  150. this.d3();
  151. }
  152. );
  153. }
  154. private d3(){
  155. let dialogs = [
  156. '快...快跑',
  157. ];
  158. let mapDialog = new FMapDialog(this.ff,this.mMapDialog);
  159. let pos = cc.v2();
  160. pos.x = this.node.x + this.mDx[3].x;
  161. pos.y = this.node.y + this.mDx[3].y + this.mDx[3].height;
  162. mapDialog.showDialog(dialogs,
  163. pos,
  164. null,
  165. ()=>{
  166. this.playAni3();
  167. }
  168. );
  169. }
  170. private playAni3(){
  171. let node = cc.instantiate(this.mBullet);
  172. let bObject = node.getComponent(BObject);
  173. let mHitEffect = bObject.mHitEffect;
  174. bObject.destroy();
  175. let p1 = this.myspine.node.getPosition();
  176. p1.y += this.myspine.node.height/2;
  177. let p2 = this.mDx[2].getPosition();
  178. p2.y += this.mDx[2].height/2;
  179. node.parent = this.node;
  180. let angle = CMath.getAngle(p1,p2)*180/Math.PI;
  181. node.angle = angle
  182. cc.tween(node).sequence(
  183. cc.moveTo(0.5,p2),
  184. cc.callFunc(()=>{
  185. node.destroy();
  186. let xnode = cc.instantiate(mHitEffect);
  187. xnode.x = this.mDx[2].x;
  188. xnode.y = this.mDx[2].y;
  189. xnode.parent = this.node;
  190. this.playAni4()
  191. this.mDead(this.mDx[2]);
  192. })
  193. ).start()
  194. }
  195. private playAni4(){
  196. let node = cc.instantiate(this.mBullet);
  197. let bObject = node.getComponent(BObject);
  198. let mHitEffect = bObject.mHitEffect;
  199. bObject.destroy();
  200. let p1 = this.myspine.node.getPosition();
  201. p1.y += this.myspine.node.height/2;
  202. let p2 = this.mDx[3].getPosition();
  203. p2.y += this.mDx[3].height/2;
  204. node.parent = this.node;
  205. let angle = CMath.getAngle(p1,p2)*180/Math.PI;
  206. node.angle = angle
  207. cc.tween(node).sequence(
  208. cc.moveTo(0.5,p2),
  209. cc.callFunc(()=>{
  210. node.destroy();
  211. let xnode = cc.instantiate(mHitEffect);
  212. xnode.x = this.mDx[3].x;
  213. xnode.y = this.mDx[3].y;
  214. xnode.parent = this.node;
  215. this.mDead(this.mDx[3]);
  216. this.mainMove();
  217. })
  218. ).start()
  219. }
  220. //主角移动进场
  221. private mainMove(){
  222. this.myspine.node.scaleX = -1
  223. let mainSprite = this.ff.mainSprite;
  224. let p1 = this.node.getPosition();
  225. p1.x -= 180;
  226. mainSprite.playAction2(SpriteActionType.run,true)
  227. cc.tween(mainSprite.node).sequence(
  228. cc.moveTo(1,p1),
  229. cc.callFunc(()=>{
  230. mainSprite.playAction2(SpriteActionType.stand,true)
  231. this.d4();
  232. })
  233. ).start()
  234. }
  235. private d4(){
  236. let dialogs = [
  237. '小巫女,你看到2个和我差不多大的人类吗?',
  238. '什么?你已经救了他们?',
  239. '太感谢你了,有没有什么我可以帮助你的?',
  240. '你要去传风带?',
  241. '#yun',
  242. '不要,我可不想跟你一起把小命丢了',
  243. ];
  244. let mapDialog = new FMapDialog(this.ff,this.mMapDialog);
  245. let pos = cc.v2();
  246. pos.x = this.node.x;
  247. pos.y = this.node.y + this.node.height;
  248. mapDialog.showDialog(dialogs,
  249. pos,
  250. this.myspine,
  251. ()=>{
  252. this.mainLose();
  253. }
  254. );
  255. }
  256. /**
  257. * 主角丢苹果在地上,然后飞到对方身上
  258. */
  259. private mainLose(){
  260. let node = new cc.Node();
  261. node.group = 'map';
  262. let sprite = node.addComponent(cc.Sprite);
  263. sprite.spriteFrame = this.mAppleIcon;
  264. let mainSprite = this.ff.mainSprite;
  265. node.x = mainSprite.node.x;
  266. node.y = mainSprite.node.y + mainSprite.node.height/2;
  267. node.parent = this.ff.mMap.mSprites;
  268. node.setScale(1.5);
  269. let jumpDis = CMath.getRandom(-100,100);
  270. let jumpBy = cc.jumpBy(0.5, cc.v2(jumpDis, 0), 100, 1);
  271. cc.tween(node).sequence(
  272. jumpBy,
  273. cc.delayTime(0.5),
  274. cc.callFunc(()=>{
  275. cc.tween(node).sequence(
  276. cc.moveTo(0.5,this.node.getPosition()),
  277. cc.callFunc(()=>{
  278. this.d5()
  279. node.destroy();
  280. })
  281. ).start()
  282. cc.tween(node).repeatForever(
  283. cc.rotateBy(1, 360)
  284. ).start()
  285. })
  286. ).start()
  287. }
  288. private d5(){
  289. let dialogs = [
  290. '好吧,好吧,看在你救了我朋友的份上',
  291. '就陪你走一趟,耶稣菩萨保佑,我们一路平安',
  292. '出发',
  293. ];
  294. let mapDialog = new FMapDialog(this.ff,this.mMapDialog);
  295. let pos = cc.v2();
  296. pos.x = this.node.x;
  297. pos.y = this.node.y + this.node.height;
  298. mapDialog.showDialog(dialogs,
  299. pos,
  300. this.myspine,
  301. ()=>{
  302. this.getPet();
  303. }
  304. );
  305. }
  306. /**
  307. * 解救伙伴
  308. */
  309. private getPet(){
  310. let mainSprite = this.ff.mainSprite;
  311. let pos = mainSprite.node.getPosition()
  312. pos.x -= this.node.x;
  313. pos.y -= this.node.y;
  314. this.myspine.setAnimation(0, SpriteActionType.run, true);
  315. cc.tween(this.myspine.node).sequence(
  316. cc.moveTo(1,pos),
  317. cc.callFunc(()=>{
  318. this.myspine.node.removeFromParent();
  319. for (let i = 0; i < this.mMonster.length; i++) {
  320. const element = this.mMonster[i];
  321. let node = cc.instantiate(element);
  322. let sp = node.getComponent(PSprite);
  323. this.ff.addRole(sp);
  324. }
  325. this.node.destroy();
  326. this.ff.pauseSprite(false);
  327. })
  328. ).start()
  329. }
  330. }