action-jump-copy.vue 38 KB

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