当前位置: 首页>>代码示例>>C#>>正文


C# BoundingBox.Intersects方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.BoundingBox.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingBox.Intersects方法的具体用法?C# BoundingBox.Intersects怎么用?C# BoundingBox.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.BoundingBox的用法示例。


在下文中一共展示了BoundingBox.Intersects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: colisao

        public void colisao()
        {
            Vector3 A = new Vector3(screen.player.positionPlayer.X+5, screen.player.positionPlayer.Y+10, 0);
            Vector3 B = new Vector3(screen.player.positionPlayer.X + 44, screen.player.positionPlayer.Y + screen.player.imgPlayer.Height - 13, 0);

            Vector3 C = new Vector3(posicao.X, posicao.Y, 0);
            Vector3 D = new Vector3(posicao.X + largura, posicao.Y + image.Height, 0);

            BoundingBox boxPlayer = new BoundingBox(A, B);
            BoundingBox boxEnemy = new BoundingBox(C, D);

            if (boxEnemy.Intersects(boxPlayer))
            {
                screen.removeComponent(this);
                screen.addComponent(new Explosao(mygame, C + new Vector3(0, 10, 0), 1, screen));
                screen.player.hp--;
                if (screen.player.hp < 0) {
                    screen.addComponent(new Explosao(mygame, new Vector3(screen.player.positionPlayer.X, screen.player.positionPlayer.Y, 0), 2, screen));
                    screen.player.vida--;
                    screen.player.hp = 5;
                }
                if(screen.player.vida < 0){
                    screen.removeComponent(screen.player);
                    mygame.setScreen(new ScreenSplash(mygame));
                }

            }
        }
开发者ID:rodrigocamina,项目名称:spaceshooterunivali2011,代码行数:28,代码来源:TiroMissel.cs

示例2: CheckInteractables

        private bool CheckInteractables(GameObject source, ref BoundingBox boundingBox, Vector3 lookVector)
        {
            bool failMove = false;

            // Check against all the interactive objects
            foreach (GameObject target in CurrentLevel.Collidables)
            {
                IActivatable activatable = target as IActivatable;

                if (activatable == null)
                    continue;

                if (!boundingBox.Intersects (TryGetOrStoreBox (target)))
                {
                    if (source.Tracking.Contains (target.ID))
                    {
                        activatable.Deactivate (source);
                        source.Tracking.Remove (target.ID);
                    }

                    continue;
                }

                activatable.Activate (source, lookVector);
                source.Tracking.Add (target.ID);

                if (target.Dense)
                    failMove = true;
            }

            return failMove;
        }
开发者ID:chillerman91,项目名称:GameAiChrisDaniel,代码行数:32,代码来源:GameState.Gamelogic.cs

示例3: VisitTree

 public static void VisitTree(OctCell root, BoundingBox box, Action<OctCell> callback)
 {
     if (box.Intersects(root.Bounds))
     {
         if (root.Leaf) callback(root);
         else foreach (var child in root.Children) VisitTree(child, box, callback);
     }
 }
开发者ID:Blecki,项目名称:GemgineCore,代码行数:8,代码来源:OctTree.cs

示例4: BuildTree

 public static void BuildTree(OctCell root, BoundingBox box, Action<OctCell> forLeaves, float leafSize)
 {
     if (box.Intersects(root.box))
     {
         if ((root.box.Max.X - root.box.Min.X) <= leafSize)
         {
             if (root.contents == null) root.contents = new List<OctNode>();
             forLeaves(root);
         }
         else
         {
             if (root.children == null) root.children = splitCell(root);
             foreach (var child in root.children) BuildTree(child, box, forLeaves, leafSize);
         }
     }
 }
开发者ID:hvp,项目名称:Gemgine,代码行数:16,代码来源:OctTree.cs

