Ejemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            world.Step((float)gameTime.ElapsedGameTime.TotalSeconds);

            if (hasLost())
            {
                return;
            }

            rightSideClicked = false;
            leftSideClicked  = false;

            MouseState mouseState = Mouse.GetState();

            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                viewportClicked(mouseState.Position.X, mouseState.Position.Y);
            }

            TouchCollection touch = TouchPanel.GetState();

            foreach (TouchLocation tl in touch)
            {
                if ((tl.State == TouchLocationState.Pressed) ||
                    (tl.State == TouchLocationState.Moved))
                {
                    viewportClicked((int)tl.Position.X, (int)tl.Position.Y);
                }
            }

            if (blocks.Count > 0)
            {
                if (leftSideClicked && !rightSideClicked)
                {
                    if (!currentBlock.hasContact() && currentBlock.getPosition().X - currentBlock.getSize().X / 2 > 0)
                    {
                        currentBlock.setPosition(currentBlock.getPosition() + new Vector2(-1.5f, 0));
                    }
                }
                else if (rightSideClicked && !leftSideClicked)
                {
                    if (!currentBlock.hasContact() && currentBlock.getPosition().X + currentBlock.getSize().X / 2 < size.X)
                    {
                        currentBlock.setPosition(currentBlock.getPosition() + new Vector2(1.5f, 0));
                    }
                }
                else if (rightSideClicked && leftSideClicked)
                {
                    currentBlock.setRotation(currentBlock.getRotation() + 0.05f);
                }
            }
        }