action-jump.vue 47 KB

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