import { _decorator, Component, debug, director, find, instantiate, Layers, Node, NodePool, Prefab, tween, Vec3 } from 'cc'; import { Cube_Infor, Cube_State } from './Cube_Infor'; import { Container_Manager } from './Container_Manager'; import { Hall } from '../hall/Hall'; const { ccclass, property } = _decorator; @ccclass('CreateIdiom') export class CreateIdiom extends Component { Container: Container_Manager; animationRunning: boolean = false; // 控制是否有动画正在运行 @property([Node]) startPos:Node[]=[]; onLoad() { this.Container = find('Container').getComponent(Container_Manager); } update(deltaTime: number) { } nodeMoving() { if (Hall.getInstance().player.get_max_floor() !== 0) { this.node.setPosition(new Vec3(0, 1.6, -0.5)); let startPos = this.node.position; // 起点,抛物线开始的坐标 let middlePos = new Vec3(this.node.position.x, this.node.position.y + 1, -0.5); // 中间控制点 let destPos = new Vec3(this.node.position.x, this.node.position.y + 2, -0.5); // 终点,抛物线上升顶点 let lastGeneratedPosition = null; // 记录上一次生成方块的位置 // 保持原来贝塞尔曲线和螺旋效果的计算 let twoBezier = (t: number, p1: Vec3, cp: Vec3, p2: Vec3) => { let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x; let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y; let z = (1 - t) * (1 - t) * p1.z + 2 * t * (1 - t) * cp.z + t * t * p2.z; let angle = t * Math.PI * 10; // 缓动的半径计算方法,调整第一圈半径的变化速度 let radius = 1.2 - Math.pow(t, 2); // 使用平方函数,t小的时候变化较大,t大时变化变缓 let xOffset = Math.cos(angle) * radius; let zOffset = Math.sin(angle) * radius; return new Vec3(x + xOffset, y, z + zOffset); }; let createdNodes = 0; // 已生成的节点计数 let animationStopped = false; // 控制动画是否已经停止 let t = 0; // 进度 t,0 为起点,1 为终点 const updatePosition = () => { if (animationStopped) return; this.node.position = twoBezier(t, startPos, middlePos, destPos); let cube = this.Container.getCube(); if (cube != null && cube.getComponent(Cube_Infor).state === Cube_State.live) { let newNode = cube; newNode.parent = director.getScene(); // 随机左右偏移量,范围设定为 [-0.5, 0.5] let randomXOffset = Math.random() * 1 - 0.5; // 生成一个[-0.5, 0.5]之间的随机值 newNode.setPosition(this.node.position.x + randomXOffset, this.node.position.y, this.node.position.z); this.Container.nodeReferences.push(newNode); lastGeneratedPosition = this.node.position.clone(); // 更新上次生成位置 console.log(cube.getComponent(Cube_Infor).Text); createdNodes++; } let totalCubes = 60; // 设置生成方块的间隔,可以调整生成速度 let interval = 0.01; // 控制生成间隔的速率,可以根据需要调整 if (createdNodes >= totalCubes) { animationStopped = true; this.Container.canTouch = true; console.log("所有方块已拿完或没有方块了,停止动画"); } // 这里控制 t 增加的速率 t += interval; if (!animationStopped) { requestAnimationFrame(updatePosition); } }; updatePosition(); }else{ for(let i=0;i1) { newNode.getComponent(Cube_Infor).state=Cube_State.wait; } } } this.Container.canTouch = true; } } }