lucky.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. // Learn cc.Class:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/class.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. var hitDirection = cc.Enum({
  8. left: 0,
  9. middle: 1,
  10. right: 2
  11. });
  12. cc.Class({
  13. extends: cc.Component,
  14. properties: {
  15. // foo: {
  16. // // ATTRIBUTES:
  17. // default: null, // The default value will be used only when the component attaching
  18. // // to a node for the first time
  19. // type: cc.SpriteFrame, // optional, default is typeof default
  20. // serializable: true, // optional, default is true
  21. // },
  22. // bar: {
  23. // get () {
  24. // return this._bar;
  25. // },
  26. // set (value) {
  27. // this._bar = value;
  28. // }
  29. // },
  30. //硬币初始值
  31. coin: {
  32. default: 3000,
  33. type: cc.Integer,
  34. tooltip: "初始分数",
  35. serializable: true,
  36. },
  37. coinNode: {
  38. default: null,
  39. type: cc.Node,
  40. tooltip: "显示可用分数",
  41. serializable: true,
  42. },
  43. index: {
  44. default: 0,
  45. type: cc.Integer,
  46. visible: false,
  47. serializable: false,
  48. },
  49. fruits: {
  50. default: [],
  51. visible: false,
  52. type: cc.Node,
  53. serializable: true
  54. },
  55. FruitsNode: {
  56. default: null,
  57. type: cc.Node,
  58. tooltip: "图标父节点",
  59. serializable: true,
  60. },
  61. FruitsMask: {
  62. default: null,
  63. type: cc.Node,
  64. tooltip: "选中的遮罩",
  65. serializable: true,
  66. },
  67. //减速时间==加速时间
  68. duration: {
  69. tooltip: "减速时间==加速时间",
  70. default: 2,
  71. type: cc.Float,
  72. max: 10,
  73. min: 1,
  74. },
  75. rewardFruits: {
  76. default: [],
  77. tooltip: "奖励的水果数组",
  78. visible: false,
  79. type: cc.Node,
  80. serializable: true
  81. },
  82. ResultNode: {
  83. default: null,
  84. type: cc.Node,
  85. tooltip: "返回结果的父节点",
  86. serializable: true,
  87. },
  88. resultFruits: {
  89. default: [],
  90. tooltip: "solt节点",
  91. visible: false,
  92. type: cc.Node,
  93. serializable: true
  94. },
  95. runSche: {
  96. default: null,
  97. visible: false,
  98. serializable: true,
  99. },
  100. //执行次数
  101. count: {
  102. default: 0,
  103. type: cc.Integer,
  104. visible: false,
  105. serializable: false,
  106. },
  107. //击中的次数
  108. hitCount: {
  109. default: 0,
  110. type: cc.Integer,
  111. visible: false,
  112. serializable: false,
  113. },
  114. //定义一个水果字典属性
  115. coinArray: {
  116. default: null,
  117. visible: false,
  118. serializable: true,
  119. },
  120. //计算结果时候奖励的金币
  121. rewardCoin: {
  122. default: 0,
  123. type: cc.Integer,
  124. visible: false,
  125. serializable: false,
  126. },
  127. rewardCoinNode: {
  128. default: null,
  129. type: cc.Node,
  130. tooltip: "当前奖励的金币数量",
  131. serializable: true,
  132. },
  133. //是否开始运行
  134. gameRun: {
  135. default: false,
  136. visible: false,
  137. serializable: false,
  138. },
  139. //是否完全停下来
  140. gameStop: {
  141. default: false,
  142. visible: false,
  143. serializable: false,
  144. },
  145. //是否在播放开始音乐
  146. audioGameStartPlay: {
  147. default: false,
  148. visible: false,
  149. serializable: false,
  150. },
  151. defaultSpriteFrame: {
  152. default: null,
  153. type: cc.spriteFrame,
  154. serializable: false,
  155. visible: false,
  156. },
  157. //左右两个进度条
  158. leftProgressBar: {
  159. default: null,
  160. type: cc.ProgressBar,
  161. serializable: true,
  162. },
  163. rightProgressBar: {
  164. default: null,
  165. serializable: true,
  166. type: cc.ProgressBar,
  167. },
  168. maxHitPower: {
  169. default: 200,
  170. type: cc.Integer,
  171. tooltip: "最大的力,公斤",
  172. serializable: false,
  173. },
  174. curHitPower: {
  175. default: 0,
  176. type: cc.Integer,
  177. tooltip: "当前的力,公斤",
  178. serializable: false,
  179. },
  180. upTime: {
  181. default: 3,
  182. type: cc.Integer,
  183. tooltip: "上升时间",
  184. serializable: true,
  185. },
  186. powerLabel: {
  187. default: null,
  188. type: cc.Label,
  189. tooltip: "显示的力量槽",
  190. serializable: true,
  191. },
  192. hitDire: {
  193. default: hitDirection.left,
  194. type: cc.Enum(hitDirection),
  195. visible: false
  196. },
  197. tipDire: {
  198. default: hitDirection.left,
  199. type: cc.Enum(hitDirection),
  200. visible: false,
  201. },
  202. tipDireBoxingNode: {
  203. default: [],
  204. visible: true,
  205. tooltip: "提示的拳击图标节点",
  206. type: cc.Node,
  207. serializable: true
  208. },
  209. explainUI: {
  210. default: null,
  211. type: cc.Node,
  212. tooltip: "说明ui节点",
  213. serializable: true,
  214. },
  215. StartButton: {
  216. default: null,
  217. type: cc.Node,
  218. tooltip: "开始按钮节点",
  219. serializable: true,
  220. },
  221. bHasPlayEnd: {
  222. default: false,
  223. tooltip: "是否播放完数字读音",
  224. serializable: true,
  225. },
  226. timeCount: {
  227. default: 0,
  228. type: cc.Integer,
  229. visible: false
  230. }
  231. },
  232. // LIFE-CYCLE CALLBACKS:
  233. syncCoin() {
  234. //显示初始分数
  235. this.coinNode.getComponent(cc.Label).string = this.coin;
  236. },
  237. syncReward() {
  238. //同步当前奖励的金币
  239. this.rewardCoinNode.getComponent(cc.Label).string = this.rewardCoin;
  240. },
  241. syncHitPower(value) {
  242. this.curHitPower = value;
  243. this.powerLabel.string = this.curHitPower;
  244. },
  245. onLoad() {
  246. //显示初始分数
  247. this.syncCoin();
  248. //同步当前奖励的金币
  249. this.syncReward();
  250. //同步当前打击力
  251. this.syncHitPower(0);
  252. //定义一个水果字典属性
  253. this.coinArray = {
  254. "apple": 100,
  255. "apple_d": 200,
  256. "bell": 300,
  257. "bell_d": 600,
  258. "seven": 700,
  259. "seven_d": 1400,
  260. "star": 1000,
  261. "star_d": 2000,
  262. "bar": 3000,
  263. "lucky": 0 //lucky不算钱
  264. }
  265. //获取水果的solt对象
  266. this.resultFruits = this.ResultNode.children;
  267. //保存一下默认的spriteFrame
  268. this.defaultSpriteFrame = this.resultFruits[0].getComponent(cc.Sprite).spriteFrame;
  269. //获取水果机的对象排序
  270. let topChild = this.FruitsNode.getChildByName("top").children;
  271. let rightChild = this.FruitsNode.getChildByName("right").children;
  272. let leftChild = this.FruitsNode.getChildByName("left").children.reverse();
  273. let bottomChild = this.FruitsNode.getChildByName("bottom").children.reverse();
  274. //这里要按顺时针 获取节点,以便循环
  275. //比如 top->right->bottom->left
  276. this.fruits = this.fruits.concat(topChild)
  277. .concat(rightChild)
  278. .concat(bottomChild)
  279. .concat(leftChild);
  280. console.log(this.fruits);
  281. //加入 fruits 数组后,后面两个需要再反转回来,不然显示会相反
  282. leftChild.reverse();
  283. bottomChild.reverse();
  284. this.schedule(() => {
  285. this.timeCount++;
  286. }, 1)
  287. },
  288. start() {
  289. //开一个计时器,5分钟判断一次
  290. this.schedule(function () {
  291. if (this.coin < 500) {
  292. this.coin += 3000;
  293. this.syncCoin();
  294. console.log("赠送金币", this.coin);
  295. }
  296. }.bind(this), 300);
  297. },
  298. //开始游戏
  299. onGameStart() {
  300. if (this.gameStop) return;
  301. if (this.gameRun) return;
  302. if (this.count >= 3) {
  303. console.log("已执行完三次打击");
  304. return;
  305. }
  306. if (this.coin == 0) {
  307. console.log("金币不能为零");
  308. myAudio.onNoCoin();
  309. return;
  310. }
  311. if (this.coin >= 500) {
  312. //计算金币
  313. this.coin -= 500;
  314. this.syncCoin();
  315. myAudio.onDeducCoin();
  316. } else {
  317. console.log("金币不足500!");
  318. myAudio.onNoCoin();
  319. return;
  320. }
  321. //开启runing
  322. this.runSche = () => {
  323. this.runing();
  324. }
  325. this.schedule(this.runSche, 0.05);
  326. this.gameRun = true;
  327. console.log("点击开始");
  328. //设置提示拳
  329. setTimeout(() => {
  330. this.onSetTipDirection();
  331. }, 500)
  332. },
  333. runing() {
  334. if (this.fruits.length == 0) {
  335. console.log("fruits 不能为空");
  336. return;
  337. }
  338. // this.index = 10;
  339. if (this.index == this.fruits.length - 1) {
  340. this.index = 0;
  341. } else {
  342. this.index++;
  343. }
  344. //获取target 的pos
  345. let tarPos = this.fruits[this.index].parent.convertToWorldSpaceAR(this.fruits[this.index].position);
  346. let endPos = this.FruitsMask.parent.convertToNodeSpaceAR(tarPos);
  347. this.FruitsMask.setPosition(endPos);
  348. },
  349. //设置提示的击打方向
  350. onSetTipDirection() {
  351. let direArray = [0, 1, 2];
  352. let index = Math.floor((Math.random() * direArray.length));
  353. for (let i = 0; i < this.tipDireBoxingNode.length; i++) {
  354. if (i == index) {
  355. this.tipDireBoxingNode[i].active = true;
  356. } else {
  357. this.tipDireBoxingNode[i].active = false;
  358. }
  359. }
  360. if (index == 0) {
  361. this.tipDire = hitDirection.left;
  362. } else if (index == 1) {
  363. this.tipDire = hitDirection.middle;
  364. } else if (index == 2) {
  365. this.tipDire = hitDirection.right;
  366. }
  367. //提示拳击方向
  368. myAudio.onPlayBoxingTip(index);
  369. console.log("设置的提示拳:", this.tipDire);
  370. },
  371. //手机加速计部分调用触发,
  372. //走完计算流程后,触发回调
  373. onHitFromDevice(data, callback) {
  374. console.log("onHitFromDevice:", data);
  375. if (data.direction == "xLCount") {
  376. //右勾拳
  377. this.onHitCall("right", data.hitPower, callback);
  378. } else if (data.direction == "xRCount") {
  379. //左勾拳
  380. this.onHitCall("left", data.hitPower, callback);
  381. } else if (data.direction == "zLCount" || data.direction == "zRCount") {
  382. //直拳
  383. this.onHitCall("middle", data.hitPower, callback);
  384. }
  385. },
  386. //调用打击
  387. onHitCall(direction, hitPower, callback) {
  388. if (!this.gameRun) {
  389. console.log("游戏未开始");
  390. return;
  391. }
  392. let ranPower = 0;
  393. if (!hitPower) {
  394. //1.计算力量,
  395. ranPower = Math.ceil(Math.random() * 200) + 100;
  396. } else {
  397. ranPower = hitPower;
  398. }
  399. if (ranPower > 999)
  400. ranPower = 999;
  401. //判断方向
  402. if (direction == "left") {
  403. this.hitDire = hitDirection.left;
  404. } else if (direction == "middle") {
  405. this.hitDire = hitDirection.middle;
  406. } else if (direction == "right") {
  407. this.hitDire = hitDirection.right;
  408. }
  409. // console.log(this.hitDire);
  410. //判断是否和提示的方向一样
  411. if (this.hitDire == this.tipDire) {
  412. this.onDelayEnd(ranPower);
  413. // console.log("击打正确");
  414. //读取播报数字
  415. this.bHasPlayEnd = false;
  416. myAudio.onPlayHitPower(ranPower.toString(), () => {
  417. this.bHasPlayEnd = true;
  418. console.log("播放完声音:", this.gameStop, this.gameRun, this.bHasPlayEnd);
  419. if (this.count == 3) {
  420. if (this.gameStop || this.gameRun) return;
  421. //计算奖励
  422. this.onRewards();
  423. } else {
  424. //如果count 不等于 3 ,继续开游戏
  425. //todo 播放音效后,继续游戏
  426. //开始游戏
  427. this.onGameStart();
  428. }
  429. });
  430. this.hitCount++;
  431. //播放击中的音效
  432. if (this.hitCount == 2) {
  433. myAudio.onTwoHits();
  434. } else if (this.hitCount == 3) {
  435. myAudio.onThreeHits();
  436. } else if (this.hitCount == 1) {
  437. myAudio.onHitSuccess();
  438. }
  439. } else {
  440. this.hitCount = 0;
  441. if (this.tipDire == 0) {
  442. console.log("请打击左勾拳");
  443. myAudio.onHitFail();
  444. //提示拳击方向
  445. myAudio.onPlayBoxingTip(0);
  446. if (callback)
  447. callback();
  448. } else if (this.tipDire == 1) {
  449. console.log("请打击直拳");
  450. myAudio.onHitFail();
  451. //提示拳击方向
  452. myAudio.onPlayBoxingTip(1);
  453. if (callback)
  454. callback();
  455. } else if (this.tipDire == 2) {
  456. console.log("请打击右勾拳");
  457. myAudio.onHitFail();
  458. //提示拳击方向
  459. myAudio.onPlayBoxingTip(2);
  460. if (callback)
  461. callback();
  462. }
  463. }
  464. },
  465. //
  466. onDelayEnd(hitPower) {
  467. if (!this.gameRun)
  468. return;
  469. this.gameRun = false;
  470. //假如已经触发停止按钮响应,但是还没完全停止
  471. this.gameStop = true;
  472. //2.根据力量值,来判断,如果超过max值,马上停止,反之停止的越慢
  473. let temPower = hitPower / this.maxHitPower;
  474. //3.计算剩余的时间time 比例,
  475. let time = (1 - temPower) * this.duration;
  476. if (time <= 0) {
  477. time = 0;
  478. }
  479. console.log("运行的时间:", time);
  480. //4.默认运行速度是0.05 最大值是0.5
  481. let obj = { a: 0.05 }
  482. let oldValue = 0.05;
  483. cc.tween(obj).to(time, { a: 0.5 }, {
  484. progress: (start, end, current, ratio) => {
  485. let tempValue = start + (end - start) * ratio;
  486. if (tempValue > oldValue * 2 + 0.001) {
  487. oldValue = tempValue;
  488. this.unschedule(this.runSche);
  489. this.schedule(this.runSche, oldValue);
  490. }
  491. return start + (end - start) * ratio;
  492. }
  493. })
  494. .call(() => {
  495. this.onEndShow(hitPower);
  496. })
  497. .start()
  498. //显示到ui
  499. this.syncHitPower(hitPower);
  500. this.onPowerBar(hitPower);
  501. console.log("点击停止");
  502. },
  503. onEndShow() {
  504. this.gameStop = false;
  505. this.count++;
  506. this.unschedule(this.runSche);
  507. this.rewardFruits.push(this.fruits[this.index]);
  508. console.log("选中的水果名字:", this.fruits[this.index].name);
  509. for (let i = 0; i < this.rewardFruits.length; i++) {
  510. //结果在resultFruits中显示
  511. this.resultFruits[i].getComponent(cc.Sprite).spriteFrame = this.rewardFruits[i].getComponent(cc.Sprite).spriteFrame;
  512. }
  513. webView.onResetAccState();
  514. console.log("this.bHasPlayEnd:", this.bHasPlayEnd);
  515. if (this.bHasPlayEnd) {
  516. if (this.count == 3) {
  517. //计算奖励
  518. this.onRewards();
  519. } else {
  520. //如果count 不等于 3 ,继续开游戏
  521. //todo 播放音效后,继续游戏
  522. //开始游戏
  523. console.log(this.gameStop, this.gameRun, this.bHasPlayEnd);
  524. this.onGameStart();
  525. }
  526. }
  527. },
  528. onRewards() {
  529. //计算分数
  530. //水果组合:
  531. //如果没有组合用户得不到任何金币(三个完全不同的水果)
  532. //三次打击完成后如果出现一对相同的水果(非双倍水果)金币加成这两个水果总金额的25%
  533. //三次打击完成后如果出现3个相同的水果(非双倍水果),金币加成这两个水果总金额的50% **
  534. //三次打击完成后如果出现一对相同的水果(双倍水果)金币加成这两个水果总金额的50%
  535. //三次打击完成后如果出现3个相同的水果(双倍水果),金币加成这两个水果总金额的100% **
  536. //三个相等
  537. if (this.rewardFruits[0].name == this.rewardFruits[1].name && this.rewardFruits[0].name == this.rewardFruits[2].name) {
  538. //不能是lucky图标,之后判断是双倍还是非双倍
  539. if (this.rewardFruits[0].name != "lucky") {
  540. let coinItem = this.coinArray[this.rewardFruits[0].name];
  541. if (this.rewardFruits[0].name.indexOf("_d") != -1) {
  542. //是双倍水果,加成总金额的100%
  543. this.rewardCoin = coinItem * 6;//coinItem * 3 * 2
  544. console.log("是双倍水果,加成总金额的100% ");
  545. } else {
  546. this.rewardCoin = coinItem * 4.5;//coinItem * 3 + coinItem * 1.5
  547. console.log("是单倍水果,加成总金额的50% ");
  548. }
  549. } else {
  550. console.log("三个lucky不加分");
  551. }
  552. }
  553. else {
  554. //记录一下相同和不同的对象
  555. let sameObj = null, defferentObj = null;
  556. if (this.rewardFruits[0].name == this.rewardFruits[1].name) {
  557. defferentObj = this.rewardFruits[2];
  558. sameObj = this.rewardFruits[0];
  559. } else if (this.rewardFruits[0].name == this.rewardFruits[2].name) {
  560. defferentObj = this.rewardFruits[1];
  561. sameObj = this.rewardFruits[0];
  562. } else if (this.rewardFruits[1].name == this.rewardFruits[2].name) {
  563. defferentObj = this.rewardFruits[0];
  564. sameObj = this.rewardFruits[1];
  565. }
  566. //判断两个相等的不是lucky,计算分数
  567. if (sameObj != null && sameObj.name != "lucky") {
  568. let coinItem = this.coinArray[sameObj.name];
  569. //判断不相等的那一个是不是lucky,如果是,则计算三个相等
  570. if (defferentObj.name == "lucky") {
  571. if (sameObj.name.indexOf("_d") != -1) {
  572. //是双倍水果,加成总金额的100%
  573. this.rewardCoin = coinItem * 6;//coinItem * 3 * 2
  574. console.log("是双倍水果,加成总金额的100% ");
  575. } else {
  576. //是单倍水果,加成总金额的50%
  577. this.rewardCoin = coinItem * 4.5;// coinItem * 3 + coinItem * 1.5
  578. console.log("是单倍水果,加成总金额的50% ");
  579. }
  580. } else {
  581. //处理只有两个相等情况
  582. if (sameObj.name.indexOf("_d") != -1) {
  583. //是双倍水果,加成总金额的50%
  584. this.rewardCoin = coinItem * 3; //coinItem * 2 + coinItem * 2 * 0.5
  585. console.log("是双倍水果,加成总金额的50% ");
  586. } else {
  587. //是单倍水果,加成总金额的25%
  588. this.rewardCoin = coinItem * 2.5;//coinItem * 2 + coinItem * 2 * 0.25
  589. console.log("是单倍水果,加成总金额的25% ");
  590. }
  591. }
  592. } else if (sameObj == null) {
  593. console.log("没有相同的项目,不加分");
  594. }
  595. }
  596. console.log("最后奖励的分数:", this.rewardCoin);
  597. if (0 == this.rewardCoin) {
  598. //失败
  599. myAudio.onPlayGameDefeat();
  600. } else {
  601. //成功
  602. myAudio.onPlayGameVictory();
  603. //金币音效
  604. myAudio.onGetCoin();
  605. this.coin += this.rewardCoin;
  606. this.syncCoin();
  607. }
  608. this.syncReward();
  609. //显示开始按钮
  610. this.StartButton.active = true;
  611. console.log("是否显示按钮:", this.StartButton.active);
  612. this.uploadScore();
  613. },
  614. //重置游戏,点击开始游戏调用
  615. onReset() {
  616. if (this.gameStop) return;
  617. if (this.gameRun) return;
  618. if (this.count < 3 && this.count != 0) {
  619. console.log("需要执行完才可以开始,count=", this.count);
  620. return;
  621. }
  622. this.count = 0;
  623. this.rewardCoin = 0;
  624. this.syncReward();
  625. this.rewardFruits = [];
  626. this.unschedule(this.runSche);
  627. for (let i = 0; i < this.resultFruits.length; i++) {
  628. //结果在resultFruits中显示
  629. this.resultFruits[i].getComponent(cc.Sprite).spriteFrame = this.defaultSpriteFrame;
  630. }
  631. this.syncHitPower(0);
  632. this.StartButton.active = false;
  633. console.log("onReset 是否显示按钮:", this.StartButton.active);
  634. if (this.audioGameStartPlay) return;
  635. this.audioGameStartPlay = true;
  636. myAudio.onPlayGameStart(() => {
  637. this.audioGameStartPlay = false;
  638. //开始游戏
  639. this.onGameStart();
  640. });
  641. },
  642. //重新初始化游戏和分数
  643. onResetGame() {
  644. this.coin = 3000;
  645. this.syncCoin();
  646. this.onReset();
  647. },
  648. onPowerBar(curHitPower) {
  649. let temPower = curHitPower / this.maxHitPower;
  650. //零到 1 之 间
  651. let obj = { a: 0 }
  652. cc.tween(obj).to(this.upTime, { a: temPower }, {
  653. progress: (start, end, current, ratio) => {
  654. let tempValue = start + (end - start) * ratio;
  655. this.leftProgressBar.progress = tempValue;
  656. this.rightProgressBar.progress = tempValue;
  657. return start + (end - start) * ratio;
  658. }
  659. })
  660. .start()
  661. },
  662. //说明规则ui
  663. onShowExplain() {
  664. this.explainUI.active = true;
  665. },
  666. onHideExplain() {
  667. this.explainUI.active = false;
  668. },
  669. uploadScore() {
  670. uni.postMessage({
  671. data: {
  672. funName: "uploadInfo",
  673. gameData: {
  674. gameScore: webView.AllPower? webView.AllPower : 0,//游戏得分
  675. gameTime: this.timeCount,//单位秒
  676. calorieBurned: webView.AllCalorie? webView.AllCalorie : 0,//消耗的卡路里
  677. }
  678. }
  679. });
  680. console.log("webView.AllPower:",webView.AllPower);
  681. console.log("webView.AllCalorie:",webView.AllCalorie);
  682. webView.onResetAllValue();
  683. }
  684. // update(dt) {
  685. // },
  686. });