1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444 |
- <template>
- <view style="width:100%; margin-bottom: 50rpx;">
- <!-- 计时器 -->
- <view class="hitBoxingTimer flex justify-center">
- <boxingCountDown ref="boxingCountDownRef" :show-day="false" :second="showSportTime" color="#9695f7" background-color="#FFFFFF"
- border-color="#007AFF" splitorColor="#FFFFFF" />
- </view>
- <view v-if="mode == 'pkMode'" style="height: 50rpx;"></view>
- <view v-else style="height: 20rpx;"></view>
- <view style="display: flex; flex-direction: column; justify-content: center;align-items: center;
- position: relative; width: 100%;">
- <!-- 波动 -->
- <view v-if="mode !== 'pkMode'" class="flex justify-around align-center" style="width: 600rpx;height: 100rpx; margin: 20rpx;">
- <view style="height: 1rpx;width: 80rpx;background-color: #FFFFFF;"></view>
- <view style="display: flex; justify-content: center; align-self: center; height: 100%;">
- <view style="display: flex; justify-content: center; align-items: center;">
- <view class="wave-d-item " v-for="(item, index) in wave_d_time" :key="index" :class="wave_d_play?'hit-wave':''"
- :style="{'--time': item.run * wave_run_ratio,'--delay':item.delay * wave_run_ratio,'height': wave_d_play?item.sHeight+'rpx':'20rpx'}"></view>
- </view>
- <view style="display: flex; justify-content: center; align-items: center; flex-direction: row-reverse;">
- <view class="wave-d-item " v-for="(item, index) in wave_d_time" :key="index" :class="wave_d_play?'hit-wave':''"
- :style="{'--time': item.run * wave_run_ratio,'--delay':item.delay * wave_run_ratio,'height': wave_d_play?item.sHeight+'rpx':'20rpx'}"></view>
- </view>
- </view>
- <view style="height: 1rpx;width: 80rpx;background-color: #FFFFFF;"></view>
- </view>
- <view v-if="mode == 'pkMode'" style="height: 30rpx;"></view>
- <!-- 当前拳击力-->
- <view v-if="mode == 'pkMode'" class="flex justify-center align-center " style="margin-top: 40rpx; background-color: rgba(255,255,255,0.1); width: 420rpx; height: 90rpx;border-radius: 60rpx;">
- <image src="/static/modal/boxing-hit/b.png" style="width: 50rpx; height: 50rpx;" mode="aspectFit"></image>
- <view class="hit-current-count">
- {{currentHitStrength}}
- </view>
- </view>
- <!-- <view v-else style="position: relative; width: 100%;" :style="{'opacity': hitStrengthOpacity}">
- <view style="position: absolute;
- left: 0;
- top: 0;
- bottom: 0;
- right: 0;" class="flex justify-center">
- <view class="flex justify-center align-center " style="background-color: rgba(0,0,0,0.4); width: 300rpx; height: 90rpx;border-radius: 60rpx;">
- <view class="hit-current-count-power">力量</view>
- <view class="hit-current-count">
- {{currentHitStrength}}
- </view>
- </view>
- </view>
- </view> -->
- <view v-if="mode == 'pkMode'" style="height: 110rpx;"></view>
- <view v-else style="height: 20rpx;"></view>
- <!-- 控制按钮 -->
- <view class="flex justify-center " :class="mode == 'pkMode'?'big':''" style="margin-top: 40rpx;" @tap="onControlPlay">
- <view style="position: relative; width: 260rpx; height: 260rpx;">
- <image style="width: 100%; height: 100%;" src="/static/modal/boxing-hit/hit-button-bg.png"></image>
- <image class="hit-button-rotate " :class="bRingAnimation?'hit-button-bg-play':'hit-button-bg-paused'" style="position: absolute;top: 10%;left: 10%;bottom: 0;right: 0;width: 80%; height: 80%;"
- src="/static/modal/boxing-hit/hit-button-ef.png"></image>
- <view style="position: absolute;top: 0;left: 0;bottom: 0;right: 0;width: 100%; height: 100%; display: flex;justify-content: center; align-items: center;">
- <image style="width: 50rpx; height: 50rpx; transform: scale(-1,1);" :src="bControlRun?'/static/modal/boxing-hit/hit-pause.png':'/static/modal/boxing-hit/hit-play.png'"></image>
- </view>
- </view>
- </view>
- <!-- <view v-if="mode == 'pkMode'" style="height: 160rpx;"></view> -->
- <!-- <view style="margin-top: 40rpx;width: 310rpx; height: 90rpx;"></view> -->
- <!-- 模式按钮 @tap="onChangeMode"-->
- <!-- <view class="flex justify-center " style="margin-top: 40rpx;">
- <view style="position: relative; width: 310rpx; height: 90rpx;background-color: #FFFFFF; display: flex;flex-direction: row;justify-content: center;align-items: center; border-radius: 50rpx;">
- <image style="width: 45rpx; height: 45rpx;" src="/static/personal/switch.png"></image>
- <view style="margin-left: 20rpx;color:#9797FF; font-weight: bold;font-size: 17px;">{{mode=="pkMode"?'健身模式':'PK模式'}}
- </view>
- </view>
- </view> -->
- <!-- <view v-if="mode == 'pkMode'" style="height: 20rpx;"></view> -->
- <view v-if="mode == 'pkMode'" style="height: 170rpx;"></view>
- <!-- <view v-else style="height: 110rpx;"></view> -->
- <view v-else style="height: 80rpx;"></view>
- <view v-if="mode == 'pkMode'" class="hit-vertical-container" :style="{'top': mode == 'pkMode'?'-120rpx':'-300rpx'}">
- <view class="hit-vertical-bar">
- <view class="hit-vertical-child" v-for="(item, index) in 25" :key="index">
- <view :class="25-aiShowCount>=index+1? 'hit-vertical-active':'hit-vertical-inactive'"></view>
- <view :class="index%5 == 0?'':'hit-text-hidden'" class="hit-vertical-text">{{index+1}}</view>
- </view>
- </view>
- <view class="hit-vertical-bar">
- <view class="hit-vertical-child" v-for="(item, index) in 25" :key="index">
- <view :class="index%5 == 0?'':'hit-text-hidden'" class="hit-vertical-text">{{index+1}}</view>
- <view :class="25-myShowCount>=index+1? 'hit-vertical-active':'hit-vertical-inactive'"></view>
- </view>
- </view>
- </view>
- <view v-else class="hit-vertical-container" :style="{'top': mode == 'pkMode'?'-120rpx':'-300rpx'}">
- <view class="hit-vertical-bar">
- <view class="hit-vertical-child" v-for="(item, index) in 25" :key="index">
- <view :class="showCount>=index+1? 'hit-vertical-active':'hit-vertical-inactive'"></view>
- <view :class="index%5 == 0?'':'hit-text-hidden'" class="hit-vertical-text">{{(index+1)*2}}</view>
- </view>
- </view>
- <view class="hit-vertical-bar">
- <view class="hit-vertical-child" v-for="(item, index) in 25" :key="index">
- <view :class="index%5 == 0?'':'hit-text-hidden'" class="hit-vertical-text">{{(index+26)*2}}</view>
- <view :class="showCount>=index+26? 'hit-vertical-active':'hit-vertical-inactive'"></view>
- </view>
- </view>
- </view>
- </view>
- <!-- <button style="margin-top: 100rpx;" @tap="onTestHit('left')">击中</button> -->
- <!-- 显示数据 -->
- <view v-if="mode == 'pkMode'" class="flex justify-around " style="margin: 0rpx 15rpx;">
- <view class="boxing-item-bg">
- <image src="/static/modal/boxing-hit/f.png" class="boxing-hit-png " mode="aspectFit"></image>
- <view class="text-white text-13px" style="margin: 10rpx 0;">最大力量</view>
- <view class="hit-count">
- {{mode == 'pkMode'?PKMaxStrength:maxStrength}}
- </view>
- </view>
- <view class="boxing-item-bg">
- <image src="/static/modal/boxing-hit/b.png" class="boxing-hit-png " mode="aspectFit"></image>
- <view class="text-white text-13px" style="margin: 10rpx 0;">平均力量</view>
- <view class="hit-count">
- {{mode == 'pkMode'?PKAverageStrength:averageStrength}}
- </view>
- </view>
- <view class="boxing-item-bg">
- <image src="/static/modal/boxing-hit/e.png" class="boxing-hit-png " mode="aspectFit"></image>
- <view class="text-white text-13px" style="margin: 10rpx 0;">平均速度</view>
- <view class="hit-count">
- {{mode == 'pkMode'?PKAverageSpeed:averageSpeed}}
- </view>
- </view>
- <view class="boxing-item-bg">
- <image src="/static/modal/boxing-hit/n.png" class="boxing-hit-png " mode="aspectFit"></image>
- <view class="text-white text-13px" style="margin: 10rpx 0;">击打数</view>
- <view class="hit-count">
- {{mode == 'pkMode'?PKAllShowHitCount:allShowHitCount}}
- </view>
- </view>
- </view>
- <view v-else class="flex margin-bottom-sm justify-center align-center">
- <view class="flex align-center">
- <view class="flex justify-start flex-direction align-center">
- <image src="/static/mileageIcon-w.png" class="data-png-26 margin-sm" mode="aspectFit"></image>
- <text style="text-align: start; line-height: 24px; font-weight: 400;color: #FFFFFF;">{{mode == 'calorieMode'?'里程':'计数'}}</text>
- </view>
- <view class="flex justify-start flex-direction">
- <view style="height: 26px;" class="margin-top-sm margin-bottom-sm">
- <view class="cu-progress" style="height: 6rpx; width: 140rpx; border-radius: 45rpx;"></view>
- </view>
- <text style="text-align: start; line-height: 24px; font-weight: 400;color: #FFFFFF;">{{mode == 'calorieMode'?runMileage+'km':ropeJumpCount}}</text>
- </view>
- </view>
- <view style="width: 40rpx;"></view>
- <view class="flex align-center">
- <view class="flex justify-start flex-direction align-center">
- <image src="/static/icon-run-normal.png" class="data-png-26 margin-sm" mode="aspectFit"></image>
- <text style="text-align: start; line-height: 24px; font-weight: 400; color: #FFFFFF;">速度</text>
- </view>
- <view class="flex justify-start flex-direction">
- <view style="height: 26px;" class="margin-top-sm margin-bottom-sm">
- <view class="cu-progress" style="height: 6rpx; width: 140rpx; border-radius: 45rpx;"></view>
- </view>
- <text style="text-align: start; line-height: 24px; font-weight: 400;color: #FFFFFF;">{{runSpeed}}m/s</text>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import boxingCountDown from '@/components/uni-count-down/uni-count-down.vue'
- import hitCharts from '@/components/u-charts/u-charts.js';
- import puchConfig from "@/util/util-js/puchConfig.js"
- import EquipmentAction from "@/util/util-js/EquipmentAction.js"
- export default {
- components: {
- boxingCountDown
- },
- props: {
- bUpdate: {
- type: Boolean,
- default: false
- },
- showTime: {
- type: Number,
- default: 0
- },
- //默认是防回弹更新
- bRebound: {
- type: Boolean,
- default: true,
- }
- },
- data() {
- return {
- mode: 'calorieMode', //pkMode calorieMode
- //满格的数值是 25
- maxShowCount: 25,
- //pk模式下,两边涨的区分,自己和ai
- myShowCount: 0,
- myPowerCount: 0,
- aiShowCount: 0,
- aiPowerCount: 0,
- //显示的点
- showCount: 0,
- //记录打击的次数
- powerCount: 0,
- //当前打击的最大值
- powerMaxCount: 0,
- xA1: 0,
- yA1: 0,
- zA1: 0,
- xA: 0,
- yA: 0,
- zA: 0,
- xO: 0,
- yO: 0,
- zO: 0,
- mass: 5,
- //大概消耗的卡路里
- calorie: 0,
- //与加速度相关的卡路里
- otherCalorie: 0,
- //大概消耗的卡路里
- PKCalorie: 0,
- //与加速度相关的卡路里
- PKOtherCalorie: 0,
- leftHookUrl: "/static/modal/boxing-post/left-hook.mp3",
- rightHookUrl: "/static/modal/boxing-post/right-hook.mp3",
- straightHookUrl: "/static/modal/boxing-post/straight-hook.mp3",
- hookAudioContext: null,
- //新手语音提示
- leftTipUrl: "/static/modal/boxing-post/tipLeft.mp3",
- rightTipUrl: "/static/modal/boxing-post/tipRight.mp3",
- straightTipUrl: "/static/modal/boxing-post/tipStraight.mp3",
- greatTipUrl: "/static/modal/boxing-post/tipGreat.mp3",
- giveGoTipUrl: "/static/modal/boxing-post/tipGiveItAGo.mp3",
- startTraining: "/static/modal/boxing-post/tipStartTraining.mp3",
- //击打状态音效
- hitUrl: "/static/elect/hit.mp3",
- missUrl: "/static/elect/miss.mp3",
- //是否在播放
- bPlay: false,
- //新手
- bGuide: false,
- //是否是特殊拳击
- bGuideEF: false,
- //运动时间
- showSportTime: this.showTime,
- sportTimeInterval: null,
- //拳击数据判断对象
- EquipmentActionObj: null,
- wave_array: [{
- wPlay: false
- },
- {
- wPlay: false
- },
- {
- wPlay: false
- },
- {
- wPlay: false
- },
- ],
- wave_run_array: [],
- wave_time: [{
- run: 0.5,
- delay: 3,
- height: 20
- },
- {
- run: 1,
- delay: 3,
- height: 30
- },
- {
- run: 2,
- delay: 3,
- height: 80
- },
- {
- run: 0.5,
- delay: 2,
- height: 50
- },
- {
- run: 1,
- delay: 2,
- height: 35
- },
- {
- run: 2,
- delay: 2,
- height: 20
- }
- ],
- wave_d_play: false,
- wave_d_timeout: null,
- wave_run_ratio: 0.4,
- wave_d_time: [{
- run: 1,
- delay: 1.1,
- height: 20,
- sHeight: 20,
- play: false
- },
- {
- run: 1,
- delay: 1,
- height: 30,
- sHeight: 20,
- play: true
- },
- {
- run: 1,
- delay: 0.9,
- height: 15,
- sHeight: 20,
- play: true
- },
- {
- run: 1,
- delay: 0.8,
- height: 50,
- sHeight: 20,
- play: true
- },
- {
- run: 1.3,
- delay: 0.7,
- height: 35,
- sHeight: 20,
- play: true
- },
- {
- run: 1.4,
- delay: 0.6,
- height: 20,
- sHeight: 20,
- play: true
- },
- {
- run: 1.5,
- delay: 0.5,
- height: 25,
- sHeight: 20,
- play: true
- },
- {
- run: 1.6,
- delay: 0.4,
- height: 40,
- sHeight: 20,
- play: true
- },
- {
- run: 1.7,
- delay: 0.3,
- height: 60,
- sHeight: 20,
- play: true
- },
- {
- run: 1.8,
- delay: 0.2,
- height: 50,
- sHeight: 20,
- play: true
- },
- {
- run: 1.9,
- delay: 0.1,
- height: 80,
- sHeight: 20,
- play: true
- },
- {
- run: 1.8,
- delay: 0,
- height: 70,
- sHeight: 20,
- play: true
- }
- ],
- bControlRun: false,
- bRingAnimation: false,
- maxStrength: 0,
- averageStrength: 0,
- allStrength: 0,
- averageSpeed: 0,
- averageSpeedInterval: null,
- tempHitCount: 0,
- allTempHitCount: 0,
- allShowHitCount: 0,
- currentHitStrength: 0,
-
- // testHitInterval: null,
- aiHitInterval: null,
- //击打时候动画对象
- hitStrengthOpacityInterval: null,
- hitStrengthOpacity: 0,
- //pk 模式下的数据
- PKMaxStrength: 0,
- PKAverageStrength: 0,
- PKAllStrength: 0,
- PKAverageSpeed: 0,
- PKAverageSpeedInterval: null,
- PKTempHitCount: 0,
- PKAllTempHitCount: 0,
- PKAllShowHitCount: 0,
- BLENum: 0,
- BLEACX: 0,
- BLEACYL: 0,
-
- /** 跑步参数*/
- runMileage:0,
- runSpeed:0,
- runTempCount:0,
- runAllTempCount:0,
- runAllCount:0,
-
- /**
- * 跳绳参数
- */
- ropeJumpCount:0
- }
- },
- watch: {
- bUpdate(val) {
- },
- showTime(val) {
- this.showSportTime = val;
- }
- },
- created() {
- let _self = this;
- _self.hookAudioContext = uni.createInnerAudioContext();
- _self.hookAudioContext.autoplay = false;
- _self.hookAudioContext.src = _self.straightHookUrl;
- _self.hookAudioContext.volume = 0.5;
- console.log(" ***** boxing-post created ******");
- _self.onBindAcc();
- _self.EquipmentActionObj = new EquipmentAction();
- _self.EquipmentActionObj.addEventListener("resultantHit", (e) => {
- // console.log("acc:",this.xA,this.yA,this.zA);
- // console.log("data:", this.xA1, this.yA1, this.zA1);
- if (this.mode == "pkMode") {
- this._pkHitOnly(e.acc, e.power);
- } else {
- this._HitOnly(e.acc, e.power);
- }
- })
- if (this.averageSpeedInterval) {
- clearInterval(this.averageSpeedInterval);
- this.averageSpeedInterval = null;
- }
- //计算平均速度
- this.averageSpeedInterval = setInterval(() => {
- if (this.mode == 'PKMode') {
- this.PKAverageSpeed = this.PKTempHitCount;
- this.PKTempHitCount = 0;
- } else {
- this.averageSpeed = this.tempHitCount;
- this.tempHitCount = 0;
-
- //跑步速度 70cm步长 速度:步长*步数/5秒
- this.runSpeed = this.runTempCount * 70 / 100;
- this.runTempCount = 0;
- }
- }, 5000)
- },
- beforeDestroy() {
- console.log(" ***** boxing-post destroyed ******");
- this.onUnbindAcc();
- // this.onUnbindOri();
- let _self = this;
- if (_self.hookAudioContext)
- _self.hookAudioContext.destroy();
- if (_self.sportTimeInterval) {
- clearInterval(_self.sportTimeInterval);
- _self.sportTimeInterval = null;
- }
- if (_self.averageSpeedInterval) {
- clearInterval(_self.averageSpeedInterval);
- _self.averageSpeedInterval = null;
- }
- // if (_self.testHitInterval) {
- // clearInterval(_self.testHitInterval);
- // _self.testHitInterval = null;
- // }
- if (this.aiHitInterval) {
- clearInterval(this.aiHitInterval);
- this.aiHitInterval = null;
- }
- },
- methods: {
- onSetRingAnimation(booleanValue) {
- this.bRingAnimation = booleanValue;
- },
- moveBoxingHandle() {
- return;
- },
- //测试打击
- onTestHit(data) {
- let _self = this;
- let maxPower = Math.floor(Math.random() * 13);
- // console.log("maxPower:", maxPower);
- if (this.mode == "pkMode") {
- this._pkHitOnly(maxPower, maxPower * 10);
- } else {
- for(let i=0;i<100;i++){
- this._HitOnly(maxPower, maxPower * 10);
- }
- }
- },
- //平时击打的力量槽动画播放
- onPlayPowerAnimation(bGreat) {
- // 暂时去掉 跑步声音
- // if (bGreat) {
- // this.hookAudioContext.stop();
- // this.hookAudioContext.src = this.greatTipUrl;
- // this.hookAudioContext.play();
- // } else {
- // this.hookAudioContext.stop();
- // this.hookAudioContext.src = this.hitUrl;
- // this.hookAudioContext.play();
- // }
- let _self = this;
- if (_self.powerInterval) {
- clearInterval(_self.powerInterval);
- _self.powerInterval = null;
- }
- let bAdd = true;
- let _oldPowerCount = _self.powerCount;
- let _currentMaxCount = _oldPowerCount + 10;
- let _duraciotn = 300 / _currentMaxCount;
- _self.powerInterval = setInterval(function() {
- if (_self.showCount >= _currentMaxCount) {
- bAdd = false;
- } else if (_self.showCount <= _oldPowerCount && !bAdd) {
- _self.showCount = _self.powerCount;
- clearInterval(_self.powerInterval);
- _self.powerInterval = null;
- return;
- }
- if (bAdd)
- _self.showCount++;
- else
- _self.showCount--;
- }, _duraciotn); //300ms/40格
- },
- //pk模式击打的力量槽动画播放
- onPKModePlayPowerAnimation(bGreat) {
- if (bGreat) {
- this.hookAudioContext.stop();
- this.hookAudioContext.src = this.greatTipUrl;
- this.hookAudioContext.play();
- } else {
- this.hookAudioContext.stop();
- this.hookAudioContext.src = this.hitUrl;
- this.hookAudioContext.play();
- }
- let _self = this;
- _self.myShowCount = _self.myPowerCount;
- // if (_self.powerInterval) {
- // clearInterval(_self.powerInterval);
- // _self.powerInterval = null;
- // }
- // let bAdd = true;
- // let _oldPowerCount = _self.myPowerCount;
- // let _currentMaxCount = _oldPowerCount + 10;
- // let _duraciotn = 300 / _currentMaxCount;
- // _self.powerInterval = setInterval(function() {
- // if (_self.myShowCount >= _currentMaxCount) {
- // bAdd = false;
- // } else if (_self.myShowCount <= _oldPowerCount && !bAdd) {
- // _self.myShowCount = _self.myPowerCount;
- // clearInterval(_self.powerInterval);
- // _self.powerInterval = null;
- // return;
- // }
- // if (bAdd)
- // _self.myShowCount++;
- // else
- // _self.myShowCount--;
- // }, _duraciotn); //300ms/40格
- },
- onBindAcc(globalAcc) {
- uni.$on('watchAcceleration', this.updateAcc);
- },
- onUnbindAcc() {
- uni.$off('watchAcceleration', this.updateAcc);
- },
- onBindOri(globalOri) {
- uni.$on('watchOrientation', this.updateOri);
- },
- onUnbindOri() {
- uni.$off('watchOrientation', this.updateOri);
- },
- updateAcc(acc) {
- // console.log("acc:" ,acc.xAxis,acc.yAxis,acc.zAxis);
- this.xA = acc.xAxis;
- this.yA = acc.yAxis;
- this.zA = acc.zAxis;
- // return;
- if (!this.bUpdate || !this.bPlay) return;
- this.EquipmentActionObj.updateAcc({
- xA: acc.xAxis,
- zA: acc.yAxis,
- yA: acc.zAxis,
- bLimitRebound: this.bRebound
- })
- },
- //旧的蓝牙模块更新数据
- onBLEUpdate(data) {
- if (!this.bPlay) return;
- if (data.num)
- this.BLENum = data.num;
- if (data.acx)
- this.BLEACX = data.acx;
- if (data.acy) {
- this.BLEACYL = data.acy;
- // let acc = Math.ceil((Math.abs(this.BLEACX) + Math.abs(this.BLEACYL))*0.0005);
- let _abs = (Math.abs(this.BLEACX) + Math.abs(this.BLEACYL));
- let _ratioAbs = _abs > 65000 ? 1 : _abs / 65000;
- // console.log("当前值:",(Math.abs(this.BLEACX) + Math.abs(this.BLEACYL)),acc,this._onReducedBlood(acc),_ratioAbs,Math.ceil(_ratioAbs*30));
- let acc = Math.ceil(_ratioAbs * 30);
- if (this.mode == "pkMode") {
- this._pkHitOnly(acc, acc * 10);
- } else {
- this._HitOnly(acc, acc * 10);
- }
- }
- },
-
- //hotman 情景下刷新
- onBLEHotmanUpdate(data) {
- console.log("onBLEHotmanUpdate:",data ,this.bUpdate,this.bPlay);
- if (!this.bUpdate || !this.bPlay) return;
- let {
- hit
- } = data;
- let power = parseInt(hit);
- let acc = power * 0.1;
- if (this.mode == "pkMode") {
- this._pkHitOnly(acc, power);
- } else {
- this._HitOnly(acc, power);
- }
- },
- //蓝牙更新数据
- onBLEHandleUpdate(data) {
- if (!this.bUpdate || !this.bPlay) return;
- let {
- ax,
- ay,
- az
- } = data.acc;
- let xA = ax * 9.80665;
- let yA = ay * 9.80665;
- let zA = az * 9.80665;
- this.xA1 = xA;
- this.yA1 = yA;
- this.zA1 = zA;
- // console.log("data:" ,xA,yA,zA);
- // updateAcc updateTriaxialAcc
- this.EquipmentActionObj.updateTriaxialAcc({
- xA: xA,
- zA: yA,
- yA: zA,
- bLimitRebound: true
- })
- },
- //rope 情景下刷新
- onBLERopeUpdate(data) {
- if (!this.bUpdate || !this.bPlay) return;
-
- let {
- jump
- } = data;
- let power = parseInt(jump);
- let acc = power * 0.1;
-
- console.log(jump,this.mode,acc,power);
- if (this.mode == "pkMode") {
- this._pkHitOnly(acc, power);
- } else {
- this._HitOnly(acc, power);
- }
- },
- updateOri(ori) {
- this.xO = ori.beta;
- this.zO = ori.alpha;
- this.yO = ori.gamma;
- },
- onControlPlay() {
- this._customControlPlay({
- bControlRun: this.bControlRun
- });
- },
- onCloseDevices() {
- let _self = this;
- if (!_self.bPlay) return;
- if (_self.sportTimeInterval) {
- clearInterval(_self.sportTimeInterval);
- _self.sportTimeInterval = null;
- }
- if (_self.aiHitInterval) {
- clearInterval(_self.aiHitInterval);
- _self.aiHitInterval = null;
- }
- _self.bPlay = false;
- _self.bControlRun = false;
- //如果是新手教程,也直接停掉
- _self.bGuide = false;
- _self.bGuideEF = false;
- if (_self.mode == "pkMode") {
- _self.myShowCount = 0;
- _self.myPowerCount = 0;
- _self.aiShowCount = 0;
- _self.aiPowerCount = 0;
- }
- _self.$emit("closeBoxingControl");
- },
- onHitPlay(bPlaying) {
- if (bPlaying) {
- this.bControlRun = bPlaying;
- } else {
- this.bControlRun = !this.bControlRun;
- }
- },
- _customControlPlay(data) {
- let _self = this;
- //1.检查是否符合要求,再进行训练
- if (data.bControlRun) {
- if (_self.sportTimeInterval) {
- clearInterval(_self.sportTimeInterval);
- _self.sportTimeInterval = null;
- }
- this.bPlay = false;
- // this.$refs.customControlButtons.onPlay();
- this.onHitPlay();
- //如果是新手教程,也直接停掉
- this.bGuide = false;
- this.bGuideEF = false;
- // if (this.testHitInterval) {
- // clearInterval(this.testHitInterval);
- // this.testHitInterval = null;
- // }
- if (this.mode == "pkMode") {
- this.myShowCount = 0;
- this.myPowerCount = 0;
- this.aiShowCount = 0;
- this.aiPowerCount = 0;
- }
- if (this.aiHitInterval) {
- clearInterval(this.aiHitInterval);
- this.aiHitInterval = null;
- }
- this.$emit("boxingPostControlPlay", false);
- } else {
- this.$emit("boxingPostCheck");
- }
- },
- _PKOver(data) {
- let _self = this;
- //1.检查是否符合要求,再进行训练
- if (_self.sportTimeInterval) {
- clearInterval(_self.sportTimeInterval);
- _self.sportTimeInterval = null;
- }
- this.bPlay = false;
- this.onHitPlay();
- //如果是新手教程,也直接停掉
- this.bGuide = false;
- this.bGuideEF = false;
- if (this.aiHitInterval) {
- clearInterval(this.aiHitInterval);
- this.aiHitInterval = null;
- }
- },
- //新手引导
- onGuideBoxingPostPlay() {
- console.log("onGuideBoxingPostPlay");
- let _self = this;
- _self.bPlay = true;
- //
- _self.bGuide = true;
- // 按钮事件
- // _self.$refs.customControlButtons.onPlay();
- _self.onHitPlay();
- },
- //训练退出时候,重新信息
- onBoxingPostStop() {
- },
- //调用播放
- onBoxingPostPlay(bPlaying) {
- let _self = this;
- //判断是否是pk模式,如果是pk模式,则用pk模式播放
- if (bPlaying) {
- _self.bPlay = true;
- // 按钮事件
- // _self.$refs.customControlButtons.onPlay(true);
- _self.onHitPlay(true);
- // if (_self.testHitInterval) {
- // clearInterval(_self.testHitInterval);
- // _self.testHitInterval = null;
- // }
- // _self.testHitInterval = setInterval(() => {
- // this.onTestHit();
- // }, 300)
- if (_self.sportTimeInterval) {
- clearInterval(_self.sportTimeInterval);
- _self.sportTimeInterval = null;
- }
- if (this.mode == 'pkMode') {
- if (this.aiHitInterval) {
- clearInterval(this.aiHitInterval);
- this.aiHitInterval = null;
- }
- this.aiHitInterval = setInterval(() => {
- let _random = Math.floor(Math.random() * 10);
- if (_random < 5) {
- this.onAiHitEvent();
- }
- }, 500)
- }
- //play true 时候,开启时间计算
- _self.sportTimeInterval = setInterval(() => {
- _self.showSportTime++;
- if (_self.showSportTime >= 20 && _self.showSportTime % 20 == 0) {
- _self.$emit("updateSportTime", _self.showSportTime);
- }
- }, 1000)
- }
- },
- //自由模式下的打击
- //首页现在尝试用于跑步
- _HitOnly(acc, power) {
- //动画的高度
- let _ratio = acc / 10;
- if (_ratio > 1) _ratio = 1;
- if (_ratio < 0.5) _ratio = 0.5;
- for (let i = 0; i < this.wave_d_time.length; i++) {
- this.wave_d_time[i].sHeight = this.wave_d_time[i].height * _ratio;
- }
- this.onPlayPowerAnimation();
- // this.allTempHitCount++;
- this.runAllTempCount++;
- this.allShowHitCount++;
- this.tempHitCount++;
-
- this.runTempCount ++;
-
- this.runAllCount = this.allShowHitCount;
-
- if(this.mode == 'calorieMode'){
- //里面转换千米
- //175公分的bai成人一般两步间距du为70厘米,zhi170公分为65厘米,180公分为75厘米。
- this.runMileage = this.runAllCount*70 / 100000;
- }else {
- this.ropeJumpCount = this.runAllCount;
- }
-
- this.currentHitStrength = power;
- if (this.maxStrength < power) {
- this.maxStrength = power;
- }
- this.allStrength += power;
-
- this.averageStrength = (this.allStrength / this.allShowHitCount).toFixed(1);
- //跑步的卡路里,allTempHiCount
- this.calorie = puchConfig.getRunCalorie(this.runAllTempCount);
- //击打的加速度添加的卡路里,是额外计算的卡路里
- // this.otherCalorie += puchConfig.getAccCalorie(acc);
- let _all = this.calorie;// this.calorie.add(this.otherCalorie);
- //100 大卡,为一个周期 分50份
- //现在显示1格子是2大卡,所以 _all要 除去一半
- this.powerCount = parseInt(_all / 2);
- if (this.powerCount >= 50) {
- console.log("同步卡路里");
- console.log("this.calorie:", this.calorie, this.otherCalorie, _all);
- this.$emit('updateCalorie', _all);
- // this.allTempHitCount = 0;
- this.runAllTempCount = 0;
- this.powerCount = 0;
- // this.otherCalorie = 0;
- }
- if (!this.wave_d_play) {
- if (this.wave_d_timeout) {
- clearTimeout(this.wave_d_timeout);
- this.wave_d_timeout = null;
- }
- this.wave_d_play = true;
- this.wave_d_timeout = setTimeout(() => {
- this.wave_d_play = false;
- }, 1000 * this.wave_run_ratio)
- }
- if (this.hitStrengthOpacityInterval) {
- clearTimeout(this.hitStrengthOpacityInterval);
- this.hitStrengthOpacityInterval = null;
- }
- this.hitStrengthOpacity = 1;
- this.hitStrengthOpacityInterval = setTimeout(() => {
- this.hitStrengthOpacity = 0;
- }, 1000)
- },
- //pk模式下的打击
- _pkHitOnly(acc, power) {
- this.onPKModePlayPowerAnimation();
- this.PKAllTempHitCount++;
- this.PKAllShowHitCount++;
- this.PKTempHitCount++;
- this.currentHitStrength = power;
- if (this.PKMaxStrength < power) {
- this.PKMaxStrength = power;
- }
- this.PKAllStrength += power;
- this.PKAverageStrength = (this.PKAllStrength / this.PKAllShowHitCount).toFixed(1);
- //击打次数一个卡路里,就是基础卡路里
- this.PKCalorie = puchConfig.getBoxingCalorie(this.PKAllTempHitCount);
- //击打的加速度添加的卡路里,是额外计算的卡路里
- // this.PKOtherCalorie += puchConfig.getAccCalorie(acc);
- // console.log( puchConfig.getAccCalorie(acc),this.calorie);
- let _all = this.PKCalorie; // this.PKCalorie.add(this.PKOtherCalorie);
- //10 大卡,为一个周期 分25份
- // this.myPowerCount = parseInt(_all * 2.5 * 20);
- //中一个小拳头扣一滴血,中一个中拳头去2滴血,中一个大拳头去3滴血。
- let _myBloodPoint = this._onReducedBlood(acc);
- this.myPowerCount += _myBloodPoint;
- //用户打击完成
- if (this.myPowerCount >= this.maxShowCount) {
- console.log("this.calorie:", this.PKCalorie, this.PKOtherCalorie, _all);
- this.$emit('updateCalorie', _all);
- this.PKAllTempHitCount = 0;
- this.myPowerCount = 0;
- this.myShowCount = 0;
- this.PKOtherCalorie = 0;
- //通知结果
- this.$emit('gameOver', {
- myWin: true
- });
- this._PKOver();
- this.aiPowerCount = 0;
- this.aiShowCount = 0;
- }
- this.$emit('hitEvent', _myBloodPoint);
- },
- onAiHitEvent() {
- let _acc = Math.ceil(Math.random() * 30);
- let _aiBloodPoint = this._onReducedBlood(_acc);
- this.aiPowerCount += _aiBloodPoint;
- // this.aiPowerCount += 20;
- this.$emit('aiHitEvent', _aiBloodPoint);
- this.aiShowCount = this.aiPowerCount; // parseInt(this.aiPowerCount / 10);
- if (this.aiShowCount >= this.maxShowCount) {
- this.$emit('gameOver', {
- myWin: false
- });
- this._PKOver();
- this.aiPowerCount = 0;
- this.aiShowCount = 0;
- this.myPowerCount = 0;
- this.myShowCount = 0;
- }
- },
- //根据加速度计算血量
- _onReducedBlood(acc) {
- let _ratio = acc > 30 ? 1 : acc / 30;
- // console.log("_ratio:", _ratio);
- if (_ratio > 0.9) {
- //大拳头
- return 3;
- } else if (_ratio > 0.7) {
- //中拳头
- return 2;
- } else {
- //小拳头
- return 1;
- }
- },
- onChangeMode() {
- //todo 切换模式时候,停止当前运行状态
- if (this.bControlRun) {
- uni.showToast({
- title: '先停止,再切换模式',
- mask: true,
- icon: 'none',
- duration: 2000,
- })
- return;
- }
- //当前的拳击力设置为0
- this.currentHitStrength = 0;
- let _name = 'pk模式';
- if (this.mode == 'pkMode') {
- this.mode = 'calorieMode';
- _name = '长跑模式'; //健身模式
- } else if (this.mode == 'calorieMode') {
- this.mode = 'pkMode';
- _name = 'pk模式';
- }
- let _data = {
- mode: this.mode,
- name: _name
- }
- this.$emit('modeEvent', _data);
- },
- //设置一个切换模式
- onSetMode(modeValue) {
- console.log("modeValue =====", modeValue);
- //todo 切换模式时候,停止当前运行状态
- if (this.bControlRun) {
- uni.showToast({
- title: '先停止,再切换模式',
- mask: true,
- icon: 'none',
- duration: 2000,
- })
- return;
- }
- //当前的拳击力设置为0
- this.currentHitStrength = 0;
- let _name = 'pk模式';
- if (modeValue == 'calorieMode') {
- this.mode = 'calorieMode';
- _name = '长跑模式';
- } else if (modeValue == 'pkMode') {
- this.mode = 'pkMode';
- _name = 'pk模式';
- } else if(modeValue == 'ropeMode'){
- this.mode = 'ropeMode';
- _name = '跳绳模式'
- }
- let _data = {
- mode: this.mode,
- name: _name
- }
- this.$emit('modeEvent', _data);
- }
- }
- }
- </script>
- <style>
- /* Loader Bar */
- .hit-vertical-container {
- position: absolute;
- top: -50rpx;
- left: 0;
- right: 0;
- display: flex;
- justify-content: space-between;
- /* border: 1rpx solid #000000; */
- pointer-events: none;
- }
- .hit-vertical-bar {
- display: flex;
- flex-direction: column-reverse;
- }
- .hit-vertical-child {
- /* position: relative; */
- width: 70rpx;
- height: 20rpx;
- margin: 14rpx 24rpx 0 24rpx;
- display: flex;
- /* align-content: center; */
- justify-content: space-between;
- }
- .hit-vertical-text {
- color: #FFFFFF;
- font-size: 8px;
- }
- .hit-text-hidden {
- visibility: hidden;
- }
- .hit-vertical-active {
- background-color: #FFFFFF;
- width: 30rpx;
- height: 100%;
- }
- .hit-vertical-inactive {
- width: 30rpx;
- height: 100%;
- background: rgba(144, 141, 246, 1);
- }
- .boxing-item-bg {
- border-radius: 15rpx;
- background-color: rgba(255, 255, 255, 0.1);
- display: flex;
- flex-direction: column;
- align-items: center;
- /* width: 160rpx; */
- }
- .hit-count {
- width: 160rpx;
- height: 60rpx;
- font-size: 22px;
- font-weight: bold;
- color: #FFFFFF;
- line-height: 60rpx;
- }
- .hit-current-count-power {
- /* margin: 0 5rpx; */
- font-size: 19px;
- line-height: 60rpx;
- /* font-weight: bold; */
- color: #FFFFFF;
- }
- .hit-current-count {
- /* width: 160rpx; */
- /* height: 100rpx; */
- margin: 0 30rpx;
- font-size: 22px;
- line-height: 60rpx;
- font-weight: bold;
- color: #FFFFFF;
- /* line-height: 22px; */
- }
- #loadbar {
- list-style: none;
- width: 400rpx;
- margin: 0 20rpx;
- }
- #loadbar-child {
- float: left;
- position: relative;
- width: 60rpx;
- height: 10rpx;
- margin-left: 1px;
- background: rgba(255, 255, 255, 0.5);
- }
- #loadbar-child:first-child {
- margin-left: 0;
- }
- .bar {
- background-color: #FFFFFF;
- width: 60rpx;
- height: 10rpx;
- }
- .show-png {
- width: 78rpx;
- height: 78rpx;
- margin: 0 10px;
- }
- .boxing-hit-png {
- margin-top: 40rpx;
- width: 50rpx;
- height: 50rpx;
- transition: transform 0.15s;
- }
- .boxing-change {
- transform: scale(1.58);
- }
- .hitBoxingTimer {
- position: absolute;
- top: -60rpx;
- left: 0;
- right: 0;
- }
- .wave-item {
- width: 8rpx;
- height: 20rpx;
- margin: 5rpx;
- background-color: #FFFFFF;
- border-radius: 10rpx;
- transition: height 0.5s;
- }
- .wave-d-item {
- width: 8rpx;
- height: 20rpx;
- margin: 5rpx;
- background-color: #FFFFFF;
- border-radius: 10rpx;
- transition: height 0.5s;
- }
- .hit-wave {
- animation: hit-d-scale calc(var(--time) * 0.5s) linear calc(var(--delay) * 1s) 1 alternate;
- }
- .wave-play {
- animation-play-state: running;
- }
- .wave-pause {
- animation-play-state: paused;
- }
- @keyframes hit-scale {
- 0% {
- transform: scale(1, 1);
- /* background-color: #999; */
- }
- 100% {
- transform: scale(1, 3);
- /* background-color: #333; */
- }
- }
- @keyframes hit-d-scale {
- 0% {
- transform: scale(1, 1);
- }
- 25% {
- transform: scale(1, 3);
- }
- 50% {
- transform: scale(1, 1);
- }
- 75% {
- transform: scale(1, 3);
- }
- 100% {
- transform: scale(1, 1);
- }
- }
- .hit-button-rotate {
- animation: hit-rotate 2s steps(16, end) infinite;
- }
- .hit-button-bg-play {
- animation-play-state: running;
- }
- .hit-button-bg-paused {
- animation-play-state: paused;
- }
- @keyframes hit-rotate {
- from {
- transform: rotate(0deg);
- }
- to {
- transform: rotate(360deg);
- }
- }
- .big {
- transform: scale(1.2);
- }
-
- /* .progress-bar-container{
-
- } */
- </style>
|