2020-08-23 22:09:22 +08:00
|
|
|
module samples {
|
|
|
|
|
import CircleCollider = es.CircleCollider;
|
|
|
|
|
import Flags = es.Flags;
|
|
|
|
|
import SpriteRenderer = es.SpriteRenderer;
|
2020-08-26 19:56:48 +08:00
|
|
|
import ProjectileHitDetector = es.ProjectileHitDetector;
|
|
|
|
|
import FollowCamera = es.FollowCamera;
|
2020-08-23 22:09:22 +08:00
|
|
|
|
|
|
|
|
export class NinjaAdventureScene extends SampleScene {
|
2020-08-26 19:56:48 +08:00
|
|
|
public async onStart() {
|
|
|
|
|
super.onStart();
|
2020-08-23 22:09:22 +08:00
|
|
|
|
|
|
|
|
let playerEntity = this.createEntity("player");
|
|
|
|
|
playerEntity.position = new es.Vector2(256, 224);
|
|
|
|
|
playerEntity.addComponent(new Ninja());
|
|
|
|
|
let collider = playerEntity.addComponent(new CircleCollider());
|
|
|
|
|
|
|
|
|
|
// 我们只希望与默认图层0上的组件发生冲突
|
|
|
|
|
Flags.setFlagExclusive(collider.collidesWithLayers, 0);
|
|
|
|
|
// 移动到第1层 保证自己的图层不会如果增加攻击方式则不会攻击到自身
|
|
|
|
|
Flags.setFlagExclusive(collider.physicsLayer, 1);
|
|
|
|
|
|
2020-08-26 19:56:48 +08:00
|
|
|
this.camera.entity.addComponent(new FollowCamera(playerEntity));
|
|
|
|
|
|
2020-08-23 22:09:22 +08:00
|
|
|
this.content.loadRes("moon_png").then(moonTexture => {
|
|
|
|
|
let moonEntity = this.createEntity("moon");
|
|
|
|
|
moonEntity.position = new es.Vector2(412, 460);
|
|
|
|
|
moonEntity.addComponent(new SpriteRenderer(moonTexture));
|
2020-08-26 19:56:48 +08:00
|
|
|
moonEntity.addComponent(new ProjectileHitDetector());
|
2020-08-23 22:09:22 +08:00
|
|
|
moonEntity.addComponent(new CircleCollider());
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-08-26 19:56:48 +08:00
|
|
|
|
|
|
|
|
public update(){
|
|
|
|
|
super.update();
|
|
|
|
|
|
|
|
|
|
this.findEntity("player").position.x -= es.Time.deltaTime * 10;
|
|
|
|
|
this.findEntity("player").position.y -= es.Time.deltaTime * 10;
|
|
|
|
|
}
|
2020-08-23 22:09:22 +08:00
|
|
|
}
|
|
|
|
|
}
|