Commit 76cc6857 authored by haiyoucuv's avatar haiyoucuv

init

parent 24b4bd2f
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
"_priority": 40000, "_priority": 40000,
"_fov": 45, "_fov": 45,
"_fovAxis": 0, "_fovAxis": 0,
"_orthoHeight": 857.2908366533865, "_orthoHeight": 695.1569767441861,
"_near": 0, "_near": 0,
"_far": 2000, "_far": 2000,
"_color": { "_color": {
...@@ -1534,7 +1534,7 @@ ...@@ -1534,7 +1534,7 @@
"_priority": 50000, "_priority": 50000,
"_fov": 45, "_fov": 45,
"_fovAxis": 0, "_fovAxis": 0,
"_orthoHeight": 857.2908366533865, "_orthoHeight": 695.1569767441861,
"_near": 1, "_near": 1,
"_far": 2000, "_far": 2000,
"_color": { "_color": {
...@@ -2241,7 +2241,7 @@ ...@@ -2241,7 +2241,7 @@
"__uuid__": "f7e4cff9-e50b-4028-b58e-f258871093ca", "__uuid__": "f7e4cff9-e50b-4028-b58e-f258871093ca",
"__expectedType__": "cc.Prefab" "__expectedType__": "cc.Prefab"
}, },
"maxFood": 200, "maxFood": 300,
"maxAnimal": 20, "maxAnimal": 20,
"joystick": { "joystick": {
"__id__": 38 "__id__": 38
......
...@@ -37,7 +37,7 @@ export class MainGame extends Scene { ...@@ -37,7 +37,7 @@ export class MainGame extends Scene {
displayName: "最多食物", displayName: "最多食物",
tooltip: "地图上随机产生食物,如果超过当前值不在产生。" tooltip: "地图上随机产生食物,如果超过当前值不在产生。"
}) })
maxFood: number = 200; maxFood: number = 300;
@property({ @property({
displayName: "NPC数量", displayName: "NPC数量",
......
...@@ -17,7 +17,7 @@ import { ...@@ -17,7 +17,7 @@ import {
import { FoodType } from "./Common/Enums"; import { FoodType } from "./Common/Enums";
import { Global } from "./Global"; import { Global } from "./Global";
import { PoolManager } from "./Manager/PoolManager"; import { PoolManager } from "./Manager/PoolManager";
import { isIntersect, loadSkin } from "./uitl"; import { isIntersect, loadSkin } from "./utils/uitl";
import { MainGame } from "./MainGame"; import { MainGame } from "./MainGame";
import { executePreFrame, getItemGenerator } from "../../Utils/ExecutePreFrame"; import { executePreFrame, getItemGenerator } from "../../Utils/ExecutePreFrame";
...@@ -101,7 +101,7 @@ export class Snake extends Component { ...@@ -101,7 +101,7 @@ export class Snake extends Component {
// 设置身体部分的贴图 // 设置身体部分的贴图
body.getComponent(Sprite).spriteFrame = i % 2 == 0 ? this.imgBody1 : this.imgBody2; body.getComponent(Sprite).spriteFrame = i % 2 == 0 ? this.imgBody1 : this.imgBody2;
body.active = false; // body.active = false;
this.bodyArr.push(body); this.bodyArr.push(body);
} }
...@@ -189,12 +189,12 @@ export class Snake extends Component { ...@@ -189,12 +189,12 @@ export class Snake extends Component {
newBody.getComponent(Sprite).spriteFrame = len % 2 == 0 ? this.imgBody1 : this.imgBody2; newBody.getComponent(Sprite).spriteFrame = len % 2 == 0 ? this.imgBody1 : this.imgBody2;
newBody.getComponent(Collider2D).tag = this.tag; newBody.getComponent(Collider2D).tag = this.tag;
newBody.active = isIntersect( // newBody.active = isIntersect(
newBody.getPosition(), // newBody.getPosition(),
this.head.getPosition(), // this.head.getPosition(),
this.vw, // this.vw,
this.vh // this.vh
); // );
this.bodyArr.splice(len, 0, newBody); this.bodyArr.splice(len, 0, newBody);
} }
...@@ -206,7 +206,7 @@ export class Snake extends Component { ...@@ -206,7 +206,7 @@ export class Snake extends Component {
isFast = false; isFast = false;
private positions: Vec3[] = []; // 存储历史位置点 private positions: Vec3[] = []; // 存储历史位置点
private readonly HISTORY_LENGTH = 100; // 增加历史点数量 private readonly HISTORY_LENGTH = 100; // 增加历史点数量
private readonly SEGMENT_SPACING = 5; // 增加节点间距 private readonly SEGMENT_SPACING = 8; // 增加节点间距
moveTime = 1 / 60; moveTime = 1 / 60;
totalTime = 0; totalTime = 0;
...@@ -271,12 +271,12 @@ export class Snake extends Component { ...@@ -271,12 +271,12 @@ export class Snake extends Component {
body.setScale(this.scale, this.scale); body.setScale(this.scale, this.scale);
body.setSiblingIndex(this.bodyArr.length - i); body.setSiblingIndex(this.bodyArr.length - i);
body.active = isIntersect( // body.active = isIntersect(
targetPos, // targetPos,
this.head.getPosition(), // this.head.getPosition(),
this.vw, // this.vw,
this.vh // this.vh
); // );
} }
} }
...@@ -302,6 +302,7 @@ export class Snake extends Component { ...@@ -302,6 +302,7 @@ export class Snake extends Component {
this.isLife = false; this.isLife = false;
this.node.active = false; this.node.active = false;
console.log(MainGame.ins.animalNode.children.length)
this.initFond(this.bodyArr.length); this.initFond(this.bodyArr.length);
......
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a23ad008-035e-4d4c-8b0a-ae8d587e1321",
"files": [],
"subMetas": {},
"userData": {}
}
function* waitSeconds(duration: number) {
let start = Date.now();
while (duration > 0) {
const current = Date.now();
const dt = current - start;
start = current;
duration -= dt;
yield;
}
}
export class CoroutineRunner {
private generatorStacks: any[];
private removeQueue: Set<any>;
private addQueue: any[];
constructor() {
this.generatorStacks = [];
this.addQueue = [];
this.removeQueue = new Set();
}
isBusy() {
return this.addQueue.length + this.generatorStacks.length > 0;
}
add(generator: Generator, delay = 0) {
const genStack = [generator];
if (delay) {
genStack.push(waitSeconds(delay));
}
this.addQueue.push(genStack);
}
remove(generator: Generator) {
this.removeQueue.add(generator);
}
update() {
this._addQueued();
this._removeQueued();
for (const genStack of this.generatorStacks) {
const main = genStack[0];
// Handle if one coroutine removes another
if (this.removeQueue.has(main)) {
continue;
}
while (genStack.length) {
const topGen = genStack[genStack.length - 1];
const { value, done } = topGen.next();
if (done) {
if (genStack.length === 1) {
this.removeQueue.add(topGen);
break;
}
genStack.pop();
} else if (value) {
genStack.push(value);
} else {
break;
}
}
}
this._removeQueued();
}
_addQueued() {
if (this.addQueue.length) {
this.generatorStacks.splice(this.generatorStacks.length, 0, ...this.addQueue);
this.addQueue = [];
}
}
_removeQueued() {
if (this.removeQueue.size) {
this.generatorStacks = this.generatorStacks.filter(genStack => !this.removeQueue.has(genStack[0]));
this.removeQueue.clear();
}
}
}
\ No newline at end of file
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "142ccfd9-e442-4f29-9e74-88e23bb5f86f",
"files": [],
"subMetas": {},
"userData": {}
}
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