Exemple #1
0
        public bool Test(BroadPhaseEntry test)
        {
            if (test == mSelf)
            {
                return(false);
            }

            if (test == mOther)
            {
                return(true);
            }

            // TODO: P2: We need a more robust way of determining what kinds of objects can block LOS.
            EntityCollidable ec = test as EntityCollidable;

            if (ec != null &&
                ec.Entity != null &&
                ec.Entity.Tag != null)
            {
                int   actorId   = (int)(ec.Entity.Tag);
                Actor testActor = GameResources.ActorManager.GetActorById(actorId);

                DynamicCollisionComponent dcc      = testActor.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);
                const float SMALL_OBJECT_THRESHOLD = 64.0f;
                if (dcc != null &&
                    dcc.Entity.LinearVelocity.LengthSquared() > 1.0f &&
                    dcc.Entity.Volume < SMALL_OBJECT_THRESHOLD)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        public void Propel(int ownerActorId)
        {
            mOwnerActorId = ownerActorId;
            DynamicCollisionComponent collisionComponent = Owner.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);

            BEPUutilities.Vector3 forward = collisionComponent.Entity.OrientationMatrix.Forward * mSpeed;
            collisionComponent.Entity.ApplyLinearImpulse(ref forward);
        }
Exemple #3
0
        private void ComponentsCreatedHandler(object sender, EventArgs e)
        {
            DynamicCollisionComponent dcc = Owner.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);

            if (dcc == null)
            {
                throw new LevelManifestException("Expected ActorComponent missing.");
            }

            dcc.Entity.CollisionInformation.Events.InitialCollisionDetected += InitialCollisionDetectedHandler;
        }
Exemple #4
0
        public void Propel()
        {
            DynamicCollisionComponent collisionComponent = Owner.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);

            BEPUutilities.Vector3 forward = collisionComponent.Entity.OrientationMatrix.Forward * mSpeed;
            collisionComponent.Entity.ApplyLinearImpulse(ref forward);

            Actor    contrailActor    = GameResources.ActorManager.SpawnTemplate("Contrail");
            Contrail contrailBehavior = contrailActor.GetBehavior <Contrail>();

            contrailBehavior.OffsetFromTarget = Vector3.Backward;
            contrailBehavior.SetTarget(Owner.Id);

            // TODO: P2: Add a launch cloud and a firey tail, and some acceleration
        }
Exemple #5
0
        private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e)
        {
            mTimeAlive += (float)(e.GameTime.ElapsedGameTime.TotalSeconds);

            float lifeMeasure = mTimeAlive * mSpeed;

            if (lifeMeasure > 435.0f)
            {
                Owner.Despawn();
            }
            else if (lifeMeasure > 285.0f)
            {
                DynamicCollisionComponent collisionComponent = Owner.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);
                collisionComponent.Entity.IsAffectedByGravity = true;
            }
        }
Exemple #6
0
        private void ItemDroppedHandler(object sender, ItemEventArgs e)
        {
            Actor dropped = GameResources.ActorManager.SpawnTemplate("GenericPickup");
            TransformComponent droppedXform = dropped.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform);
            TransformComponent ownerXform   = Owner.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform);

            droppedXform.Transform = Matrix.CreateTranslation(5.0f, 3.0f, -3.0f) * ownerXform.Transform;
            InventoryPickup ip = dropped.GetBehavior <InventoryPickup>();

            ip.Item = e.Item;

            DynamicCollisionComponent collisionComponent = dropped.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);

            BEPUutilities.Vector3 forward = collisionComponent.Entity.OrientationMatrix.Forward * ITEM_POP_SPEED;
            collisionComponent.Entity.ApplyLinearImpulse(ref forward);
        }
Exemple #7
0
        private void ComponentsCreatedHandler(object sender, EventArgs e)
        {
            DynamicCollisionComponent cc = Owner.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);

            if (cc == null)
            {
                throw new LevelManifestException("Expected ActorComponent missing.");
            }

            TransformComponent tc = Owner.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform);

            if (tc == null)
            {
                throw new LevelManifestException("Expected ActorComponent missing.");
            }

            cc.Entity.IsAffectedByGravity = false;
            cc.Entity.CollisionInformation.Events.InitialCollisionDetected += CollisionDetectedHandler;

            mOrigScale = tc.Scale;
        }
