2020-06-08 18:26:05 +08:00
|
|
|
class MainScene extends Scene {
|
2020-06-29 15:41:02 +08:00
|
|
|
constructor() {
|
2020-06-23 16:18:14 +08:00
|
|
|
super();
|
2020-06-08 18:26:05 +08:00
|
|
|
|
2020-06-11 00:03:26 +08:00
|
|
|
// this.addEntityProcessor(new SpawnerSystem(new Matcher()));
|
2020-06-09 19:45:09 +08:00
|
|
|
this.astarTest();
|
2020-06-10 12:23:19 +08:00
|
|
|
this.dijkstraTest();
|
|
|
|
|
this.breadthfirstTest();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 14:32:29 +08:00
|
|
|
public async onStart() {
|
|
|
|
|
let data = await this.content.loadRes("http://www.hyuan.org/123.jpeg", false);
|
|
|
|
|
let bgSprite = new Sprite(data);
|
|
|
|
|
let bg = this.createEntity("bg");
|
|
|
|
|
bg.position = new Vector2(0, 0);
|
|
|
|
|
bg.addComponent(new SpriteRenderer()).setSprite(bgSprite);
|
2020-06-29 15:41:02 +08:00
|
|
|
|
2020-06-30 14:32:29 +08:00
|
|
|
for (let i = 0; i < 20; i++) {
|
|
|
|
|
let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
|
|
|
|
|
let player2 = this.createEntity("player2");
|
|
|
|
|
player2.addComponent(new SpriteRenderer()).setSprite(sprite);
|
|
|
|
|
player2.position = new Vector2(Math.random() * 100 * i, Math.random() * 100 * i);
|
|
|
|
|
player2.addComponent(new BoxCollider());
|
|
|
|
|
}
|
2020-06-29 15:41:02 +08:00
|
|
|
|
2020-06-30 22:22:52 +08:00
|
|
|
let pool = new ComponentPool<SimplePooled>(SimplePooled);
|
|
|
|
|
let c1 = pool.obtain();
|
|
|
|
|
let c2 = pool.obtain();
|
|
|
|
|
pool.free(c1);
|
|
|
|
|
let c1b = pool.obtain();
|
|
|
|
|
|
|
|
|
|
console.log(c1 != c2);
|
|
|
|
|
console.log(c1 == c1b);
|
|
|
|
|
|
2020-06-30 14:32:29 +08:00
|
|
|
let button = new eui.Button();
|
|
|
|
|
button.label = "切换场景";
|
|
|
|
|
this.addChild(button);
|
|
|
|
|
button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
|
|
|
|
|
SceneManager.startSceneTransition(new FadeTransition(() => {
|
|
|
|
|
return new MainScene();
|
|
|
|
|
}));
|
|
|
|
|
}, this);
|
2020-06-21 10:27:15 +08:00
|
|
|
}
|
|
|
|
|
|
2020-06-29 15:41:02 +08:00
|
|
|
public breadthfirstTest() {
|
2020-06-10 12:23:19 +08:00
|
|
|
let graph = new UnweightedGraph<string>();
|
|
|
|
|
|
|
|
|
|
graph.addEdgesForNode("a", ["b"]); // a->b
|
|
|
|
|
graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d
|
|
|
|
|
graph.addEdgesForNode("c", ["a"]); // c->a
|
|
|
|
|
graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a
|
|
|
|
|
graph.addEdgesForNode("e", ["b"]); // e->b
|
|
|
|
|
|
|
|
|
|
// 计算从c到e的路径
|
|
|
|
|
let path = BreadthFirstPathfinder.search(graph, "c", "e");
|
|
|
|
|
console.log(path);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 15:41:02 +08:00
|
|
|
public dijkstraTest() {
|
2020-06-10 12:23:19 +08:00
|
|
|
let graph = new WeightedGridGraph(20, 20);
|
|
|
|
|
|
|
|
|
|
graph.weightedNodes.push(new Point(3, 3));
|
|
|
|
|
graph.weightedNodes.push(new Point(3, 4));
|
|
|
|
|
graph.weightedNodes.push(new Point(4, 3));
|
|
|
|
|
graph.weightedNodes.push(new Point(4, 4));
|
|
|
|
|
|
|
|
|
|
let path = graph.search(new Point(3, 4), new Point(15, 17));
|
|
|
|
|
console.log(path);
|
2020-06-09 19:45:09 +08:00
|
|
|
}
|
|
|
|
|
|
2020-06-29 15:41:02 +08:00
|
|
|
public astarTest() {
|
2020-06-09 19:45:09 +08:00
|
|
|
let graph = new AstarGridGraph(20, 20);
|
|
|
|
|
|
|
|
|
|
graph.weightedNodes.push(new Point(3, 3));
|
|
|
|
|
graph.weightedNodes.push(new Point(3, 4));
|
|
|
|
|
graph.weightedNodes.push(new Point(4, 3));
|
|
|
|
|
graph.weightedNodes.push(new Point(4, 4));
|
|
|
|
|
|
|
|
|
|
let path = graph.search(new Point(3, 4), new Point(15, 17));
|
|
|
|
|
console.log(path);
|
2020-06-08 18:26:05 +08:00
|
|
|
}
|
|
|
|
|
}
|