Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            if (!drag)
            {
                if (Globals.mouseState.LeftButtonHold && startDragGridPosition == Grid.ToGridLocation(Globals.mouseState.Position.ToPoint(), gridLocation, Globals.TileDimensions) && Main.WindowRectangle.Contains(Globals.mouseState.Position))
                {
                    dragHoldTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                    if (!(dragHoldTimer < DRAG_HOLD_TIME))
                    {
                        drag          = true;
                        dragHoldTimer = 0;
                    }
                }
            }

            if (Globals.mouseState.LeftButtonPressed && Main.WindowRectangle.Contains(Globals.mouseState.Position))
            {
                if (selectedCharacter.Hitbox.Contains(Globals.mouseState.Position))
                {
                    drag = true;
                }
                else
                {
                    foreach (Character c in Armies.army)
                    {
                        if (c.Hitbox.Contains(Globals.mouseState.Position))
                        {
                            SelectCharacter(c);
                        }
                    }
                }

                // Check switchable unit
                foreach (KeyValuePair <Character.Rank, Sprite> entry in armyDict)
                {
                    Rectangle hitbox = new Rectangle((int)entry.Value.position.X, (int)entry.Value.position.Y, entry.Value.sourceRectangle.Width, entry.Value.sourceRectangle.Height);

                    if (hitbox.Contains(Globals.mouseState.Position))
                    {
                        if (selectedCharacter.special == Character.Special.None)
                        {
                            if (selectedCharacter.rank == entry.Key)
                            {
                                ChangeCharacter(entry.Key);
                            }
                        }
                        else
                        {
                            switch (entry.Key)
                            {
                            case Character.Rank.Spy:
                            case Character.Rank.Miner:
                            case Character.Rank.Healer:
                                ChangeCharacter(entry.Key);
                                break;

                            case Character.Rank.Bomb:
                                if (selectedCharacter.rank == Character.Rank.Bomb)
                                {
                                    ChangeCharacter(entry.Key);
                                }
                                break;
                            }
                        }
                    }
                }

                if (LeftNextButtonHitbox.Contains(Globals.mouseState.Position))
                {
                    switch (currentArmy)
                    {
                    case Character.Army.Normal: SetArmyDictionary(Character.Army.Sea); break;

                    case Character.Army.Tiki: SetArmyDictionary(Character.Army.Normal); break;

                    case Character.Army.Sea: SetArmyDictionary(Character.Army.Tiki); break;
                    }
                }

                if (RightNextButtonHitbox.Contains(Globals.mouseState.Position))
                {
                    switch (currentArmy)
                    {
                    case Character.Army.Normal: SetArmyDictionary(Character.Army.Tiki); break;

                    case Character.Army.Tiki: SetArmyDictionary(Character.Army.Sea); break;

                    case Character.Army.Sea: SetArmyDictionary(Character.Army.Normal); break;
                    }
                }
            }

            if (drag && Globals.mouseState.LeftButtonReleased)
            {
                Vector2 mouseGridPosition = (Grid.ToGridLocation(Globals.mouseState.Position.ToPoint(), gridLocation, Globals.TileDimensions) * Globals.TileDimensions + gridLocation).ToVector2();

                if (GridArea.Contains(mouseGridPosition))
                {
                    bool overlap = false;

                    // Check for overlapping with another character
                    foreach (Character c in Armies.army)
                    {
                        if (c.position == mouseGridPosition)
                        {
                            overlap = true;

                            // Swap drag Character with overlap character
                            c.position = selectedCharacter.position;
                            selectedCharacter.position = mouseGridPosition;

                            break;
                        }
                    }

                    if (!overlap)
                    {
                        selectedCharacter.position = mouseGridPosition;
                    }
                }

                drag = false;
            }

            statsUI.UpdateAnimation(gameTime);
            statsUI.UpdateWeaponChanging();
        }