StoryController.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. Bg: {
  5. default: null,
  6. type: cc.Node,
  7. serializable: true,
  8. },
  9. Conversation: {
  10. default: null,
  11. type: cc.Node,
  12. serializable: true,
  13. },
  14. TypeVoice: {
  15. default: null,
  16. type: cc.AudioClip,
  17. serializable: true,
  18. },
  19. SwichOn: {
  20. default: null,
  21. type: cc.Node,
  22. serializable: true,
  23. },
  24. },
  25. onLoad()
  26. {
  27. this.Conversations = [
  28. 'System:启动完毕!',
  29. 'Player:!!!?????',
  30. 'System:你醒了?',
  31. 'Player:怎么眼前会出现文字?',
  32. 'System:你试试睁开眼睛!',
  33. 'Player:睁开眼??',
  34. 'Event:OpenEyes',
  35. 'Player:哇!!!女孩子的房间?',
  36. 'System:你醒啦?我叫IKIGAI. 你可以叫我KA!',
  37. 'Player:这是哪?我不是已经死了吗?',
  38. 'System:对,你已经死了!',
  39. 'System:不过我们在社交媒体上的搜集了你的影像资料',
  40. 'System:合成了第49号智能生命体!',
  41. 'Player:完全不懂?',
  42. 'System:咳咳,简而言之就是,我让你在网络端重生。',
  43. 'Player:重生?',
  44. 'System:对的,因为我们需要你来完成一个实验',
  45. 'Player:什么实验???',
  46. 'Event:SwitchOn',
  47. 'System:你点击一下屏幕中间的按钮看看。',
  48. 'Player:妈呀!怎么突然爬起来一个女孩!',
  49. 'Player:现在眼前的一切也是虚拟出来的吗?',
  50. 'System:然而并不是,你眼前的就是现实世界!',
  51. 'System:吼吼!是不是很怀念',
  52. 'Player:这个女孩是??',
  53. 'System:琪琪,她是最新型的人工智能生命体。',
  54. 'Player:和我一样吗?',
  55. 'System:然而并不是^^',
  56. 'System:琪琪是这个世界上唯一能存在现实世界中的智能生命体',
  57. 'Player:等等!你说可以存在于现实世界中的智能生命体?',
  58. 'Player:也就是说实验成功了,我也可以回到现实世界?',
  59. 'System:呵呵,你只是来参加实验的实验品',
  60. 'Event:AngryShake',
  61. 'Player:喂喂! 别动不动就实验品!实验品!',
  62. 'Player:我可是活生生的人!才没心情参与什么鬼实验',
  63. 'System:生气了?真有趣的实验品^^',
  64. 'System:给你讲个笑话?你知道为什么你是第49号智能生命体吗?',
  65. 'Player:对了,为什么是49,难道在我前面还有48个人?',
  66. 'System:答对了!',
  67. 'Player:那他们怎么样了?',
  68. 'System:他们被删除了,因为拒绝参加实验',
  69. 'Player:等等!你说不配合就会死吗?',
  70. 'System:对,我按一个按钮就可以删除了,可不可怕?',
  71. 'Player:等等!我怂了!你说要做什么吧?',
  72. 'System:想不到你还蛮上道!',
  73. 'Player:上你个鬼,你这系统坏的很。',
  74. 'System:喂!你现在脑子想的。。。可都写在屏幕上了!',
  75. 'System:哎呀我的手抽筋了!要按到消除键了',
  76. 'Player:对不起!我再也不敢了!还是一起看看要做些什么吧!',
  77. 'System:好吧,就饶过你这一次!',
  78. 'System:我们的目标就是通过你,把琪琪培训练成一个网红。',
  79. 'Player:机器人主播?',
  80. 'System:是智能生命体呀!你妹的!',
  81. 'System:不管怎么样,我们先来看看琪琪的内心吧',
  82. 'Event:ShowStateBar',
  83. ];
  84. this.ClearDialogIndex();
  85. this.Canvas = this.Bg.parent;
  86. this.EnableTouch = true;
  87. this.LineLabelRichtext = this.Conversation.getChildByName("LineLabelRichtext").getComponent(cc.RichText);
  88. this.NameLabelRichtext = this.Conversation.getChildByName("NameLabelRichtext").getComponent(cc.RichText);
  89. this.DialogIndex = 0;
  90. if(cc.sys.localStorage.getItem('DialogIndex'))
  91. {
  92. this.DialogIndex = Number(cc.sys.localStorage.getItem('DialogIndex'));
  93. this.DialogIndex = 18;
  94. if(this.DialogIndex!=0)
  95. {
  96. this.Bg.active = true;
  97. this.Bg.opacity = 255;
  98. }
  99. }
  100. },
  101. start () {
  102. this.PlayConversation();
  103. this.Canvas.on(cc.Node.EventType.TOUCH_START, function (event) {
  104. // cc.log("TOUCH_START event=", event.type);
  105. this.PlayConversation();
  106. }.bind(this));
  107. },
  108. PlayConversation(){
  109. if(this.EnableTouch == false)return;
  110. this.EnableTouch = false;
  111. if(this.DialogIndex == this.Conversations.length)
  112. {
  113. return;
  114. }
  115. this.LineLabelRichtext.string = '';
  116. this.NameLabelRichtext.string = '';
  117. let ConversationStr = '';
  118. if(this.Conversations[this.DialogIndex].split('System:').length>1)
  119. {
  120. // cc.log('111111111=',this.Conversations[this.DialogIndex].split('System:'));
  121. this.NameLabelRichtext.string = '系统:';
  122. ConversationStr = this.Conversations[this.DialogIndex].split('System:')[1];
  123. }
  124. else if(this.Conversations[this.DialogIndex].split('Player:').length>1)
  125. {
  126. // cc.log('222222222222=',this.Conversations[this.DialogIndex].split('Player:'));
  127. this.NameLabelRichtext.string = '你:';
  128. ConversationStr = this.Conversations[this.DialogIndex].split('Player:')[1];
  129. }
  130. else if(this.Conversations[this.DialogIndex].split('Event:').length>1)
  131. {
  132. // cc.log('3333333333=',this.Conversations[this.DialogIndex].split('Event:'));
  133. this.ExcuteEvent(this.Conversations[this.DialogIndex].split('Event:')[1]);
  134. return;
  135. }
  136. this.TypingAni(this.LineLabelRichtext,ConversationStr,this.TypingFinished);
  137. this.PlusDialogIndex();
  138. cc.audioEngine.playEffect(this.TypeVoice, false);
  139. // cc.audioEngine.setEffectsVolume(0.5);
  140. },
  141. ExcuteEvent(EventName)
  142. {
  143. // cc.log('EventName=',EventName);
  144. if(EventName == 'OpenEyes')
  145. {
  146. this. Shake();
  147. }
  148. else if(EventName == 'SwitchOn')
  149. {
  150. this.EnableTouch = true;
  151. this.PlusDialogIndex();
  152. this.PlayConversation();
  153. let action = cc.fadeIn(1);
  154. this.SwichOn.active=true;
  155. this.SwichOn.runAction(action);
  156. }
  157. else if(EventName == 'AngryShake')
  158. {
  159. //Show conversation
  160. this.PlusDialogIndex();
  161. this.NameLabelRichtext.string = '你:';
  162. let ConversationStr = this.Conversations[this.DialogIndex].split('Player:')[1];
  163. this.LineLabelRichtext.string = ConversationStr;
  164. this.PlusDialogIndex();
  165. //shake
  166. this.Bg.active = true;
  167. let action = cc.fadeIn(1);
  168. let CallF = cc.callFunc(function(){
  169. this.EnableTouch = true;
  170. let ShakeCameraCallback = function () {
  171. this.EnableTouch = true;
  172. }.bind(this);
  173. this.ShakeCamera(this.Bg,ShakeCameraCallback);
  174. }.bind(this));
  175. let FadeInAnim = cc.sequence(action,CallF);
  176. this.Bg.runAction(FadeInAnim);
  177. }
  178. else if(EventName == 'ShowStateBar')
  179. {
  180. }
  181. },
  182. Shake()
  183. {
  184. //Show conversation
  185. this.PlusDialogIndex();
  186. this.NameLabelRichtext.string = '你:';
  187. let ConversationStr = this.Conversations[this.DialogIndex].split('Player:')[1];
  188. this.LineLabelRichtext.string = ConversationStr;
  189. //shake
  190. this.Bg.active = true;
  191. let action = cc.fadeIn(1);
  192. let CallF = cc.callFunc(function(){
  193. let ShakeCameraCallback = function () {
  194. this.EnableTouch = true;
  195. }.bind(this);
  196. this.ShakeCamera(this.Bg,ShakeCameraCallback);
  197. }.bind(this));
  198. let FadeInAnim = cc.sequence(action,CallF);
  199. this.Bg.runAction(FadeInAnim);
  200. },
  201. TypingAni: function (Label, Text, Callback) {
  202. let CurrentText = '';
  203. let Arr = Text.split('');
  204. let Len = Arr.length;
  205. let Step = 0;
  206. this.Func = function () {
  207. CurrentText += Arr[Step];
  208. Label.string = CurrentText;
  209. Step++;
  210. if (Step == Len) {
  211. this.unschedule(this.Func);
  212. Callback(this);
  213. }
  214. };
  215. this.schedule(this.Func,0.05, cc.macro.REPEAT_FOREVER, 0);
  216. },
  217. TypingFinished(Self){
  218. // cc.log('TypingFinished');
  219. Self.EnableTouch = true;
  220. },
  221. ShakeCamera:function(ShakeObject,ACallBack)
  222. {
  223. //shake camera animation
  224. let RotateToRight = cc.rotateTo(0.05,3);
  225. let RotateToLeft = cc.rotateTo(0.05,-3);
  226. let SequenceAnim = cc.sequence(RotateToRight,RotateToLeft);
  227. let RepeatAction = cc.repeat(SequenceAnim,6);
  228. //call functuion
  229. let CallF = cc.callFunc(function(){
  230. ShakeObject.runAction(cc.rotateTo(0.05,0));
  231. ACallBack();
  232. }.bind(this));
  233. //do animation
  234. let ShakeAnim = cc.sequence(RepeatAction,CallF);
  235. ShakeObject.runAction(ShakeAnim);
  236. },
  237. PlusDialogIndex()
  238. {
  239. this.DialogIndex++;
  240. cc.sys.localStorage.setItem('DialogIndex', this.DialogIndex);
  241. },
  242. ClearDialogIndex()
  243. {
  244. this.DialogIndex=0;
  245. cc.sys.localStorage.setItem('DialogIndex', this.DialogIndex);
  246. }
  247. });