private void initBoombTexture() { Packer.createRegion("bomb", 20, 1921, 14, 14); Packer.createRegion("boomb01", 73, 1920, 15, 15); Packer.createRegion("boomb02", 94, 1906, 47, 43); Packer.createRegion("boomb03", 147, 1915, 28, 28); Packer.createRegion("boomb04", 183, 1915, 28, 28); Packer.createRegion("boomb05", 197, 1921, 18, 18); Packer.createRegion("boomb06", 239, 1920, 19, 19); Packer.createRegion("boomb07", 263, 1920, 18, 18); Packer.createRegion("boomb08", 289, 1918, 20, 22); Packer.createRegion("boomb09", 316, 1914, 23, 25); Packer.createRegion("boomb010", 347, 1909, 28, 32); Packer.createRegion("boomb011", 381, 1901, 30, 33); Packer.createRegion("boomb012", 418, 1905, 32, 36); Packer.createRegion("boomb013", 460, 1904, 30, 36); Packer.createRegion("boomb014", 499, 1925, 29, 36); Packer.createRegion("boomb015", 538, 1904, 29, 37); Packer.createRegion("boomb016", 575, 1905, 26, 36); Packer.createRegion("boomb017", 605, 1905, 26, 36); Packer.createRegion("boomb018", 634, 1905, 22, 36); Packer.createRegion("boomb019", 655, 1905, 20, 36); Packer.createRegion("boomb020", 678, 1905, 15, 27); Packer.spriteAnimationDetails = new Dictionary <string, List <int> >(); Packer.spriteAnimationDetails.Add("waitboom", new List <int>() { 0 }); Packer.spriteAnimationDetails.Add("bombboom", new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }); }
public override void onAddedToScene() { base.onAddedToScene(); this.setScale(2f); this.actorProperty = addComponent <ActorPropertyComponent>(); this.actorProperty.HP = this.actorProperty.MaxHP = 30; this.actorProperty.moveSpeed = 70f; var texture = scene.content.Load <Texture2D>("Images/Enemys/Bat"); var texturePacker = new TexturePackerAtlas(texture); var idleTexture = texturePacker.createRegion("batidle", 0, 33, 16, 16); var flyTextur1 = texturePacker.createRegion("fly01", 0, 9, 16, 16); var flyTextur2 = texturePacker.createRegion("fly02", 16, 9, 16, 16); var flyTextur3 = texturePacker.createRegion("fly03", 32, 9, 16, 16); var flyTextur4 = texturePacker.createRegion("fly04", 48, 9, 16, 16); animation = addComponent(new Sprite <BatAnimations>(idleTexture)); animation.setRenderLayer(GameLayerSetting.tiledActorUpLayer); animation.addAnimation(BatAnimations.Idle, new SpriteAnimation(idleTexture)); animation.addAnimation(BatAnimations.Fly, new SpriteAnimation(new List <Subtexture>() { flyTextur1, flyTextur2, flyTextur3, flyTextur4 })); animation.currentAnimation = BatAnimations.Idle; addComponent <FSRigidBody>() .setBodyType(BodyType.Dynamic). setLinearDamping(0.8f) .setMass(1.5f); var enemtCollider = addComponent <FSCollisionCircle>() .setRadius(8); enemtCollider.setCollisionCategories(CollisionSetting.enemyCategory); enemtCollider.setCollidesWith( CollisionSetting.allAttackTypeCategory | CollisionSetting.playerAttackCategory ); var damageTriger = addComponent <DamageTrigerComponent>(); damageTriger.setRadius(10).setIsSensor(true); damageTriger.setCollisionCategories( CollisionSetting.enemyAttackCategory); damageTriger.setCollidesWith(CollisionSetting.playerCategory); damageTriger.onAdded += () => { damageTriger.GetFixture().onCollision += (fixtureA, fixtureB, contact) => { var component = fixtureB.userData as Component; var actorProperty = component.entity.getComponent <ActorPropertyComponent>(); actorProperty.executeDamage?.Invoke(AttackTypes.Physics, 5); var rigidbody = component.entity.getComponent <FSRigidBody>(); var dir = component.entity.position - this.position; dir.Normalize(); rigidbody.body.applyLinearImpulse(dir * rigidbody.body.mass); return(true); }; }; var viewFieldTrigger = addComponent <EnemyViewComponent>(); viewFieldTrigger.setRadius(fieldOfView); viewFieldTrigger.setIsSensor(true); viewFieldTrigger.setCollisionCategories(CollisionSetting.enemyCategory); viewFieldTrigger.setCollidesWith(CollisionSetting.playerCategory); viewFieldTrigger.onAdded += () => { viewFieldTrigger.GetFixture().onCollision += (fixtureA, fixtureB, contact) => { target = ((Component)(fixtureB.userData)).entity; isFindTarget = true; return(true); }; }; addComponent <RigidBodyVelocityLimited>(); addComponent(new BatSampleStateMachine(this)); }