示例5: Update

        public int[] Update(Vector2 characterPosition, Texture2D characterTexture)
        {
            int counter = 0;
            List<int> l = new List<int>();
            int[] IDsToBeReturned;

            BoundingBox characterBox = new BoundingBox(new Vector3(characterPosition.X, characterPosition.Y, 0),
                new Vector3(characterPosition.X + characterTexture.Width, characterPosition.Y + characterTexture.Height, 0));
            for (int i = 0; i < triggerArray.Length; i++)
            {
                if (characterBox.Intersects(triggerArray[i].BB))
                {
                    counter++;
                    for (int j = 0; j < triggerArray[i].IDsToBeActivated.Length; j++)
                    {
                        int x = triggerArray[i].IDsToBeActivated[j];
                        l.Add(x);
                    }
                }
            }
            IDsToBeReturned = l.ToArray();
            return IDsToBeReturned;
        }
开发者ID:Cnidarias,项目名称:RageGame,代码行数:23,代码来源:Triggers.cs

示例6: TryTalk

 protected override void TryTalk()
 {
   switch (this.PlayerManager.Action)
   {
     case ActionType.Idle:
     case ActionType.Walking:
     case ActionType.Running:
     case ActionType.Sliding:
       if (this.PlayerManager.Background || !this.SpeechManager.Hidden || this.Npc.ActorType == ActorType.Owl && (this.OwlInvisible || this.CurrentAction == NpcAction.TakeOff || this.CurrentAction == NpcAction.Fly))
         break;
       if (this.Npc.CustomSpeechLine == null)
       {
         if (this.InputManager.CancelTalk != FezButtonState.Pressed)
           break;
         Vector3 vector3_1 = Vector3.UnitY + (FezMath.SideMask(this.CameraManager.Viewpoint) + FezMath.DepthMask(this.CameraManager.Viewpoint)) * 1.5f;
         BoundingBox boundingBox = new BoundingBox(this.Position - vector3_1, this.Position + vector3_1);
         Vector3 mask = FezMath.GetMask(FezMath.VisibleAxis(this.CameraManager.Viewpoint));
         Vector3 vector3_2 = FezMath.ForwardVector(this.CameraManager.Viewpoint);
         Ray ray = new Ray()
         {
           Position = this.PlayerManager.Center * (Vector3.One - mask) - vector3_2 * this.LevelManager.Size,
           Direction = vector3_2
         };
         float? nullable = boundingBox.Intersects(ray);
         if (!nullable.HasValue || this.TestObstruction(ray.Position, nullable.Value))
           break;
       }
       this.Talk();
       break;
   }
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:31,代码来源:GameNpcState.cs

示例7: CheckBallCollisions

        /// <summary>
        /// Check ball collisions
        /// </summary>
        void CheckBallCollisions(float moveFactorPerSecond)
        {
            // Check top, left and right screen borders
            float MinYPos = 0.0235f;
            if (ballPosition.Y < MinYPos)
            {
                ballSpeedVector.Y = -ballSpeedVector.Y;
                // Move ball back into screen space
                if (ballPosition.X < MinYPos)
                    ballPosition.X = MinYPos;
                // Play hit sound
                soundBank.PlayCue("PongBallHit");
            } // if
            float MinXPos = 0.018f;
            if (ballPosition.X < MinXPos ||
                ballPosition.X > 1 - MinXPos)
            {
                ballSpeedVector.X = -ballSpeedVector.X;
                // Move ball back into screen space
                if (ballPosition.X < MinXPos)
                    ballPosition.X = MinXPos;
                if (ballPosition.X > 1 - MinXPos)
                    ballPosition.X = 1 - MinXPos;
                // Play hit sound
                soundBank.PlayCue("PongBallHit");
            } // if

            // Check for collisions with the paddles
            // Construct bounding boxes to use the intersection helper method.
            Vector2 ballSize = new Vector2(24 / 1024.0f, 24 / 768.0f);
            BoundingBox ballBox = new BoundingBox(
                new Vector3(ballPosition.X - ballSize.X / 2, ballPosition.Y - ballSize.Y / 2, 0),
                new Vector3(ballPosition.X + ballSize.X / 2, ballPosition.Y + ballSize.Y / 2, 0));
            Vector2 paddleSize = new Vector2(
                GamePaddleRect.Width / 1024.0f, GamePaddleRect.Height / 768.0f);
            BoundingBox paddleBox = new BoundingBox(
                new Vector3(paddlePosition - paddleSize.X / 2, 0.95f-paddleSize.Y * 0.7f, 0),
                new Vector3(paddlePosition + paddleSize.X / 2, 0.95f, 0));

            // Ball hit paddle?
            if (ballBox.Intersects(paddleBox))
            {
                // Bounce off in the direction vector from the paddle
                ballSpeedVector.X += (ballPosition.X - paddlePosition) / (MinXPos * 3);
                // Max to -1 and +1
                if (ballSpeedVector.X < -1)
                    ballSpeedVector.X = -1;
                if (ballSpeedVector.X > 1)
                    ballSpeedVector.X = 1;
                // Bounce of the paddle
                ballSpeedVector.Y = -1;// -ballSpeedVector.Y;
                // Move away from the paddle
                ballPosition.Y -= moveFactorPerSecond * BallSpeedMultiplicator;
                // Normalize vector
                ballSpeedVector.Normalize();
                // Play sound
                soundBank.PlayCue("PongBallHit");
            } // if

            // Ball hits any block?
            for (int y = 0; y < NumOfRows; y++)
                for (int x = 0; x < NumOfColumns; x++)
                    if (blocks[x, y])
                    {
                        // Collision check
                        if (ballBox.Intersects(blockBoxes[x, y]))
                        {
                            // Kill block
                            blocks[x, y] = false;
                            // Add score
                            score++;
                            // Update title
                            Window.Title =
                                "XnaBreakout - Level " + (level + 1) + " - Score " + score;
                            // Play sound
                            soundBank.PlayCue("BreakoutBlockKill");
                            // Bounce ball back, but first find out which side we hit.
                            // Start with left/right borders.
                            if (Math.Abs(blockBoxes[x, y].Max.X - ballBox.Min.X) <
                                moveFactorPerSecond)
                            {
                                ballSpeedVector.X = Math.Abs(ballSpeedVector.X);
                                // Also move back a little
                                ballPosition.X += (ballSpeedVector.X < 0 ? -1 : 1) *
                                    moveFactorPerSecond;
                            } // else
                            else if (Math.Abs(blockBoxes[x, y].Min.X - ballBox.Max.X) <
                                moveFactorPerSecond)
                            {
                                ballSpeedVector.X = -Math.Abs(ballSpeedVector.X);
                                // Also move back a little
                                ballPosition.X += (ballSpeedVector.X < 0 ? -1 : 1) *
                                    moveFactorPerSecond;
                            } // else
                            // Now check top/bottom borders
                            else if (Math.Abs(blockBoxes[x, y].Max.Y - ballBox.Min.Y) <
                                moveFactorPerSecond)
//.........这里部分代码省略.........
开发者ID:kiichi7,项目名称:SpeedyRacerContentAndSourceCode,代码行数:101,代码来源:BreakoutGame.cs

示例8: checkExperienceGrabs

        private void checkExperienceGrabs()
        {
            foreach (Character player in currentLevel.players)
            {
                BoundingBox playerbox = new BoundingBox(new Vector3(player.getX(), player.getY() - player.height, Constants.CHARACTER_DEPTH),
                    new Vector3(player.getX() + player.width, player.getY(), Constants.CHARACTER_DEPTH));
                foreach (ExperienceOrb exp in expOrbs)
                {
                    if (exp.isAlive)
                    {
                        BoundingBox expBox = new BoundingBox(new Vector3(exp.position.X, exp.position.Y - exp.height, Constants.CHARACTER_DEPTH),
                            new Vector3(exp.position.X + exp.width, exp.position.Y, Constants.CHARACTER_DEPTH));

                        if (playerbox.Intersects(expBox))
                        {
                            ((UserControlledCharacter)player).applyExperience(exp);
                            exp.isAlive = false;
                            break;
                        }
                    }
                }
            }
        }
开发者ID:bmaxwell921,项目名称:LandOfAmbrosia,代码行数:23,代码来源:LevelManager.cs

示例9: CheckCollision

 // ----------------------- Feng ------------------------------------------------
 // check if the rocket runs into a hazard
 private void CheckCollision(Hazard theHazard)
 {
     // wrap the hazard and car with BoundingBox
     BoundingBox aHazardBox = new BoundingBox(new Vector3(theHazard.Position.X, theHazard.Position.Y, 0), new Vector3(theHazard.Position.X + (mHazard.Width * .5f), theHazard.Position.Y + ((mHazard.Height) * .5f), 0));
     BoundingBox aCarBox = new BoundingBox(new Vector3(mCarPosition.X, mCarPosition.Y, 0), new Vector3(mCarPosition.X + (mCar.Width * .8f), mCarPosition.Y + (mCar.Height * .8f), 0));
     BoundingBox aCarBoxPerfect = new BoundingBox(new Vector3(mCarPosition.X, mCarPosition.Y, 0), new Vector3(mCarPosition.X + (mCar.Width * .8f), mCarPosition.Y + (mCar.Height * .8f) * 0.05f, 0));
     BoundingBox aHazardBoxPerfect = new BoundingBox(new Vector3(theHazard.Position.X, theHazard.Position.Y + (mHazard.Height * .25f), 0), new Vector3(theHazard.Position.X + (mHazard.Width * .5f), theHazard.Position.Y + ((mHazard.Height) * .5f), 0));
     if (aHazardBox.Intersects(aCarBox) == true) // collided
     {
         if (aHazardBoxPerfect.Intersects(aCarBoxPerfect) == true)
         {
             mScore += 2;
             mHazardsPerfect++;
             theHazard.sign = Hazard.Sign.Perfect;
         }
         else
         {
             mScore++;
             mHazardsGood++;
             theHazard.sign = Hazard.Sign.Good;
         }
         mHazardsCombo++;
         hitSE.Play();
         theHazard.Visible = false;
         theHazard.SignDisplayTime = (double)mHazard.Height / mVelocityY; // show "Perfect" or "Good" in the game scene
     }
 }
开发者ID:Xivid,项目名称:RhythmHit,代码行数:29,代码来源:Game1.cs

示例10: BlockLookedAt

        /// <summary>
        /// This takes as input a position and a Ray and a maximum distance, then finds
        /// the first Block impacted by the Ray on this map, if any.  Return types are
        /// through a large number of "out" parameters.  Note it will never return the
        /// cell which contains the start of the Ray.
        /// 
        /// Note: if successful is FALSE, the returned data will be garbage (since it's
        /// not easily nullable).  So be aware of that.
        /// </summary>
        /// <param name="chunkX">The chunk(X) position to start the Ray from.  This will be
        /// set to the chunk(X) position we end on.</param>
        /// <param name="chunkZ">The chunk(Z) position to start the Ray from.  This will be
        /// set to the chunk(Z) position we end on.</param>
        /// <param name="lookRay">The Ray to look along.</param>
        /// <param name="maxDistance">The maximum distance along the ray that collisions
        /// will be considered.  Uses the MAX distance.</param>
        /// <param name="requireVisible">Whether or not to skip invisible blocks.</param>
        /// <param name="requireImpassable">Whether or not to skip passable blocks.</param>
        /// <param name="foundBlock">The block that was actually found.</param>
        /// <param name="blockPosition">The in-chunk (integer) position of the block that was found.</param>
        /// <param name="faceTouched">The face that was first touched by the Ray.</param>
        /// <param name="successful">Whether ot not anything was found</param>
        public void BlockLookedAt(ref int chunkX, ref int chunkZ, Ray lookRay, int maxDistance,
            bool requireVisible, bool requireImpassable,
            out Block foundBlock, out Point3 blockPosition,
            out Face faceTouched, out bool successful)
        {
            if (lookRay.Position.Y < 0 || lookRay.Position.Y >= GameConstants.CHUNK_Y_HEIGHT)
                throw new ArgumentException("Can't cast rays from offscreen!");

            successful = false;

            blockPosition = Point3.RoundDown(lookRay.Position);
            BoundingBox blockBounds = new BoundingBox(
                new Vector3(blockPosition.X, blockPosition.Y, blockPosition.Z),
                new Vector3(blockPosition.X + 1, blockPosition.Y + 1, blockPosition.Z + 1));

            if (!blockBounds.Intersects(lookRay).HasValue)
                throw new NotImplementedException();

            int xChange = Numerical.sign(lookRay.Direction.X);
            int yChange = Numerical.sign(lookRay.Direction.Y);
            int zChange = Numerical.sign(lookRay.Direction.Z);

            faceTouched = Face.FRONT;
            foundBlock = new Block();

            while (blockPosition.Y >= 0 && blockPosition.Y < GameConstants.CHUNK_Y_HEIGHT)
            {
                bool canMoveX = (xChange != 0);
                bool canMoveY = (yChange != 0 && (blockPosition.Y + yChange >= 0 && blockPosition.Y + yChange < GameConstants.CHUNK_Y_HEIGHT));
                bool canMoveZ = (zChange != 0);

                bool hitX = false;
                bool hitY = false;
                bool hitZ = false;

                BoundingBox oldBox = blockBounds;

                int hits = 0;

                #region Move and count hits...
                if (canMoveX)
                {
                    BoundingBox box = new BoundingBox(oldBox.Min + new Vector3(xChange, 0, 0), oldBox.Max + new Vector3(xChange, 0, 0));

                    float? result = box.Intersects(lookRay);
                    hitX = result.HasValue;

                    if (hitX)
                    {
                        hits++;

                        blockPosition.X += xChange;
                        faceTouched = (xChange < 0 ? Face.RIGHT : Face.LEFT);
                        blockBounds = box;

                        if (Math.Abs(blockPosition.X - lookRay.Position.X) > maxDistance) return;
                    }
                }

                if (canMoveY)
                {
                    BoundingBox box = new BoundingBox(oldBox.Min + new Vector3(0, yChange, 0), oldBox.Max + new Vector3(0, yChange, 0));

                    float? result = box.Intersects(lookRay);
                    hitY = result.HasValue;

                    if (hitY)
                    {
                        hits++;

                        blockPosition.Y += yChange;
                        faceTouched = (yChange < 0 ? Face.TOP : Face.BOTTOM);
                        blockBounds = box;

                        if (Math.Abs(blockPosition.Y - lookRay.Position.Y) > maxDistance) return;
                    }
                }

//.........这里部分代码省略.........
开发者ID:rodya-mirov,项目名称:Voxelist,代码行数:101,代码来源:Map.cs

示例11: Update


//.........这里部分代码省略.........

            #endregion

            #region Block Interaction

            if (lastInteract.HasValue)
            {
                ushort lastBlock = localChunkCache.GetBlock(lastInteract.Value);
                localChunkCache.SetBlock(lastInteract.Value, 0);

                if (lastBlock != 0)
                {
                    var blockDefinition = DefinitionManager.Instance.GetBlockDefinitionByIndex(lastBlock);

                    var slot = Player.Inventory.Where(s => s.Definition == blockDefinition && s.Amount < blockDefinition.StackLimit).FirstOrDefault();

                    // Wenn noch kein Slot da ist oder der vorhandene voll, dann neuen Slot
                    if (slot == null || slot.Amount >= blockDefinition.StackLimit)
                    {
                        slot = new InventorySlot()
                        {
                            Definition = blockDefinition,
                            Amount = 0
                        };
                        Player.Inventory.Add(slot);
                    }
                    slot.Amount++;
                }
                lastInteract = null;
            }

            if (lastApply.HasValue)
            {
                if (ActiveTool != null)
                {
                    Index3 add = new Index3();
                    switch (lastOrientation)
                    {
                        case OrientationFlags.SideWest: add = new Index3(-1, 0, 0); break;
                        case OrientationFlags.SideEast: add = new Index3(1, 0, 0); break;
                        case OrientationFlags.SideSouth: add = new Index3(0, -1, 0); break;
                        case OrientationFlags.SideNorth: add = new Index3(0, 1, 0); break;
                        case OrientationFlags.SideBottom: add = new Index3(0, 0, -1); break;
                        case OrientationFlags.SideTop: add = new Index3(0, 0, 1); break;
                    }

                    if (ActiveTool.Definition is IBlockDefinition)
                    {
                        IBlockDefinition definition = ActiveTool.Definition as IBlockDefinition;

                        Index3 idx = lastApply.Value + add;
                        var boxes = definition.GetCollisionBoxes(localChunkCache, idx.X, idx.Y, idx.Z);
                        float gap = 0.01f;
                        var playerBox = new BoundingBox(
                            new Vector3(
                                Player.Position.GlobalBlockIndex.X + Player.Position.BlockPosition.X - Player.Radius + gap,
                                Player.Position.GlobalBlockIndex.Y + Player.Position.BlockPosition.Y - Player.Radius + gap,
                                Player.Position.GlobalBlockIndex.Z + Player.Position.BlockPosition.Z + gap),
                            new Vector3(
                                Player.Position.GlobalBlockIndex.X + Player.Position.BlockPosition.X + Player.Radius - gap,
                                Player.Position.GlobalBlockIndex.Y + Player.Position.BlockPosition.Y + Player.Radius - gap,
                                Player.Position.GlobalBlockIndex.Z + Player.Position.BlockPosition.Z + Player.Height - gap)
                            );

                        // Nicht in sich selbst reinbauen
                        bool intersects = false;
                        foreach (var box in boxes)
                        {
                            var newBox = new BoundingBox(idx + box.Min, idx + box.Max);
                            if (newBox.Intersects(playerBox))
                                intersects = true;
                        }

                        if (!intersects)
                        {
                            localChunkCache.SetBlock(idx, DefinitionManager.Instance.GetBlockDefinitionIndex(definition));

                            ActiveTool.Amount--;
                            if (ActiveTool.Amount <= 0)
                            {
                                Player.Inventory.Remove(ActiveTool);
                                ActiveTool = null;
                            }
                        }
                    }

                    // TODO: Fix Interaction ;)
                    //ushort block = _manager.GetBlock(lastApply.Value);
                    //IBlockDefinition blockDefinition = BlockDefinitionManager.GetForType(block);
                    //IItemDefinition itemDefinition = ActiveTool.Definition;

                    //blockDefinition.Hit(blockDefinition, itemDefinition.GetProperties(null));
                    //itemDefinition.Hit(null, blockDefinition.GetProperties(block));
                }

                lastApply = null;
            }

            #endregion
        }
开发者ID:ManuelHu,项目名称:octoawesome,代码行数:101,代码来源:ActorHost.cs

示例12: GetMostLikelyDesignation

        public BuildRoomOrder GetMostLikelyDesignation(Voxel v)
        {
            BoundingBox larger = new BoundingBox(v.GetBoundingBox().Min - new Vector3(0.5f, 0.5f, 0.5f), v.GetBoundingBox().Max + new Vector3(0.5f, 0.5f, 0.5f));

            return (from room in BuildDesignations
                from buildDesignation in room.VoxelOrders
                where larger.Intersects(buildDesignation.Voxel.GetBoundingBox())
                select room).FirstOrDefault();
        }
开发者ID:scorvi,项目名称:dwarfcorp,代码行数:9,代码来源:RoomBuilder.cs

示例13: IsInViewFrustumWithNoFarClipping

        bool IsInViewFrustumWithNoFarClipping(BoundingBox box, BoundingFrustum viewFrustum)
        {
            // TODO: this causes a lot of allocations - maybe use a extension method with custom iterator?
            // Actually, the lambda below also generates allocations.  Maybe unroll this?  Not sure what
            // perf improvement that would have, if any
            var planes = new [] { viewFrustum.Near, viewFrustum.Left, viewFrustum.Right, viewFrustum.Top, viewFrustum.Bottom};

            return planes.All(plane => box.Intersects(plane) != PlaneIntersectionType.Front);
        }
开发者ID:GunioRobot,项目名称:GenesisEngine,代码行数:9,代码来源:QuadMesh.cs

示例14: CheckForCollision

        void CheckForCollision()
        {
            BoundingBox bb1 = new BoundingBox(new Vector3(spritePosition1.X - (sprite1Width / 2), spritePosition1.Y - (sprite1Height / 2), 0), new Vector3(spritePosition1.X + (sprite1Width / 2), spritePosition1.Y + (sprite1Height / 2), 0));

            BoundingBox bb2 = new BoundingBox(new Vector3(spritePosition2.X - (sprite2Width / 2), spritePosition2.Y - (sprite2Height / 2), 0), new Vector3(spritePosition2.X + (sprite2Width / 2), spritePosition2.Y + (sprite2Height / 2), 0));

            if (bb1.Intersects(bb2))
            {
                soundEffect.Play();
            }

        }
开发者ID:JackieWang,项目名称:Exercise.WP7,代码行数:12,代码来源:Game1.cs

示例15: Update

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            X = "X:";
            X += modelPosition.X;
            Y = "Y:";
            Y += modelPosition.Y;
            Z = "Z:";
            Z += modelPosition.Z;
            boundingBoxChar = new BoundingBox(new Vector3(modelPosition.X - 10, modelPosition.Y, modelPosition.Z - 10), new Vector3(modelPosition.X + 10, modelPosition.Y + 50, modelPosition.Z + 10));
            BoundingBoxBlock = new BoundingBox(new Vector3(- 110, -10, - 110), new Vector3(110, 50, 110));
            if (boundingBoxChar.Intersects(BoundingBoxBlock))
            {
                if (modelPosition.Z <= -109)
                {
                    modelVelocity.Z -= 3;
                }
                if (modelPosition.Z >= 109)
                {
                    modelVelocity.Z += 3;
                }
                if (modelPosition.X <= -109)
                {
                    modelVelocity.X -= 3;
                }
                if (modelPosition.X >= 109)
                {
                    modelVelocity.X += 3;
                }
            }
            /*for(int i = 0; i < block.Meshes.Count; i++)
            {
                BoundingSphere c1BoundingSphere = block.Meshes[i].BoundingSphere;
                c1BoundingSphere.Center += modelPosition;
                for (int j = 0; j < myModel.Meshes.Count; j++)
                {
                    BoundingSphere c2BoundingSphere = myModel.Meshes[j].BoundingSphere;
                    c2BoundingSphere.Center += modelPosition;
                    if (!c1BoundingSphere.Intersects(c2BoundingSphere))
                    {
                        modelPosition.Z += 20;
                        break;
                    }
                }
            }*/

            // Get some input.
            UpdateInput(gameTime);

            // Add velocity to the current position.
            modelPosition += modelVelocity;

            // Bleed off velocity over time.
            modelVelocity *= 0.0f;

            base.Update(gameTime);
        }
开发者ID:rutger438,项目名称:Blasters,代码行数:59,代码来源:Blasters.cs


注:本文中的Microsoft.Xna.Framework.BoundingBox.Intersects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。