action-jump.vue 47 KB

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