Exemple #1
0
        public virtual void Draw(SpriteBatch sb)
        {
            DrawCard(sb);

            if (PlacingBuilding)
            {
                PlacementBuilding.Draw(sb, World.CanPlaceBuilding(PlacementBuilding));
            }
            if (PlacingUnit)
            {
                PlacementUnit.Draw(sb, World.CanPlaceUnit(PlacementUnit));
            }
        }
Exemple #2
0
        public virtual void Update(GameTime gt)
        {
            Index = Hand.IndexOf(this);

            Hovering = Mouse.Hitbox.Intersects(Hitbox);

            Position -= new Vector2((Position.X - ((Index + 1) * Spacing + Padding)) * 13 * (float)gt.ElapsedGameTime.TotalSeconds, 0);

            MouseState state = Mouse.GetState();

            if (Hovering)
            {
                Position -= new Vector2(0, (Position.Y - HoverPosition.Y) * 6f * (float)gt.ElapsedGameTime.TotalSeconds);

                if (state.LeftButton == ButtonState.Pressed)
                {
                    LeftButtonClicked = true;
                }
            }
            else
            {
                Position += new Vector2(0, (OriginalPosition.Y - Position.Y) * 6f * (float)gt.ElapsedGameTime.TotalSeconds);
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                if (Placing && CanPlace)
                {
                    CanPlace = false;

                    bool cont = true;

                    for (int i = 0; i < World.Tiles.GetLength(0) && cont; i++)
                    {
                        for (int j = 0; j < World.Tiles.GetLength(1) && cont; j++)
                        {
                            if (World.Tiles[i, j].Hitbox.Intersects(Mouse.Hitbox))
                            {
                                Type type = GetType();

                                if (Type == CardType.BUILDING)
                                {
                                    if (World.CanPlaceBuilding(PlacementBuilding))
                                    {
                                        World.Buildings.Add(PlacementBuilding);
                                        Team.Discover(Building.VisionRange);

                                        Used            = true;
                                        PlacingBuilding = false;
                                    }
                                }
                                else
                                {
                                    if (World.CanPlaceUnit(PlacementUnit))
                                    {
                                        World.Units.Add(PlacementUnit);
                                        PlacementUnit.Place();

                                        Used        = true;
                                        PlacingUnit = false;
                                    }
                                }

                                cont = false;

                                break;
                            }
                        }
                    }
                }

                if (Hitbox.Intersects(Mouse.Hitbox))
                {
                    if (!Placing)
                    {
                        Type type = GetType();

                        if (Type == CardType.BUILDING)
                        {
                            if (type == typeof(CardFarm))
                            {
                                PlacementBuilding = new Farm(new Vector2(Mouse.Position.X - Mouse.Position.X % TileWidth, Mouse.Position.Y - Mouse.Position.Y % TileWidth).ToPoint());
                            }
                            else if (type == typeof(CardMine))
                            {
                                PlacementBuilding = new Mine(new Vector2(Mouse.Position.X - Mouse.Position.X % TileWidth, Mouse.Position.Y - Mouse.Position.Y % TileWidth).ToPoint());
                            }
                            else if (type == typeof(CardQuarry))
                            {
                                PlacementBuilding = new Quarry(new Vector2(Mouse.Position.X - Mouse.Position.X % TileWidth, Mouse.Position.Y - Mouse.Position.Y % TileWidth).ToPoint());
                            }

                            PlacingBuilding = true;
                        }
                        else
                        {
                            if (type == typeof(CardWarrior))
                            {
                                PlacementUnit = new UnitWarrior(new Vector2(Mouse.Position.X - Mouse.Position.X % TileWidth, Mouse.Position.Y - Mouse.Position.Y % TileWidth).ToPoint(), World);
                            }
                            else if (type == typeof(CardScout))
                            {
                                PlacementUnit = new UnitScout(new Vector2(Mouse.Position.X - Mouse.Position.X % TileWidth, Mouse.Position.Y - Mouse.Position.Y % TileWidth).ToPoint(), World);
                            }
                            else if (type == typeof(CardWorker))
                            {
                                PlacementUnit = new UnitWorker(new Vector2(Mouse.Position.X - Mouse.Position.X % TileWidth, Mouse.Position.Y - Mouse.Position.Y % TileWidth).ToPoint(), World);
                            }

                            PlacingUnit = true;
                        }

                        HiddenPosition = Position;
                    }
                }
            }
            else
            {
                if (Placing)
                {
                    CanPlace = true;
                }
            }

            if (LeftButtonClicked && !Hovering && state.LeftButton == ButtonState.Released)
            {
                LeftButtonClicked = false;
            }

            if (PlacingBuilding)
            {
                if (PlacementBuilding != null)
                {
                    PlacementBuilding.Position = new Vector2((Mouse.Position.X - Mouse.Position.X % TileWidth), (Mouse.Position.Y - Mouse.Position.Y % TileWidth));

                    PlacementBuilding.Update(gt);
                }
                else
                {
                    PlacingBuilding = false;
                }
            }
            else if (PlacingUnit)
            {
                if (PlacementUnit != null)
                {
                    PlacementUnit.Position = new Vector2((Mouse.Position.X - Mouse.Position.X % TileWidth), (Mouse.Position.Y - Mouse.Position.Y % TileWidth));

                    PlacementUnit.Update(gt);
                    PlacementUnit.OriginalPosition = PlacementUnit.Position;
                }
                else
                {
                    PlacingUnit = false;
                }
            }

            Hitbox = new Rectangle(new Vector2(Camera.Position.X + Position.X + (Placing ? Mouse.Position.X : 0), Camera.Position.Y + Position.Y + (Placing ? Mouse.Position.Y : 0)).ToPoint(), new Vector2(CardSize.X * Scale, CardSize.Y * Scale).ToPoint());
        }