Esempio n. 1
0
        public Hex GetCurrentMouseHoverHex()
        {
            Hex currentHex = FractionalHex.HexRound(
                Layout.PixelToHex(GameManager.gridLayout, new Vector2(
                                      Controls.getMousePosition().X, Controls.getMousePosition().Y)));

            return(currentHex);
        }
Esempio n. 2
0
        static public List <Hex> HexLinedraw(Hex a, Hex b)
        {
            int        N       = Hex.Distance(a, b);
            List <Hex> results = new List <Hex> {
            };
            double step        = 1.0 / Math.Max(N, 1);

            for (int i = 0; i <= N; i++)
            {
                results.Add(FractionalHex.HexRound(FractionalHex.HexLerp(a, b, step * i)));
            }
            return(results);
        }
Esempio n. 3
0
        public override void drawObject(SpriteBatch spriteBatch)
        {
            /* Drawing hex hover */
            Hex currentHex = GetCurrentMouseHoverHex();

            for (int i = 0; i < getHexes().Count; i++)
            {
                Color color = new Color();

                if (getHexes()[i].q == currentHex.q && getHexes()[i].r == currentHex.r)
                {
                    color = Color.Blue;
                }
                else
                {
                    color = Color.White;
                }
                spriteBatch.Draw(
                    sprite,
                    Layout.HexToPixel(GameManager.gridLayout, getHexes()[i]),
                    null,
                    color,
                    0f,
                    new Vector2(sprite.Width / 2f, sprite.Height / 2f),
                    GameManager.gridLayout.size / sprite.Width * 2f,
                    SpriteEffects.None,
                    0f);
            }

            /* Registering grid mouse clicks. To be moved to Controls */
            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                Hex clickedHex = FractionalHex.HexRound(
                    Layout.PixelToHex(
                        GameManager.gridLayout,
                        new Vector2(Controls.getMousePosition().X, Controls.getMousePosition().Y)
                        )
                    );
                Unit currentUnit = UnitManager.GetCurrentUnit();
                if (currentUnit.State == Unit.States.Moving)
                {
                    MoveManager.MoveUnit(currentUnit, clickedHex);
                }
                else
                {
                    UnitManager.SelectUnitByHex(clickedHex);
                }
            }

            /* Drawing unit move path */
            // TODO: this should be moved somewhere else.
            if (path != null)
            {
                Color color = Color.Green;
                for (int i = 0; i < path.Count; i++)
                {
                    if (i > UnitManager.GetCurrentUnit().CurrentMove())
                    {
                        color = Color.Red;
                    }
                    spriteBatch.Draw(
                        sprite,
                        Layout.HexToPixel(GameManager.gridLayout, path[i]),
                        null,
                        color,
                        0f,
                        new Vector2(sprite.Width / 2f, sprite.Height / 2f),
                        GameManager.gridLayout.size / sprite.Width * 2,
                        SpriteEffects.None,
                        0f);
                }
            }
        }