Exemplo n.º 1
0
        /// <summary>
        /// Handle thumbstick logic
        /// </summary>
        public void HandleThumbStick(Block[,] blocks, Bomberman bomberman, InputState input)
        {
            this.blocks = blocks;

            isSmokeButtonClicked = false;
            IEnumerable<Bomb> bombsToBeDeleted = bomberman.Bombs.Where(bomb => bomb.IsExploded);
            if (bombsToBeDeleted.Count() > 0)
            {
                foreach (Bomb bomb in bombsToBeDeleted)
                {
                    screenManager.Game.Components.Remove(bomb);
                    bomb.Stop();
                }
            }

            // If there was any touch
            if (VirtualThumbsticks.RightThumbstickCenter.HasValue)
            {
                // Button BodyRectangle
                Rectangle buttonRectangle = new Rectangle((int) smokeButtonPosition.X, (int) smokeButtonPosition.Y, 60,
                                                          109);

                // Touch BodyRectangle
                Rectangle touchRectangle = new Rectangle((int) VirtualThumbsticks.RightThumbstickCenter.Value.X,
                                                         (int) VirtualThumbsticks.RightThumbstickCenter.Value.Y, 1, 1);

                // If the touch is in the button
                if (buttonRectangle.Contains(touchRectangle))
                {
                    isSmokeButtonClicked = true;
                }
            }

            if (input.TouchState.Count > 0)
            {
                foreach (TouchLocation touch in input.TouchState)
                {
                    lastTouchPosition = touch.Position;
                }
            }

            // Calculate the rectangle of the outer circle of the thumbstick
            Rectangle outerControlstick = new Rectangle(
                0,
                (int) controlstickBoundaryPosition.Y - 35,
                controlstickBoundary.Width + 60,
                controlstickBoundary.Height + 60);

            //handle bomb Button
            if (isSmokeButtonClicked)
            {
                dropBomb(bomberman);
            }

            // Reset the thumbstick position when it is idle
            if (VirtualThumbsticks.LeftThumbstick == Vector2.Zero)
            {
                bomberman.SetMovement(Vector2.Zero);
                controlstickStartupPosition = new Vector2(55, 369);
            }
            else
            {
                // If not in motion and the touch point is not in the control bounds - there is no movement
                Rectangle touchRectangle = new Rectangle((int) lastTouchPosition.X, (int) lastTouchPosition.Y, 1, 1);

                if (!outerControlstick.Contains(touchRectangle))
                {
                    controlstickStartupPosition = new Vector2(55, 369);
                    return;
                }

                // Move the beekeeper
                setMotion(bomberman);

                // Moves the thumbstick's inner circle
                float radious = controlstick.Width/2 + 35;
                controlstickStartupPosition = new Vector2(55, 369) + (VirtualThumbsticks.LeftThumbstick*radious);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Moves the beekeeper.
        /// </summary>
        private void setMotion(Bomberman bomberman)
        {
            Vector2 leftThumbstick = VirtualThumbsticks.LeftThumbstick;

            Vector2 bomberCalculatedPosition = new Vector2(bomberman.CollisionArea.X, bomberman.CollisionArea.Y) +
                                               leftThumbstick*12f;

            if (bomberCalculatedPosition.X < 20 ||
                bomberCalculatedPosition.X + bomberman.CollisionArea.Width > screenManager.GraphicsDevice.Viewport.Width)
            {
                leftThumbstick.X = 0;
            }
            if (bomberCalculatedPosition.Y < 20 ||
                bomberCalculatedPosition.Y + bomberman.CollisionArea.Height >
                screenManager.GraphicsDevice.Viewport.Height)
            {
                leftThumbstick.Y = 0;
            }

            if (leftThumbstick != Vector2.Zero)
            {
                if (bomberman.GetDirection == Bomberman.WalkingDirection.Down ||
                    bomberman.GetDirection == Bomberman.WalkingDirection.Up)
                {
                    if (checkBlockCollision(bomberCalculatedPosition, bomberman))
                    {
                        leftThumbstick.Y = 0;
                        bomberCalculatedPosition = new Vector2(bomberman.CollisionArea.X, bomberman.CollisionArea.Y) +
                                                   leftThumbstick*12;

                        if (!checkBlockCollision(bomberCalculatedPosition, bomberman))
                        {
                            bomberman.SetMovement(leftThumbstick*12f);
                        }
                    }
                }
                else
                {
                    if (checkBlockCollision(bomberCalculatedPosition, bomberman))
                    {
                        leftThumbstick.X = 0;
                        bomberCalculatedPosition = new Vector2(bomberman.CollisionArea.X, bomberman.CollisionArea.Y) +
                                                   leftThumbstick*12;

                        if (!checkBlockCollision(bomberCalculatedPosition, bomberman))
                        {
                            bomberman.SetMovement(leftThumbstick*12f);
                        }
                    }
                }

                bomberCalculatedPosition = new Vector2(bomberman.CollisionArea.X, bomberman.CollisionArea.Y) +
                                           leftThumbstick*12;

                if (!checkBlockCollision(bomberCalculatedPosition, bomberman))
                {
                    bomberman.SetMovement(leftThumbstick*12f);
                }
            }
        }