예제 #1
0
        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);
        }
예제 #2
0
        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>();
        }
예제 #3
0
        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>();
        }