action-jump.vue 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. <template>
  2. <view style="width: 750rpx;">
  3. <view class="flex justify-center" style="margin-top: 32rpx;">
  4. <!-- 目前格子数量不代表数字,显示完成度而已 -460rpx;-->
  5. <view class="grid-progress-vertical-container" style="top:-520rpx; ">
  6. <view class="grid-progress-vertical-bar">
  7. <view class="grid-progress-vertical-child" v-for="(item, index) in maxShowCount +1" :key="index"
  8. v-if="index!==0">
  9. <view
  10. :class="showCurCount>=index? 'grid-progress-vertical-active':'grid-progress-vertical-inactive'">
  11. </view>
  12. <view :class="(index%5 == 0||index == 1)?'':'grid-progress-text-hidden'"
  13. class="grid-progress-vertical-text">
  14. {{Math.floor(taskSignCount / 40 * index)}}
  15. </view>
  16. </view>
  17. </view>
  18. <view class="grid-progress-vertical-bar">
  19. <view class="grid-progress-vertical-child" v-for="(item, index) in maxShowCount +1" :key="index"
  20. v-if="index!==0">
  21. <view :class="(index%5 == 0||index == 1)?'':'grid-progress-text-hidden'"
  22. class="grid-progress-vertical-text">
  23. {{Math.floor(taskSignCount / 40 * index)+taskSignCount/2}}
  24. </view>
  25. <view
  26. :class="showCurCount>=index+20? 'grid-progress-vertical-active':'grid-progress-vertical-inactive'">
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="flex align-center justify-center" style="font-size: 14px;">
  32. <view style="position: relative;">
  33. <image style="width: 135px;height: 75px;" src="../../../static/modal/action-jump/Fill.png"></image>
  34. <view class="mid-absolute flex flex-direction align-center justify-center text-white">
  35. <view class="flex align-center">
  36. <image style="width: 22rpx;height: 28rpx;"
  37. src="../../../static/modal/action-jump/jumpSpeed.png"></image>
  38. <view style="margin-left: 6rpx;">平均速度</view>
  39. </view>
  40. <view style="margin-top: 12rpx;">{{jumpSpeed}}</view>
  41. </view>
  42. </view>
  43. <view id="ActionJumpPlay" class="flex" style="position: relative;" @click="onControllerPlay">
  44. <image style="width: 110px;height: 110px;" src="../../../static/modal/action-jump/midButton.png">
  45. </image>
  46. <image v-if="!bJumpPlay" class="mid-absolute" style=" width: 28rpx;height: 28rpx;"
  47. src="../../../static/modal/action-jump/midPlay.png">
  48. </image>
  49. <image v-else class="mid-absolute" style="width: 28rpx;height: 28rpx;"
  50. src="../../../static/modal/action-jump/midPause.png">
  51. </image>
  52. </view>
  53. <view style="position: relative;">
  54. <image style="width: 135px;height: 75px; transform: scaleX(-1);"
  55. src="../../../static/modal/action-jump/Fill.png"></image>
  56. <view class="mid-absolute flex flex-direction align-center justify-center text-white">
  57. <view class="flex align-center">
  58. <image style="width: 22rpx;height: 28rpx;"
  59. src="../../../static/modal/action-jump/jumpCalorie.png"></image>
  60. <view style="margin-left: 6rpx;">卡路里</view>
  61. </view>
  62. <view style="margin-top: 12rpx;">{{jumpCalorie}}</view>
  63. </view>
  64. </view>
  65. </view>
  66. <!-- <view class="flex justify-center align-center" style="height: 100rpx; width: 444rpx; ">
  67. <view v-if="bTipLevel" class="cu-btn make-text-bPurple text-16px text-bold"
  68. style="width: 272rpx;height:80rpx;border-radius: 10px;" @click="onTipLevel">选择关卡</view>
  69. <view v-else class="text-12px text-white text-center">
  70. {{taskDescribe}}
  71. </view>
  72. </view> -->
  73. </view>
  74. <view class="position-relative">
  75. <canvas canvas-id="actionJumpCanvas" :style="{ width: canvasW + 'px', height: canvasH + 'px' }"></canvas>
  76. <canvas class="position-absolute-center" canvas-id="effectCanvas"
  77. :style="{ width: canvasW + 'px', height: '164px' }"></canvas>
  78. </view>
  79. <view class="flex align-center justify-center" style="width: 750rpx;">
  80. <view class="flex justify-center align-center" style="height: 120rpx; width: 444rpx; ">
  81. <view class="text-12px text-white text-center">
  82. {{taskDescribe}}
  83. </view>
  84. </view>
  85. </view>
  86. <!-- <view style="height: 41px;"></view> -->
  87. <!-- 测试按钮 -->
  88. <!-- <view style="display: flex;justify-content: space-between;">
  89. <view>{{isY?'Y':'X'}}</view>
  90. <button @click="onChangeY">Y为旋转轴</button>
  91. <button @click="onChangeX">X为旋转轴</button>
  92. </view> -->
  93. <!-- #ifdef H5 -->
  94. <view style="display: flex;justify-content: space-between;" class="margin-top margin-bottom">
  95. <button @click="onJumpType(0)">jump</button>
  96. <button @click="onJumpType(1)">left</button>
  97. <button @click="onJumpType(2)">right</button>
  98. <button @click="onJumpType(3)">rLeft</button>
  99. <button @click="onJumpType(4)">rRight</button>
  100. </view>
  101. <!-- #endif -->
  102. <!-- <view style="display: flex;justify-content: space-around; padding-bottom: 100rpx;">
  103. <view style="font-size: 14px;">t:{{countdown}}</view>
  104. <view style="font-size: 14px;">e:{{eliminationCount}}</view>
  105. <view style="font-size: 14px;">f:{{faultCount}}</view>
  106. </view> -->
  107. </view>
  108. </template>
  109. <script>
  110. import ActionJump from "@/util/util-js/action/jump-0.1.js"
  111. import {
  112. CONDITIONPASSED
  113. } from "@/util/util-js/enum.js"
  114. import Firework from "@/util/util-js/effect/firework.js"
  115. import {
  116. mapState,
  117. mapMutations
  118. } from 'vuex';
  119. export default {
  120. computed: mapState(['systemInfo']),
  121. components: {
  122. },
  123. props: {
  124. showTime: {
  125. type: Number,
  126. default: 0
  127. },
  128. levelData: {
  129. type: Object,
  130. default: null
  131. },
  132. currentMode: {
  133. type: String,
  134. default: ''
  135. }
  136. },
  137. data() {
  138. return {
  139. isY: true,
  140. canvasW: 0, // 画布宽
  141. canvasH: 0, // 画布高
  142. // SystemInfo: {}, // 设备信息
  143. directionJump: null,
  144. midJump: null,
  145. rotateJump: null,
  146. directionJumpWhite: null,
  147. midJumpWhite: null,
  148. rotateJumpWhite: null,
  149. //参考图片
  150. cankao: null,
  151. jumpTipImage: null,
  152. jumpNormalImage: null,
  153. jumpTypeArray: [{
  154. jumpName: 'NORMAL',
  155. jumpCode: 0,
  156. icon: 'midJump',
  157. scaleX: 1,
  158. bTrigger: false,
  159. }, {
  160. jumpName: 'LEFT',
  161. jumpCode: 1,
  162. icon: 'directionJump',
  163. scaleX: -1,
  164. bTrigger: false,
  165. }, {
  166. jumpName: 'RIGHT',
  167. jumpCode: 2,
  168. icon: 'directionJump',
  169. scaleX: 1,
  170. bTrigger: false,
  171. }, {
  172. jumpName: 'LEFT_ROTATE',
  173. jumpCode: 3,
  174. icon: 'rotateJump',
  175. scaleX: -1,
  176. bTrigger: false,
  177. }, {
  178. jumpName: 'RIGHT_ROTATE',
  179. jumpCode: 4,
  180. icon: 'rotateJump',
  181. scaleX: 1,
  182. bTrigger: false,
  183. }],
  184. spawnArray: [],
  185. //下一个生成是相反的方向
  186. bNextSpawnRightDirection: false,
  187. bNextSpawnRightRotateDirection: false,
  188. //生成预制的模板,用count 来判断生成哪一种
  189. template: [{ //原地
  190. count: 1,
  191. spawnList: [
  192. [0]
  193. ]
  194. }, {
  195. count: 2,
  196. spawnList: [
  197. [2, 1],
  198. [1, 2],
  199. [3, 4],
  200. [4, 3]
  201. ]
  202. }, {
  203. count: 3,
  204. spawnList: [
  205. [2, 0, 1],
  206. [1, 0, 2],
  207. [3, 0, 4],
  208. [4, 0, 3]
  209. ]
  210. }, ],
  211. level: 3,
  212. levelType: 0,
  213. countdown: 60,
  214. countdownInterval: null,
  215. faultCount: 0,
  216. eliminationCount: 0,
  217. bJumpPlay: false,
  218. jumpCalorie: 1000,
  219. jumpSpeed: 1000,
  220. //硬件设备处理
  221. BLEAccIndex: 0,
  222. bJump: false,
  223. xA: 0,
  224. yA: 0,
  225. zA: 0,
  226. actionJumpObj: null,
  227. /**
  228. * 交互数据处理
  229. */
  230. //当前选择的关卡信息
  231. selfLevelData: null,
  232. // 双人模式下 数据
  233. //标记块数量
  234. taskSignCount: 0, //总数
  235. taskSignCurCount: 0, //当前计数
  236. //{"type":1,"explain":"规定时间内跳完所有标志块","limitType":1}
  237. taskConditionPassed: null,
  238. taskDescribe: '',
  239. //满格的数值是 25
  240. maxShowCount: 20,
  241. addShowCountUnit: 0,
  242. showCurCount: 0,
  243. roundingCount: 0,
  244. //游戏结束
  245. isGameOver: false,
  246. //pk模式下操作
  247. leftShowCurCount: 0,
  248. rightShowCurCount: 0,
  249. isleftPlayer: true,
  250. /**
  251. * 是否允许绘制
  252. */
  253. canOnDraw: false,
  254. /**
  255. * 是否去到下一个关卡
  256. */
  257. canGoNext: false,
  258. /**
  259. * 生成的特效
  260. */
  261. canSpawnTemp: null,
  262. onLogData: '',
  263. /**
  264. * 是否显示关卡提示
  265. */
  266. bTipLevel: false,
  267. /**
  268. * 烟花相关
  269. */
  270. // firework collection
  271. fireworks: [],
  272. fireworkImage: null,
  273. loop: null,
  274. count: 100,
  275. effectCanvas: null,
  276. effectCurrentSpawn: null,
  277. effectSpawnPosX: 0,
  278. /**
  279. * 管理三个绘制
  280. */
  281. bDrawBg: false,
  282. bDrawJump: false,
  283. bKeepBg: false,
  284. bKeepType: '',
  285. bDrawBoomEffect: false
  286. }
  287. },
  288. watch: {
  289. levelData(val) {
  290. //更新数据
  291. // console.log("levelData ============>", JSON.stringify(val));
  292. if (val) {
  293. this.taskSignCount = val.signCount;
  294. this.taskConditionPassed = val.conditionPassed;
  295. this.taskDescribe = val.describe;
  296. this.addShowCountUnit = (this.maxShowCount * 2) / this.taskSignCount;
  297. // console.log("this.addShowCountUnit:", this.addShowCountUnit, this.maxShowCount * 2, this
  298. // .taskSignCount);
  299. this.showCount = 0;
  300. //用signType 做等级类型
  301. this.levelType = val.signType;
  302. console.log(JSON.stringify(this.taskConditionPassed));
  303. }
  304. },
  305. currentMode(val) {
  306. console.log('==========> action jump currentMode:', val);
  307. }
  308. },
  309. created() {
  310. let _self = this;
  311. this.actionJumpCanvas = uni.createCanvasContext("actionJumpCanvas", this);
  312. this.effectCanvas = uni.createCanvasContext("effectCanvas", this);
  313. // this.SystemInfo = this.systemInfo; // uni.getSystemInfoSync();
  314. this.canvasW = this.systemInfo.windowWidth; // 画布宽度
  315. this.canvasH = 114;
  316. this.onLoadImage();
  317. setTimeout(() => {
  318. this.onListenActionJump();
  319. }, 2000)
  320. //更新一次状态
  321. const value = uni.getStorageSync('levelButtonPrompt');
  322. if (value) {
  323. _self.bTipLevel = !value.isSelected;
  324. } else {
  325. _self.bTipLevel = true;
  326. }
  327. // console.log('==========>levelButtonPrompt:', _self.bTipLevel);
  328. },
  329. methods: {
  330. ...mapMutations(['onWriteBLEConnectionValue', 'onConvertDeviceData']),
  331. //更新新手状态提示
  332. onUpdateTipLevelValue(value) {
  333. this.bTipLevel = value;
  334. },
  335. onListenActionJump() {
  336. let _self = this;
  337. console.log("*****************onListenActionJump*****************************");
  338. _self.actionJumpObj = new ActionJump();
  339. _self.actionJumpObj.addEventListener('resultant', (e) => {
  340. if (e.type == 'jump') {
  341. // this.jumpCount++;
  342. this.bJump = true;
  343. } else if (e.type == 'stateDataOfJump') {
  344. //发送给game,在game里面处理判断
  345. this.listenStateDataOfJump(e);
  346. } else if (e.type == 'stop') {
  347. this.onClearData();
  348. this.actionJumpObj.resetAll();
  349. if (this.canOnDraw) {
  350. this.canOnDraw = false;
  351. // //这里更新特效
  352. // this.onDrawEffect(this.canSpawnTemp);
  353. this.onDraw("tipHit");
  354. }
  355. if (this.canGoNext) {
  356. this.canGoNext = false;
  357. // //这里更新特效
  358. // this.onDrawEffect(this.canSpawnTemp);
  359. //绘制新触发状态
  360. this.onDraw("normal");
  361. setTimeout(() => {
  362. this.startJumpGame();
  363. }, 500)
  364. }
  365. // console.log('stop');
  366. //这里处理生成下一个
  367. }
  368. })
  369. },
  370. //load 相关图片
  371. onLoadImage() {
  372. let _self = this;
  373. uni.getImageInfo({
  374. src: "../../../static/modal/action-jump/directionJump.png",
  375. success: function(image) {
  376. _self.directionJump = image;
  377. }
  378. });
  379. uni.getImageInfo({
  380. src: "../../../static/modal/action-jump/midJump.png",
  381. success: function(image) {
  382. _self.midJump = image;
  383. }
  384. });
  385. uni.getImageInfo({
  386. src: "../../../static/modal/action-jump/rotateJump.png",
  387. success: function(image) {
  388. _self.rotateJump = image;
  389. }
  390. });
  391. uni.getImageInfo({
  392. src: "../../../static/modal/action-jump/directionJumpWhite.png",
  393. success: function(image) {
  394. _self.directionJumpWhite = image;
  395. }
  396. });
  397. uni.getImageInfo({
  398. src: "../../../static/modal/action-jump/midJumpWhite.png",
  399. success: function(image) {
  400. _self.midJumpWhite = image;
  401. }
  402. });
  403. uni.getImageInfo({
  404. src: "../../../static/modal/action-jump/rotateJumpWhite.png",
  405. success: function(image) {
  406. _self.rotateJumpWhite = image;
  407. }
  408. });
  409. uni.getImageInfo({
  410. src: "../../../static/modal/action-jump/jumpTip.png",
  411. success: function(image) {
  412. _self.jumpTipImage = image;
  413. }
  414. });
  415. uni.getImageInfo({
  416. src: "../../../static/modal/action-jump/jumpNormal.png",
  417. success: function(image) {
  418. _self.jumpNormalImage = image;
  419. _self.onDrawBg();
  420. }
  421. });
  422. uni.getImageInfo({
  423. src: "../../../static/modal/action-jump/cankao.png",
  424. success: function(image) {
  425. _self.cankao = image;
  426. }
  427. });
  428. /**
  429. * 烟花照片
  430. */
  431. uni.getImageInfo({
  432. src: "../../../static/modal/action-jump/boom.png",
  433. success: function(image) {
  434. _self.fireworkImage = image;
  435. }
  436. });
  437. },
  438. /**
  439. * 重置生成数组,重置倒计时
  440. */
  441. resetJumpGame() {
  442. this.spawnArray = [];
  443. if (this.countdownInterval) {
  444. clearInterval(this.countdownInterval);
  445. this.countdownInterval = null;
  446. }
  447. // this.resetCountdown(60);
  448. },
  449. startJumpGame() {
  450. this.isGameOver = false;
  451. this.resetJumpGame();
  452. //开始游戏
  453. this.index = 0;
  454. // this.levelLabel.string = '关卡' + this.level;
  455. let _ranType = Math.floor(Math.random() * 2);
  456. if (this.levelType == 0) {
  457. //随便生成一组跳的数据
  458. let _spawnList = this.template[0].spawnList;
  459. for (let i = 0; i < 4; i++) {
  460. this.spawnJumpPrefabsFromType(i, _spawnList[0][0]);
  461. }
  462. } else if (this.levelType == 1) {
  463. //生成一组 左跳右跳
  464. let _spawnList = this.template[1].spawnList;
  465. let ran = Math.floor(Math.random() * 2);
  466. // if (_ranType >= 1) ran += 2;
  467. for (let i = 0; i < _spawnList[ran].length; i++) {
  468. this.spawnJumpPrefabsFromType(i, _spawnList[ran][i]);
  469. }
  470. } else if (this.levelType == 2) {
  471. //生成一组 左跳右跳原地
  472. let _spawnList = this.template[2].spawnList;
  473. let ran = Math.floor(Math.random() * 2);
  474. // if (_ranType >= 1) ran += 2;
  475. for (let i = 0; i < _spawnList[ran].length; i++) {
  476. this.spawnJumpPrefabsFromType(i, _spawnList[ran][i]);
  477. }
  478. } else if (this.levelType == 3) {
  479. //生成一组 左旋跳右旋跳
  480. let _spawnList = this.template[1].spawnList;
  481. let ran = Math.floor(Math.random() * 2) + 2;
  482. for (let i = 0; i < _spawnList[ran].length; i++) {
  483. this.spawnJumpPrefabsFromType(i, _spawnList[ran][i]);
  484. }
  485. } else if (this.levelType == 4) {
  486. //生成一组 左旋跳右旋跳
  487. let _spawnList = this.template[2].spawnList;
  488. let ran = Math.floor(Math.random() * 2) + 2;
  489. for (let i = 0; i < _spawnList[ran].length; i++) {
  490. this.spawnJumpPrefabsFromType(i, _spawnList[ran][i]);
  491. }
  492. } else if (this.levelType == 5) {
  493. //随便生成三组数据
  494. let _newArray = [];
  495. // let _spawnList1 = this.template[1].spawnList;
  496. // let ran1 = Math.floor(Math.random() * 2);
  497. // _newArray = _newArray.concat(_spawnList1[ran1]);
  498. let _spawnList2 = this.template[2].spawnList;
  499. let ran2 = Math.floor(Math.random() * 2);
  500. let ran3 = Math.floor(Math.random() * 2);
  501. if (_ranType >= 1) {
  502. ran2 += 2;
  503. ran3 += 2;
  504. }
  505. _newArray = _newArray.concat(_spawnList2[ran2]);
  506. _newArray = _newArray.concat(_spawnList2[ran3]);
  507. for (let i = 0; i < _newArray.length; i++) {
  508. this.spawnJumpPrefabsFromType(i, _newArray[i]);
  509. }
  510. //todo 暂时给循环
  511. this.level = 0;
  512. }
  513. // if (this.level == 2) {
  514. // //随便生成二组数据
  515. // let _newArray = [];
  516. // let _spawnList1 = this.template[1].spawnList;
  517. // let ran1 = Math.floor(Math.random() * 2);
  518. // _newArray = _newArray.concat(_spawnList1[ran1]);
  519. // let _spawnList2 = this.template[2].spawnList;
  520. // let ran2 = Math.floor(Math.random() * 2);
  521. // if (_ranType >= 1) ran2 += 2;
  522. // _newArray = _newArray.concat(_spawnList2[ran2]);
  523. // // console.log(_newArray);
  524. // for (let i = 0; i < _newArray.length; i++) {
  525. // this.spawnJumpPrefabsFromType(i, _newArray[i]);
  526. // }
  527. // }
  528. this.level++;
  529. //倒计时
  530. // this.countdownInterval = setInterval(() => {
  531. // if (this.countdown <= 0) {
  532. // clearInterval(this.countdownInterval);
  533. // this.countdownInterval = null;
  534. // //处理下一个关卡
  535. // // console.warn('时间到,处理下一个关卡');
  536. // this.startJumpGame();
  537. // return;
  538. // }
  539. // this.setCountdown(1);
  540. // }, 1000);
  541. this.onDraw("tipHit");
  542. },
  543. spawnJumpPrefabsFromType(index, _jumpType) {
  544. //todo 生成的节点,后面再处理节奏问题。比如生成顺序
  545. for (let i = 0; i < this.jumpTypeArray.length; i++) {
  546. if (this.jumpTypeArray[i].jumpCode == _jumpType) {
  547. let _jumpPrefab = Object.assign({}, this.jumpTypeArray[i]);
  548. this.spawnArray.push(_jumpPrefab);
  549. break;
  550. }
  551. }
  552. },
  553. spawnJumpPrefabs(index) {
  554. let ran = Math.floor(Math.random() * 5);
  555. //todo 生成的节点,后面再处理节奏问题。比如生成顺序
  556. let _jumpPrefab = Object.assign({}, this.jumpTypeArray[ran]);
  557. //这里处理相反方向,比如生成了一个左旋转,下一个右旋转
  558. if (_jumpPrefab.jumpName == 'LEFT') {
  559. if (this.bNextSpawnRightDirection) {
  560. //如果是对应的需要记录一个对应的准确值
  561. this.bNextSpawnRightDirection = false;
  562. } else {
  563. ran = 2; //RIGHT;
  564. this.bNextSpawnRightDirection = true;
  565. }
  566. } else if (_jumpPrefab.jumpName == 'RIGHT') {
  567. if (this.bNextSpawnRightDirection) {
  568. ran = 1; //LEFT;
  569. this.bNextSpawnRightDirection = false;
  570. } else {
  571. this.bNextSpawnRightDirection = true;
  572. }
  573. }
  574. if (_jumpPrefab.jumpName == 'LEFT_ROTATE') {
  575. if (this.bNextSpawnRightRotateDirection) {
  576. //如果是对应的需要记录一个对应的准确值
  577. this.bNextSpawnRightRotateDirection = false;
  578. } else {
  579. ran = 4; //RIGHT_ROTATE;
  580. this.bNextSpawnRightRotateDirection = true;
  581. }
  582. // console.log('l==rotate', ran);
  583. } else if (_jumpPrefab.jumpName == 'RIGHT_ROTATE') {
  584. if (this.bNextSpawnRightRotateDirection) {
  585. ran = 3; //LEFT_ROTATE;
  586. this.bNextSpawnRightRotateDirection = false;
  587. } else {
  588. //如果是对应的需要记录一个对应的准确值
  589. this.bNextSpawnRightRotateDirection = true;
  590. }
  591. }
  592. this.spawnArray.push(_jumpPrefab);
  593. },
  594. //单纯的绘制八个背景
  595. onDrawBg() {
  596. this.bDrawBg = true;
  597. this.bKeepBg = true;
  598. this.actionJumpCanvas.clearRect(0, 0, this.canvasW, this.canvasH);
  599. let _currentBgStartX = this.canvasW / 2;
  600. let count = 4;
  601. for (let i = 0; i < count; i++) {
  602. let _currentStartPos = _currentBgStartX - i * 50 - 50;
  603. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentStartPos, 0, 50,
  604. 114);
  605. let _currentEndPos = _currentBgStartX + i * 50;
  606. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentEndPos, 0, 50, 114);
  607. }
  608. this.actionJumpCanvas.draw();
  609. },
  610. onDraw(type) {
  611. this.bDrawJump = true;
  612. this.bKeepBg = false;
  613. this.bKeepType = type;
  614. this.actionJumpCanvas.clearRect(0, 0, this.canvasW, 114);
  615. //计算一个对象
  616. let _drawObj = {
  617. path: null,
  618. startX: 0,
  619. width: 0,
  620. bgWidth: 0,
  621. bgStartXAllNormal: 0,
  622. bgStartXHasTip: 0,
  623. }
  624. //计算居中的点
  625. _drawObj.width = this.spawnArray.length * (50 + 10);
  626. _drawObj.startX = this.canvasW / 2 - _drawObj.width / 2;
  627. //全部是普通背景
  628. _drawObj.bgStartXAllNormal = this.canvasW / 2 - (this.spawnArray.length * 50) / 2;
  629. _drawObj.bgStartXHasTip = this.canvasW / 2 - (this.spawnArray.length * 50 + 40) / 2;
  630. let _currentBgStartX = this.index == this.spawnArray.length || type == "normal" ? _drawObj
  631. .bgStartXAllNormal : _drawObj
  632. .bgStartXHasTip;
  633. //最后还要绘制一个
  634. if (this.spawnArray[this.spawnArray.length - 1].bTrigger) {
  635. _currentBgStartX -= 20;
  636. }
  637. //绘制八个位置。如果生成数量不够的话。补上对应的数量
  638. let count = 8 - this.spawnArray.length;
  639. count = Math.ceil(count / 2);
  640. //计算一个节点数组
  641. for (let i = 0; i < this.spawnArray.length; i++) {
  642. //默认 mid 图标
  643. let _temp = this.spawnArray[i].bTrigger ? this.midJump : this.midJumpWhite;
  644. if (this.spawnArray[i].icon == 'directionJump') {
  645. _temp = this.spawnArray[i].bTrigger ? this.directionJump : this.directionJumpWhite;
  646. } else if (this.spawnArray[i].icon == 'rotateJump') {
  647. _temp = this.spawnArray[i].bTrigger ? this.rotateJump : this.rotateJumpWhite;
  648. }
  649. //如果是相反绘制,需要加多一个自身位置偏移
  650. let _pos = this.spawnArray[i].scaleX < 0 ? i + 1 : i;
  651. let _spacing = i == 0 ? 0 : 1;
  652. let _addData = 0;
  653. //大图提示后面要加上大图占的位置,为大图宽度减小图( 90 - 50 )
  654. if (i >= this.index && type !== "normal") {
  655. _addData = 40;
  656. }
  657. if (i == 0) {
  658. //_frontBgData 为减去大图位置,10 为偏移位置
  659. let _frontBgData = 40;
  660. //绘制前背景
  661. for (let i = 0; i < count; i++) {
  662. let _currentStartPos = _currentBgStartX - _frontBgData - i * 50 - 10;
  663. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentStartPos, 0,
  664. 50, 114)
  665. }
  666. }
  667. this.actionJumpCanvas.save();
  668. // this.spawnArray[i].bTrigger ? 0.7 : 1;
  669. this.actionJumpCanvas.globalAlpha = 1;
  670. this.actionJumpCanvas.scale(this.spawnArray[i].scaleX, 1);
  671. let _currentPos = 0;
  672. let _currentCenterPos = 0;
  673. if (i == this.index && type !== "normal") {
  674. _currentPos = (_currentBgStartX + _pos * 90 - i * 40) *
  675. this
  676. .spawnArray[i]
  677. .scaleX;
  678. this.actionJumpCanvas.drawImage(this.jumpTipImage.path, _currentPos, 0, 90, 114);
  679. //计算对应中心点的值
  680. _currentCenterPos = _currentPos + 90 / 2 - 25 / 2;
  681. //57 - 40/2 是取画布中心y点,减去图标本身高的一半的值
  682. this.actionJumpCanvas.drawImage(_temp.path, _currentCenterPos - 7.5, 37, 40, 40);
  683. //这里记录一个生成点,后面用于生成特效
  684. this.effectSpawnPosX = _currentPos;
  685. } else {
  686. _currentPos = (_currentBgStartX + _addData + _pos *
  687. 50) * this
  688. .spawnArray[i]
  689. .scaleX;
  690. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentPos, 0, 50, 114)
  691. //计算对应中心点的值
  692. _currentCenterPos = _currentPos + 50 / 2 - 25 / 2;
  693. if (!this.spawnArray[i].bTrigger) {
  694. //44.5 是取画布中心y点,减去图标本身高的一半的值
  695. this.actionJumpCanvas.drawImage(_temp.path, _currentCenterPos, 44.5, 25, 25);
  696. }
  697. }
  698. this.actionJumpCanvas.restore();
  699. let _spawnLength = this.spawnArray.length;
  700. if (i == _spawnLength - 1) {
  701. //绘制结束位置
  702. let _endCount = count + 1;
  703. for (let i = 0; i < _endCount; i++) {
  704. let _bigDataX = 40;
  705. // if (i == 0 && this.spawnArray[_spawnLength - 1].bTrigger) {
  706. // let _currentEndPos = (_currentBgStartX + _spawnLength * 90 - _spawnLength * 40) *
  707. // this
  708. // .spawnArray[i]
  709. // .scaleX;
  710. // this.actionJumpCanvas.drawImage(this.jumpTipImage.path, _currentEndPos, 0, 90, 114);
  711. // _bigDataX = 0;
  712. // }
  713. if (this.spawnArray[_spawnLength - 1].bTrigger) {
  714. _bigDataX = 0;
  715. }
  716. let _currentEndPos = _currentBgStartX + _bigDataX + (this.spawnArray.length +
  717. i) * 50;
  718. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentEndPos, 0,
  719. 50, 114)
  720. }
  721. }
  722. }
  723. this.actionJumpCanvas.draw();
  724. },
  725. onDrawEffect(_temp) {
  726. //根据当前消除的生成一个
  727. // console.log("生成的_temp:" + JSON.stringify(_temp));
  728. let spawnTemp = this.midJump;
  729. if (_temp.icon == 'directionJump') {
  730. spawnTemp = this.directionJump;
  731. } else if (_temp.icon == 'rotateJump') {
  732. spawnTemp = this.rotateJump;
  733. }
  734. let tempFirework = new Firework(this.fireworkImage,
  735. spawnTemp, _temp.scaleX, this.effectSpawnPosX, 0, this.canvasW, 164);
  736. this.fireworks.push(tempFirework);
  737. this.bDrawBoomEffect = true;
  738. this.onInitFirework();
  739. },
  740. onClear() {
  741. this.resetJumpGame();
  742. this.onDrawBg();
  743. this.xA = 0;
  744. this.yA = 0;
  745. this.zA = 0;
  746. this.bJump = false;
  747. this.actionJumpObj.resetAll();
  748. },
  749. /**
  750. * 统一绘制 效果 背景,交互,烟花
  751. */
  752. onInitFirework() {
  753. if (this.loop != null) {
  754. return;
  755. }
  756. this.loop = setInterval(() => {
  757. if (!this.bDrawBoomEffect) {
  758. clearInterval(this.loop);
  759. this.loop = null;
  760. // console.log("结束绘制");
  761. this.effectCanvas.clearRect(0, 0, this.canvasW, 164);
  762. this.effectCanvas.draw();
  763. return;
  764. }
  765. this.effectCanvas.clearRect(0, 0, this.canvasW, 164);
  766. if (this.bDrawBoomEffect) {
  767. // loop over each firework, draw it, update it
  768. var i = this.fireworks.length;
  769. while (i--) {
  770. this.fireworks[i].draw(this.effectCanvas, () => {
  771. this.fireworks.splice(i, 1);
  772. if (this.fireworks.length == 0) {
  773. this.bDrawBoomEffect = false;
  774. }
  775. });
  776. }
  777. }
  778. this.effectCanvas.draw();
  779. }, 30)
  780. },
  781. onJumpType(event) {
  782. // console.log("onJumpType:", event);
  783. if (this.isGameOver || !this.bJumpPlay) return;
  784. this.eliminateJumpPrefab(event);
  785. },
  786. // update (dt) {}
  787. //模拟测试调用
  788. eliminateJumpPrefab(_jumpType) {
  789. let _temp = this.spawnArray[this.index];
  790. // let _temp = this.jumpTypeArray[Math.floor(Math.random()*4) ];
  791. //这里更新特效
  792. // this.onDrawEffect(_temp);
  793. // return;
  794. //如果当前的跳类型和预制目标一样
  795. if (_jumpType == _temp.jumpCode) {
  796. _temp.bTrigger = true;
  797. this.index++;
  798. //这里更新特效
  799. let _endTemp = Object.assign({}, _temp);
  800. this.onDrawEffect(_endTemp);
  801. if (this.index >= this.spawnArray.length) {
  802. clearInterval(this.countdownInterval);
  803. this.countdownInterval = null;
  804. //绘制新触发状态
  805. this.onDraw("normal");
  806. setTimeout(() => {
  807. this.startJumpGame();
  808. }, 2000)
  809. } else {
  810. //绘制新触发状态
  811. this.onDraw('tipHit');
  812. }
  813. //成功
  814. this.setEliminationCount(1);
  815. } else {
  816. //失误
  817. this.setFaultCount(1);
  818. }
  819. },
  820. //设置倒计时
  821. setCountdown(value) {
  822. this.countdown -= value;
  823. // this.countdownLabel.string = '倒计时:' + this.countdown;
  824. this.$emit('actionJumpCountDownUpdate', {
  825. countDown: this.countdown
  826. });
  827. },
  828. resetCountdown(value) {
  829. this.countdown = value;
  830. // this.countdownLabel.string = '倒计时:' + this.countdown;
  831. this.$emit('actionJumpCountDownUpdate', {
  832. countDown: this.countdown
  833. });
  834. },
  835. //设置ui信息
  836. setEliminationCount(value) {
  837. this.taskSignCurCount++;
  838. this.roundingCount += this.addShowCountUnit;
  839. this.eliminationCount += value;
  840. // this.eliminationLabel.string = '消除数量:' + this.eliminationCount.toString();
  841. this.$emit('actionJumpDataUpdate', {
  842. eliminationCount: this.eliminationCount,
  843. faultCount: this.faultCount
  844. });
  845. //如果是pk模式。不走下面判断
  846. if (this.currentMode == 'pkMode') return;
  847. if (CONDITIONPASSED.ENERGYBARFULL == this.taskConditionPassed.limitType) {
  848. //能量条的条件下才显示能量条动
  849. //取两位后计算Math floor,不然会有偏差值问题 Math.floor(39.9999999+ 0.1111111) = 39
  850. this.showCurCount = Math.floor(this.roundingCount.toFixed(2));
  851. //1.能量槽满的时候,说明踩中次数到达
  852. if (this.taskSignCurCount >= this.taskSignCount)
  853. this.onGameOver("energyBarFull");
  854. } else if (CONDITIONPASSED.SKIPALLFLAGWITHINTIME == this.taskConditionPassed.limitType) {
  855. //规定时间下也给显示能量条
  856. this.showCurCount = Math.floor(this.roundingCount.toFixed(2));
  857. //2.规定时间内跳完所有标志块
  858. if (this.taskSignCurCount >= this.taskSignCount)
  859. this.onGameOver("skipAllFlagWithinTime");
  860. } else if (this.taskConditionPassed.isScore) {
  861. //3.达到一定分数
  862. //如果是用分数判断
  863. //分数是 跳对的加1分,错的扣1分,0不扣分。
  864. let curScore = this.eliminationCount - this.faultCount;
  865. curScore = curScore < 0 ? 0 : curScore;
  866. //当前分数达到,胜利
  867. if (curScore >= this.taskConditionPassed.limitScore)
  868. this.onGameOver("score");
  869. }
  870. },
  871. onGameOver(type) {
  872. this.isGameOver = true;
  873. //处理参数
  874. this.onClear();
  875. this.onClearData();
  876. this.bJumpPlay = false;
  877. /**
  878. * 判断胜利和失败
  879. */
  880. let myWin = false; //默认失败
  881. //比如, 1.充满左右两边蓄能槽.2.规定时间内跳完所有标志块.
  882. if (type == "energyBarFull") {
  883. //1.能量槽满的时候,说明踩中次数到达
  884. if (this.taskSignCurCount >= this.taskSignCount) {
  885. myWin = true;
  886. }
  887. } else if (type == 'skipAllFlagWithinTime') {
  888. myWin = true;
  889. } else if (type == "timeUp") {
  890. //2.规定时间内跳完所有标志块
  891. //查看消除数量是否到达总数,未达成就是未完成
  892. if (this.taskSignCurCount >= this.taskSignCount) {
  893. myWin = true;
  894. }
  895. } else if (type == "score") {
  896. myWin = true;
  897. }
  898. console.log(type, {
  899. myWin: myWin
  900. });
  901. this.$emit('gameOver', {
  902. myWin: myWin,
  903. type: 'calorieMode',
  904. isOffEvent: true
  905. });
  906. },
  907. //pk模式下结束游戏关卡
  908. onPKModeGameOver(type) {
  909. this.isGameOver = true;
  910. //处理参数
  911. this.onClear();
  912. this.onClearData();
  913. this.bJumpPlay = false;
  914. this.$emit('gameOver', {
  915. type: 'pkMode',
  916. isOffEvent: true
  917. });
  918. },
  919. setFaultCount(value) {
  920. this.faultCount += value;
  921. // this.faultLabel.string = '失误:' + this.faultCount;
  922. this.$emit('actionJumpDataUpdate', {
  923. eliminationCount: this.eliminationCount,
  924. faultCount: this.faultCount
  925. });
  926. },
  927. //控制播放
  928. onControllerPlay() {
  929. if (this.bJumpPlay) {
  930. //仅仅暂停,没有清空数据
  931. this._changePlay(false);
  932. this.$emit("actionJumpControllerPlay", false);
  933. } else {
  934. this.$emit("actionJumpCheck");
  935. }
  936. },
  937. onContinueGame() {
  938. this._changePlay(true);
  939. },
  940. onClearActionJumpData() {
  941. console.log("onClearActionJumpData");
  942. this.onClear();
  943. this.onClearData();
  944. },
  945. //修改状态
  946. _changePlay(bPlaying) {
  947. if (bPlaying) {
  948. this.bJumpPlay = bPlaying;
  949. } else {
  950. this.bJumpPlay = !this.bJumpPlay;
  951. }
  952. },
  953. onActionJumpPlay() {
  954. this.onClear();
  955. this.onClearData();
  956. this.startJumpGame();
  957. this._changePlay(true);
  958. //reset 对应计算数据
  959. this.taskSignCurCount = 0;
  960. this.showCurCount = 0;
  961. this.roundingCount = 0;
  962. this.faultCount = 0;
  963. this.eliminationCount = 0;
  964. },
  965. getCurrentJumpType() {
  966. let _temp = this.spawnArray[this.index];
  967. return _temp.jumpCode;
  968. },
  969. //监听跳的状态数据
  970. listenStateDataOfJump(data) {
  971. if (this.isGameOver || !this.bJumpPlay) return;
  972. if (this.spawnArray.length == this.index) return;
  973. let _jumpType = this.getCurrentJumpType();
  974. //初始全部默认状态
  975. let _tempState = [{
  976. jumpName: 'NORMAL',
  977. jumpCode: 0,
  978. bTrigger: true,
  979. describe: '正常跳'
  980. },
  981. {
  982. jumpName: 'LEFT',
  983. jumpCode: 1,
  984. bTrigger: false,
  985. describe: '左直跳'
  986. },
  987. {
  988. jumpName: 'RIGHT',
  989. jumpCode: 2,
  990. bTrigger: false,
  991. describe: '右直跳'
  992. },
  993. {
  994. jumpName: 'LEFT_ROTATE',
  995. jumpCode: 3,
  996. bTrigger: false,
  997. describe: '左旋转跳'
  998. },
  999. {
  1000. jumpName: 'RIGHT_ROTATE',
  1001. jumpCode: 4,
  1002. bTrigger: false,
  1003. describe: '右旋转跳'
  1004. }
  1005. ];
  1006. let {
  1007. currentMaxValue,
  1008. oGyroValue,
  1009. peakOfWaveMaxValue,
  1010. valleyOfWaveMinValue
  1011. } = data
  1012. // console.log('stateDataOfJump:');
  1013. // console.log(JSON.stringify(data));
  1014. this.onLogData = data;
  1015. let _rotateLimit = 4;
  1016. let _jumpLimit = 8;
  1017. switch (_jumpType) {
  1018. case 0:
  1019. //JumpType.NORMAL = 0
  1020. _tempState[0].bTrigger = true;
  1021. this.eliminateJumpPrefabFormTemp(_tempState);
  1022. break;
  1023. case 1:
  1024. if (currentMaxValue < -_jumpLimit || valleyOfWaveMinValue < -20) {
  1025. //left jump
  1026. _tempState[1].bTrigger = true;
  1027. }
  1028. this.eliminateJumpPrefabFormTemp(_tempState);
  1029. break;
  1030. case 2:
  1031. if (currentMaxValue > _jumpLimit || peakOfWaveMaxValue > 20) {
  1032. //right jump
  1033. _tempState[2].bTrigger = true;
  1034. }
  1035. this.eliminateJumpPrefabFormTemp(_tempState);
  1036. break;
  1037. case 4:
  1038. if (oGyroValue > _rotateLimit) {
  1039. _tempState[4].bTrigger = true;
  1040. }
  1041. this.eliminateJumpPrefabFormTemp(_tempState);
  1042. break;
  1043. case 3:
  1044. if (oGyroValue < -_rotateLimit) {
  1045. _tempState[3].bTrigger = true;
  1046. }
  1047. this.eliminateJumpPrefabFormTemp(_tempState);
  1048. break;
  1049. default:
  1050. console.log('没有对应的_jumpType', _jumpType);
  1051. break;
  1052. }
  1053. // if (currentMaxValue == 0) {
  1054. // } else {
  1055. // // console.log('2====', data);
  1056. // if (this.isY) {
  1057. // //如果是检测到旋转跳
  1058. // if (oGyroValue > _rotateLimit) {
  1059. // // console.log('y right:', oGyroValue);
  1060. // _tempState[4].bTrigger = true;
  1061. // } else if (oGyroValue < -_rotateLimit) {
  1062. // // console.log('y left:', oGyroValue);
  1063. // _tempState[3].bTrigger = true;
  1064. // }
  1065. // if (valleyOfWaveMinValue < -_jumpLimit) {
  1066. // //left jump
  1067. // _tempState[1].bTrigger = true;
  1068. // } else if (peakOfWaveMaxValue > _jumpLimit) {
  1069. // //right jump
  1070. // _tempState[2].bTrigger = true;
  1071. // }
  1072. // } else {
  1073. // //如果是检测到旋转跳
  1074. // if (oGyroValue < -5) {
  1075. // // console.log('x right:', oGyroValue);
  1076. // _tempState[4].bTrigger = true;
  1077. // } else if (oGyroValue > 5) {
  1078. // // console.log('x left:', oGyroValue);
  1079. // _tempState[3].bTrigger = true;
  1080. // }
  1081. // if (valleyOfWaveMinValue < -_jumpLimit) {
  1082. // //left jump
  1083. // _tempState[1].bTrigger = true;
  1084. // } else if (peakOfWaveMaxValue > _jumpLimit) {
  1085. // //right jump
  1086. // _tempState[2].bTrigger = true;
  1087. // }
  1088. // }
  1089. // this.eliminateJumpPrefabFormTemp(_tempState);
  1090. // }
  1091. },
  1092. eliminateJumpPrefabFormTemp(_tempState) {
  1093. //如果消除完,需要重新生成
  1094. let _temp = this.spawnArray[this.index];
  1095. let bSuccess = false;
  1096. for (let i = 0; i < _tempState.length; i++) {
  1097. let _state = _tempState[i];
  1098. if (_state.bTrigger)
  1099. console.log(JSON.stringify(_state) + JSON.stringify(this.onLogData));
  1100. //如果当前的跳类型和预制目标一样
  1101. if (_state.jumpCode == _temp.jumpCode && _state.bTrigger) {
  1102. //成功
  1103. bSuccess = true;
  1104. break;
  1105. }
  1106. }
  1107. //如果存在其中一个为true
  1108. if (bSuccess) {
  1109. // console.log("bSuccess:", bSuccess);
  1110. _temp.bTrigger = true;
  1111. this.index++;
  1112. this.canSpawnTemp = _temp;
  1113. setTimeout(()=>{
  1114. //这里更新特效
  1115. this.onDrawEffect(this.canSpawnTemp);
  1116. },150);
  1117. if (this.index >= this.spawnArray.length) {
  1118. clearInterval(this.countdownInterval);
  1119. this.countdownInterval = null;
  1120. this.canGoNext = true;
  1121. // this.onDraw("normal");
  1122. } else {
  1123. //绘制新触发状态
  1124. this.canOnDraw = true;
  1125. // this.onDraw("normal");
  1126. }
  1127. //成功
  1128. this.setEliminationCount(1);
  1129. } else {
  1130. //失误
  1131. this.setFaultCount(1);
  1132. }
  1133. },
  1134. /**
  1135. * @param {Object} gameData
  1136. * 识别跳部分数据处理
  1137. */
  1138. onBLERopeUpdate(gameData) {
  1139. if (!this.bJumpPlay || this.isGameOver) return;
  1140. //********陀螺仪角速度********
  1141. let {
  1142. gx,
  1143. gy,
  1144. gz
  1145. } = gameData.gyro;
  1146. let {
  1147. min,
  1148. s,
  1149. ms
  1150. } = gameData;
  1151. //-gameData.acc.ax * 10;
  1152. let _ax = gameData.acc.ax * 10;
  1153. let _ay = gameData.acc.ay * 10;
  1154. let _az = gameData.acc.az * 10;
  1155. //低通滤波分离重力
  1156. let alpha = 0.8;
  1157. this.xA = alpha * this.xA + (1 - alpha) * _ax;
  1158. this.yA = alpha * this.yA + (1 - alpha) * _ay;
  1159. this.zA = alpha * this.zA + (1 - alpha) * _az;
  1160. //高通滤波获取线性速度
  1161. let linear_acceleration_x = _ax - this.xA;
  1162. let linear_acceleration_y = _az - this.zA;
  1163. let linear_acceleration_z = _ay - this.yA;
  1164. let _temp = {
  1165. linearAcc: {
  1166. lAccX: linear_acceleration_x,
  1167. lAccY: linear_acceleration_y,
  1168. lAccZ: linear_acceleration_z
  1169. }, //gameData.acc,
  1170. oriAcc: {
  1171. oAccX: _ax,
  1172. oAccY: _ay,
  1173. oAccZ: _az
  1174. },
  1175. gravityAcc: {
  1176. gravityX: this.xA,
  1177. gravityY: this.yA,
  1178. gravityZ: this.zA
  1179. },
  1180. bLimitRebound: false,
  1181. resultant: Math.sqrt(_ax * _ax +
  1182. _ay * _ay + _az * _az),
  1183. runIndex: this.BLEAccIndex,
  1184. //陀螺仪
  1185. oriGyro: {
  1186. oGyroX: gx,
  1187. oGyroY: gy,
  1188. oGyroZ: gz
  1189. },
  1190. //输入当前轴
  1191. bYAxis: true,
  1192. };
  1193. this.actionJumpObj.updateJump(_temp);
  1194. // if (this.BLEAccIndex > 150) {
  1195. // this.onClearData();
  1196. // this.bJump = false;
  1197. // return;
  1198. // }
  1199. this.BLEAccIndex++;
  1200. },
  1201. onClearData() {
  1202. this.BLEAccIndex = 0;
  1203. },
  1204. onChangeY() {
  1205. this.isY = true;
  1206. },
  1207. onChangeX() {
  1208. this.isY = false;
  1209. },
  1210. onGetActionJumpPlayView(callback) {
  1211. let view = uni.createSelectorQuery().select('#ActionJumpPlay');
  1212. view.boundingClientRect(data => {
  1213. if (callback)
  1214. callback(data);
  1215. }).exec();
  1216. },
  1217. onTipLevel() {
  1218. this.$emit("tipLevel", {
  1219. hiddenType: 'normal'
  1220. });
  1221. console.log("**************22");
  1222. }
  1223. }
  1224. }
  1225. </script>
  1226. <style lang="scss">
  1227. .mid-absolute {
  1228. position: absolute;
  1229. top: 0;
  1230. bottom: 0;
  1231. right: 0;
  1232. left: 0;
  1233. margin: auto;
  1234. }
  1235. .action-jump-timer {
  1236. position: absolute;
  1237. top: -150rpx;
  1238. }
  1239. </style>