|
@@ -120,6 +120,9 @@
|
|
|
import boxingCountDown from '@/components/uni-count-down/uni-count-down.vue'
|
|
|
|
|
|
|
|
|
+ import ActionJump from "@/util/util-js/action/jump.js"
|
|
|
+
|
|
|
+
|
|
|
export default {
|
|
|
components: {
|
|
|
boxingCountDown
|
|
@@ -177,13 +180,13 @@
|
|
|
jumpName: 'LEFT_ROTATE',
|
|
|
jumpCode: 3,
|
|
|
icon: 'rotateJump',
|
|
|
- scaleX: 1,
|
|
|
+ scaleX: -1,
|
|
|
bTrigger: false,
|
|
|
}, {
|
|
|
jumpName: 'RIGHT_ROTATE',
|
|
|
jumpCode: 4,
|
|
|
icon: 'rotateJump',
|
|
|
- scaleX: -1,
|
|
|
+ scaleX: 1,
|
|
|
bTrigger: false,
|
|
|
}],
|
|
|
spawnArray: [],
|
|
@@ -225,7 +228,15 @@
|
|
|
|
|
|
bJumpPlay: false,
|
|
|
jumpCalorie: 1000,
|
|
|
- jumpSpeed: 1000
|
|
|
+ jumpSpeed: 1000,
|
|
|
+
|
|
|
+ //硬件设备处理
|
|
|
+ BLEAccIndex: 0,
|
|
|
+ bJump: false,
|
|
|
+ xA: 0,
|
|
|
+ yA: 0,
|
|
|
+ zA: 0,
|
|
|
+ actionJumpObj: null
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -241,6 +252,41 @@
|
|
|
this.canvasW = this.SystemInfo.windowWidth; // 画布宽度
|
|
|
this.canvasH = 114;
|
|
|
|
|
|
+ // this.xA = 0;
|
|
|
+ // this.yA = 0;
|
|
|
+ // this.zA = 0;
|
|
|
+ // this.bJump = false;
|
|
|
+
|
|
|
+ _self.actionJumpObj = new ActionJump();
|
|
|
+
|
|
|
+ _self.actionJumpObj.addEventListener('resultant', (e) => {
|
|
|
+ if (e.type == 'jump') {
|
|
|
+ // this.jumpCount++;
|
|
|
+ this.bJump = true;
|
|
|
+ } else if (e.type == 'peakOfWave') {} else if (e.type == 'valleyOfWave') {} else if (e.type ==
|
|
|
+ 'curAngle') {
|
|
|
+ // if (e.value > 0) {
|
|
|
+ // this.rotate.rotation = 180;
|
|
|
+ // this.playerControScript.leftJump();
|
|
|
+ // } else {
|
|
|
+ // this.rotate.rotation = 0;
|
|
|
+ // this.playerControScript.rightJump();
|
|
|
+ // }
|
|
|
+ } else if (e.type == 'rotate') {
|
|
|
+
|
|
|
+ } else if (e.type == 'stateDataOfJump') {
|
|
|
+ //发送给game,在game里面处理判断
|
|
|
+ this.listenStateDataOfJump(e);
|
|
|
+ } else if (e.type == 'bUpdateDraw') {
|
|
|
+
|
|
|
+ } else if (e.type == 'stop') {
|
|
|
+
|
|
|
+ this.onClearData();
|
|
|
+ console.log('stop');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ })
|
|
|
},
|
|
|
methods: {
|
|
|
//load 相关图片
|
|
@@ -352,7 +398,7 @@
|
|
|
if (_ranType >= 1) ran2 += 2;
|
|
|
|
|
|
_newArray = _newArray.concat(_spawnList2[ran2]);
|
|
|
- console.log(_newArray);
|
|
|
+ // console.log(_newArray);
|
|
|
for (let i = 0; i < _newArray.length; i++) {
|
|
|
this.spawnJumpPrefabsFromType(i, _newArray[i]);
|
|
|
}
|
|
@@ -395,17 +441,17 @@
|
|
|
|
|
|
this.onDraw();
|
|
|
},
|
|
|
- spawnJumpPrefabsFromType(index,_jumpType) {
|
|
|
+ spawnJumpPrefabsFromType(index, _jumpType) {
|
|
|
|
|
|
//todo 生成的节点,后面再处理节奏问题。比如生成顺序
|
|
|
- for(let i=0;i<this.jumpTypeArray.length;i++){
|
|
|
- if(this.jumpTypeArray[i].jumpCode == _jumpType){
|
|
|
+ for (let i = 0; i < this.jumpTypeArray.length; i++) {
|
|
|
+ if (this.jumpTypeArray[i].jumpCode == _jumpType) {
|
|
|
let _jumpPrefab = Object.assign({}, this.jumpTypeArray[i]);
|
|
|
this.spawnArray.push(_jumpPrefab);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
},
|
|
|
spawnJumpPrefabs(index) {
|
|
@@ -590,22 +636,25 @@
|
|
|
// update (dt) {}
|
|
|
|
|
|
eliminateJumpPrefab(_jumpType) {
|
|
|
- //如果消除完,需要重新生成
|
|
|
- if (this.index >= this.spawnArray.length) return;
|
|
|
let _temp = this.spawnArray[this.index];
|
|
|
- _temp.bTrigger = true;
|
|
|
- this.index++;
|
|
|
- //绘制新触发状态
|
|
|
- this.onDraw();
|
|
|
//如果当前的跳类型和预制目标一样
|
|
|
if (_jumpType == _temp.jumpCode) {
|
|
|
+ _temp.bTrigger = true;
|
|
|
+ this.index++;
|
|
|
+ if (this.index >= this.spawnArray.length) {
|
|
|
+ clearInterval(this.countdownInterval);
|
|
|
+ this.countdownInterval = null;
|
|
|
+ this.startJumpGame();
|
|
|
+ } else {
|
|
|
+ //绘制新触发状态
|
|
|
+ this.onDraw();
|
|
|
+ }
|
|
|
//成功
|
|
|
this.setEliminationCount(1);
|
|
|
} else {
|
|
|
//失误
|
|
|
this.setFaultCount(1);
|
|
|
}
|
|
|
-
|
|
|
},
|
|
|
|
|
|
//设置倒计时
|
|
@@ -628,12 +677,209 @@
|
|
|
},
|
|
|
//控制播放
|
|
|
onControllerPlay() {
|
|
|
+ this.$emit("onControllerPlay");
|
|
|
this.bJumpPlay = !this.bJumpPlay;
|
|
|
if (this.bJumpPlay) {
|
|
|
this.startJumpGame();
|
|
|
} else {
|
|
|
this.onClear();
|
|
|
}
|
|
|
+ },
|
|
|
+
|
|
|
+ getCurrentJumpType() {
|
|
|
+ let _temp = this.spawnArray[this.index];;
|
|
|
+ return _temp.jumpCode;
|
|
|
+ },
|
|
|
+
|
|
|
+ //监听跳的状态数据
|
|
|
+ listenStateDataOfJump(data) {
|
|
|
+ let _jumpType = this.getCurrentJumpType();
|
|
|
+ //初始全部默认状态
|
|
|
+ let _tempState = [{
|
|
|
+ jumpName: 'NORMAL',
|
|
|
+ jumpCode: 0,
|
|
|
+ bTrigger: true,
|
|
|
+ describe: '正常跳'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ jumpName: 'LEFT',
|
|
|
+ jumpCode: 1,
|
|
|
+ bTrigger: false,
|
|
|
+ describe: '左直跳'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ jumpName: 'RIGHT',
|
|
|
+ jumpCode: 2,
|
|
|
+ bTrigger: false,
|
|
|
+ describe: '右直跳'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ jumpName: 'LEFT_ROTATE',
|
|
|
+ jumpCode: 3,
|
|
|
+ bTrigger: false,
|
|
|
+ describe: '左旋转跳'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ jumpName: 'RIGHT_ROTATE',
|
|
|
+ jumpCode: 4,
|
|
|
+ bTrigger: false,
|
|
|
+ describe: '右旋转跳'
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ let {
|
|
|
+ currentMaxValue,
|
|
|
+ oGyroValue
|
|
|
+ } = data
|
|
|
+ console.log('====', data);
|
|
|
+ if (currentMaxValue == 0) {
|
|
|
+ //JumpType.NORMAL = 0
|
|
|
+ if (_jumpType == 0) {
|
|
|
+ console.log('1====', data);
|
|
|
+ this.eliminateJumpPrefabFormTemp(_tempState);
|
|
|
+ }
|
|
|
+ //JumpType.RIGHT_ROTATE = 4
|
|
|
+ else if (_jumpType == 4 && oGyroValue < 0) {
|
|
|
+ console.log('right1:', oGyroValue);
|
|
|
+ _tempState[4].bTrigger = true;
|
|
|
+ this.eliminateJumpPrefabFormTemp(_tempState);
|
|
|
+ }
|
|
|
+ //JumpType.LEFT_ROTATE = 3
|
|
|
+ else if (_jumpType == 3 && oGyroValue > 0) {
|
|
|
+ console.log('left1:', oGyroValue);
|
|
|
+ _tempState[3].bTrigger = true;
|
|
|
+ this.eliminateJumpPrefabFormTemp(_tempState);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ console.log('2====', data);
|
|
|
+ if (currentMaxValue > 5) {
|
|
|
+ _tempState[1].bTrigger = true;
|
|
|
+ } else if (currentMaxValue < -5) {
|
|
|
+ _tempState[2].bTrigger = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果是检测到旋转跳
|
|
|
+ if (oGyroValue < -5) {
|
|
|
+ console.log('right:', oGyroValue);
|
|
|
+ _tempState[4].bTrigger = true;
|
|
|
+ } else if (oGyroValue > 5) {
|
|
|
+ console.log('left:', oGyroValue);
|
|
|
+ _tempState[3].bTrigger = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.eliminateJumpPrefabFormTemp(_tempState);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ eliminateJumpPrefabFormTemp(_tempState) {
|
|
|
+ //如果消除完,需要重新生成
|
|
|
+ let _temp = this.spawnArray[this.index];
|
|
|
+ let bSuccess = false;
|
|
|
+ console.log(_tempState);
|
|
|
+ for (let i = 0; i < _tempState.length; i++) {
|
|
|
+ let _state = _tempState[i];
|
|
|
+ //如果当前的跳类型和预制目标一样
|
|
|
+ if (_state.jumpCode == _temp.jumpCode && _state.bTrigger) {
|
|
|
+ //成功
|
|
|
+ bSuccess = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //如果存在其中一个为true
|
|
|
+ if (bSuccess) {
|
|
|
+ console.log("bSuccess:", bSuccess);
|
|
|
+ _temp.bTrigger = true;
|
|
|
+ this.index++;
|
|
|
+ if (this.index >= this.spawnArray.length) {
|
|
|
+ clearInterval(this.countdownInterval);
|
|
|
+ this.countdownInterval = null;
|
|
|
+ this.startJumpGame();
|
|
|
+ } else {
|
|
|
+ //绘制新触发状态
|
|
|
+ this.onDraw();
|
|
|
+ }
|
|
|
+ //成功
|
|
|
+ this.setEliminationCount(1);
|
|
|
+ } else {
|
|
|
+ //失误
|
|
|
+ this.setFaultCount(1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param {Object} gameData
|
|
|
+ * 识别跳部分数据处理
|
|
|
+ */
|
|
|
+ onBLERopeUpdate(gameData) {
|
|
|
+ //********陀螺仪角速度********
|
|
|
+ let {
|
|
|
+ gx,
|
|
|
+ gy,
|
|
|
+ gz
|
|
|
+ } = gameData.gyro;
|
|
|
+ let {
|
|
|
+ min,
|
|
|
+ s,
|
|
|
+ ms
|
|
|
+ } = gameData;
|
|
|
+
|
|
|
+ let _ax = -gameData.acc.ax * 10;
|
|
|
+ let _ay = gameData.acc.ay * 10;
|
|
|
+ let _az = gameData.acc.az * 10;
|
|
|
+ //低通滤波分离重力
|
|
|
+ let alpha = 0.8;
|
|
|
+ this.xA = alpha * this.xA + (1 - alpha) * _ax;
|
|
|
+ this.yA = alpha * this.yA + (1 - alpha) * _ay;
|
|
|
+ this.zA = alpha * this.zA + (1 - alpha) * _az;
|
|
|
+
|
|
|
+ //高通滤波获取线性速度
|
|
|
+ let linear_acceleration_x = _ax - this.xA;
|
|
|
+ let linear_acceleration_y = _az - this.zA;
|
|
|
+ let linear_acceleration_z = _ay - this.yA;
|
|
|
+
|
|
|
+ let _temp = {
|
|
|
+ linearAcc: {
|
|
|
+ lAccX: linear_acceleration_x,
|
|
|
+ lAccY: linear_acceleration_y,
|
|
|
+ lAccZ: linear_acceleration_z
|
|
|
+ }, //gameData.acc,
|
|
|
+ oriAcc: {
|
|
|
+ oAccX: _ax,
|
|
|
+ oAccY: _ay,
|
|
|
+ oAccZ: _az
|
|
|
+ },
|
|
|
+ gravityAcc: {
|
|
|
+ gravityX: this.xA,
|
|
|
+ gravityY: this.yA,
|
|
|
+ gravityZ: this.zA
|
|
|
+ },
|
|
|
+ bLimitRebound: false,
|
|
|
+ resultant: Math.sqrt(_ax * _ax +
|
|
|
+ _ay * _ay + _az * _az),
|
|
|
+ runIndex: this.BLEAccIndex,
|
|
|
+ //陀螺仪
|
|
|
+ oriGyro: {
|
|
|
+ oGyroX: gx,
|
|
|
+ oGyroY: gy,
|
|
|
+ oGyroZ: gz
|
|
|
+ }
|
|
|
+ };
|
|
|
+ this.actionJumpObj.updateJump(_temp);
|
|
|
+
|
|
|
+
|
|
|
+ if (this.BLEAccIndex > 150) {
|
|
|
+ this.onClearData();
|
|
|
+ this.bJump = false;
|
|
|
+ }
|
|
|
+ this.BLEAccIndex++;
|
|
|
+ this.oldxA = this.xA;
|
|
|
+ },
|
|
|
+ onClearData() {
|
|
|
+ this.BLEAccIndex = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|