Exemple #8
0
        public override void AssignAvatar(int actorId)
        {
            base.AssignAvatar(actorId);

            PlayerIndex inputIndex = GameResources.PlaySession.LocalPlayers[PlayerId];

            Actor avatar = GameResources.ActorManager.GetActorById(ActorId);
            BipedControllerComponent bipedControl = avatar.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);

            bipedControl.AimCheck = delegate() { return(mInputMode == InputMode.Aiming); };

            // Begin InputProcessors configuration:

            // Biped, aloof mode:
            TPBipedFixedControlsInputProcessor bipedProc;

            if (mInputProcs[(int)(InputMode.Aloof)].ContainsKey(typeof(TPBipedFixedControlsInputProcessor)))
            {
                bipedProc = (TPBipedFixedControlsInputProcessor)(mInputProcs[(int)(InputMode.Aloof)][typeof(TPBipedFixedControlsInputProcessor)]);
            }
            else
            {
                bipedProc = new TPBipedFixedControlsInputProcessor(inputIndex, mCamera);
                mInputProcs[(int)(InputMode.Aloof)].Add(typeof(TPBipedFixedControlsInputProcessor), bipedProc);
            }
            bipedProc.ActiveInputMap = mPlayerInputMap;
            bipedProc.SetControllerComponent(bipedControl);

            // Biped, aiming mode:
            TPAimingBipedMovementInputProcessor aimingBipedProc;

            if (mInputProcs[(int)(InputMode.Aiming)].ContainsKey(typeof(TPAimingBipedMovementInputProcessor)))
            {
                aimingBipedProc = (TPAimingBipedMovementInputProcessor)(mInputProcs[(int)(InputMode.Aiming)][typeof(TPAimingBipedMovementInputProcessor)]);
            }
            else
            {
                aimingBipedProc = new TPAimingBipedMovementInputProcessor(inputIndex);
                mInputProcs[(int)(InputMode.Aiming)].Add(typeof(TPAimingBipedMovementInputProcessor), aimingBipedProc);
            }
            aimingBipedProc.ActiveInputMap = mPlayerInputMap;
            aimingBipedProc.SetControllerComponent(bipedControl);

            // Skill palette, shared between aiming and aloof modes:
            TPBipedPaletteInputProcessor paletteProc;

            if (mInputProcs[(int)(InputMode.Aloof)].ContainsKey(typeof(TPBipedPaletteInputProcessor)))
            {
                paletteProc = (TPBipedPaletteInputProcessor)(mInputProcs[(int)(InputMode.Aloof)][typeof(TPBipedPaletteInputProcessor)]);
            }
            else
            {
                paletteProc = new TPBipedPaletteInputProcessor(inputIndex);
                mInputProcs[(int)(InputMode.Aloof)].Add(typeof(TPBipedPaletteInputProcessor), paletteProc);
            }
            if (!(mInputProcs[(int)(InputMode.Aiming)].ContainsKey(typeof(TPBipedPaletteInputProcessor))))
            {
                mInputProcs[(int)(InputMode.Aiming)].Add(typeof(TPBipedPaletteInputProcessor), paletteProc);
            }
            paletteProc.ActiveInputMap = mPlayerInputMap;
            paletteProc.SetControllerComponent(bipedControl);
            BipedSkillPalette skillPalette = avatar.GetBehaviorThatImplementsType <BipedSkillPalette>();

            paletteProc.SetSkillPalette(skillPalette);

            // Camera, aloof mode:
            TPCameraInputProcessor camera;

            if (mInputProcs[(int)(InputMode.Aloof)].ContainsKey(typeof(TPCameraInputProcessor)))
            {
                camera = (TPCameraInputProcessor)(mInputProcs[(int)(InputMode.Aloof)][typeof(TPCameraInputProcessor)]);
            }
            else
            {
                camera = new TPCameraInputProcessor(inputIndex, mMmoCameraDesc);
                mInputProcs[(int)(InputMode.Aloof)].Add(typeof(TPCameraInputProcessor), camera);
            }
            camera.ActiveInputMap = mPlayerInputMap;
            // Done with InputProcessor configuration.

            // Reset camera placement:
            mMmoCameraDesc.Distance = 38.0f;
            mMmoCameraDesc.Pitch    = -MathHelper.Pi / 6.0f; // Positive pitch will move the camera -Y since it's on the +Z side
            mMmoCameraDesc.Yaw      = 0.0f;

            DynamicCollisionComponent dcc = avatar.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);

            mAvatarBepuEntity = dcc.Entity;
        }
