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


C# Rectangle.topOf方法代码示例

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


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

示例1: Update

        public void Update(GameTime gametime, int side, List<Platform> Plats, int heightScreen)
        {
            heroRec = new Rectangle((int)position.X, (int)position.Y, frameWidth, frameHeight);

            foreach (Platform plat in Plats)
            {
                if (heroRec.topOf(plat.PlatRec))
                {
                    velocity.Y = 0;
                }
            }

            int k = 0;
            for (int i1 = 0; i1 < Plats.Count(); i1++)
            {
                if (!heroRec.topOf(Plats[i1].PlatRec))
                    k++;
            }
            if ((k == Plats.Count()) && (heroRec.Bottom < heightScreen))
            {
                velocity.Y += 5f;
                k = 0;
            }
            else
                velocity.Y = 0;

            if (!isFight)
            {
                timer += (float)gametime.ElapsedGameTime.TotalMilliseconds;
                if (timer > interval)
                {
                    animRec = new Rectangle(currentFrame * frameWidth, 0, frameWidth, frameHeight);
                    original_Pos = new Vector2(animRec.Width / 2, animRec.Height / 2);
                    position = position + velocity;

                    if (isRight > 9)
                    {
                        goesRight = true;
                    }
                    if (isRight < 0)
                    {
                        goesRight = false;
                    }

                    if (goesRight)
                    {
                        Right(gametime);
                        velocity.X = 10;
                        isRight--;
                    }
                    else if (!goesRight)
                    {
                        Left(gametime);
                        velocity.X = -10;
                        isRight++;
                    }
                    timer = 0;
                }
                if (side == 1)
                    position.X -= 3;
                if (side == -1)
                    position.X += 3;

            }
        }
开发者ID:AlexZavkn,项目名称:LabWorks,代码行数:65,代码来源:Enemy.cs

示例2: Update

        public void Update(GameTime gametime, bool isOnSide, List<Platform>Plats, int heightScreen, int widthScreen, SoundEffect jump,SoundEffect fight, SoundEffect run )
        {
            animRec = new Rectangle(currentFrame * frameWidth, 0, frameWidth, frameHeight);
            original_Pos = new Vector2(animRec.Width / 2, animRec.Height / 2);
            position = position + velocity;
            heroRec = new Rectangle((int)position.X, (int)position.Y, frameWidth, frameHeight);
            healthRec = new Rectangle(widthScreen*(2/7), heightScreen*(1/15), live / 10, 30);

            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                right = true;
                Right(gametime);
                velocity.X = widthScreen/240;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                right = false;
                Left(gametime);
                velocity.X = -widthScreen / 240;
            }
            else
            {
                velocity.X = 0f;
            }

            if ((Keyboard.GetState().IsKeyDown(Keys.R)) && (alreadyJump == false))
            {
                position.Y -= (float)( heightScreen / 10);
                alreadyJump = true;
                velocity.Y -= (float)( heightScreen / 20);
                jump.Play();
            }
            if (alreadyJump == true)
            {
                int i = 1;
                velocity.Y += ((float)(heightScreen/120))*i;
            }

            if (position.Y + animRec.Height >= heightScreen*(1.155f))
            {
                alreadyJump = false;
            }

            if (alreadyJump == false)
            {
                velocity.Y = 0f;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if (right)
                    ThrowingRight(gametime);
                else
                    ThrowingLeft(gametime);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F) && State.IsKeyUp(Keys.F))
            {
                fight.Play();
                if (right)
                    FightRight(gametime);
                else
                    FightLeft(gametime);

            }

            State = Keyboard.GetState();

            foreach (Platform plat in Plats)
            {
                if (heroRec.topOf(plat.PlatRec))
                {
                    velocity.Y = 0;
                    alreadyJump = false;
                }
            }

            int k = 0;
            for (int i1 = 0; i1 < Plats.Count(); i1++)
            {
                if (!heroRec.topOf(Plats[i1].PlatRec))
                    k++;
                if ((k == Plats.Count()) && (heroRec.Bottom < heightScreen * (7 / 6)) && (!alreadyJump))
                {
                    velocity.Y += (heightScreen/64f);
                    alreadyJump = true;
                    k = 0;
                }
            }
        }
开发者ID:AlexZavkn,项目名称:LabWorks,代码行数:90,代码来源:Hero.cs


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