Exemple #1
0
            public TextureMissile(GameModel model, Vector3 target, GameTexture carriedTex, Player p, GameModel targetModel, bool followPlayer = true)
            {
                FollowPlayer     = followPlayer;
                player           = p;
                this.targetModel = targetModel;

                Model      = model;
                Target     = target;
                CarriedTex = carriedTex;

                Vector3 up      = Vector3.UnitZ;
                Vector3 forward = Target - MathConverter.Convert(model.Entity.Position);

                forward.Normalize();
                Vector3 left = Vector3.Cross(up, forward);

                BEPUutilities.Matrix3x3 m = new BEPUutilities.Matrix3x3();
                m.Left    = left;
                m.Forward = forward;
                m.Up      = up;
                Model.Entity.OrientationMatrix = m;

                linearMotor = new SingleEntityLinearMotor(model.Entity, model.Entity.Position);
                linearMotor.Settings.Mode       = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
                linearMotor.Settings.Servo.Goal = Target;
                linearMotor.IsActive            = true;
            }
Exemple #2
0
        public void Update(GameTime gameTime, List <FluidVolume> water)
        {
            character.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

            bool underwaterLastFrame = underwater;

            underwater = false;
            foreach (FluidVolume f in water)
            {
                if (f.BoundingBox.Max.X > Renderer.Camera.Position.X && f.BoundingBox.Min.X < Renderer.Camera.Position.X &&
                    f.BoundingBox.Max.Y > Renderer.Camera.Position.Y && f.BoundingBox.Min.Y < Renderer.Camera.Position.Y &&
                    f.BoundingBox.Max.Z > Renderer.Camera.Position.Z && f.BoundingBox.Min.Z < Renderer.Camera.Position.Z)
                {
                    underwater = true;
                    break;
                }
            }
            if (underwater != underwaterLastFrame)
            {
                Program.Game.Loader.Splash.Play();
            }

            targetedTexture = null;
            GameModel targetedModel = null;
            //Find the earliest ray hit
            RayCastResult raycastResult;

            if (GameManager.Space.RayCast(new BEPUutilities.Ray(Renderer.Camera.Position, Renderer.Camera.WorldMatrix.Forward), 10, RayCastFilter, out raycastResult))
            {
                var entityCollision = raycastResult.HitObject as EntityCollidable;
                if (entityCollision != null && entityCollision.Entity.Tag is GameModel)
                {
                    var tag = entityCollision.Entity.Tag as GameModel;
                    targetedModel = tag;
                    if (tag.CanBeRipped && !tag.Texture.Wireframe)
                    {
                        targetedTexture = tag.Texture;
                    }
                }
            }

            int indexDirection = 0;

            if (Input.ControlScheme == ControlScheme.Keyboard)
            {
                int mouseScroll = Input.MouseState.ScrollWheelValue - Input.MouseLastFrame.ScrollWheelValue;
                indexDirection = -Math.Sign(mouseScroll);
            }
            else
            {
                if (Input.CheckXboxJustPressed(Microsoft.Xna.Framework.Input.Buttons.LeftShoulder))
                {
                    indexDirection = -1;
                }
                else if (Input.CheckXboxJustPressed(Microsoft.Xna.Framework.Input.Buttons.RightShoulder))
                {
                    indexDirection = 1;
                }
            }
            if (indexDirection != 0)
            {
                int originalIndex = textureIndex;
                do
                {
                    if (textureIndex == 0 && indexDirection == -1)
                    {
                        textureIndex = 4;
                    }
                    else
                    {
                        textureIndex = (textureIndex + indexDirection) % heldTextures.Length;
                    }
                } while(heldTextures[textureIndex] == null && originalIndex != textureIndex);
            }

            if (targetedModel != null && canTakeTextures && targetedTexture != null &&
                ((Input.ControlScheme == ControlScheme.Keyboard && Input.CheckForMouseJustReleased(1)) ||
                 (Input.ControlScheme == ControlScheme.XboxController && Input.CheckXboxJustPressed(Microsoft.Xna.Framework.Input.Buttons.LeftTrigger))))
            {
                GameTexture t        = targetedModel.RipTexture();
                GameTexture burstTex = new GameTexture("Burst", t.ActualTexture,
                                                       new PhysicsProperties(0, 0.5f, 0.5f, 10, false, true),
                                                       new GameProperties(null, null, false, null, null));
                GameModel m = new GameModel(targetedModel.Entity.Position, missileModel, burstTex, false);
                m.Entity.CollisionInformation.CollisionRules.Group = noCollisionGroup;
                CollisionRules.AddRule(m.Entity, character.CharacterController.Body, CollisionRule.NoSolver);
                TextureMissile missile = new TextureMissile(m, character.CharacterController.Body.Position, t, this, targetedModel);
                missiles.Add(missile);
                Renderer.Add(missile.Model);
                GameManager.Space.Add(missile);
            }
            else if (heldTextures[textureIndex] != null && targetedModel != null && targetedTexture == null &&
                     ((Input.ControlScheme == ControlScheme.Keyboard && Input.CheckForMouseJustReleased(2)) ||
                      (Input.ControlScheme == ControlScheme.XboxController && Input.CheckXboxJustPressed(Microsoft.Xna.Framework.Input.Buttons.RightTrigger))))
            {
                Program.Game.Loader.ApplyTexture.Play();
                GameTexture t        = heldTextures[textureIndex];
                GameTexture burstTex = new GameTexture("Burst", t.ActualTexture,
                                                       new PhysicsProperties(0, 0.5f, 0.5f, 10, false, true),
                                                       new GameProperties(null, null, false, null, null));
                GameModel m = new GameModel(character.CharacterController.Body.Position, missileModel, burstTex, false);
                m.Entity.CollisionInformation.CollisionRules.Group = noCollisionGroup;
                CollisionRules.AddRule(m.Entity, targetedModel.Entity, CollisionRule.NoSolver);
                TextureMissile missile = new TextureMissile(m, targetedModel.Entity.Position, t, this, targetedModel, false);
                missiles.Add(missile);
                Renderer.Add(missile.Model);
                GameManager.Space.Add(missile);

                heldTextures[textureIndex] = null;
                compressTextureList();
            }
            else if ((Input.ControlScheme == ControlScheme.Keyboard && (Input.CheckForMouseJustReleased(1)) || Input.CheckForMouseJustReleased(2)) ||
                     (Input.ControlScheme == ControlScheme.XboxController && (Input.CheckXboxJustPressed(Microsoft.Xna.Framework.Input.Buttons.LeftTrigger) ||
                                                                              Input.CheckXboxJustPressed(Microsoft.Xna.Framework.Input.Buttons.RightTrigger))))
            {
                Program.Game.Loader.InvalidApplicationRemovalGrab.Play();
            }
        }