action-jump.vue 46 KB

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