private void initCollision() { rigidBody = addComponent <FSRigidBody>() .setBodyType(BodyType.Dynamic) .setFixedRotation(true) .setIsSleepingAllowed(false) .setLinearDamping(0.8f) .setMass(2f); collider = addComponent <FSCollisionCircle>(); collider.setRadius(20) .setIsSensor(true); collider.setCollisionCategories(CollisionSetting.enemyCategory); collider.setCollidesWith( CollisionSetting.playerAttackCategory ); addComponent <RigidBodyVelocityLimited>(); colliderEntity = scene.createEntity("collision").setPosition(this.position); colliderEntity.addComponent <FSRigidBody>() .setBodyType(BodyType.Static); var shape = colliderEntity.addComponent <FSCollisionBox>() .setSize(28, 28); shape.setCollisionCategories(CollisionSetting.wallCategory); }
private void initCollision() { rigidBody = addComponent <FSRigidBody>() .setBodyType(FarseerPhysics.Dynamics.BodyType.Dynamic) .setLinearDamping(0.8f) .setMass(2f); collider = addComponent <FSCollisionCircle>() .setRadius(8); collider.setCollisionCategories(CollisionSetting.enemyCategory); collider.setCollidesWith(CollisionSetting.wallCategory | CollisionSetting.allAttackTypeCategory | CollisionSetting.playerAttackCategory ); damageTriger = addComponent <DamageTrigerComponent>(); damageTriger.setRadius(16).setIsSensor(true); damageTriger.setCollisionCategories( CollisionSetting.enemyAttackCategory); damageTriger.setCollidesWith(CollisionSetting.playerCategory); damageTriger.onAdded += damageOnAdded; viewFieldTrigger = addComponent <EnemyViewComponent>(); viewFieldTrigger.setRadius(fieldOfView); viewFieldTrigger.setIsSensor(true); viewFieldTrigger.setCollisionCategories(CollisionSetting.enemyCategory); viewFieldTrigger.setCollidesWith(CollisionSetting.playerCategory); viewFieldTrigger.onAdded += onAdded; addComponent <RigidBodyVelocityLimited>(); }
private void initCollision() { rigidBody = addComponent <FSRigidBody>() .setBodyType(BodyType.Dynamic) .setFixedRotation(true) .setLinearDamping(0.8f) .setMass(2f); collider = addComponent <FSCollisionCircle>() .setRadius(8); collider.setCollisionCategories(CollisionSetting.enemyCategory); collider.setCollidesWith(CollisionSetting.wallCategory | CollisionSetting.allAttackTypeCategory | CollisionSetting.playerAttackCategory | CollisionSetting.tiledHoleCategory ); var damageTriger = addComponent <DamageTrigerComponent>(); damageTriger.setRadius(8).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); }; }; addComponent <RigidBodyVelocityLimited>(); }
public override void onAddedToScene() { base.onAddedToScene(); this.actorProperty = addComponent <ActorPropertyComponent>(); this.actorProperty.HP = this.actorProperty.MaxHP = 30; this.actorProperty.moveSpeed = 70; this.actorProperty.executeDamage = executeDamageMethod; var texture1 = scene.content.Load <Texture2D>("Images/Enemys/BlackOctor1"); var texture2 = scene.content.Load <Texture2D>("Images/Enemys/BlackOctor2"); var texture3 = GameResources.GameTextureResource.xObjectPacker.Packer.getSubtexture(750); animations = addComponent(new Sprite <OctorAnimations>(new Subtexture(texture1))); animations.setLayerDepth(LayerDepthExt.caluelateLayerDepth(this.position.Y)); animations.addAnimation(OctorAnimations.Attack, new SpriteAnimation(new Subtexture(texture2))); animations.addAnimation(OctorAnimations.Appera, new SpriteAnimation(new Subtexture(texture1))); animations.addAnimation(OctorAnimations.Hide, new SpriteAnimation(texture3)); animations.currentAnimation = OctorAnimations.Hide; rigidBody = addComponent <FSRigidBody>() .setBodyType(BodyType.Dynamic) .setLinearDamping(int.MaxValue) .setMass(2f); var collider = addComponent <FSCollisionCircle>() .setRadius(5); collider.setCollisionCategories(CollisionSetting.enemyCategory); collider.setCollidesWith(CollisionSetting.allAttackTypeCategory | CollisionSetting.playerAttackCategory); ViewTrigger = scene.createEntity("OctorViewTrigger").setPosition(this.position); ViewTrigger.addComponent <FSRigidBody>() .setBodyType(BodyType.Dynamic); var view = ViewTrigger.addComponent <EnemyViewComponent>(); view.setRadius(fieldOfView) .setIsSensor(true); view.setCollisionCategories(CollisionSetting.enemyCategory); view.setCollidesWith(CollisionSetting.playerCategory); view.onAdded += () => { view.GetFixture().onCollision += (fixtureA, fixtureB, contact) => { var compoent = fixtureB.userData as Component; target = compoent.entity; isFindTarget = true; return(true); }; view.GetFixture().onSeparation += (fixtureA, fixtureB) => { target = null; isFindTarget = false; }; }; colliderEntity = scene.createEntity("collision").setPosition(this.position); colliderEntity.addComponent <FSRigidBody>() .setBodyType(BodyType.Static); colliderShape = colliderEntity.addComponent <FSCollisionCircle>() .setRadius(7); colliderShape.setCollisionCategories(CollisionSetting.wallCategory); stateMachine = addComponent(new OctorSimpleStateMachine(this)); }