first commit
This commit is contained in:
58
assets/scripts/GameManager.ts
Normal file
58
assets/scripts/GameManager.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
// assets/scripts/GameManager.ts
|
||||
import { _decorator, Component, Node, Label, Vec3 } from "cc";
|
||||
import { BallPhysics } from "./BallPhysics";
|
||||
// import { CameraRig } from "./CameraRig";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("GameManager")
|
||||
export class GameManager extends Component {
|
||||
@property(Node) ball!: Node;
|
||||
// @property(Node) cameraRig!: Node;
|
||||
// @property(Label) scoreLabel!: Label;
|
||||
// @property(Label) windLabel!: Label;
|
||||
|
||||
private score = 0;
|
||||
private ballPhys!: BallPhysics;
|
||||
// private cam!: CameraRig;
|
||||
|
||||
onLoad() {
|
||||
this.ballPhys = this.ball.getComponent(BallPhysics)!;
|
||||
this.ballPhys.init();
|
||||
// this.cam = this.cameraRig.getComponent(CameraRig)!;
|
||||
|
||||
// 监听进球
|
||||
this.node.on("GOAL", this.onGoal, this);
|
||||
|
||||
this.newRound();
|
||||
}
|
||||
|
||||
onGoal() {
|
||||
this.score += 1;
|
||||
this.updateScore();
|
||||
this.scheduleOnce(() => {
|
||||
this.newRound();
|
||||
}, 1.0);
|
||||
}
|
||||
|
||||
private updateScore() {
|
||||
// if (this.scoreLabel) this.scoreLabel.string = `${this.score}`;
|
||||
}
|
||||
|
||||
private newRound() {
|
||||
// 重置球与镜头
|
||||
this.ballPhys.resetBall();
|
||||
// this.cam.setModeStatic();
|
||||
|
||||
// 随机风
|
||||
// const dir = new Vec3(Math.random() - 0.5, 0, Math.random() - 0.5);
|
||||
// const strength = 4 * Math.random(); // 0~4
|
||||
// this.ballPhys.setWind(dir, strength);
|
||||
// if (this.windLabel) {
|
||||
// const a = (Math.atan2(dir.x, dir.z) * 180) / Math.PI; // 粗略角度显示
|
||||
// this.windLabel.string = `Wind ${strength.toFixed(1)} @ ${a.toFixed(0)}°`;
|
||||
// }
|
||||
|
||||
// 几百毫秒后把镜头切为跟随(等玩家射门后也可在 KickInput 里触发)
|
||||
// this.scheduleOnce(() => this.cam.setModeFollow(), 0.6);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user