/** * 加速门 */ import { _decorator, Component, isValid, Node, sp, tween, UITransform, Vec3 } from 'cc'; import { IAccelerateGateProperty } from '../../../game/ChapterPlayTypes'; import { MapObstacle, ObstacleType } from '../MapObstacle'; import { SingleAccelerateGate } from './SingleAccelerateGate'; const { ccclass, property } = _decorator; @ccclass('MechanismAccGateSchedule') export class MechanismAccGateSchedule extends Component { _dt: number = 0 /**加速门属性 */ accGateInfo: IAccelerateGateProperty = null isStartTime: boolean = false start() { } protected update(dt: number): void { if (!gg.game.CurentBattle.canUpdateFrame()) return; if (!this.isStartTime) { return } this._dt += dt * gg.game.CurentBattle.TimeScale; if (this._dt >= 1) { this._dt = 0 this.checkAccGateLaunchTime() } } init(accGateInfo: IAccelerateGateProperty) { this.accGateInfo = accGateInfo this.isStartTime = true } /**检查是否到了释放时间 */ checkAccGateLaunchTime() { if (this.accGateInfo && this.accGateInfo.timeArr && this.accGateInfo.timeArr.length > 0 && gg.game.CurentBattle.BattleTime >= this.accGateInfo.timeArr[0]) { this.accGateInfo.timeArr.shift() this.releaseAccGate(this.accGateInfo) } } /**释放加速门 */ releaseAccGate(accGateInfo: IAccelerateGateProperty) { //随机释放1-3个 let num = Math.floor(Math.random() * 3) + 2 let randomPosArr = gg.game.CurentBattle.Map.getRandomCanPutObstacleMapGrids(num); for (let i = 0; i < randomPosArr.length; i++) { let grid = randomPosArr[i]; let comp = grid.getComponent(MapObstacle); comp.setObstacle(ObstacleType.加速门); comp.node.getComponentInChildren(SingleAccelerateGate).init(accGateInfo, grid) grid.isCanPutGrid = false; } } }