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

            return(currentHex);
        }
示例#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);
        }
示例#3
0
        static public Hex HexRound(FractionalHex h)
        {
            int    q      = (int)(Math.Round(h.q));
            int    r      = (int)(Math.Round(h.r));
            int    s      = (int)(Math.Round(h.s));
            double q_diff = Math.Abs(q - h.q);
            double r_diff = Math.Abs(r - h.r);
            double s_diff = Math.Abs(s - h.s);

            if (q_diff > r_diff && q_diff > s_diff)
            {
                q = -r - s;
            }
            else
            if (r_diff > s_diff)
            {
                r = -q - s;
            }
            else
            {
                s = -q - r;
            }
            return(new Hex(q, r, s));
        }
示例#4
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);
                }
            }
        }