utils.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. window.utils = {
  2. //04月25日,单位改为万公里了
  3. StarDistnaces: [
  4. //"月球",
  5. 15210,
  6. //"火星",
  7. 22794,
  8. //"木星",
  9. 77833,
  10. //"土星",
  11. 142700,
  12. //"天王星",
  13. 287099,
  14. //"海王星",
  15. 450400,
  16. //"黑洞"
  17. 591352,
  18. //"飞出太阳系"
  19. 600000,
  20. //飞出银河系
  21. 24598080000000],
  22. //判断是手机
  23. isMobile: function (callback) {
  24. if (cc.sys.platform == cc.sys.MOBILE_BROWSER) {
  25. if (callback != null) {
  26. callback();
  27. }
  28. }
  29. },
  30. //获得一个 ?aa=aa.jpg 后缀的网络图片地址
  31. getNewHttpImage(avatarUrl){
  32. var str = "?aa=aa.jpg";
  33. var temp = avatarUrl;
  34. if (avatarUrl.indexOf(str) == -1) {
  35. temp +=str
  36. return temp
  37. }
  38. return avatarUrl;
  39. },
  40. //判断是手机
  41. isWeb: function (callback) {
  42. if (cc.sys.platform == cc.sys.DESKTOP_BROWSER) {
  43. if (callback != null) {
  44. callback();
  45. }
  46. }
  47. },
  48. //加载网络图片
  49. loadHttpSpriteFrame: function (avatarUrl, sprite) {
  50. cc.loader.load(this.getNewHttpImage(avatarUrl), function (err, texture) {
  51. if (sprite.node!=null) {
  52. sprite.spriteFrame = new cc.SpriteFrame(texture);
  53. }
  54. });
  55. },
  56. //跳转到某个场景名字
  57. toLoadScene: function (SceneName, callback) {
  58. cc.director.loadScene(SceneName, callback);
  59. },
  60. //准备去某个场景
  61. redytoLoadScene: function (SceneName) {
  62. cc.director.preloadScene(SceneName);
  63. },
  64. //加载 resources 文件夹下面的 图片
  65. loadResSpriteFrame: function (src, callback) {
  66. cc.loader.loadRes(src, cc.SpriteFrame, function (err, texture) {
  67. if (callback != null) {
  68. callback(texture);
  69. }
  70. }.bind(this));
  71. },
  72. dragonBonesPlay: function (node, name, playTimes) {
  73. let armature = node.getComponent(dragonBones.ArmatureDisplay);
  74. armature.playAnimation(name, playTimes);
  75. },
  76. dragonBonesGet: function (node) {
  77. let armature = node.getComponent(dragonBones.ArmatureDisplay);
  78. // console.log("是啥",armature.getAnimationNames(armature.armatureName));
  79. return armature.getAnimationNames(armature.armatureName)
  80. },
  81. getShareData: function (callback) {
  82. // let data = {
  83. // der: der,
  84. // pianyi: pianyi,
  85. // power: power,
  86. // ballSpeed: ballSpeed,
  87. // kitTime: kitTime,
  88. // ATime: ATime
  89. // }
  90. //击打三拳的数据
  91. let everypowerdata = UserInfo.PlayerGameData.everypowerdata;
  92. // let everypowerdata = Statistics.player1;
  93. //打击的力量
  94. // 力量
  95. let everypowers = [];
  96. // 准确度
  97. let types = [];
  98. // 拳速
  99. let speend = [];
  100. let missTimes = [];
  101. let hitTimes = [];
  102. for (var i = 0; i < everypowerdata.length; i++) {
  103. let tempdata = everypowerdata[i];
  104. //拳速
  105. speend.push(tempdata.ballSpeed);
  106. everypowers.push(tempdata.power);
  107. // console.log("流量值type", tempdata.type);
  108. types.push(tempdata.pianyi);
  109. // if (!tempdata.isOK) {
  110. // missTimes.push(tempdata.type);
  111. // } else {
  112. // hitTimes.push(tempdata.type);
  113. // }
  114. hitTimes.push(tempdata.type);
  115. }
  116. // 流浪值
  117. let power = parseInt(UserInfo.PlayerGameData.power);
  118. let types_average = 0;
  119. for (var i = 0; i < types.length; i++) {
  120. types_average += types[i];
  121. }
  122. console.log("准确率", (types_average / types.length));
  123. console.log("流量值", power);
  124. //最大连击
  125. let maxCombo = Statistics.player1.continuitymax;
  126. // for (var i = 0; i < types.length; i++) {
  127. // if (i == 0) {
  128. // maxCombo++;
  129. // } else {
  130. // if (types[i - 1] == 1 && types[i] == 1) {
  131. // maxCombo++;
  132. // } else {
  133. // maxCombo = 0;
  134. // }
  135. // }
  136. // }
  137. console.log("现在最高练级11111" + maxCombo);
  138. let speend_average = 0;
  139. for (var i = 0; i < speend.length; i++) {
  140. speend_average += speend[i];
  141. }
  142. let speends = isNaN(Math.round(speend_average / speend.length))?0:Math.round(speend_average / speend.length)
  143. console.log("判断 平均速度" , speends);
  144. //最大拳速
  145. let speend_max = 0;
  146. let temp_speend = 0;
  147. for (var i = 0; i < speend.length; i++) {
  148. if (speend[i] > temp_speend) {
  149. temp_speend = speend[i];
  150. }
  151. }
  152. speend_max = temp_speend;
  153. let powers_max = 0;
  154. let temp_powers = 0;
  155. for (var i = 0; i < everypowers.length; i++) {
  156. if (everypowers[i] > temp_powers) {
  157. temp_powers = everypowers[i];
  158. }
  159. }
  160. powers_max = temp_powers;
  161. console.log("速度", (speend_average / speend.length));
  162. let everypowers_average = 0;
  163. for (var i = 0; i < everypowers.length; i++) {
  164. everypowers_average += everypowers[i];
  165. }
  166. console.log("力量", (everypowers_average / everypowers.length));
  167. let calorie = isNaN(Math.round(everypowers_average / everypowers.length))?0:Math.round(everypowers_average / everypowers.length)
  168. var distance = this.SetDistance(UserInfo.PlayerGameData.currtag, power);
  169. let types_averages = isNaN(parseInt((types_average / types.length)))?0:parseInt((types_average / types.length))
  170. console.log("判断 命中率" , types_averages);
  171. let callbackdata = {
  172. //平均速度
  173. speend_average: Math.round(speend_average / speend.length),
  174. //平均力量
  175. everypowers_average: calorie,
  176. //准确率
  177. types_average: types_averages,
  178. //流浪值
  179. power: power,
  180. //给app 的 数据
  181. setResult: {
  182. //总打击拳数
  183. times: Statistics.dishu.num,
  184. //给 android 的
  185. controlTimes : Statistics.dishu.num,
  186. // miss拳数
  187. missTimes: missTimes.length,
  188. // 命中率
  189. hitRate: types_averages,
  190. // 命中拳数
  191. hitTimes: UserInfo.PlayerGameData.everypowerdataOK.length,
  192. // 游戏总时长
  193. duration: (new Date().getTime() - GameData.gameStartTime),
  194. // 游戏开始时间
  195. requestTime: GameData.gameStartTime,
  196. // 分数
  197. score: Statistics.player1.score,
  198. // 最大力量
  199. maxPower: powers_max,
  200. // 是否赢得游戏
  201. winGame: 1,
  202. // 最大球速
  203. maxSpeed: speend_max,
  204. // 平均球速
  205. avgSpeed: speends,
  206. // 最大连击
  207. maxCombo: maxCombo,
  208. // 光年距离(先是死的)
  209. alternative: distance,
  210. // 扩展数据(不要给)
  211. // extraJson : ""
  212. // 卡路里 4.24添加
  213. calorie: calorie * 6,
  214. // int rankingType, 字段排名 0-score排名 1-alternative排名
  215. // int type 排名类型 1-好友 2-全国
  216. //便捷接口
  217. rankingType : 0,
  218. type : 2,
  219. }
  220. }
  221. if (callback != null) {
  222. callback(callbackdata);
  223. }
  224. },
  225. SetDistance: function (currtag, power) {
  226. var distance = 0;
  227. var distanceUnit = "万公里";
  228. var a = 0;
  229. //普通星球
  230. if (currtag >= 0 && currtag <= 6) {
  231. distance = this.StarDistnaces[currtag];
  232. }
  233. //太阳系
  234. else if (currtag == 99) {
  235. distance = this.StarDistnaces[7];
  236. }
  237. //银河系
  238. else if (currtag == 100) {
  239. distance = this.StarDistnaces[8];
  240. }
  241. a = power / 10000;
  242. a = Math.floor(a * 100) / 100;//保留两位小数点
  243. distance = distance + a;
  244. return distance;
  245. },
  246. //开始
  247. startAnimation(animation,name){
  248. animation.play(name)
  249. },
  250. setAnimationCallBack(animation,type,AnimationName,callback){
  251. // play : 开始播放时
  252. // stop : 停止播放时
  253. // pause : 暂停播放时
  254. // resume : 恢复播放时
  255. // lastframe : 假如动画循环次数大于 1,当动画播放到最后一帧时
  256. // finished : 动画播放完成时
  257. animation.on(type, function (event,state) {
  258. if (callback) {
  259. if (AnimationName == state.name && event ==type ) {
  260. callback()
  261. animation.off(type);
  262. }
  263. }
  264. },this);
  265. },
  266. getAnimations(animation){
  267. return animation.getClips();
  268. },
  269. }
  270. window.Log = {
  271. isShow : true,
  272. // isShow : false,
  273. info(){
  274. if (this.isShow) {
  275. console.log.apply(console,arguments);
  276. }
  277. }
  278. }
  279. window.qiu = {}
  280. //以下为js缓动函数
  281. window.Tween = {
  282. Linear: function (t, b, c, d) {
  283. return c * t / d + b;
  284. },
  285. Quad: {
  286. easeIn: function (t, b, c, d) {
  287. return c * (t /= d) * t + b;
  288. },
  289. easeOut: function (t, b, c, d) {
  290. return -c * (t /= d) * (t - 2) + b;
  291. },
  292. easeInOut: function (t, b, c, d) {
  293. if ((t /= d / 2) < 1) return c / 2 * t * t + b;
  294. return -c / 2 * ((--t) * (t - 2) - 1) + b;
  295. }
  296. },
  297. Cubic: {
  298. easeIn: function (t, b, c, d) {
  299. return c * (t /= d) * t * t + b;
  300. },
  301. easeOut: function (t, b, c, d) {
  302. return c * ((t = t / d - 1) * t * t + 1) + b;
  303. },
  304. easeInOut: function (t, b, c, d) {
  305. if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
  306. return c / 2 * ((t -= 2) * t * t + 2) + b;
  307. }
  308. },
  309. Quart: {
  310. easeIn: function (t, b, c, d) {
  311. return c * (t /= d) * t * t * t + b;
  312. },
  313. easeOut: function (t, b, c, d) {
  314. return -c * ((t = t / d - 1) * t * t * t - 1) + b;
  315. },
  316. easeInOut: function (t, b, c, d) {
  317. if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
  318. return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
  319. }
  320. },
  321. Quint: {
  322. easeIn: function (t, b, c, d) {
  323. return c * (t /= d) * t * t * t * t + b;
  324. },
  325. easeOut: function (t, b, c, d) {
  326. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  327. },
  328. easeInOut: function (t, b, c, d) {
  329. if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
  330. return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
  331. }
  332. },
  333. Sine: {
  334. easeIn: function (t, b, c, d) {
  335. return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
  336. },
  337. easeOut: function (t, b, c, d) {
  338. return c * Math.sin(t / d * (Math.PI / 2)) + b;
  339. },
  340. easeInOut: function (t, b, c, d) {
  341. return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
  342. }
  343. },
  344. Expo: {
  345. easeIn: function (t, b, c, d) {
  346. return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
  347. },
  348. easeOut: function (t, b, c, d) {
  349. return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
  350. },
  351. easeInOut: function (t, b, c, d) {
  352. if (t == 0) return b;
  353. if (t == d) return b + c;
  354. if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
  355. return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
  356. }
  357. },
  358. Circ: {
  359. easeIn: function (t, b, c, d) {
  360. return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
  361. },
  362. easeOut: function (t, b, c, d) {
  363. return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
  364. },
  365. easeInOut: function (t, b, c, d) {
  366. if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
  367. return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
  368. }
  369. },
  370. Elastic: {
  371. easeIn: function (t, b, c, d, a, p) {
  372. if (t == 0) return b;
  373. if ((t /= d) == 1) return b + c;
  374. if (!p) p = d * .3;
  375. if (!a || a < Math.abs(c)) {
  376. a = c;
  377. var s = p / 4;
  378. } else var s = p / (2 * Math.PI) * Math.asin(c / a);
  379. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  380. },
  381. easeOut: function (t, b, c, d, a, p) {
  382. if (t == 0) return b;
  383. if ((t /= d) == 1) return b + c;
  384. if (!p) p = d * .3;
  385. if (!a || a < Math.abs(c)) {
  386. a = c;
  387. var s = p / 4;
  388. } else var s = p / (2 * Math.PI) * Math.asin(c / a);
  389. return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b);
  390. },
  391. easeInOut: function (t, b, c, d, a, p) {
  392. if (t == 0) return b;
  393. if ((t /= d / 2) == 2) return b + c;
  394. if (!p) p = d * (.3 * 1.5);
  395. if (!a || a < Math.abs(c)) {
  396. a = c;
  397. var s = p / 4;
  398. } else var s = p / (2 * Math.PI) * Math.asin(c / a);
  399. if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  400. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
  401. }
  402. },
  403. Back: {
  404. easeIn: function (t, b, c, d, s) {
  405. if (s == undefined) s = 1.70158;
  406. return c * (t /= d) * t * ((s + 1) * t - s) + b;
  407. },
  408. easeOut: function (t, b, c, d, s) {
  409. if (s == undefined) s = 1.70158;
  410. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
  411. },
  412. easeInOut: function (t, b, c, d, s) {
  413. if (s == undefined) s = 1.70158;
  414. if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
  415. return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
  416. }
  417. },
  418. Bounce: {
  419. easeIn: function (t, b, c, d) {
  420. return c - Tween.Bounce.easeOut(d - t, 0, c, d) + b;
  421. },
  422. easeOut: function (t, b, c, d) {
  423. if ((t /= d) < (1 / 2.75)) {
  424. return c * (7.5625 * t * t) + b;
  425. } else if (t < (2 / 2.75)) {
  426. return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  427. } else if (t < (2.5 / 2.75)) {
  428. return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
  429. } else {
  430. return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  431. }
  432. },
  433. easeInOut: function (t, b, c, d) {
  434. if (t < d / 2) return Tween.Bounce.easeIn(t * 2, 0, c, d) * .5 + b;
  435. else return Tween.Bounce.easeOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  436. }
  437. }
  438. }