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


C# MouseState.Position方法代码示例

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


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

示例1: Update

        public override void Update(GameTime gameTime)
        {
            if (player != Game1.localPlayer)
                return; // this puzzle only updates by its owner

            mouse = Mouse.GetState();
            if (mouse.LeftButton == ButtonState.Pressed && prevMouse.LeftButton == ButtonState.Released)
                leftClick.Play(gameTime, mouse.Position());

            Vector2 relativePos = Mouse.GetState().Position() - (drawRegion.Location.ToVector2());

            if (Game1.random.Next(0, 100) % 25 == 0)
            {
                if (Game1.random.Next(0, 1) == 0 && block1State == BlockState.Waiting)
                {
                    if(block1Rec.Right == backgroundRec.Right)
                        block1State = BlockState.MovingLeft;
                    else
                        block1State = BlockState.MovingRight;
                }
                else if (block2State == BlockState.Waiting)
                {
                    if(block2Rec.Right == backgroundRec.Right)
                        block2State = BlockState.MovingLeft;
                    else
                        block2State = BlockState.MovingRight;
                }
            }

            if (block1State == BlockState.MovingLeft)
            {
                if (block1Rec.Left <= backgroundRec.Left)
                {
                    block1Rec.X = backgroundRec.Left;
                    block1State = BlockState.Waiting;
                }
                else
                    block1Rec.X -= blockMoveSpeed;
            }
            else if (block1State == BlockState.MovingRight)
            {
                if (block1Rec.Right >= backgroundRec.Right)
                {
                    block1Rec.X = backgroundRec.Right - block1Rec.Width;
                    block1State = BlockState.Waiting;
                }
                else
                    block1Rec.X += blockMoveSpeed;
            }
            if (block2State == BlockState.MovingLeft)
            {
                if (block2Rec.Left <= backgroundRec.Left)
                {
                    block2Rec.X = backgroundRec.Left;
                    block2State = BlockState.Waiting;
                }
                else
                    block2Rec.X -= blockMoveSpeed;
            }
            else if (block2State >= BlockState.MovingRight)
            {
                if (block2Rec.Right == backgroundRec.Right)
                {
                    block2Rec.X = backgroundRec.Right - block2Rec.Width;
                    block2State = BlockState.Waiting;
                }
                else
                    block2Rec.X += blockMoveSpeed;
            }

            if (mouse.LeftButton == ButtonState.Pressed && ball1Rec.Contains(relativePos))
                ball1State = ClickedState.Clicked;
            else if (mouse.LeftButton == ButtonState.Pressed && ball2Rec.Contains(relativePos))
                ball2State = ClickedState.Clicked;
            else
            {
                ball1Rec = new Rectangle(4, 0, 22, 22);
                ball2Rec = new Rectangle(223, 128, 22, 22);
            }

            if (ball1State == ClickedState.Clicked)
            {
                ball1Rec.Location = new Point((int)relativePos.X - 11, (int)relativePos.Y - 11);

                if (ball1Rec.Bottom >= bottomWall1.Top && ball1Rec.Left <= bottomPart1.Right)
                {
                    if (ball1Rec.Left <= leftWall1.Right)
                        ball1Rec.X = leftWall1.Right;
                    ball1Rec.Y = bottomWall1.Top - 22;
                }
                else if (ball1Rec.Left >= bottomPart1.Right && ball1Rec.Bottom >= backgroundRec.Bottom)
                    ball1Rec.Y = backgroundRec.Bottom - 22;
                else if (ball1Rec.Top <= topWall1.Bottom && ball1Rec.Right >= topPart1.Left)
                {
                    if (ball1Rec.Left <= rightWall1.Left)
                        ball1Rec.Y = topWall1.Bottom;
                }
                else if (ball1Rec.Right <= topPart1.Left && ball1Rec.Top <= backgroundRec.Top)
                    ball1Rec.Y = backgroundRec.Top;
                if (ball1Rec.Left <= leftWall1.Right)
//.........这里部分代码省略.........
开发者ID:TAMUCC-cosc3325-team2,项目名称:TheTeamGame,代码行数:101,代码来源:DragCircleAvoidBlocks.cs

示例2: MouseAimVector

 public Vector2 MouseAimVector(MouseState ms, Vector2 relativeposition)
 {
     Vector2 ret;
     ret = this.Camera.ConvertScreenToWorld(ms.Position()) - relativeposition;
     ret.Normalize();
     return ret;
 }
开发者ID:nadams810,项目名称:axiosengine,代码行数:7,代码来源:AxiosGameScreen.cs

示例3: Update

        public override void Update(GameTime gameTime)
        {
            if (player != Game1.localPlayer)
                return; // this puzzle only updates by its owner
            countUpdates++;

            mouse = Mouse.GetState();

            Vector2 relativePos = Mouse.GetState().Position() - (drawRegion.Location.ToVector2());

            if (mouse.LeftButton == ButtonState.Pressed && prevMouse.LeftButton == ButtonState.Released)
            {
                leftClick.Play(gameTime, mouse.Position());
                foreach (Triangle tri in Triangles)
                    if (tri.Contains(relativePos) && tri.Stat == Status.Waiting)
                        tri.Stat = Status.Rotating;
            }

            foreach (Triangle tri in Triangles)
            {
                if (tri.Stat == Status.Waiting)
                {
                    switch (tri.Rot)
                    {
                        case Orientation.Right:
                            tri.Degrees = 90;
                            break;
                        case Orientation.Down:
                            tri.Degrees = 180;
                            break;
                        case Orientation.Up:
                            tri.Degrees = 0;
                            break;
                        case Orientation.Left:
                            tri.Degrees = 270;
                            break;
                    }
                }
                else if (tri.Stat == Status.Rotating)
                {
                    tri.Degrees = tri.Degrees + 5;
                    if (tri.Degrees % 90 == 0)
                    {
                        tri.Stat = Status.Waiting;
                        switch (tri.Degrees)
                        {
                            case 0:
                                tri.Rot = Orientation.Up;
                                break;
                            case 90:
                                tri.Rot = Orientation.Right;
                                break;
                            case 180:
                                tri.Rot = Orientation.Down;
                                break;
                            case 270:
                                tri.Rot = Orientation.Left;
                                break;
                            case 360:
                                tri.Degrees = 0;
                                tri.Rot = Orientation.Up;
                                break;
                        }
                    }
                }
            }
            if (tri1.Rot == Orientation.Down && tri2.Rot == Orientation.Right && tri3.Rot == Orientation.Left && tri4.Rot == Orientation.Up)
                PuzzleOver(true);

            //Uncomment for timeout.
            //if (countUpdates > 520)
            //    PuzzleOver(false);

            prevMouse = mouse;
        }
开发者ID:TAMUCC-cosc3325-team2,项目名称:TheTeamGame,代码行数:75,代码来源:CreateASquare.cs

示例4: Update

        /// <summary>
        /// Updates the <see cref="Slider"/>, checking if any mouse event are occuring.
        /// </summary>
        /// <param name="state"> The current state of the <see cref="Mouse"/>. </param>
        public override void Update(MouseState state)
        {
            base.Update(state);

            if (Enabled)
            {
                if (sliding && leftDown)
                {
                    Invoke(MouseDown, this, GetMouseEventArgs());
                    Refresh();
                }
                else if (sliding && !leftDown && !IsSliding(state.Position()))
                {
                    sliding = false;
                    oldOffset = Vector2.Zero;
                    Refresh();
                }
            }
        }
开发者ID:MentulaGames,项目名称:XnaGuiItems,代码行数:23,代码来源:Slider.cs

示例5: Update

        public override void Update(GameTime gameTime)
        {
            if (player != Game1.localPlayer)
                return; // this puzzle only updates by its owner
            if (timesDisplayed > 60)
            {
                ballColor = (MyColor)((Game1.random.Next(1, 4) + (int)ballColor) % 4);
                textColor = (MyColor)((Game1.random.Next(1, 4) + (int)textColor) % 4);
                if (textColor == ballColor)
                    textColor = (MyColor)(((int) textColor + 1) % 4);
                textWord = (MyColor)((Game1.random.Next(1, 4) + (int)textWord) % 4);
                if (textWord == textColor && Game1.random.Next(2) == 1)
                    textWord = ballColor;
                timesDisplayed = 0;
                if (ballColor == textWord)
                    numberMissed++;
                if (numberMissed > 2)
                    PuzzleOver(false);
                return;
            }

            mouse = Mouse.GetState();

            if (mouse.LeftButton == ButtonState.Pressed && prevMouse.LeftButton == ButtonState.Released)
                leftClick.Play(gameTime, mouse.Position());

            if (mouse.LeftButton.IsClicked() && ballPosition.Contains(mouse.PPosition()))
            {
                if (ballColor == textWord)
                    PuzzleOver(true); // Correct
                else
                    PuzzleOver(false);
            }
            prevMouse = mouse;
        }
开发者ID:TAMUCC-cosc3325-team2,项目名称:TheTeamGame,代码行数:35,代码来源:TextNamesColorOfCircle.cs

示例6: Update

        public override void Update(GameTime gameTime)
        {
            if (player != Game1.localPlayer)
                return; // this puzzle only updates by its owner

            //after 3 seconds, player can select a color
            if (stopWatch.ElapsedMilliseconds > 3000)
            {
                if (prompt)
                {
                    memorizePrompt.Play();
                    prompt = false;
                }

                mouse = Mouse.GetState();
                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    if (new Rectangle(drawRegion.Center.X - 100, drawRegion.Center.Y + 13, 50, 50).Contains(mouse.Position()))
                    {
                        selected = Color.Red;
                        if (selected == correct.color)
                        {
                            PuzzleOver(true);
                        }
                        else
                        {
                            PuzzleOver(false);
                        }
                    }
                    if (new Rectangle(drawRegion.Center.X - 50, drawRegion.Center.Y + 13, 50, 50).Contains(mouse.Position()))
                    {
                        selected = Color.Green;
                        if (selected == correct.color)
                        {
                            PuzzleOver(true);
                        }
                        else
                        {
                            PuzzleOver(false);
                        }
                    }
                    if (new Rectangle(drawRegion.Center.X, drawRegion.Center.Y + 13, 50, 50).Contains(mouse.Position()))
                    {
                        selected = Color.Blue;
                        if (selected == correct.color)
                        {
                            PuzzleOver(true);
                        }
                        else
                        {
                            PuzzleOver(false);
                        }
                    }
                    if (new Rectangle(drawRegion.Center.X + 50, drawRegion.Center.Y + 13, 50, 50).Contains(mouse.Position()))
                    {
                        selected = Color.Yellow;
                        if (selected == correct.color)
                        {
                            PuzzleOver(true);
                        }
                        else
                        {
                            PuzzleOver(false);
                        }
                    }
                }
            }
        }
开发者ID:TAMUCC-cosc3325-team2,项目名称:TheTeamGame,代码行数:68,代码来源:MemorizeWhatYouSee.cs

示例7: GetRotatedMouse

 /// <summary>
 /// Gets the position of the mouse in respect to the <see cref="GuiItem"/>.
 /// </summary>
 /// <param name="state"> The <see cref="MouseState"/> to use. </param>
 /// <returns> The position of the <see cref="Mouse"/> rotated like the <see cref="GuiItem"/>. </returns>
 /// <remarks>
 /// This method is used internaly to determine whether the mouse is inside the client rectangle of the GuiItem.
 /// </remarks>
 /// <example>
 /// This example show how the method is used internaly.
 /// 
 /// <code>
 /// public virtual void Update(MouseState mState)
 /// {
 ///    if (Enabled)
 ///    {
 ///        Vector2 mPos = GetRotatedMouse(mState);
 ///        over = bounds.Contains(mPos.ToPoint());
 ///        <![CDATA[bool down = over && (mState.LeftButton == ButtonState.Pressed || mState.RightButton == ButtonState.Pressed);]]>
 ///     }
 /// }
 /// </code>
 /// </example>
 protected Vector2 GetRotatedMouse(MouseState state)
 {
     return Vector2.Transform(state.Position() - Position, Matrix.CreateRotationZ(-rotation)) + Position;
 }
开发者ID:MentulaGames,项目名称:XnaGuiItems,代码行数:27,代码来源:GuiItem.cs


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