StoryController.js 10 KB

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