Exemplo n.º 1
0
        public Vector2?GetFirstTouchPosition()
        {
            if (_touchCollection.Count == 0)
            {
                return(null);
            }
            var touch = _touchCollection.FirstOrDefault();

            if (touch != null && touch.State == TouchLocationState.Moved)
            {
                int   gameResolutionWidth    = AeEngine.Singleton().Graphics.GraphicsSettings.GameResolutionWidth;
                int   gameResolutionHeight   = AeEngine.Singleton().Graphics.GraphicsSettings.GameResolutionHeight;
                int   screenResolutionWidth  = AeEngine.Singleton().Graphics.GraphicsSettings.ScreenResolutionWidth;
                int   screenResolutionHeight = AeEngine.Singleton().Graphics.GraphicsSettings.ScreenResolutionHeight;
                float touchModifierX         = gameResolutionWidth / (float)screenResolutionWidth;
                float touchModifierY         = gameResolutionHeight / (float)screenResolutionHeight;
                var   position = touch.Position;
                position.X *= touchModifierX;
                position.Y *= touchModifierY;
                return(position);
            }
            return(null);
        }
Exemplo n.º 2
0
        public void UpdateTouch(Game1 game, GameTime gameTime)
        {
            tc = TouchPanel.GetState();

            //foreach (TouchLocation tl in tc)
            //{
            //    Console.WriteLine(tl.ToString());
            //}

            TouchLocation touch = tc.FirstOrDefault();

            switch (touch.State)
            {
            case TouchLocationState.Pressed:

                if (cursor.Status == Cursor.CursorStatus.Zoomed)
                {
                    cursor.HeldCard.Pos   = cursor.PickupPoint.ToVector2();
                    cursor.HeldCard.Scale = new Vector2(0.25f, 0.25f);
                    cursor.Status         = Cursor.CursorStatus.Empty;
                    cursor.Active         = false;
                    cursor.HeldCard       = null;

                    game.Player1Hand.UpdatePositions();
                    return;
                }

                game.Player1Hand._CardList.ForEach(card =>
                {
                    card.ZIndex = 0;


                    //if (touch.Position.X > card.Pos.X && touch.Position.X < card.Pos.X + card.Texture.Width * card.Scale.X
                    //    && touch.Position.Y > card.Pos.Y && touch.Position.Y < card.Pos.Y + card.Texture.Height * card.Scale.Y)
                    if (card.Collider.Contains(touch.Position))
                    {
                        if (!card.wasPlayed)
                        {
                            selectedCard = card;
                            timeHeld     = (int)gameTime.TotalGameTime.TotalMilliseconds;

                            // AFRICA: Move this to a routine in Cursor
                            cursor.HeldCard    = card;
                            cursor.Active      = true;
                            cursor.Status      = Cursor.CursorStatus.Staged;
                            cursor.PickupPoint = card.Pos.ToPoint();

                            Cell cell = game.Board.GameGrid.Cells.Find(c => c.Occupant == card);
                            if (cell != null)
                            {
                                cell.Occupant   = null;
                                cell.isOccupied = false;
                            }
                        }
                    }
                });

                if (cursor.HeldCard != null)
                {
                    cursor.HeldCard.ZIndex       = 1;
                    cursor.HeldCard.Rotation3D.Z = 0f;
                    cursor.HeldCard.Pos          = cursor.HeldCard.Pos + (Vector2.UnitY * -500);
                    cursor.HeldCard.Scale        = new Vector2(0.35f, 0.35f);
                }
                else
                {
                    game.Player1Hand.AddCards(game.Player1Deck.Deal(1));
                }

                cursor.Update(touch);

                Console.WriteLine(touch.Position.ToString());

                break;

            case TouchLocationState.Moved:

                cursor.Update(touch);

                break;

            case TouchLocationState.Released:

                if (cursor.HeldCard == null || cursor.Status == Cursor.CursorStatus.Zoomed)
                {
                    return;
                }

                if (gameTime.TotalGameTime.TotalMilliseconds - timeHeld <= 200)
                {
                    cursor.HeldCard.Pos    = new Vector2(game.GraphicsDevice.Viewport.Width / 2, game.GraphicsDevice.Viewport.Height / 2);
                    cursor.HeldCard.Scale  = Vector2.One;
                    cursor.HeldCard.ZIndex = 1;
                    cursor.Status          = Cursor.CursorStatus.Zoomed;
                    return;
                }

                game.Board.GameGrid.Cells.ForEach(cell =>
                {
                    if (cell.Rectangle.Contains(touch.Position.ToPoint()))
                    {
                        if (!cell.isOccupied && cursor.HeldCard != null && cursor.HeldCard._CardType == CardType.Minion)
                        {
                            // AFRICA: Move this stuff to routines in their associated classes
                            cursor.HeldCard.Pos = cell.Rectangle.Location.ToVector2() + new Vector2(cell.Rectangle.Width / 2, cell.Rectangle.Height / 2);
                            _game.tweener.TweenTo(cursor.HeldCard, c => c.Scale, Vector2.One * 0.25f, 0.1f, 0f);
                            cursor.HeldCard.wasPlayed = true;
                            cell.isOccupied           = true;
                            cell.Occupant             = cursor.HeldCard;
                            cursor.Status             = Cursor.CursorStatus.Empty;
                            cursor.Active             = false;
                            cursor.HeldCard           = null;
                            game.Player1Hand.RemoveCard(selectedCard);
                            selectedCard = null;
                        }
                        else
                        {
                            // check artifact stuff
                        }
                    }
                });

                if (cursor.Active)
                {
                    cursor.HeldCard.Pos = cursor.PickupPoint.ToVector2();
                    _game.tweener.TweenTo(cursor.HeldCard, c => c.Scale, Vector2.One * 0.25f, 0.1f, 0f);
                    cursor.Status   = Cursor.CursorStatus.Empty;
                    cursor.Active   = false;
                    cursor.HeldCard = null;

                    game.Player1Hand.UpdatePositions();
                }

                cursor.Update(touch);

                break;

            default: break;
            }
        }