コード例 #1
0
        public GameTexture RipTexture()
        {
            if (Texture.Wireframe)
            {
                throw new InvalidOperationException("Can't rip a texture from a textureless model!");
            }
            if (!CanBeRipped)
            {
                throw new InvalidOperationException("Can't rip an unrippable texture!");
            }

            GameTexture output = Texture;

            output.GameProperties.OnTextureRipped(this);
            output.CurrentModel = null;
            Texture             = new GameTexture("Wireframe", Texture.ActualTexture)
            {
                Wireframe = true
            };
            Entity.AngularVelocity = Entity.LinearVelocity = Vector3.Zero;
            Program.Game.Loader.RemoveTexture.Play();
            return(output);
        }
コード例 #2
0
 public GameModel(Vector3 origin, Model m, GameTexture t, bool rippable = true)
     : this(null, origin, m, t, rippable)
 {
 }
コード例 #3
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();
            }
        }