action-jump.vue 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. <!-- 新版本跳区域部分文件 -->
  2. <template>
  3. <view style="width: 750rpx;">
  4. <view class="flex justify-center" style="margin-top: 68rpx;">
  5. <!-- 目前格子数量不代表数字,显示完成度而已 -460rpx;-->
  6. <view class="grid-progress-vertical-container" style="top:-376rpx;">
  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" style="position: absolute;right: 0;top: -4px;">
  15. {{Math.floor(taskSignCount / 26 * 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" style="position: absolute;left: 0;top: -4px;">
  24. {{Math.floor(taskSignCount / 26 * index)+taskSignCount/2}}
  25. </view>
  26. <!-- 设置空位 -->
  27. <view></view>
  28. <view
  29. :class="showCurCount>=index+13? 'grid-progress-vertical-active':'grid-progress-vertical-inactive'">
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="position-relative">
  36. <!-- <image class="position-absolute-left-top" style="width: 86.12px;height:55.96px; left: 146rpx;top:-100rpx;"
  37. src="../../../static/modal/action-jump/progress-tip-add.png"></image> -->
  38. <view class="position-absolute-left-top flex justify-center align-center " style="width: 86.12px;height:55.96px;
  39. left: 146rpx;top:-90rpx; ">
  40. <view style="transform: scale(0.5);">
  41. <view class="sprite-yellow-arrow " :class="bRuning?'animation-play-state-play':''"></view>
  42. </view>
  43. </view>
  44. <view class="position-absolute-right-bottom flex justify-center align-center "
  45. style="width: 317rpx; height:138px; right: 46rpx; bottom: 15rpx;">
  46. <view class="flex flex-direction justify-between" style="transform: scale(0.5); height: 276px; ">
  47. <block v-if="bJumpPlay">
  48. <view class="sprite-rightToLeftArrow" :class="bJumpPlay?'sprite-rightToLeftArrow-play':''">
  49. </view>
  50. <view class="sprite-rightToLeftArrow" :class="bJumpPlay?'sprite-rightToLeftArrow-play':''">
  51. </view>
  52. </block>
  53. <block v-else>
  54. <image style="width: 317px; height: 42px;"
  55. src="../../../static/modal/action-jump/progress-tip.png"></image>
  56. <image style="width: 317px; height: 42px;"
  57. src="../../../static/modal/action-jump/progress-tip.png"></image>
  58. </block>
  59. </view>
  60. </view>
  61. <canvas canvas-id="actionJumpCanvas" :style="{ width: canvasW + 'px', height: canvasH + 'px' }"></canvas>
  62. <canvas class="position-absolute-center" canvas-id="effectCanvas"
  63. :style="{ width: canvasW + 'px', height: '164px' }"></canvas>
  64. </view>
  65. <view class="flex align-center justify-center" style="font-size: 14px;">
  66. <view style="position: relative;">
  67. <image style="width: 135px;height: 75px;" src="../../../static/modal/action-jump/Fill.png"></image>
  68. <view class="mid-absolute flex flex-direction align-center justify-center text-white">
  69. <view class="flex align-center">
  70. <image style="width: 22rpx;height: 28rpx;"
  71. src="../../../static/modal/action-jump/jumpSpeed.png"></image>
  72. <view style="margin-left: 6rpx;">平均速度</view>
  73. </view>
  74. <view style="margin-top: 12rpx;">{{averageSpeed}}</view>
  75. </view>
  76. </view>
  77. <view id="ActionJumpPlay" class="flex" style="position: relative;" @click="onControllerPlay">
  78. <image style="width: 110px;height: 110px;"
  79. src="../../../static/modal/action-jump/mid-button-orange@2x.png">
  80. </image>
  81. <image v-if="!bJumpPlay" class="mid-absolute" style="left:12rpx; width: 56rpx;height: 70rpx;"
  82. src="../../../static/play.png">
  83. </image>
  84. <image v-else class="mid-absolute" style="width: 100rpx;height: 100rpx;"
  85. src="../../../static/e-pause.png">
  86. </image>
  87. </view>
  88. <view style="position: relative;">
  89. <image style="width: 135px;height: 75px; transform: scaleX(-1);"
  90. src="../../../static/modal/action-jump/Fill.png"></image>
  91. <view class="mid-absolute flex flex-direction align-center justify-center text-white">
  92. <view class="flex align-center">
  93. <image style="width: 22rpx;height: 28rpx;"
  94. src="../../../static/modal/action-jump/jumpCalorie.png"></image>
  95. <view style="margin-left: 6rpx;">卡路里</view>
  96. </view>
  97. <view style="margin-top: 12rpx;">{{Math.floor(jumpCalorie)}}</view>
  98. </view>
  99. </view>
  100. </view>
  101. <view class="flex align-center justify-center" style="width: 750rpx;margin-top: 16rpx;">
  102. <view class="flex justify-center align-center" style="height: 120rpx; width: 444rpx; ">
  103. <view class="text-12px text-white text-center">
  104. {{taskDescribe}}
  105. </view>
  106. </view>
  107. </view>
  108. <!-- <view style="height: 41px;"></view> -->
  109. <!-- 测试按钮 -->
  110. <!-- <view style="display: flex;justify-content: space-between;">
  111. <view>{{isY?'Y':'X'}}</view>
  112. <button @click="onChangeY">Y为旋转轴</button>
  113. <button @click="onChangeX">X为旋转轴</button>
  114. </view> -->
  115. <!-- #ifdef H5 -->
  116. <view style="display: flex;justify-content: space-between;" class="margin-top margin-bottom">
  117. <button @click="onJumpType(0)">jump</button>
  118. <button @click="onJumpType(1)">left</button>
  119. <button @click="onJumpType(2)">right</button>
  120. <button @click="onJumpType(3)">rLeft</button>
  121. <button @click="onJumpType(4)">rRight</button>
  122. </view>
  123. <!-- #endif -->
  124. <!-- <view style="display: flex;justify-content: space-around; padding-bottom: 100rpx;">
  125. <view style="font-size: 14px;">t:{{countdown}}</view>
  126. <view style="font-size: 14px;">e:{{eliminationCount}}</view>
  127. <view style="font-size: 14px;">f:{{faultCount}}</view>
  128. </view> -->
  129. </view>
  130. </template>
  131. <script>
  132. import ActionJump from "@/util/util-js/action/jump-0.1.js"
  133. import {
  134. CONDITIONPASSED
  135. } from "@/util/util-js/enum.js"
  136. import Firework from "@/util/util-js/effect/firework.js"
  137. import Animation from "@/util/util-js/Animation.js"
  138. import puchConfig from "@/util/util-js/puchConfig.js"
  139. import {
  140. mapState,
  141. mapMutations
  142. } from 'vuex';
  143. export default {
  144. computed: mapState(['systemInfo']),
  145. components: {
  146. },
  147. props: {
  148. showTime: {
  149. type: Number,
  150. default: 0
  151. },
  152. levelData: {
  153. type: Object,
  154. default: null
  155. },
  156. currentMode: {
  157. type: String,
  158. default: ''
  159. }
  160. },
  161. data() {
  162. return {
  163. isY: true,
  164. canvasW: 0, // 画布宽
  165. canvasH: 0, // 画布高
  166. // SystemInfo: {}, // 设备信息
  167. directionJumpRight: null,
  168. directionJumpLeft: null,
  169. midJump: null,
  170. rotateJumpRight: null,
  171. rotateJumpLeft: null,
  172. directionJumpWhiteRight: null,
  173. directionJumpWhiteLeft: null,
  174. midJumpWhite: null,
  175. rotateJumpWhiteRight: null,
  176. rotateJumpWhiteLeft: null,
  177. //参考图片
  178. cankao: null,
  179. jumpTipImage: null,
  180. JumpTipOrange: null,
  181. jumpNormalLine: null,
  182. jumpNormalRect: null,
  183. jumpNormalWidth: 70,
  184. jumpNormalHeight: 164,
  185. jumpProgressTip: null,
  186. jumpTypeArray: [{
  187. jumpName: 'NORMAL',
  188. jumpCode: 0,
  189. icon: 'midJump',
  190. scaleX: 1,
  191. bTrigger: false,
  192. bShow: true,
  193. }, {
  194. jumpName: 'LEFT',
  195. jumpCode: 1,
  196. icon: 'directionJump',
  197. scaleX: 1,
  198. bTrigger: false,
  199. bShow: true,
  200. }, {
  201. jumpName: 'RIGHT',
  202. jumpCode: 2,
  203. icon: 'directionJump',
  204. scaleX: 1,
  205. bTrigger: false,
  206. bShow: true,
  207. }, {
  208. jumpName: 'LEFT_ROTATE',
  209. jumpCode: 3,
  210. icon: 'rotateJump',
  211. scaleX: 1,
  212. bTrigger: false,
  213. bShow: true,
  214. }, {
  215. jumpName: 'RIGHT_ROTATE',
  216. jumpCode: 4,
  217. icon: 'rotateJump',
  218. scaleX: 1,
  219. bTrigger: false,
  220. bShow: true,
  221. }],
  222. spawnArray: [],
  223. deleteSpawn: null, //已删除的对象
  224. deleteImage: null,
  225. /**
  226. * 生成的背景位置
  227. */
  228. spawnPos: [],
  229. spawnAnimation: null,
  230. spawnProcess: 1,
  231. //下一个生成是相反的方向
  232. bNextSpawnRightDirection: false,
  233. bNextSpawnRightRotateDirection: false,
  234. //生成预制的模板,用count 来判断生成哪一种
  235. template: [{ //原地
  236. count: 1,
  237. spawnList: [
  238. [0]
  239. ]
  240. }, {
  241. count: 2,
  242. spawnList: [
  243. [2, 1],
  244. [1, 2],
  245. [3, 4],
  246. [4, 3]
  247. ]
  248. }, {
  249. count: 3,
  250. spawnList: [
  251. [2, 0, 1],
  252. [1, 0, 2],
  253. [3, 0, 4],
  254. [4, 0, 3]
  255. ]
  256. }, ],
  257. //模板对象池,管理生成对象
  258. templatePool: [],
  259. levelType: 0,
  260. countdown: 60,
  261. countdownInterval: null,
  262. faultCount: 0,
  263. eliminationCount: 0,
  264. bJumpPlay: false,
  265. jumpCalorie: 0,
  266. averageSpeedInterval: null,
  267. averageSpeed: 0,
  268. tempHitCount: 0,
  269. //硬件设备处理
  270. BLEAccIndex: 0,
  271. xA: 0,
  272. yA: 0,
  273. zA: 0,
  274. actionJumpObj: null,
  275. /**
  276. * 交互数据处理
  277. */
  278. //当前选择的关卡信息
  279. selfLevelData: null,
  280. // 双人模式下 数据
  281. //标记块数量
  282. taskSignCount: 0, //总数
  283. taskSignCurCount: 0, //当前计数
  284. //{"type":1,"explain":"规定时间内跳完所有标志块","limitType":1}
  285. taskConditionPassed: null,
  286. taskDescribe: '',
  287. //满格的数值是 25
  288. maxShowCount: 13,
  289. addShowCountUnit: 0,
  290. showCurCount: 0,
  291. roundingCount: 0,
  292. //游戏结束
  293. isGameOver: false,
  294. //pk模式下操作
  295. leftShowCurCount: 0,
  296. rightShowCurCount: 0,
  297. isleftPlayer: true,
  298. /**
  299. * 是否允许绘制
  300. */
  301. canOnDraw: false,
  302. /**
  303. * 是否去到下一个关卡
  304. */
  305. canGoNext: false,
  306. /**
  307. * 生成的特效
  308. */
  309. canSpawnTemp: null,
  310. onLogData: '',
  311. /**
  312. * 是否显示关卡提示
  313. */
  314. bTipLevel: false,
  315. /**
  316. * 烟花相关
  317. */
  318. // firework collection
  319. fireworks: [],
  320. fireworkImage: null,
  321. loop: null,
  322. count: 100,
  323. effectCanvas: null,
  324. effectCurrentSpawn: null,
  325. effectSpawnPosX: 0,
  326. /**
  327. * 烟花特效
  328. */
  329. bDrawBoomEffect: false,
  330. //绘制箭头效果
  331. bRuning: false,
  332. bRuningInfinite: false,
  333. yellowRuningTimeout: null,
  334. }
  335. },
  336. watch: {
  337. levelData(val) {
  338. //更新数据
  339. // console.log("levelData ============>"+JSON.stringify(val));
  340. if (val) {
  341. this.taskSignCount = val.signCount;
  342. this.taskConditionPassed = val.conditionPassed;
  343. this.taskDescribe = val.describe;
  344. this.addShowCountUnit = (this.maxShowCount * 2) / this.taskSignCount;
  345. // console.log("this.addShowCountUnit:", this.addShowCountUnit, this.maxShowCount * 2, this
  346. // .taskSignCount);
  347. this.showCount = 0;
  348. //用signType 做等级类型
  349. this.levelType = val.signType;
  350. // console.log(JSON.stringify(this.taskConditionPassed));
  351. }
  352. },
  353. currentMode(val) {
  354. // console.log('==========> action jump currentMode:', val);
  355. }
  356. },
  357. created() {
  358. let _self = this;
  359. this.actionJumpCanvas = uni.createCanvasContext("actionJumpCanvas", this);
  360. this.effectCanvas = uni.createCanvasContext("effectCanvas", this);
  361. // this.SystemInfo = this.systemInfo; // uni.getSystemInfoSync();
  362. this.canvasW = this.systemInfo.windowWidth; // 画布宽度
  363. this.canvasH = 147.68;
  364. this.onLoadImage();
  365. setTimeout(() => {
  366. this.onListenActionJump();
  367. }, 2000)
  368. //更新一次状态
  369. const value = uni.getStorageSync('levelButtonPrompt');
  370. if (value) {
  371. _self.bTipLevel = !value.isSelected;
  372. } else {
  373. _self.bTipLevel = true;
  374. }
  375. // console.log('==========>levelButtonPrompt:', _self.bTipLevel);
  376. if (this.averageSpeedInterval) {
  377. clearInterval(this.averageSpeedInterval);
  378. this.averageSpeedInterval = null;
  379. }
  380. //计算平均速度
  381. this.averageSpeedInterval = setInterval(() => {
  382. this.averageSpeed = this.tempHitCount;
  383. this.tempHitCount = 0;
  384. }, 3000)
  385. },
  386. methods: {
  387. ...mapMutations(['onWriteBLEConnectionValue', 'onConvertDeviceData']),
  388. //更新新手状态提示
  389. onUpdateTipLevelValue(value) {
  390. this.bTipLevel = value;
  391. },
  392. onListenActionJump() {
  393. let _self = this;
  394. console.log("*****************onListenActionJump*****************************");
  395. _self.actionJumpObj = new ActionJump();
  396. _self.actionJumpObj.addEventListener('resultant', (e) => {
  397. if (e.type == 'stateDataOfJump') {
  398. //发送给game,在game里面处理判断
  399. this.listenStateDataOfJump(e);
  400. } else if (e.type == 'stop') {
  401. this.onClearData();
  402. this.actionJumpObj.resetAll();
  403. if (this.canOnDraw) {
  404. this.canOnDraw = false;
  405. // //这里更新特效
  406. // this.onDrawEffect(this.canSpawnTemp);
  407. this.onDraw("tipHit", true);
  408. }
  409. if (this.canGoNext) {
  410. this.canGoNext = false;
  411. // //这里更新特效
  412. // this.onDrawEffect(this.canSpawnTemp);
  413. //绘制新触发状态
  414. this.onDraw("normal", false);
  415. setTimeout(() => {
  416. this.startJumpGame();
  417. }, 500)
  418. }
  419. // console.log('stop');
  420. //这里处理生成下一个
  421. }
  422. })
  423. },
  424. //load 相关图片
  425. onLoadImage() {
  426. let _self = this;
  427. uni.getImageInfo({
  428. src: "../../../static/modal/action-jump/directionJump-left.png",
  429. success: function(image) {
  430. _self.directionJumpLeft = image;
  431. }
  432. });
  433. uni.getImageInfo({
  434. src: "../../../static/modal/action-jump/directionJump-right.png",
  435. success: function(image) {
  436. _self.directionJumpRight = image;
  437. }
  438. });
  439. uni.getImageInfo({
  440. src: "../../../static/modal/action-jump/midJump.png",
  441. success: function(image) {
  442. _self.midJump = image;
  443. }
  444. });
  445. uni.getImageInfo({
  446. src: "../../../static/modal/action-jump/rotateJump-right.png",
  447. success: function(image) {
  448. _self.rotateJumpRight = image;
  449. }
  450. });
  451. uni.getImageInfo({
  452. src: "../../../static/modal/action-jump/rotateJump-left.png",
  453. success: function(image) {
  454. _self.rotateJumpLeft = image;
  455. }
  456. });
  457. uni.getImageInfo({
  458. src: "../../../static/modal/action-jump/directionJumpWhite-right.png",
  459. success: function(image) {
  460. _self.directionJumpWhiteRight = image;
  461. }
  462. });
  463. uni.getImageInfo({
  464. src: "../../../static/modal/action-jump/directionJumpWhite-left.png",
  465. success: function(image) {
  466. _self.directionJumpWhiteLeft = image;
  467. }
  468. });
  469. uni.getImageInfo({
  470. src: "../../../static/modal/action-jump/midJumpWhite.png",
  471. success: function(image) {
  472. _self.midJumpWhite = image;
  473. }
  474. });
  475. uni.getImageInfo({
  476. src: "../../../static/modal/action-jump/rotateJumpWhite-right.png",
  477. success: function(image) {
  478. _self.rotateJumpWhiteRight = image;
  479. }
  480. });
  481. uni.getImageInfo({
  482. src: "../../../static/modal/action-jump/rotateJumpWhite-left.png",
  483. success: function(image) {
  484. _self.rotateJumpWhiteLeft = image;
  485. }
  486. });
  487. uni.getImageInfo({
  488. src: "../../../static/modal/action-jump/jumpTip.png",
  489. success: function(image) {
  490. _self.jumpTipImage = image;
  491. }
  492. });
  493. uni.getImageInfo({
  494. src: "../../../static/modal/action-jump/jump-tip-orange@2x.png",
  495. success: function(image) {
  496. _self.JumpTipOrange = image;
  497. }
  498. })
  499. uni.getImageInfo({
  500. src: "../../../static/modal/action-jump/progress-tip.png",
  501. success: function(image) {
  502. _self.jumpProgressTip = image;
  503. }
  504. })
  505. uni.getImageInfo({
  506. src: "../../../static/modal/action-jump/jumpNormal-line.png",
  507. success: function(image) {
  508. _self.jumpNormalLine = image;
  509. }
  510. });
  511. uni.getImageInfo({
  512. src: "../../../static/modal/action-jump/jumpNormal-rect.png",
  513. success: function(image) {
  514. _self.jumpNormalRect = image;
  515. _self.onDrawBg(true);
  516. }
  517. });
  518. uni.getImageInfo({
  519. src: "../../../static/modal/action-jump/cankao.png",
  520. success: function(image) {
  521. _self.cankao = image;
  522. }
  523. });
  524. /**
  525. * 烟花照片
  526. */
  527. uni.getImageInfo({
  528. src: "../../../static/modal/action-jump/boom.png",
  529. success: function(image) {
  530. _self.fireworkImage = image;
  531. }
  532. });
  533. },
  534. /**
  535. * 重置生成数组,重置倒计时
  536. */
  537. resetJumpGame() {
  538. this.spawnArray = [];
  539. this.templatePool = [];
  540. if (this.countdownInterval) {
  541. clearInterval(this.countdownInterval);
  542. this.countdownInterval = null;
  543. }
  544. // this.resetCountdown(60);
  545. },
  546. startJumpGame() {
  547. this.isGameOver = false;
  548. this.resetJumpGame();
  549. //开始游戏
  550. this.index = 0;
  551. // this.levelType = 5;
  552. let spawnCount = 7;
  553. let _ranType = Math.floor(Math.random() * 2);
  554. //生成二个占位
  555. this.addTemplatePoolFromType(false, this.template[0].spawnList[0][0]);
  556. this.addTemplatePoolFromType(false, this.template[0].spawnList[0][0]);
  557. if (this.levelType == 0) {
  558. //随便生成一组跳的数据
  559. let _spawnList = this.template[0].spawnList;
  560. for (let i = 0; i < 30; i++) {
  561. //再对象池里面生成一组对象
  562. this.addTemplatePoolFromType(true, _spawnList[0][0]);
  563. }
  564. //先生成spawnCount个
  565. for (let i = 0; i < spawnCount; i++) {
  566. this.spawnArray.push(this.templatePool[this.index]);
  567. this.index++;
  568. }
  569. } else if (this.levelType == 1) {
  570. //生成一组 左跳右跳
  571. let _spawnList = this.template[1].spawnList;
  572. for (let i = 0; i < 30; i++) {
  573. let ran = Math.floor(Math.random() * 2);
  574. for (let j = 0; j < _spawnList[ran].length; j++) {
  575. //再对象池里面生成一组对象
  576. this.addTemplatePoolFromType(true, _spawnList[ran][j]);
  577. }
  578. }
  579. //先生成spawnCount个
  580. for (let i = 0; i < spawnCount; i++) {
  581. this.spawnArray.push(this.templatePool[this.index]);
  582. this.index++;
  583. }
  584. } else if (this.levelType == 2) {
  585. //生成一组 左跳右跳原地
  586. let _spawnList = this.template[2].spawnList;
  587. for (let i = 0; i < 30; i++) {
  588. let ran = Math.floor(Math.random() * 2);
  589. for (let j = 0; j < _spawnList[ran].length; j++) {
  590. //再对象池里面生成一组对象
  591. this.addTemplatePoolFromType(true, _spawnList[ran][j]);
  592. }
  593. }
  594. //先生成spawnCount个
  595. for (let i = 0; i < spawnCount; i++) {
  596. this.spawnArray.push(this.templatePool[this.index]);
  597. this.index++;
  598. }
  599. } else if (this.levelType == 3) {
  600. //生成一组 左旋跳右旋跳
  601. let _spawnList = this.template[1].spawnList;
  602. for (let i = 0; i < 30; i++) {
  603. let ran = Math.floor(Math.random() * 2) + 2;
  604. for (let j = 0; j < _spawnList[ran].length; j++) {
  605. //再对象池里面生成一组对象
  606. this.addTemplatePoolFromType(true, _spawnList[ran][j]);
  607. }
  608. }
  609. //先生成spawnCount个
  610. for (let i = 0; i < spawnCount; i++) {
  611. this.spawnArray.push(this.templatePool[this.index]);
  612. this.index++;
  613. }
  614. } else if (this.levelType == 4) {
  615. //生成一组 左旋跳右旋跳
  616. let _spawnList = this.template[2].spawnList;
  617. for (let i = 0; i < 30; i++) {
  618. let ran = Math.floor(Math.random() * 2) + 2;
  619. for (let j = 0; j < _spawnList[ran].length; j++) {
  620. //再对象池里面生成一组对象
  621. this.addTemplatePoolFromType(true, _spawnList[ran][j]);
  622. }
  623. }
  624. //先生成spawnCount个
  625. for (let i = 0; i < spawnCount; i++) {
  626. this.spawnArray.push(this.templatePool[this.index]);
  627. this.index++;
  628. }
  629. } else if (this.levelType == 5) {
  630. for (let i = 0; i < 20; i++) {
  631. //随便生成三组数据
  632. let _newArray = [];
  633. let _spawnList2 = this.template[2].spawnList;
  634. let ran2 = Math.floor(Math.random() * 2);
  635. let ran3 = Math.floor(Math.random() * 2);
  636. if (_ranType >= 1) {
  637. ran2 += 2;
  638. ran3 += 2;
  639. }
  640. _newArray = _newArray.concat(_spawnList2[ran2]);
  641. _newArray = _newArray.concat(_spawnList2[ran3]);
  642. for (let j = 0; j < _newArray.length; j++) {
  643. this.addTemplatePoolFromType(true, _newArray[j]);
  644. }
  645. }
  646. //先生成spawnCount个
  647. for (let i = 0; i < spawnCount; i++) {
  648. this.spawnArray.push(this.templatePool[this.index]);
  649. this.index++;
  650. }
  651. }
  652. this.onDraw("tipHit", false);
  653. },
  654. /**
  655. * 生成对应预制对象
  656. * @param {Object} bShow
  657. * @param {Object} _jumpType
  658. */
  659. addTemplatePoolFromType(bShow, _jumpType) {
  660. for (let i = 0; i < this.jumpTypeArray.length; i++) {
  661. if (this.jumpTypeArray[i].jumpCode == _jumpType) {
  662. let _jumpPrefab = Object.assign({}, this.jumpTypeArray[i], {
  663. bShow: bShow,
  664. bInit: true,
  665. position: 0,
  666. animation: null, //动画
  667. });
  668. this.templatePool.push(_jumpPrefab);
  669. break;
  670. }
  671. }
  672. },
  673. //单纯的绘制八个背景
  674. onDrawBg(bDraw) {
  675. this.spawnPos = [];
  676. if (bDraw) {
  677. this.actionJumpCanvas.clearRect(0, 0, this.canvasW, this.canvasH);
  678. }
  679. let _currentBgStartX = this.canvasW / 2;
  680. let count = 7;
  681. let _currentPos = -12,
  682. _addPos = 0;
  683. // this.actionJumpCanvas.drawImage(this.jumpProgressTip.path, _currentBgStartX, 5, 171, 24.66);
  684. // this.actionJumpCanvas.drawImage(this.jumpProgressTip.path, _currentBgStartX, 116, 171, 24.66);
  685. for (let i = 0; i < count; i++) {
  686. if (0 !== i) {
  687. _currentPos += this.jumpNormalWidth;
  688. } else {
  689. _currentPos -= this.jumpNormalWidth;
  690. }
  691. if (2 === i) {
  692. //结尾时候快消除完绘制一次大图背景。不然会为空白
  693. if (this.spawnArray.length < 3)
  694. this.actionJumpCanvas.drawImage(this.jumpTipImage.path, _currentPos, 0, 120, this.canvasH);
  695. if (bDraw) {
  696. this.actionJumpCanvas.drawImage(this.JumpTipOrange.path, _currentPos + 3, 7, 113, this
  697. .canvasH -
  698. 14);
  699. }
  700. // this.actionJumpCanvas.drawImage(this.midJump.path, _currentPos + 30, 46, 60, 60);
  701. //添加对应生成点
  702. this.spawnPos.push({
  703. center: _currentPos + 30
  704. })
  705. _currentPos += 50;
  706. } else {
  707. this.actionJumpCanvas.drawImage(this.jumpNormalLine.path, _currentPos, 0, this.jumpNormalWidth,
  708. this.canvasH);
  709. if (bDraw) {
  710. this.actionJumpCanvas.drawImage(this.jumpNormalRect.path, _currentPos, 0, this.jumpNormalWidth,
  711. this.canvasH);
  712. }
  713. // this.actionJumpCanvas.drawImage(this.midJump.path, _currentPos + 16, 55, 40, 40);
  714. //添加对应生成点
  715. this.spawnPos.push({
  716. center: _currentPos + 16
  717. })
  718. }
  719. }
  720. if (bDraw) {
  721. this.actionJumpCanvas.draw();
  722. }
  723. },
  724. onDraw(type, bAnimation) {
  725. let _self = this;
  726. if (bAnimation && _self.spawnAnimation == null) {
  727. _self.spawnProcess = 0;
  728. _self.spawnAnimation = new Animation({
  729. timing: 'linear',
  730. duration: 200,
  731. onProcess: function onProcess(process) {
  732. _self.spawnProcess = process;
  733. _self.onDraw('normal', true);
  734. // console.log("process=" + process);
  735. },
  736. onAnimationFinish: function onAnimationFinish() {
  737. // console.log("finish animation");
  738. _self.spawnAnimation = null;
  739. }
  740. })
  741. }
  742. this.actionJumpCanvas.clearRect(0, 0, this.canvasW, this.canvasH);
  743. //单纯绘制背景
  744. this.onDrawBg(false);
  745. //计算一个节点数组
  746. // let _oldRectMoveDis = 1;
  747. for (let i = 0; i < this.spawnArray.length; i++) {
  748. //默认 mid 图标
  749. let _temp = this.spawnArray[i].bTrigger ? this.midJump : this.midJumpWhite;
  750. if (this.spawnArray[i].icon == 'directionJump') {
  751. if (this.spawnArray[i].jumpName == "RIGHT") {
  752. _temp = this.spawnArray[i].bTrigger ? this.directionJumpRight : this.directionJumpWhiteRight;
  753. } else {
  754. _temp = this.spawnArray[i].bTrigger ? this.directionJumpLeft : this.directionJumpWhiteLeft;
  755. }
  756. } else if (this.spawnArray[i].icon == 'rotateJump') {
  757. if (this.spawnArray[i].jumpName == "RIGHT_ROTATE") {
  758. _temp = this.spawnArray[i].bTrigger ? this.rotateJumpRight : this.rotateJumpWhiteRight;
  759. } else {
  760. _temp = this.spawnArray[i].bTrigger ? this.rotateJumpLeft : this.rotateJumpWhiteLeft;
  761. }
  762. }
  763. this.actionJumpCanvas.save();
  764. // let _opacity = this.spawnArray[i].bTrigger ? 0.7 : 1;
  765. // this.actionJumpCanvas.globalAlpha = this.spawnArray[i].bShow ? _opacity : 0;
  766. // this.actionJumpCanvas.scale(this.spawnArray[i].scaleX, 1);
  767. let _currentPos = this.spawnPos[i].center;
  768. let _currentCenterPos = 0;
  769. if (2 === i) {
  770. //这里分两部分走,从小图走到大图
  771. let _spawnBiggerToLeft = this.spawnArray[i];
  772. //这里记录一个生成点,后面用于生成特效
  773. this.effectSpawnPosX = _currentPos;
  774. //大图
  775. let tempPosition = _currentPos;
  776. if (!bAnimation || _spawnBiggerToLeft.bInit) {
  777. _spawnBiggerToLeft.position = _currentPos;
  778. _spawnBiggerToLeft.bInit = false;
  779. } else {
  780. tempPosition = _spawnBiggerToLeft.position - Math.abs(_currentPos - _spawnBiggerToLeft
  781. .position) * _self.spawnProcess;
  782. }
  783. if (1 === this.spawnProcess) {
  784. _spawnBiggerToLeft.position = tempPosition;
  785. } else {
  786. //绘制一次前面方块背景前移
  787. this.actionJumpCanvas.drawImage(this.jumpNormalRect.path, tempPosition - 16, 0, this
  788. .jumpNormalWidth,
  789. this.canvasH);
  790. this.actionJumpCanvas.clearRect(this.spawnPos[i].center - 30, 0, 120, this.canvasH);
  791. }
  792. let _width = 40 + 20 * _self.spawnProcess;
  793. this.actionJumpCanvas.drawImage(_temp.path, tempPosition, 55 - 9 * _self.spawnProcess, _width,
  794. _width);
  795. //绘制多一次背景
  796. this.actionJumpCanvas.drawImage(this.jumpTipImage.path, this.spawnPos[i].center - 30, 0, 120, this
  797. .canvasH);
  798. this.actionJumpCanvas.drawImage(this.JumpTipOrange.path, this.spawnPos[i].center - 27, 7, 113, this
  799. .canvasH -
  800. 14);
  801. } else {
  802. //小图
  803. let _otherObj = this.spawnArray[i];
  804. let tempPosition = _currentPos;
  805. if (!bAnimation || _otherObj.bInit) {
  806. _otherObj.position = _currentPos;
  807. _otherObj.bInit = false;
  808. // console.log(i + " add== " + _otherObj.position + " == " + tempPosition);
  809. } else {
  810. tempPosition = _otherObj.position - Math.abs(_currentPos - _otherObj.position) * _self
  811. .spawnProcess;
  812. // if (i === 1) {
  813. // console.log(tempPosition + "==" + _otherObj.position + "==" + Math.abs(_currentPos -
  814. // _otherObj.position));
  815. // }
  816. }
  817. if (1 === this.spawnProcess) {
  818. _otherObj.position = tempPosition;
  819. }
  820. // if (1 === i) {
  821. // _oldRectMoveDis = Math.abs(_currentPos - _otherObj.position);
  822. // }
  823. this.actionJumpCanvas.drawImage(this.jumpNormalRect.path, tempPosition - 16, 0, this
  824. .jumpNormalWidth,
  825. this.canvasH);
  826. if (this.spawnArray[i].bShow) {
  827. this.actionJumpCanvas.drawImage(_temp.path, tempPosition, 55, 40, 40);
  828. }
  829. }
  830. this.actionJumpCanvas.restore();
  831. }
  832. this.actionJumpCanvas.draw();
  833. },
  834. onDrawEffect(_temp) {
  835. if (!this.bRuning) {
  836. this.bRuning = true;
  837. // console.log(this.bRuning);
  838. if (this.yellowRuningTimeout) {
  839. clearTimeout(this.yellowRuningTimeout)
  840. this.yellowRuningTimeout = null;
  841. }
  842. this.yellowRuningTimeout = setTimeout(() => {
  843. this.bRuning = false;
  844. // console.log(this.bRuning);
  845. }, 1000)
  846. }
  847. //根据当前消除的生成一个
  848. // console.log("生成的_temp:" + JSON.stringify(_temp));
  849. let spawnTemp = this.midJump;
  850. let offest = 5;
  851. if (_temp.icon == 'directionJump') {
  852. spawnTemp = _temp.jumpName == "RIGHT" ? this.directionJumpRight : this.directionJumpLeft;
  853. } else if (_temp.icon == 'rotateJump') {
  854. spawnTemp = _temp.jumpName == "RIGHT_ROTATE" ? this.rotateJumpRight : this.rotateJumpLeft;
  855. offest = _temp.jumpName == "RIGHT_ROTATE" ? 8 : 6;
  856. }
  857. let tempFirework = new Firework(this.fireworkImage,
  858. spawnTemp, _temp.scaleX, this.effectSpawnPosX, 0, this.canvasW, 164, offest);
  859. this.fireworks.push(tempFirework);
  860. this.bDrawBoomEffect = true;
  861. this.onInitFirework();
  862. },
  863. onClear() {
  864. this.resetJumpGame();
  865. this.onDrawBg(true);
  866. this.xA = 0;
  867. this.yA = 0;
  868. this.zA = 0;
  869. this.actionJumpObj.resetAll();
  870. },
  871. /**
  872. * 统一绘制 效果 背景,交互,烟花
  873. */
  874. onInitFirework() {
  875. if (this.loop != null) {
  876. return;
  877. }
  878. this.loop = setInterval(() => {
  879. if (!this.bDrawBoomEffect) {
  880. clearInterval(this.loop);
  881. this.loop = null;
  882. // console.log("结束绘制");
  883. this.effectCanvas.clearRect(0, 0, this.canvasW, 164);
  884. this.effectCanvas.draw();
  885. return;
  886. }
  887. this.effectCanvas.clearRect(0, 0, this.canvasW, 164);
  888. if (this.bDrawBoomEffect) {
  889. // loop over each firework, draw it, update it
  890. var i = this.fireworks.length;
  891. while (i--) {
  892. this.fireworks[i].draw(this.effectCanvas, () => {
  893. this.fireworks.splice(i, 1);
  894. if (this.fireworks.length == 0) {
  895. this.bDrawBoomEffect = false;
  896. }
  897. });
  898. }
  899. }
  900. this.effectCanvas.draw();
  901. }, 30)
  902. },
  903. onJumpType(event) {
  904. // console.log("onJumpType:", event);
  905. if (this.isGameOver || !this.bJumpPlay) return;
  906. this.eliminateJumpPrefab(event);
  907. },
  908. // update (dt) {}
  909. //模拟测试调用
  910. eliminateJumpPrefab(_jumpType) {
  911. //只触发第二个
  912. if (this.spawnArray.length < 3) {
  913. return;
  914. }
  915. let _temp = this.spawnArray[2];
  916. //如果当前的跳类型和预制目标一样
  917. if (_jumpType == _temp.jumpCode) {
  918. _temp.bTrigger = true;
  919. this.deleteSpawn = this.spawnArray.splice(0, 1);
  920. if (this.index < this.templatePool.length) {
  921. this.spawnArray.push(this.templatePool[this.index]);
  922. this.index++;
  923. }
  924. //这里更新特效
  925. let _endTemp = Object.assign({}, _temp);
  926. this.onDrawEffect(_endTemp);
  927. //绘制新触发状态
  928. this.onDraw('tipHit', true);
  929. //成功
  930. this.setEliminationCount(1);
  931. //替换数组
  932. // console.log(this.index + " == " + this.spawnArray.length);
  933. if (this.spawnArray.length < 3 && this.index > 3) {
  934. clearInterval(this.countdownInterval);
  935. this.countdownInterval = null;
  936. //绘制新触发状态
  937. this.onDraw("normal", false);
  938. setTimeout(() => {
  939. this.startJumpGame();
  940. }, 2000)
  941. }
  942. } else {
  943. //失误
  944. this.setFaultCount(1);
  945. }
  946. },
  947. //设置倒计时
  948. setCountdown(value) {
  949. this.countdown -= value;
  950. // this.countdownLabel.string = '倒计时:' + this.countdown;
  951. this.$emit('actionJumpCountDownUpdate', {
  952. countDown: this.countdown
  953. });
  954. },
  955. resetCountdown(value) {
  956. this.countdown = value;
  957. // this.countdownLabel.string = '倒计时:' + this.countdown;
  958. this.$emit('actionJumpCountDownUpdate', {
  959. countDown: this.countdown
  960. });
  961. },
  962. //设置ui信息
  963. setEliminationCount(value) {
  964. this.tempHitCount++;
  965. this.taskSignCurCount++;
  966. this.roundingCount += this.addShowCountUnit;
  967. this.eliminationCount += value;
  968. // this.eliminationLabel.string = '消除数量:' + this.eliminationCount.toString();
  969. this.$emit('actionJumpDataUpdate', {
  970. eliminationCount: this.eliminationCount,
  971. faultCount: this.faultCount
  972. });
  973. this.jumpCalorie += puchConfig.getJumpCalorie(this.eliminationCount + this.faultCount);
  974. //如果是pk模式。不走下面判断
  975. if (this.currentMode == 'pkMode') return;
  976. if (CONDITIONPASSED.ENERGYBARFULL == this.taskConditionPassed.limitType) {
  977. //能量条的条件下才显示能量条动
  978. //取两位后计算Math floor,不然会有偏差值问题 Math.floor(39.9999999+ 0.1111111) = 39
  979. this.showCurCount = Math.floor(this.roundingCount.toFixed(2));
  980. //1.能量槽满的时候,说明踩中次数到达
  981. if (this.taskSignCurCount >= this.taskSignCount)
  982. this.onGameOver("energyBarFull");
  983. } else if (CONDITIONPASSED.SKIPALLFLAGWITHINTIME == this.taskConditionPassed.limitType) {
  984. //规定时间下也给显示能量条
  985. this.showCurCount = Math.floor(this.roundingCount.toFixed(2));
  986. //2.规定时间内跳完所有标志块
  987. if (this.taskSignCurCount >= this.taskSignCount)
  988. this.onGameOver("skipAllFlagWithinTime");
  989. } else if (this.taskConditionPassed.isScore) {
  990. //3.达到一定分数
  991. //如果是用分数判断
  992. //分数是 跳对的加1分,错的扣1分,0不扣分。
  993. let curScore = this.eliminationCount - this.faultCount;
  994. curScore = curScore < 0 ? 0 : curScore;
  995. //当前分数达到,胜利
  996. if (curScore >= this.taskConditionPassed.limitScore)
  997. this.onGameOver("score");
  998. }
  999. },
  1000. onGameOver(type) {
  1001. this.isGameOver = true;
  1002. //处理参数
  1003. this.onClear();
  1004. this.onClearData();
  1005. this.bJumpPlay = false;
  1006. /**
  1007. * 判断胜利和失败
  1008. */
  1009. let myWin = false; //默认失败
  1010. //比如, 1.充满左右两边蓄能槽.2.规定时间内跳完所有标志块.
  1011. if (type == "energyBarFull") {
  1012. //1.能量槽满的时候,说明踩中次数到达
  1013. if (this.taskSignCurCount >= this.taskSignCount) {
  1014. myWin = true;
  1015. }
  1016. } else if (type == 'skipAllFlagWithinTime') {
  1017. myWin = true;
  1018. } else if (type == "timeUp") {
  1019. //2.规定时间内跳完所有标志块
  1020. //查看消除数量是否到达总数,未达成就是未完成
  1021. if (this.taskSignCurCount >= this.taskSignCount) {
  1022. myWin = true;
  1023. }
  1024. } else if (type == "score") {
  1025. myWin = true;
  1026. }
  1027. console.log(type, {
  1028. myWin: myWin
  1029. });
  1030. this.$emit('gameOver', {
  1031. myWin: myWin,
  1032. type: 'calorieMode',
  1033. isOffEvent: true
  1034. });
  1035. },
  1036. //pk模式下结束游戏关卡
  1037. onPKModeGameOver(type) {
  1038. this.isGameOver = true;
  1039. //处理参数
  1040. this.onClear();
  1041. this.onClearData();
  1042. this.bJumpPlay = false;
  1043. this.$emit('gameOver', {
  1044. type: 'pkMode',
  1045. isOffEvent: true
  1046. });
  1047. },
  1048. setFaultCount(value) {
  1049. this.tempHitCount++;
  1050. this.faultCount += value;
  1051. // this.faultLabel.string = '失误:' + this.faultCount;
  1052. this.$emit('actionJumpDataUpdate', {
  1053. eliminationCount: this.eliminationCount,
  1054. faultCount: this.faultCount
  1055. });
  1056. this.jumpCalorie += puchConfig.getJumpCalorie(this.eliminationCount + this.faultCount);
  1057. },
  1058. //控制播放
  1059. onControllerPlay() {
  1060. if (this.bJumpPlay) {
  1061. //仅仅暂停,没有清空数据
  1062. this._changePlay(false);
  1063. this.$emit("actionJumpControllerPlay", false);
  1064. } else {
  1065. this.$emit("actionJumpCheck");
  1066. }
  1067. },
  1068. onContinueGame() {
  1069. this._changePlay(true);
  1070. },
  1071. onClearActionJumpData() {
  1072. console.log("onClearActionJumpData");
  1073. this.onClear();
  1074. this.onClearData();
  1075. },
  1076. //修改状态
  1077. _changePlay(bPlaying) {
  1078. if (bPlaying) {
  1079. this.bJumpPlay = bPlaying;
  1080. } else {
  1081. this.bJumpPlay = !this.bJumpPlay;
  1082. }
  1083. },
  1084. onActionJumpPlay() {
  1085. this.onClear();
  1086. this.onClearData();
  1087. this.startJumpGame();
  1088. this._changePlay(true);
  1089. //reset 对应计算数据
  1090. this.taskSignCurCount = 0;
  1091. this.showCurCount = 0;
  1092. this.roundingCount = 0;
  1093. this.faultCount = 0;
  1094. this.eliminationCount = 0;
  1095. },
  1096. getCurrentJumpType() {
  1097. let _temp = this.spawnArray[2];
  1098. return _temp.jumpCode;
  1099. },
  1100. //监听跳的状态数据
  1101. listenStateDataOfJump(data) {
  1102. if (this.isGameOver || !this.bJumpPlay) return;
  1103. if (this.spawnArray.length < 3) return;
  1104. let _jumpType = this.getCurrentJumpType();
  1105. //初始全部默认状态
  1106. let _tempState = [{
  1107. jumpName: 'NORMAL',
  1108. jumpCode: 0,
  1109. bTrigger: true,
  1110. describe: '正常跳'
  1111. },
  1112. {
  1113. jumpName: 'LEFT',
  1114. jumpCode: 1,
  1115. bTrigger: false,
  1116. describe: '左直跳'
  1117. },
  1118. {
  1119. jumpName: 'RIGHT',
  1120. jumpCode: 2,
  1121. bTrigger: false,
  1122. describe: '右直跳'
  1123. },
  1124. {
  1125. jumpName: 'LEFT_ROTATE',
  1126. jumpCode: 3,
  1127. bTrigger: false,
  1128. describe: '左旋转跳'
  1129. },
  1130. {
  1131. jumpName: 'RIGHT_ROTATE',
  1132. jumpCode: 4,
  1133. bTrigger: false,
  1134. describe: '右旋转跳'
  1135. }
  1136. ];
  1137. let {
  1138. currentMaxValue,
  1139. oGyroValue,
  1140. peakOfWaveMaxValue,
  1141. valleyOfWaveMinValue
  1142. } = data
  1143. // console.log('stateDataOfJump:');
  1144. // console.log(JSON.stringify(data));
  1145. this.onLogData = data;
  1146. let _rotateLimit = 4;
  1147. let _jumpLimit = 8;
  1148. switch (_jumpType) {
  1149. case 0:
  1150. //JumpType.NORMAL = 0
  1151. _tempState[0].bTrigger = true;
  1152. this.eliminateJumpPrefabFormTemp(_tempState);
  1153. break;
  1154. case 1:
  1155. if (currentMaxValue < -_jumpLimit || valleyOfWaveMinValue < -20) {
  1156. //left jump
  1157. _tempState[1].bTrigger = true;
  1158. }
  1159. this.eliminateJumpPrefabFormTemp(_tempState);
  1160. break;
  1161. case 2:
  1162. if (currentMaxValue > _jumpLimit || peakOfWaveMaxValue > 20) {
  1163. //right jump
  1164. _tempState[2].bTrigger = true;
  1165. }
  1166. this.eliminateJumpPrefabFormTemp(_tempState);
  1167. break;
  1168. case 4:
  1169. if (oGyroValue > _rotateLimit) {
  1170. _tempState[4].bTrigger = true;
  1171. }
  1172. this.eliminateJumpPrefabFormTemp(_tempState);
  1173. break;
  1174. case 3:
  1175. if (oGyroValue < -_rotateLimit) {
  1176. _tempState[3].bTrigger = true;
  1177. }
  1178. this.eliminateJumpPrefabFormTemp(_tempState);
  1179. break;
  1180. default:
  1181. console.log('没有对应的_jumpType', _jumpType);
  1182. break;
  1183. }
  1184. // if (currentMaxValue == 0) {
  1185. // } else {
  1186. // // console.log('2====', data);
  1187. // if (this.isY) {
  1188. // //如果是检测到旋转跳
  1189. // if (oGyroValue > _rotateLimit) {
  1190. // // console.log('y right:', oGyroValue);
  1191. // _tempState[4].bTrigger = true;
  1192. // } else if (oGyroValue < -_rotateLimit) {
  1193. // // console.log('y left:', oGyroValue);
  1194. // _tempState[3].bTrigger = true;
  1195. // }
  1196. // if (valleyOfWaveMinValue < -_jumpLimit) {
  1197. // //left jump
  1198. // _tempState[1].bTrigger = true;
  1199. // } else if (peakOfWaveMaxValue > _jumpLimit) {
  1200. // //right jump
  1201. // _tempState[2].bTrigger = true;
  1202. // }
  1203. // } else {
  1204. // //如果是检测到旋转跳
  1205. // if (oGyroValue < -5) {
  1206. // // console.log('x right:', oGyroValue);
  1207. // _tempState[4].bTrigger = true;
  1208. // } else if (oGyroValue > 5) {
  1209. // // console.log('x left:', oGyroValue);
  1210. // _tempState[3].bTrigger = true;
  1211. // }
  1212. // if (valleyOfWaveMinValue < -_jumpLimit) {
  1213. // //left jump
  1214. // _tempState[1].bTrigger = true;
  1215. // } else if (peakOfWaveMaxValue > _jumpLimit) {
  1216. // //right jump
  1217. // _tempState[2].bTrigger = true;
  1218. // }
  1219. // }
  1220. // this.eliminateJumpPrefabFormTemp(_tempState);
  1221. // }
  1222. },
  1223. eliminateJumpPrefabFormTemp(_tempState) {
  1224. //只触发第三个
  1225. if (this.spawnArray.length < 3) {
  1226. return;
  1227. }
  1228. let _temp = this.spawnArray[2];
  1229. let bSuccess = false;
  1230. for (let i = 0; i < _tempState.length; i++) {
  1231. let _state = _tempState[i];
  1232. if (_state.bTrigger)
  1233. {
  1234. console.log('识别跳的类型:' +_state.describe + ',当前预制类型:'+_temp.jumpName +
  1235. "\n直跳判断值:"+this.onLogData.currentMaxValue+",旋转跳值:"+this.onLogData.oGyroValue);
  1236. }
  1237. //如果当前的跳类型和预制目标一样
  1238. if (_state.jumpCode == _temp.jumpCode && _state.bTrigger) {
  1239. //成功
  1240. bSuccess = true;
  1241. break;
  1242. }
  1243. }
  1244. //如果存在其中一个为true
  1245. if (bSuccess) {
  1246. _temp.bTrigger = true;
  1247. this.canSpawnTemp = _temp;
  1248. setTimeout(() => {
  1249. //这里更新特效
  1250. this.onDrawEffect(this.canSpawnTemp);
  1251. }, 150);
  1252. this.deleteSpawn = this.spawnArray.splice(0, 1);
  1253. if (this.index < this.templatePool.length) {
  1254. this.spawnArray.push(this.templatePool[this.index]);
  1255. this.index++;
  1256. }
  1257. //成功
  1258. this.setEliminationCount(1);
  1259. //替换数组
  1260. // console.log(this.index + " == " + this.spawnArray.length);
  1261. if (this.spawnArray.length < 3 && this.index > 3) {
  1262. clearInterval(this.countdownInterval);
  1263. this.countdownInterval = null;
  1264. //绘制新触发状态
  1265. this.canGoNext = true;
  1266. } else {
  1267. //绘制新触发状态
  1268. this.canOnDraw = true;
  1269. }
  1270. } else {
  1271. //失误
  1272. this.setFaultCount(1);
  1273. }
  1274. },
  1275. /**
  1276. * @param {Object} gameData
  1277. * 识别跳部分数据处理
  1278. */
  1279. onBLERopeUpdate(gameData) {
  1280. if (!this.bJumpPlay || this.isGameOver) return;
  1281. //********陀螺仪角速度********
  1282. let {
  1283. gx,
  1284. gy,
  1285. gz
  1286. } = gameData.gyro;
  1287. let {
  1288. min,
  1289. s,
  1290. ms
  1291. } = gameData;
  1292. //-gameData.acc.ax * 10;
  1293. let _ax = gameData.acc.ax * 10;
  1294. let _ay = gameData.acc.ay * 10;
  1295. let _az = gameData.acc.az * 10;
  1296. //低通滤波分离重力
  1297. let alpha = 0.8;
  1298. this.xA = alpha * this.xA + (1 - alpha) * _ax;
  1299. this.yA = alpha * this.yA + (1 - alpha) * _ay;
  1300. this.zA = alpha * this.zA + (1 - alpha) * _az;
  1301. //高通滤波获取线性速度
  1302. let linear_acceleration_x = _ax - this.xA;
  1303. let linear_acceleration_y = _az - this.zA;
  1304. let linear_acceleration_z = _ay - this.yA;
  1305. let _temp = {
  1306. linearAcc: {
  1307. lAccX: linear_acceleration_x,
  1308. lAccY: linear_acceleration_y,
  1309. lAccZ: linear_acceleration_z
  1310. }, //gameData.acc,
  1311. oriAcc: {
  1312. oAccX: _ax,
  1313. oAccY: _ay,
  1314. oAccZ: _az
  1315. },
  1316. gravityAcc: {
  1317. gravityX: this.xA,
  1318. gravityY: this.yA,
  1319. gravityZ: this.zA
  1320. },
  1321. bLimitRebound: false,
  1322. resultant: Math.sqrt(_ax * _ax +
  1323. _ay * _ay + _az * _az),
  1324. runIndex: this.BLEAccIndex,
  1325. //陀螺仪
  1326. oriGyro: {
  1327. oGyroX: gx,
  1328. oGyroY: gy,
  1329. oGyroZ: gz
  1330. },
  1331. //输入当前轴
  1332. bYAxis: true,
  1333. };
  1334. this.actionJumpObj.updateJump(_temp);
  1335. this.BLEAccIndex++;
  1336. },
  1337. onClearData() {
  1338. this.BLEAccIndex = 0;
  1339. },
  1340. onChangeY() {
  1341. this.isY = true;
  1342. },
  1343. onChangeX() {
  1344. this.isY = false;
  1345. },
  1346. onGetActionJumpPlayView(callback) {
  1347. let view = uni.createSelectorQuery().select('#ActionJumpPlay');
  1348. view.boundingClientRect(data => {
  1349. if (callback)
  1350. callback(data);
  1351. }).exec();
  1352. },
  1353. onTipLevel() {
  1354. this.$emit("tipLevel", {
  1355. hiddenType: 'normal'
  1356. });
  1357. console.log("**************22");
  1358. }
  1359. }
  1360. }
  1361. </script>
  1362. <style lang="scss">
  1363. .mid-absolute {
  1364. position: absolute;
  1365. top: 0;
  1366. bottom: 0;
  1367. right: 0;
  1368. left: 0;
  1369. margin: auto;
  1370. }
  1371. .action-jump-timer {
  1372. position: absolute;
  1373. top: -150rpx;
  1374. }
  1375. .grid-progress-vertical-container {
  1376. min-height: 376rpx;
  1377. }
  1378. .grid-progress-vertical-bar {
  1379. max-height: 376rpx;
  1380. }
  1381. .grid-progress-vertical-child {
  1382. width: 35px;
  1383. height: 7.36px;
  1384. margin: 7.36px 0 0 0;
  1385. position: relative;
  1386. }
  1387. .grid-progress-vertical-active {
  1388. width: 28rpx;
  1389. }
  1390. .grid-progress-vertical-inactive {
  1391. width: 28rpx;
  1392. }
  1393. .sprite-yellow-arrow {
  1394. display: inline-block;
  1395. overflow: hidden;
  1396. background-repeat: no-repeat;
  1397. width: 194px;
  1398. height: 232px;
  1399. background-image: url('@/static/modal/action-jump/yellow-arrow.png');
  1400. // border: 1rpx solid #00CE47;
  1401. }
  1402. .animation-play-state-play {
  1403. animation: yellowArrowRun 1s steps(1, end); // infinite
  1404. animation-play-state: running;
  1405. }
  1406. .animation-play-state-paused {
  1407. animation-play-state: paused;
  1408. }
  1409. /**
  1410. * 箭头动画
  1411. */
  1412. @keyframes yellowArrowRun {
  1413. 0% {
  1414. background-position: -0px -0px;
  1415. }
  1416. 5% {
  1417. background-position: -0px -0px;
  1418. }
  1419. 10% {
  1420. background-position: -194px -0px;
  1421. }
  1422. 15% {
  1423. background-position: -388px -0px;
  1424. }
  1425. 20% {
  1426. background-position: -582px -0px;
  1427. }
  1428. 25% {
  1429. background-position: -776px -0px;
  1430. }
  1431. 30% {
  1432. background-position: -0px -232px;
  1433. }
  1434. 35% {
  1435. background-position: -194px -232px;
  1436. }
  1437. 40% {
  1438. background-position: -388px -232px;
  1439. }
  1440. 45% {
  1441. background-position: -582px -232px;
  1442. }
  1443. 50% {
  1444. background-position: -776px -232px;
  1445. }
  1446. 55% {
  1447. background-position: -0px -464px;
  1448. }
  1449. 60% {
  1450. background-position: -194px -464px;
  1451. }
  1452. 65% {
  1453. background-position: -388px -464px;
  1454. }
  1455. 70% {
  1456. background-position: -582px -464px;
  1457. }
  1458. 75% {
  1459. background-position: -776px -464px;
  1460. }
  1461. 80% {
  1462. background-position: -0px -696px;
  1463. }
  1464. 85% {
  1465. background-position: -194px -696px;
  1466. }
  1467. 90% {
  1468. background-position: -388px -696px;
  1469. }
  1470. 95% {
  1471. background-position: -582px -696px;
  1472. }
  1473. 100% {
  1474. background-position: -776px -696px;
  1475. }
  1476. }
  1477. .sprite-rightToLeftArrow {
  1478. display: inline-block;
  1479. overflow: hidden;
  1480. background-repeat: no-repeat;
  1481. width: 317px;
  1482. height: 42px;
  1483. background-image: url('@/static/modal/action-jump/rightToLeftArrow.png');
  1484. // border: 1rpx solid #00CE47;
  1485. }
  1486. .sprite-rightToLeftArrow-play {
  1487. animation: rightToLeftArrowRun 1s steps(1, end) infinite;
  1488. }
  1489. @keyframes rightToLeftArrowRun {
  1490. 0% {
  1491. background-position: -0px -0px;
  1492. }
  1493. 3.33% {
  1494. background-position: -0px -0px;
  1495. }
  1496. 6.66% {
  1497. background-position: -317px -0px;
  1498. }
  1499. 9.99% {
  1500. background-position: -0px -42px;
  1501. }
  1502. 13.33% {
  1503. background-position: -317px -42px;
  1504. }
  1505. 16.66% {
  1506. background-position: -0px -84px;
  1507. }
  1508. 19.99% {
  1509. background-position: -317px -84px;
  1510. }
  1511. 23.33% {
  1512. background-position: -0px -126px;
  1513. }
  1514. 26.66% {
  1515. background-position: -317px -126px;
  1516. }
  1517. 29.99% {
  1518. background-position: -0px -168px;
  1519. }
  1520. 33.33% {
  1521. background-position: -317px -168px;
  1522. }
  1523. 36.66% {
  1524. background-position: -0px -210px;
  1525. }
  1526. 39.99% {
  1527. background-position: -317px -210px;
  1528. }
  1529. 43.33% {
  1530. background-position: -0px -252px;
  1531. }
  1532. 46.66% {
  1533. background-position: -317px -252px;
  1534. }
  1535. 49.99% {
  1536. background-position: -0px -294px;
  1537. }
  1538. 53.33% {
  1539. background-position: -317px -294px;
  1540. }
  1541. 56.66% {
  1542. background-position: -0px -336px;
  1543. }
  1544. 59.99% {
  1545. background-position: -317px -336px;
  1546. }
  1547. 63.33% {
  1548. background-position: -0px -378px;
  1549. }
  1550. 66.66% {
  1551. background-position: -317px -378px;
  1552. }
  1553. 69.99% {
  1554. background-position: -0px -420px;
  1555. }
  1556. 73.33% {
  1557. background-position: -317px -420px;
  1558. }
  1559. 76.66% {
  1560. background-position: -0px -462px;
  1561. }
  1562. 79.99% {
  1563. background-position: -317px -462px;
  1564. }
  1565. 83.33% {
  1566. background-position: -0px -504px;
  1567. }
  1568. 86.66% {
  1569. background-position: -317px -504px;
  1570. }
  1571. 89.99% {
  1572. background-position: -0px -546px;
  1573. }
  1574. 93.33% {
  1575. background-position: -317px -546px;
  1576. }
  1577. 96.66% {
  1578. background-position: -0px -588px;
  1579. }
  1580. 100% {
  1581. background-position: -317px -588px;
  1582. }
  1583. }
  1584. </style>