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)
                {
                    if (ball1Rec.Bottom >= bottomWall1.Top)
                        ball1Rec.Y = bottomWall1.Top - 22;
                    ball1Rec.X = leftWall1.Right;
                }
                else if (ball1Rec.Right >= rightWall1.Left)
                {
                    if (ball1Rec.Top <= topWall1.Bottom)
                        ball1Rec.Y = topWall1.Bottom;
                    ball1Rec.X = rightWall1.Left - 22;
                }

                ball2Rec.X = backgroundRec.Right - 22 - ball1Rec.X;
                ball2Rec.Y = backgroundRec.Bottom - 22 - ball1Rec.Y;

                if (mouse.LeftButton == ButtonState.Released)
                    ball1State = ClickedState.Released;
            }

            else if (ball2State == ClickedState.Clicked)
            {
                ball2Rec.Location = new Point((int)relativePos.X - 11, (int)relativePos.Y - 11);

                if (ball2Rec.Bottom >= bottomWall2.Top && ball2Rec.Left <= bottomPart2.Right)
                {
                    if (ball2Rec.Left <= leftWall2.Right)
                        ball2Rec.X = leftWall2.Right;
                    ball2Rec.Y = bottomWall2.Top - 22;
                }
                else if (ball2Rec.Left >= bottomPart2.Right && ball2Rec.Bottom >= backgroundRec.Bottom)
                    ball2Rec.Y = backgroundRec.Bottom - 22;
                else if (ball2Rec.Top <= topWall2.Bottom && ball2Rec.Right >= topPart2.Left)
                {
                    if (ball2Rec.Left <= rightWall2.Left)
                        ball2Rec.Y = topWall2.Bottom;
                }
                else if (ball2Rec.Right <= topPart2.Left && ball2Rec.Top <= backgroundRec.Top)
                    ball2Rec.Y = backgroundRec.Top;
                if (ball2Rec.Left <= leftWall2.Right)
                {
                    if (ball2Rec.Bottom >= bottomWall2.Top)
                        ball2Rec.Y = bottomWall2.Top - 22;
                    ball2Rec.X = leftWall2.Right;
                }
                else if (ball2Rec.Right >= rightWall2.Left)
                {
                    if (ball2Rec.Top <= topWall2.Bottom)
                        ball2Rec.Y = topWall2.Bottom;
                    ball2Rec.X = rightWall2.Left - 22;
                }

                ball1Rec.X = backgroundRec.Right - 22 - ball2Rec.X;
                ball1Rec.Y = backgroundRec.Bottom - 22 - ball2Rec.Y;

                if (mouse.LeftButton == ButtonState.Released)
                    ball2State = ClickedState.Released;
            }

            if (block1Rec.Intersects(ball1Rec) || block1Rec.Intersects(ball2Rec))
                PuzzleOver(false);
            else if (block2Rec.Intersects(ball1Rec) || block2Rec.Intersects(ball2Rec))
                PuzzleOver(false);

            if ((ball1Rec.Center.ToVector2() - goalRec.Center.ToVector2()).LengthSquared() <= 11)
                PuzzleOver(true);
            prevMouse = mouse;
        }
示例#2
0
 public Vector2 MouseAimVector(MouseState ms, Vector2 relativeposition)
 {
     Vector2 ret;
     ret = this.Camera.ConvertScreenToWorld(ms.Position()) - relativeposition;
     ret.Normalize();
     return ret;
 }
        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;
        }
示例#4
0
        /// <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();
                }
            }
        }
        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;
        }
        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);
                        }
                    }
                }
            }
        }
示例#7
0
 /// <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;
 }