action-jump.vue 46 KB

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