action-jump.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  1. <template>
  2. <view style="width: 750rpx;">
  3. <view class="flex justify-center" style="height: 75px; margin-top: 46rpx;">
  4. <!-- 计时器 -->
  5. <!-- <view class="action-jump-timer flex justify-center">
  6. <boxingCountDown ref="boxingCountDownRef" :show-day="false" :second="showTime" color="#FFFFFF"
  7. background-color="rgba(255,255,255,0);" border-color="#007AFF" splitorColor="#FFFFFF" />
  8. </view> -->
  9. <view class="grid-progress-vertical-container" style="top:-460rpx; ">
  10. <view class="grid-progress-vertical-bar">
  11. <view class="grid-progress-vertical-child" v-for="(item, index) in 20" :key="index">
  12. <view
  13. :class="showCount>=index+1? 'grid-progress-vertical-active':'grid-progress-vertical-inactive'">
  14. </view>
  15. <view :class="index%5 == 0?'':'grid-progress-text-hidden'" class="grid-progress-vertical-text">
  16. {{(index+1)*2}}
  17. </view>
  18. </view>
  19. </view>
  20. <view class="grid-progress-vertical-bar">
  21. <view class="grid-progress-vertical-child" v-for="(item, index) in 20" :key="index">
  22. <view :class="index%5 == 0?'':'grid-progress-text-hidden'" class="grid-progress-vertical-text">
  23. {{(index+26)*2}}
  24. </view>
  25. <view
  26. :class="showCount>=index+26? 'grid-progress-vertical-active':'grid-progress-vertical-inactive'">
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="flex justify-center align-center"
  32. style="height: 52rpx; width: 412rpx; background-color: rgba(255,255,255,0.11); border-radius: 12rpx;">
  33. <!-- 居中绘制星星样式 -->
  34. <view class="text-14px text-white">
  35. 拉伸运动:
  36. </view>
  37. <view class="flex flex-direction" v-for="(item, index) in 5" :key="index">
  38. <image style="width: 34rpx;height: 32rpx;" src="../../../static/modal/action-jump/stars.png">
  39. </image>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- <view class="action-jump-parent margin-bottom">
  44. <view class="action-jump-container">
  45. </view>
  46. </view> -->
  47. <canvas canvas-id="actionJumpCanvas" :style="{ width: canvasW + 'px', height: canvasH + 'px' }"></canvas>
  48. <view class="flex align-center justify-center" style="font-size: 14px;">
  49. <view style="position: relative;">
  50. <image style="width: 135px;height: 75px;" src="../../../static/modal/action-jump/Fill.png"></image>
  51. <view class="mid-absolute flex flex-direction align-center justify-center text-white">
  52. <view class="flex align-center">
  53. <image style="width: 22rpx;height: 28rpx;"
  54. src="../../../static/modal/action-jump/jumpSpeed.png"></image>
  55. <view style="margin-left: 6rpx;">平均速度</view>
  56. </view>
  57. <view style="margin-top: 12rpx;">{{jumpSpeed}}</view>
  58. </view>
  59. </view>
  60. <view class="flex" style="position: relative;" @click="onControllerPlay">
  61. <image style="width: 112px;height: 111px;" src="../../../static/modal/action-jump/midButton.png">
  62. </image>
  63. <image v-if="!bJumpPlay" class="mid-absolute" style=" width: 28rpx;height: 28rpx;"
  64. src="../../../static/modal/action-jump/midPlay.png">
  65. </image>
  66. <image v-else class="mid-absolute" style="width: 28rpx;height: 28rpx;"
  67. src="../../../static/modal/action-jump/midPause.png">
  68. </image>
  69. </view>
  70. <view style="position: relative;">
  71. <image style="width: 135px;height: 75px; transform: scaleX(-1);"
  72. src="../../../static/modal/action-jump/Fill.png"></image>
  73. <view class="mid-absolute flex flex-direction align-center justify-center text-white">
  74. <view class="flex align-center">
  75. <image style="width: 22rpx;height: 28rpx;"
  76. src="../../../static/modal/action-jump/jumpCalorie.png"></image>
  77. <view style="margin-left: 6rpx;">卡路里</view>
  78. </view>
  79. <view style="margin-top: 12rpx;">{{jumpCalorie}}</view>
  80. </view>
  81. </view>
  82. </view>
  83. <view style="height: 41px;"></view>
  84. <!-- 测试按钮 -->
  85. <view style="display: flex;justify-content: space-between;">
  86. <!-- <button @click="startJumpGame">startGame</button> -->
  87. <!-- <button @click="onClear">onClear</button> -->
  88. <view>{{isY?'Y':'X'}}</view>
  89. <button @click="onChangeY">Y为旋转轴</button>
  90. <button @click="onChangeX">X为旋转轴</button>
  91. </view>
  92. <!-- <view style="display: flex;justify-content: space-between;" class="margin-top margin-bottom">
  93. <button @click="onJumpType(0)">jump</button>
  94. <button @click="onJumpType(1)">left</button>
  95. <button @click="onJumpType(2)">right</button>
  96. <button @click="onJumpType(3)">rLeft</button>
  97. <button @click="onJumpType(4)">rRight</button>
  98. </view> -->
  99. <view style="display: flex;justify-content: space-around;">
  100. <view style="font-size: 14px;">t:{{countdown}}</view>
  101. <view style="font-size: 14px;">e:{{eliminationCount}}</view>
  102. <view style="font-size: 14px;">f:{{faultCount}}</view>
  103. </view>
  104. </view>
  105. </template>
  106. <script>
  107. // import boxingCountDown from '@/components/uni-count-down/uni-count-down.vue'
  108. import ActionJump from "@/util/util-js/action/jump.js"
  109. import {
  110. mapMutations
  111. } from 'vuex';
  112. export default {
  113. components: {
  114. // boxingCountDown
  115. },
  116. props: {
  117. showTime: {
  118. type: Number,
  119. default: 0
  120. }
  121. },
  122. data() {
  123. return {
  124. isY: true,
  125. //满格的数值是 25
  126. maxShowCount: 25,
  127. //显示的点
  128. showCount: 0,
  129. canvasW: 0, // 画布宽
  130. canvasH: 0, // 画布高
  131. SystemInfo: {}, // 设备信息
  132. directionJump: null,
  133. midJump: null,
  134. rotateJump: null,
  135. directionJumpWhite: null,
  136. midJumpWhite: null,
  137. rotateJumpWhite: null,
  138. //参考图片
  139. cankao: null,
  140. jumpTipImage: null,
  141. jumpNormalImage: null,
  142. jumpTypeArray: [{
  143. jumpName: 'NORMAL',
  144. jumpCode: 0,
  145. icon: 'midJump',
  146. scaleX: 1,
  147. bTrigger: false,
  148. }, {
  149. jumpName: 'LEFT',
  150. jumpCode: 1,
  151. icon: 'directionJump',
  152. scaleX: -1,
  153. bTrigger: false,
  154. }, {
  155. jumpName: 'RIGHT',
  156. jumpCode: 2,
  157. icon: 'directionJump',
  158. scaleX: 1,
  159. bTrigger: false,
  160. }, {
  161. jumpName: 'LEFT_ROTATE',
  162. jumpCode: 3,
  163. icon: 'rotateJump',
  164. scaleX: -1,
  165. bTrigger: false,
  166. }, {
  167. jumpName: 'RIGHT_ROTATE',
  168. jumpCode: 4,
  169. icon: 'rotateJump',
  170. scaleX: 1,
  171. bTrigger: false,
  172. }],
  173. spawnArray: [],
  174. //下一个生成是相反的方向
  175. bNextSpawnRightDirection: false,
  176. bNextSpawnRightRotateDirection: false,
  177. //生成预制的模板,用count 来判断生成哪一种
  178. template: [{
  179. count: 1,
  180. spawnList: [
  181. [0]
  182. ]
  183. }, {
  184. count: 2,
  185. spawnList: [
  186. [2, 1],
  187. [1, 2],
  188. [3, 4],
  189. [4, 3]
  190. ]
  191. }, {
  192. count: 3,
  193. spawnList: [
  194. [2, 0, 1],
  195. [1, 0, 2],
  196. [3, 0, 4],
  197. [4, 0, 3]
  198. ]
  199. }, ],
  200. level: 3,
  201. countdown: 60,
  202. countdownInterval: null,
  203. faultCount: 0,
  204. eliminationCount: 0,
  205. bJumpPlay: false,
  206. jumpCalorie: 1000,
  207. jumpSpeed: 1000,
  208. //硬件设备处理
  209. BLEAccIndex: 0,
  210. bJump: false,
  211. xA: 0,
  212. yA: 0,
  213. zA: 0,
  214. actionJumpObj: null
  215. }
  216. },
  217. created() {
  218. let _self = this;
  219. this.actionJumpCanvas = uni.createCanvasContext("actionJumpCanvas", this);
  220. // console.log("this.actionJumpCanvas:", this.actionJumpCanvas);
  221. this.SystemInfo = uni.getSystemInfoSync();
  222. this.canvasW = this.SystemInfo.windowWidth; // 画布宽度
  223. this.canvasH = 114;
  224. this.onLoadImage();
  225. this.onListenActionJump();
  226. },
  227. methods: {
  228. ...mapMutations(['onWriteBLEConnectionValue']),
  229. onListenActionJump() {
  230. let _self = this;
  231. _self.actionJumpObj = new ActionJump();
  232. _self.actionJumpObj.addEventListener('resultant', (e) => {
  233. if (e.type == 'jump') {
  234. // this.jumpCount++;
  235. this.bJump = true;
  236. } else if (e.type == 'stateDataOfJump') {
  237. //发送给game,在game里面处理判断
  238. this.listenStateDataOfJump(e);
  239. } else if (e.type == 'stop') {
  240. this.onClearData();
  241. // console.log('stop');
  242. }
  243. })
  244. },
  245. //load 相关图片
  246. onLoadImage() {
  247. let _self = this;
  248. uni.getImageInfo({
  249. src: "../../../static/modal/action-jump/directionJump.png",
  250. success: function(image) {
  251. _self.directionJump = image;
  252. }
  253. });
  254. uni.getImageInfo({
  255. src: "../../../static/modal/action-jump/midJump.png",
  256. success: function(image) {
  257. _self.midJump = image;
  258. console.log("==============", image);
  259. }
  260. });
  261. uni.getImageInfo({
  262. src: "../../../static/modal/action-jump/rotateJump.png",
  263. success: function(image) {
  264. _self.rotateJump = image;
  265. }
  266. });
  267. uni.getImageInfo({
  268. src: "../../../static/modal/action-jump/directionJumpWhite.png",
  269. success: function(image) {
  270. _self.directionJumpWhite = image;
  271. }
  272. });
  273. uni.getImageInfo({
  274. src: "../../../static/modal/action-jump/midJumpWhite.png",
  275. success: function(image) {
  276. _self.midJumpWhite = image;
  277. console.log("==============", image);
  278. }
  279. });
  280. uni.getImageInfo({
  281. src: "../../../static/modal/action-jump/rotateJumpWhite.png",
  282. success: function(image) {
  283. _self.rotateJumpWhite = image;
  284. }
  285. });
  286. uni.getImageInfo({
  287. src: "../../../static/modal/action-jump/jumpTip.png",
  288. success: function(image) {
  289. _self.jumpTipImage = image;
  290. }
  291. });
  292. uni.getImageInfo({
  293. src: "../../../static/modal/action-jump/jumpNormal.png",
  294. success: function(image) {
  295. _self.jumpNormalImage = image;
  296. console.log('-------------------》宽度:', _self.canvasW);
  297. _self.onDrawBg();
  298. }
  299. });
  300. uni.getImageInfo({
  301. src: "../../../static/modal/action-jump/cankao.png",
  302. success: function(image) {
  303. _self.cankao = image;
  304. }
  305. });
  306. },
  307. /**
  308. * 重置生成数组,重置倒计时
  309. */
  310. resetJumpGame() {
  311. this.spawnArray = [];
  312. if (this.countdownInterval) {
  313. clearInterval(this.countdownInterval);
  314. this.countdownInterval = null;
  315. }
  316. this.resetCountdown(60);
  317. },
  318. startJumpGame() {
  319. this.resetJumpGame();
  320. //开始游戏
  321. this.index = 0;
  322. // this.levelLabel.string = '关卡' + this.level;
  323. let _ranType = Math.floor(Math.random() * 2);
  324. if (this.level == 1) {
  325. //随便生成一组数据
  326. let _spawnList = this.template[1].spawnList;
  327. let ran = Math.floor(Math.random() * 2);
  328. if (_ranType >= 1) ran += 2;
  329. for (let i = 0; i < _spawnList[ran].length; i++) {
  330. this.spawnJumpPrefabsFromType(i, _spawnList[ran][i]);
  331. }
  332. } else if (this.level == 2) {
  333. //随便生成二组数据
  334. let _newArray = [];
  335. let _spawnList1 = this.template[1].spawnList;
  336. let ran1 = Math.floor(Math.random() * 2);
  337. _newArray = _newArray.concat(_spawnList1[ran1]);
  338. let _spawnList2 = this.template[2].spawnList;
  339. let ran2 = Math.floor(Math.random() * 2);
  340. if (_ranType >= 1) ran2 += 2;
  341. _newArray = _newArray.concat(_spawnList2[ran2]);
  342. // console.log(_newArray);
  343. for (let i = 0; i < _newArray.length; i++) {
  344. this.spawnJumpPrefabsFromType(i, _newArray[i]);
  345. }
  346. } else if (this.level == 3) {
  347. //随便生成三组数据
  348. let _newArray = [];
  349. // let _spawnList1 = this.template[1].spawnList;
  350. // let ran1 = Math.floor(Math.random() * 2);
  351. // _newArray = _newArray.concat(_spawnList1[ran1]);
  352. let _spawnList2 = this.template[2].spawnList;
  353. let ran2 = Math.floor(Math.random() * 2);
  354. let ran3 = Math.floor(Math.random() * 2);
  355. if (_ranType >= 1) {
  356. ran2 += 2;
  357. ran3 += 2;
  358. }
  359. _newArray = _newArray.concat(_spawnList2[ran2]);
  360. _newArray = _newArray.concat(_spawnList2[ran3]);
  361. for (let i = 0; i < _newArray.length; i++) {
  362. this.spawnJumpPrefabsFromType(i, _newArray[i]);
  363. }
  364. //todo 暂时给循环
  365. this.level = 0;
  366. }
  367. this.level++;
  368. //倒计时
  369. // this.countdownInterval = setInterval(() => {
  370. // if (this.countdown <= 0) {
  371. // clearInterval(this.countdownInterval);
  372. // this.countdownInterval = null;
  373. // //处理下一个关卡
  374. // // console.warn('时间到,处理下一个关卡');
  375. // this.startJumpGame();
  376. // return;
  377. // }
  378. // this.setCountdown(1);
  379. // }, 1000);
  380. this.onDraw();
  381. },
  382. spawnJumpPrefabsFromType(index, _jumpType) {
  383. //todo 生成的节点,后面再处理节奏问题。比如生成顺序
  384. for (let i = 0; i < this.jumpTypeArray.length; i++) {
  385. if (this.jumpTypeArray[i].jumpCode == _jumpType) {
  386. let _jumpPrefab = Object.assign({}, this.jumpTypeArray[i]);
  387. this.spawnArray.push(_jumpPrefab);
  388. break;
  389. }
  390. }
  391. },
  392. spawnJumpPrefabs(index) {
  393. let ran = Math.floor(Math.random() * 5);
  394. //todo 生成的节点,后面再处理节奏问题。比如生成顺序
  395. let _jumpPrefab = Object.assign({}, this.jumpTypeArray[ran]);
  396. //这里处理相反方向,比如生成了一个左旋转,下一个右旋转
  397. if (_jumpPrefab.jumpName == 'LEFT') {
  398. if (this.bNextSpawnRightDirection) {
  399. //如果是对应的需要记录一个对应的准确值
  400. this.bNextSpawnRightDirection = false;
  401. } else {
  402. ran = 2; //RIGHT;
  403. this.bNextSpawnRightDirection = true;
  404. }
  405. } else if (_jumpPrefab.jumpName == 'RIGHT') {
  406. if (this.bNextSpawnRightDirection) {
  407. ran = 1; //LEFT;
  408. this.bNextSpawnRightDirection = false;
  409. } else {
  410. this.bNextSpawnRightDirection = true;
  411. }
  412. }
  413. if (_jumpPrefab.jumpName == 'LEFT_ROTATE') {
  414. if (this.bNextSpawnRightRotateDirection) {
  415. //如果是对应的需要记录一个对应的准确值
  416. this.bNextSpawnRightRotateDirection = false;
  417. } else {
  418. ran = 4; //RIGHT_ROTATE;
  419. this.bNextSpawnRightRotateDirection = true;
  420. }
  421. // console.log('l==rotate', ran);
  422. } else if (_jumpPrefab.jumpName == 'RIGHT_ROTATE') {
  423. if (this.bNextSpawnRightRotateDirection) {
  424. ran = 3; //LEFT_ROTATE;
  425. this.bNextSpawnRightRotateDirection = false;
  426. } else {
  427. //如果是对应的需要记录一个对应的准确值
  428. this.bNextSpawnRightRotateDirection = true;
  429. }
  430. }
  431. this.spawnArray.push(_jumpPrefab);
  432. },
  433. //单纯的绘制八个背景
  434. onDrawBg() {
  435. this.actionJumpCanvas.clearRect(0, 0, this.canvasW, this.canvasH);
  436. let _currentBgStartX = this.canvasW / 2;
  437. let count = 4;
  438. for (let i = 0; i < count; i++) {
  439. let _currentStartPos = _currentBgStartX - i * 50 - 50;
  440. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentStartPos, 0, 50, 114);
  441. let _currentEndPos = _currentBgStartX + i * 50;
  442. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentEndPos, 0, 50, 114);
  443. }
  444. this.actionJumpCanvas.draw();
  445. },
  446. onDraw() {
  447. this.actionJumpCanvas.clearRect(0, 0, this.canvasW, 114);
  448. //计算一个对象
  449. let _drawObj = {
  450. path: null,
  451. startX: 0,
  452. width: 0,
  453. bgWidth: 0,
  454. bgStartXAllNormal: 0,
  455. bgStartXHasTip: 0,
  456. }
  457. //计算居中的点
  458. _drawObj.width = this.spawnArray.length * (50 + 10);
  459. _drawObj.startX = this.canvasW / 2 - _drawObj.width / 2;
  460. //全部是普通背景
  461. _drawObj.bgStartXAllNormal = this.canvasW / 2 - (this.spawnArray.length * 50) / 2;
  462. _drawObj.bgStartXHasTip = this.canvasW / 2 - (this.spawnArray.length * 50 + 40) / 2;
  463. let _currentBgStartX = this.index == this.spawnArray.length ? _drawObj.bgStartXAllNormal : _drawObj
  464. .bgStartXHasTip;
  465. // console.log("_drawObj.startX:", _drawObj.startX, _drawObj.width / 2);
  466. //绘制八个位置。如果生成数量不够的话。补上对应的数量
  467. let count = 8 - this.spawnArray.length;
  468. count = Math.ceil(count / 2);
  469. //计算一个节点数组
  470. for (let i = 0; i < this.spawnArray.length; i++) {
  471. //默认 mid 图标
  472. let _temp = this.spawnArray[i].bTrigger ? this.midJump : this.midJumpWhite;
  473. if (this.spawnArray[i].icon == 'directionJump') {
  474. _temp = this.spawnArray[i].bTrigger ? this.directionJump : this.directionJumpWhite;
  475. } else if (this.spawnArray[i].icon == 'rotateJump') {
  476. _temp = this.spawnArray[i].bTrigger ? this.rotateJump : this.rotateJumpWhite;
  477. }
  478. //如果是相反绘制,需要加多一个自身位置偏移
  479. let _pos = this.spawnArray[i].scaleX < 0 ? i + 1 : i;
  480. let _spacing = i == 0 ? 0 : 1;
  481. let _addData = 0;
  482. //大图提示后面要加上大图占的位置,为大图宽度减小图( 90 - 50 )
  483. if (i >= this.index) {
  484. _addData = 40;
  485. }
  486. if (i == 0) {
  487. //_frontBgData 为减去大图位置,10 为偏移位置
  488. let _frontBgData = 40;
  489. //绘制前背景
  490. for (let i = 0; i < count; i++) {
  491. let _currentStartPos = _currentBgStartX - _frontBgData - i * 50 - 10;
  492. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentStartPos, 0, 50, 114)
  493. }
  494. }
  495. this.actionJumpCanvas.save();
  496. this.actionJumpCanvas.globalAlpha = this.spawnArray[i].bTrigger ? 0.7 : 1;
  497. this.actionJumpCanvas.scale(this.spawnArray[i].scaleX, 1);
  498. let _currentPos = 0;
  499. let _currentCenterPos = 0;
  500. if (i == this.index) {
  501. _currentPos = (_currentBgStartX + _pos * 90 - i * 40) *
  502. this
  503. .spawnArray[i]
  504. .scaleX;
  505. this.actionJumpCanvas.drawImage(this.jumpTipImage.path, _currentPos, 0, 90, 114);
  506. //计算对应中心点的值
  507. _currentCenterPos = _currentPos + 90 / 2 - 25 / 2;
  508. //57 - 40/2 是取画布中心y点,减去图标本身高的一半的值
  509. this.actionJumpCanvas.drawImage(_temp.path, _currentCenterPos - 7.5, 37, 40, 40);
  510. } else {
  511. _currentPos = (_currentBgStartX + _addData + _pos *
  512. 50) * this
  513. .spawnArray[i]
  514. .scaleX;
  515. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentPos, 0, 50, 114)
  516. //计算对应中心点的值
  517. _currentCenterPos = _currentPos + 50 / 2 - 25 / 2;
  518. //44.5 是取画布中心y点,减去图标本身高的一半的值
  519. this.actionJumpCanvas.drawImage(_temp.path, _currentCenterPos, 44.5, 25, 25);
  520. }
  521. this.actionJumpCanvas.restore();
  522. if (i == this.spawnArray.length - 1) {
  523. //绘制结束位置
  524. // console.log("count:", count);
  525. for (let i = 0; i < count; i++) {
  526. let _currentEndPos = _currentBgStartX + _addData + (this.spawnArray.length + i) * 50;
  527. // console.log("end _currentEndPos:", _currentEndPos);
  528. this.actionJumpCanvas.drawImage(this.jumpNormalImage.path, _currentEndPos, 0, 50, 114)
  529. }
  530. }
  531. }
  532. this.actionJumpCanvas.draw();
  533. },
  534. onClear() {
  535. this.resetJumpGame();
  536. this.onDrawBg();
  537. this.xA = 0;
  538. this.yA = 0;
  539. this.zA = 0;
  540. this.bJump = false;
  541. this.actionJumpObj.resetAll();
  542. },
  543. onJumpType(event) {
  544. // console.log("onJumpType:", event);
  545. this.eliminateJumpPrefab(event);
  546. },
  547. // update (dt) {}
  548. eliminateJumpPrefab(_jumpType) {
  549. let _temp = this.spawnArray[this.index];
  550. //如果当前的跳类型和预制目标一样
  551. if (_jumpType == _temp.jumpCode) {
  552. _temp.bTrigger = true;
  553. this.index++;
  554. if (this.index >= this.spawnArray.length) {
  555. clearInterval(this.countdownInterval);
  556. this.countdownInterval = null;
  557. this.startJumpGame();
  558. } else {
  559. //绘制新触发状态
  560. this.onDraw();
  561. }
  562. //成功
  563. this.setEliminationCount(1);
  564. } else {
  565. //失误
  566. this.setFaultCount(1);
  567. }
  568. },
  569. //设置倒计时
  570. setCountdown(value) {
  571. this.countdown -= value;
  572. // this.countdownLabel.string = '倒计时:' + this.countdown;
  573. },
  574. resetCountdown(value) {
  575. this.countdown = value;
  576. // this.countdownLabel.string = '倒计时:' + this.countdown;
  577. },
  578. //设置ui信息
  579. setEliminationCount(value) {
  580. this.eliminationCount += value;
  581. // this.eliminationLabel.string = '消除数量:' + this.eliminationCount.toString();
  582. },
  583. setFaultCount(value) {
  584. this.faultCount += value;
  585. // this.faultLabel.string = '失误:' + this.faultCount;
  586. },
  587. //控制播放
  588. onControllerPlay() {
  589. // this.bJumpPlay = !this.bJumpPlay;
  590. if (this.bJumpPlay) {
  591. this.onClear();
  592. this.onClearData();
  593. this._changePlay();
  594. this.$emit("actionJumpControllerPlay", false);
  595. } else {
  596. this.$emit("actionJumpCheck");
  597. }
  598. },
  599. //修改状态
  600. _changePlay(bPlaying) {
  601. if (bPlaying) {
  602. this.bJumpPlay = bPlaying;
  603. } else {
  604. this.bJumpPlay = !this.bJumpPlay;
  605. }
  606. },
  607. onActionJumpPlay(){
  608. this.onClear();
  609. this.onClearData();
  610. this.startJumpGame();
  611. this._changePlay(true);
  612. },
  613. getCurrentJumpType() {
  614. let _temp = this.spawnArray[this.index];;
  615. return _temp.jumpCode;
  616. },
  617. //监听跳的状态数据
  618. listenStateDataOfJump(data) {
  619. let _jumpType = this.getCurrentJumpType();
  620. //初始全部默认状态
  621. let _tempState = [{
  622. jumpName: 'NORMAL',
  623. jumpCode: 0,
  624. bTrigger: true,
  625. describe: '正常跳'
  626. },
  627. {
  628. jumpName: 'LEFT',
  629. jumpCode: 1,
  630. bTrigger: false,
  631. describe: '左直跳'
  632. },
  633. {
  634. jumpName: 'RIGHT',
  635. jumpCode: 2,
  636. bTrigger: false,
  637. describe: '右直跳'
  638. },
  639. {
  640. jumpName: 'LEFT_ROTATE',
  641. jumpCode: 3,
  642. bTrigger: false,
  643. describe: '左旋转跳'
  644. },
  645. {
  646. jumpName: 'RIGHT_ROTATE',
  647. jumpCode: 4,
  648. bTrigger: false,
  649. describe: '右旋转跳'
  650. }
  651. ];
  652. let {
  653. currentMaxValue,
  654. oGyroValue
  655. } = data
  656. // console.log(data);
  657. if (currentMaxValue == 0) {
  658. //JumpType.NORMAL = 0
  659. if (_jumpType == 0) {
  660. // console.log('1====', data);
  661. this.eliminateJumpPrefabFormTemp(_tempState);
  662. }
  663. //JumpType.RIGHT_ROTATE = 4
  664. else if (_jumpType == 4 && (!this.isY && oGyroValue < 0 || this.isY && oGyroValue > 0)) {
  665. // console.log('right1:', oGyroValue);
  666. _tempState[4].bTrigger = true;
  667. this.eliminateJumpPrefabFormTemp(_tempState);
  668. }
  669. //JumpType.LEFT_ROTATE = 3
  670. else if (_jumpType == 3 && (!this.isY && oGyroValue > 0 || this.isY && oGyroValue < 0)) {
  671. // console.log('left1:', oGyroValue);
  672. _tempState[3].bTrigger = true;
  673. this.eliminateJumpPrefabFormTemp(_tempState);
  674. }
  675. } else {
  676. console.log('2====', data);
  677. if (currentMaxValue > 5) {
  678. _tempState[1].bTrigger = true;
  679. } else if (currentMaxValue < -5) {
  680. _tempState[2].bTrigger = true;
  681. }
  682. if (this.isY) {
  683. //如果是检测到旋转跳
  684. if (oGyroValue > 5) {
  685. // console.log('y right:', oGyroValue);
  686. _tempState[4].bTrigger = true;
  687. } else if (oGyroValue < -5) {
  688. // console.log('y left:', oGyroValue);
  689. _tempState[3].bTrigger = true;
  690. }
  691. } else {
  692. //如果是检测到旋转跳
  693. if (oGyroValue < -5) {
  694. // console.log('x right:', oGyroValue);
  695. _tempState[4].bTrigger = true;
  696. } else if (oGyroValue > 5) {
  697. // console.log('x left:', oGyroValue);
  698. _tempState[3].bTrigger = true;
  699. }
  700. }
  701. this.eliminateJumpPrefabFormTemp(_tempState);
  702. }
  703. },
  704. eliminateJumpPrefabFormTemp(_tempState) {
  705. //如果消除完,需要重新生成
  706. let _temp = this.spawnArray[this.index];
  707. let bSuccess = false;
  708. console.log(_tempState);
  709. for (let i = 0; i < _tempState.length; i++) {
  710. let _state = _tempState[i];
  711. //如果当前的跳类型和预制目标一样
  712. if (_state.jumpCode == _temp.jumpCode && _state.bTrigger) {
  713. //成功
  714. bSuccess = true;
  715. break;
  716. }
  717. }
  718. //如果存在其中一个为true
  719. if (bSuccess) {
  720. console.log("bSuccess:", bSuccess);
  721. _temp.bTrigger = true;
  722. this.index++;
  723. if (this.index >= this.spawnArray.length) {
  724. clearInterval(this.countdownInterval);
  725. this.countdownInterval = null;
  726. this.startJumpGame();
  727. } else {
  728. //绘制新触发状态
  729. this.onDraw();
  730. }
  731. //成功
  732. this.setEliminationCount(1);
  733. } else {
  734. //失误
  735. this.setFaultCount(1);
  736. }
  737. },
  738. /**
  739. * @param {Object} gameData
  740. * 识别跳部分数据处理
  741. */
  742. onBLERopeUpdate(gameData) {
  743. if (!this.bJumpPlay) return;
  744. //********陀螺仪角速度********
  745. let {
  746. gx,
  747. gy,
  748. gz
  749. } = gameData.gyro;
  750. let {
  751. min,
  752. s,
  753. ms
  754. } = gameData;
  755. let _ax = -gameData.acc.ax * 10;
  756. let _ay = gameData.acc.ay * 10;
  757. let _az = gameData.acc.az * 10;
  758. //低通滤波分离重力
  759. let alpha = 0.8;
  760. this.xA = alpha * this.xA + (1 - alpha) * _ax;
  761. this.yA = alpha * this.yA + (1 - alpha) * _ay;
  762. this.zA = alpha * this.zA + (1 - alpha) * _az;
  763. //高通滤波获取线性速度
  764. let linear_acceleration_x = _ax - this.xA;
  765. let linear_acceleration_y = _az - this.zA;
  766. let linear_acceleration_z = _ay - this.yA;
  767. let _temp = {
  768. linearAcc: {
  769. lAccX: linear_acceleration_x,
  770. lAccY: linear_acceleration_y,
  771. lAccZ: linear_acceleration_z
  772. }, //gameData.acc,
  773. oriAcc: {
  774. oAccX: _ax,
  775. oAccY: _ay,
  776. oAccZ: _az
  777. },
  778. gravityAcc: {
  779. gravityX: this.xA,
  780. gravityY: this.yA,
  781. gravityZ: this.zA
  782. },
  783. bLimitRebound: false,
  784. resultant: Math.sqrt(_ax * _ax +
  785. _ay * _ay + _az * _az),
  786. runIndex: this.BLEAccIndex,
  787. //陀螺仪
  788. oriGyro: {
  789. oGyroX: gx,
  790. oGyroY: gy,
  791. oGyroZ: gz
  792. },
  793. //输入当前轴
  794. bYAxis: this.isY,
  795. };
  796. this.actionJumpObj.updateJump(_temp);
  797. if (this.BLEAccIndex > 150) {
  798. this.onClearData();
  799. this.bJump = false;
  800. return;
  801. }
  802. this.BLEAccIndex++;
  803. },
  804. onClearData() {
  805. this.BLEAccIndex = 0;
  806. },
  807. onChangeY() {
  808. this.isY = true;
  809. },
  810. onChangeX() {
  811. this.isY = false;
  812. }
  813. }
  814. }
  815. </script>
  816. <style lang="scss">
  817. // .action-jump-parent {
  818. // border: 1rpx solid #ffaa7f;
  819. // position: relative;
  820. // display: flex;
  821. // justify-content: center;
  822. // overflow: hidden;
  823. // top: 0;
  824. // width: 100%;
  825. // }
  826. // .action-jump-container {
  827. // width: 100%;
  828. // height: 114px;
  829. // border: 1rpx solid #000000;
  830. // position: relative;
  831. // }
  832. .mid-absolute {
  833. position: absolute;
  834. top: 0;
  835. bottom: 0;
  836. right: 0;
  837. left: 0;
  838. margin: auto;
  839. }
  840. .action-jump-timer {
  841. position: absolute;
  842. top: -150rpx;
  843. }
  844. </style>