Commit 0a527e6e authored by Master Q's avatar Master Q

1

parent c2e93616
This diff is collapsed.
This diff is collapsed.
......@@ -821,6 +821,9 @@ export class CarScene extends PerspectiveScene {
preSpeedNum: number = 0 // 前一帧速度
preVehiclePositionY: number = 0 // 前一帧高度
_currDistance: number = 0
_preVehiclePos: THREE.Vector3 = new THREE.Vector3()
_rotateNum: number = 0
_prerotateflag: number = 0
get currDistance() {
return this._currDistance
......@@ -833,6 +836,14 @@ export class CarScene extends PerspectiveScene {
})
}
get rotateNum() {
return this._rotateNum
}
set rotateNum(v) {
this._rotateNum = v
}
onEnterFrame(e: any) {
const delta = e.data.delta
if (this.physicWorld) {
......@@ -846,7 +857,8 @@ export class CarScene extends PerspectiveScene {
this.updateCamera(this.camera)
if (this.vehicleIns && this.UICtn) {
const h = this.vehicleIns.chassisMesh.position.y
const vehiclePos = this.vehicleIns.chassisMesh.position
const h = vehiclePos.y
const currSpeedNum = this.vehicleIns.speedNum
const minH = GameConfig.h
......@@ -854,24 +866,38 @@ export class CarScene extends PerspectiveScene {
// 高于 一定高度
if (h > minH) {
// this.currDistance += currSpeedNum * delta
const _t = new THREE.Vector3(vehiclePos.x, 0, vehiclePos.z)
const currflag = _defaultVector3.crossVectors(this._preVehiclePos, _t).y
let rn = 0
if (this.preVehiclePositionY < minH) {
console.log('开始积分')
// 刚开始进入
this.currDistance = 0
this.currDistance += currSpeedNum * delta
this.rotateNum = 0
} else {
const isReversal = currSpeedNum * this.preSpeedNum < 0
if (isReversal) {
const isReversalSpeed = currSpeedNum * this.preSpeedNum < 0
// 跑的方向 相反
const isReversal = this._prerotateflag * currflag < 0
rn = this._preVehiclePos.angleTo(_t)
if (isReversalSpeed || isReversal) {
this.onGameSubmit(this.currDistance)
console.log('开始积分')
this.currDistance = 0
this.rotateNum = 0
}
this.currDistance += currSpeedNum * delta
}
this.currDistance += currSpeedNum * delta
this.rotateNum += rn
this._preVehiclePos.copy(_t)
this._prerotateflag = currflag
} else {
if (this.currDistance != 0) {
// 提交
this.onGameSubmit(this.currDistance)
this.currDistance = 0
this.rotateNum = 0
}
}
......@@ -882,7 +908,7 @@ export class CarScene extends PerspectiveScene {
}
onGameSubmit(n: number) {
console.log('当前分数:', Math.abs(n))
console.log('当前分数:', Math.abs(n), '圈数:', (this.rotateNum / Math.PI / 2).toFixed(2))
GDispather.dispatchEvent('distanceUpdate', {
distance: Math.abs(n)
})
......
......@@ -13,5 +13,6 @@ export const ResJson = {
"name": "skybox"
}
],
"path": "./resource/"
// eslint-disable-next-line
"path": "https://yun.duiba.com.cn/db_games/activity/template/1663753225/resource/"
}
\ No newline at end of file
......@@ -27,15 +27,19 @@ export class StageScene {
async initStage() {
RES.loadConfig(ResJson)
// @ts-ignore
Ammo().then(() => {
if (typeof Ammo === 'function') {
// @ts-ignore
Ammo().then(() => {
this.stage = new CarScene(this.renderDom, this.UIParentNode)
})
} else {
this.stage = new CarScene(this.renderDom, this.UIParentNode)
})
}
}
destroy() {
this.stage.destroy()
this.stage && this.stage.destroy()
}
}
\ No newline at end of file
......@@ -4,7 +4,7 @@ const webpack = require('webpack');
const path = require('path')
module.exports = merge(common, {
mode: "development",//production development
mode: "production",//production development
devtool: 'source-map',
plugins: [
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment