Commit 3cd61290 authored by haiyoucuv's avatar haiyoucuv

init

parent f6a7549d
...@@ -44,7 +44,7 @@ export class Rank extends Component { ...@@ -44,7 +44,7 @@ export class Rank extends Component {
return b.length - a.length; return b.length - a.length;
}); });
this.rankTxt.string = `${snakes.indexOf(MainGame.ins.player) + 1}`; this.rankTxt.string = `${snakes.indexOf(MainGame.ins.player) + 1}`;
const playerIndex = snakes.indexOf(MainGame.ins.player); const playerIndex = snakes.indexOf(MainGame.ins.player);
......
...@@ -275,15 +275,29 @@ export class MainGame extends Scene { ...@@ -275,15 +275,29 @@ export class MainGame extends Scene {
update(dt: number) { update(dt: number) {
if (!this.isStart) return; if (!this.isStart) return;
let now = performance.now();
let temp = 0;
this.player.onUpdate(dt); this.player.onUpdate(dt);
temp = performance.now();
console.log(`玩家更新:${temp - now}ms`);
now = temp;
// 更新相机位置 // 更新相机位置
this.camera.node.setPosition(this.player.head.position); this.camera.node.setPosition(this.player.head.position);
// 更新NPC移动 // 更新NPC移动
this.animalNode.children.forEach(child => { this.animalNode.children.forEach(child => {
child.getComponent(AISnake)?.onUpdate(dt); child.getComponent(AISnake)?.onUpdate(dt);
// temp = performance.now();
// console.log(`ai更新:${temp - now}ms`);
// now = temp;
}); });
temp = performance.now();
console.log(`ai更新:${temp - now}ms`);
now = temp;
} }
initAiSnake(nickName?: string, tag?: number) { initAiSnake(nickName?: string, tag?: number) {
......
...@@ -357,7 +357,7 @@ export class Snake extends Component { ...@@ -357,7 +357,7 @@ export class Snake extends Component {
private readonly HISTORY_LENGTH = 10; // 增加历史点数量 private readonly HISTORY_LENGTH = 10; // 增加历史点数量
private readonly SEGMENT_SPACING = 6.3; // 增加节点间距 private readonly SEGMENT_SPACING = 6.3; // 增加节点间距
moveTime = 1 / 60; moveTime = 1 / 30;
totalTime = 0; totalTime = 0;
moveScale = 1; moveScale = 1;
...@@ -371,8 +371,8 @@ export class Snake extends Component { ...@@ -371,8 +371,8 @@ export class Snake extends Component {
while (this.totalTime >= this.moveTime) { while (this.totalTime >= this.moveTime) {
this.totalTime -= this.moveTime; this.totalTime -= this.moveTime;
this.move(this.moveTime); this.move(this.moveTime);
this.updateAccEffect();
} }
this.updateAccEffect();
} }
protected move(dt: number) { protected move(dt: number) {
...@@ -392,7 +392,6 @@ export class Snake extends Component { ...@@ -392,7 +392,6 @@ export class Snake extends Component {
this.head.setPosition(newHeadPos.x, newHeadPos.y); this.head.setPosition(newHeadPos.x, newHeadPos.y);
const flipY = headAngle > 90 && headAngle < 270; const flipY = headAngle > 90 && headAngle < 270;
this.head.setScale(this.scale, flipY ? -this.scale : this.scale); this.head.setScale(this.scale, flipY ? -this.scale : this.scale);
// this.head.setSiblingIndex(bodyLen - 1);
const space = this.SEGMENT_SPACING * this.scale; const space = this.SEGMENT_SPACING * this.scale;
...@@ -426,7 +425,6 @@ export class Snake extends Component { ...@@ -426,7 +425,6 @@ export class Snake extends Component {
body.setPosition(targetPos.x, targetPos.y); body.setPosition(targetPos.x, targetPos.y);
body.setScale(this.scale, this.scale); body.setScale(this.scale, this.scale);
// body.setSiblingIndex(bodyLen - i - 1);
// body.active = isIntersect( // body.active = isIntersect(
// targetPos, // targetPos,
...@@ -438,16 +436,16 @@ export class Snake extends Component { ...@@ -438,16 +436,16 @@ export class Snake extends Component {
} }
// 边界检查 // 边界检查
const mapHalfWidth = Global.MAP_WIDTH / 2; // const mapHalfWidth = Global.MAP_WIDTH / 2;
const mapHalfHeight = Global.MAP_HEIGHT / 2; // const mapHalfHeight = Global.MAP_HEIGHT / 2;
if ( // if (
newHeadPos.x <= -mapHalfWidth // newHeadPos.x <= -mapHalfWidth
|| newHeadPos.x >= mapHalfWidth // || newHeadPos.x >= mapHalfWidth
|| newHeadPos.y <= -mapHalfHeight // || newHeadPos.y <= -mapHalfHeight
|| newHeadPos.y >= mapHalfHeight // || newHeadPos.y >= mapHalfHeight
) { // ) {
this.death(); // this.death();
} // }
} }
......
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