Exemple #9
0
        public void ImpactHandler(object sender, UpdateStepEventArgs e)
        {
            GameResources.ActorManager.PostPhysicsUpdateStep -= ImpactHandler;
            // TODO: P2: Some boooom sound effects...

            TransformComponent myXForm = Owner.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform);
            // Do a sphere cast to get actors in the blast radius
            List <RayCastResult> inRangeActors = new List <RayCastResult>();
            SphereShape          blastZone     = new SphereShape(mBlastRadius);
            RigidTransform       blastPosition = new RigidTransform(BepuConverter.Convert(myXForm.Translation));

            BEPUutilities.Vector3 bepuZero = BEPUutilities.Vector3.Zero;
            GameResources.ActorManager.SimSpace.ConvexCast(blastZone, ref blastPosition, ref bepuZero, inRangeActors);

            RayCastDistanceComparer rcdc = new RayCastDistanceComparer();

            for (int a = 0; a < inRangeActors.Count; ++a)
            {
                EntityCollidable inRangeEntityCollidable = inRangeActors[a].HitObject as EntityCollidable;
                if (inRangeEntityCollidable != null &&
                    inRangeEntityCollidable.Entity != null &&
                    inRangeEntityCollidable.Entity.Tag != null)
                {
                    Actor      blastedActor = GameResources.ActorManager.GetActorById((int)(inRangeEntityCollidable.Entity.Tag));
                    IDamagable actorDamage  = blastedActor.GetBehaviorThatImplementsType <IDamagable>();
                    DynamicCollisionComponent actorCollidable = blastedActor.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);
                    BepuVec3 blastToActorCenter = actorCollidable.Entity.Position - blastPosition.Position;
                    BepuRay  loeRay             = new BepuRay(blastPosition.Position, blastToActorCenter);
                    bool     hasCover           = false;
                    float    distance           = mBlastRadius;
                    if (actorDamage != null || (actorCollidable != null && actorCollidable.IsDynamic && !(actorCollidable.Entity.CollisionInformation.CollisionRules.Personal.HasFlag(BEPUphysics.CollisionRuleManagement.CollisionRule.NoSolver))))
                    {
                        List <RayCastResult> loeResults = new List <RayCastResult>();
                        GameResources.ActorManager.SimSpace.RayCast(loeRay, mBlastRadius, loeResults);
                        loeResults.Sort(rcdc);

                        for (int c = 0; c < loeResults.Count; ++c)
                        {
                            EntityCollidable possibleCover = loeResults[c].HitObject as EntityCollidable;
                            if (possibleCover != null &&
                                possibleCover.Entity == inRangeEntityCollidable.Entity)
                            {
                                // Hit
                                distance = loeResults[c].HitData.T;
                                break;
                            }
                            Terrain possibleCoverTerrain = loeResults[c].HitObject as Terrain;
                            if (possibleCoverTerrain != null)
                            {
                                hasCover = true;
                                break;
                            }
                            if (possibleCover != null &&
                                possibleCover.Entity != null &&
                                !possibleCover.Entity.IsDynamic)
                            {
                                hasCover = true;
                                break;
                            }
                        }
                    }

                    if (!hasCover && actorDamage != null)
                    {
                        actorDamage.TakeDamage((int)(MathHelper.Lerp(1.0f, 0.25f, distance / mBlastRadius) * mDamage));
                    }

                    if (!hasCover && actorCollidable != null && actorCollidable.IsDynamic && !(actorCollidable.Entity.CollisionInformation.CollisionRules.Personal.HasFlag(BEPUphysics.CollisionRuleManagement.CollisionRule.NoSolver)))
                    {
                        blastToActorCenter.Normalize();
                        blastToActorCenter = blastToActorCenter * 1200; // Math.Min(5000.0f / (distance + 1.0f));
                        actorCollidable.Entity.ApplyLinearImpulse(ref blastToActorCenter);
                        if (!actorCollidable.Entity.ActivityInformation.IsActive)
                        {
                            actorCollidable.Entity.ActivityInformation.Activate();
                        }
                    }
                }
            }

            DynamicCollisionComponent dcc = Owner.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics);
            Vector3            myVelocity = BepuConverter.Convert(dcc.Entity.LinearVelocity);
            Actor              fireball   = GameResources.ActorManager.SpawnTemplate("ExplosionFire");
            TransformComponent fireXForm  = fireball.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform);

            fireXForm.Translation = myXForm.Translation;
            ExplosionFire fireBehavior = fireball.GetBehavior <ExplosionFire>();

            fireBehavior.Emit(myVelocity);
            Actor smoke = GameResources.ActorManager.SpawnTemplate("ExplosionSmoke");
            TransformComponent smokeXForm = smoke.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform);

            smokeXForm.Translation = myXForm.Translation;
            ExplosionSmoke smokeBehavior = smoke.GetBehavior <ExplosionSmoke>();

            smokeBehavior.Emit(myVelocity);

            Owner.Despawn();
        }