Example #1
0
        public SideDisplayBox(GraphicsDevice graphicsDevice, SpriteFont textFont, Vector2 pos, float width)
        {
            this.width    = (int)width;
            this.pos      = pos;
            this.textFont = textFont;

            playerNameBox = new RectBox(graphicsDevice,
                                        this.pos,
                                        this.width, nameBoxHeight);

            divisorA = new Line(graphicsDevice,
                                new Vector2(pos.X, playerNameBox.GetBottom()),
                                new Vector2(pos.X + width, playerNameBox.GetBottom()),
                                5, Color.White);

            characterSpriteBox = new RectBox(graphicsDevice,
                                             new Vector2(pos.X, playerNameBox.GetBottom()),
                                             this.width, spriteBoxHeight);

            divisorB = new Line(graphicsDevice,
                                new Vector2(pos.X, characterSpriteBox.GetBottom()),
                                new Vector2(pos.X + width, characterSpriteBox.GetBottom()),
                                5, Color.White);

            characterInfoBox = new RectBox(graphicsDevice,
                                           new Vector2(pos.X, characterSpriteBox.GetBottom()),
                                           this.width, infoBoxHeight);

            dimensions = new Vector2(width,
                                     playerNameBox.GetHeight() + characterSpriteBox.GetHeight() + characterInfoBox.GetHeight());
        }
Example #2
0
        public ActionLogBox(GraphicsDevice graphicsDevice, int capacity, SpriteFont textFont, Vector2 pos)
        {
            this.pos      = pos;
            this.textFont = textFont;

            //generate a colourless pixel to draw colour blocks with.
            emptyRect = UiTools.GeneratePixelTexture(graphicsDevice);


            textBox = new RectBox(graphicsDevice,
                                  this.pos,
                                  width, textBoxHeight);

            divisorA = new Line(graphicsDevice,
                                new Vector2(pos.X, textBox.GetBottom()),
                                new Vector2(pos.X + width, textBox.GetBottom()),
                                5, Color.White);

            actionBoxes = new RectBox[capacity];

            for (int i = 0; i < capacity; i++)
            {
                actionBoxes[i] = new RectBox(graphicsDevice,
                                             new Vector2(
                                                 pos.X,
                                                 (i == 0)? textBox.GetBottom() : actionBoxes[i - 1].GetBottom()),
                                             width, actionBoxHeight);
            }


            dimensions = new Vector2(width,
                                     textBox.GetHeight() + capacity * actionBoxHeight);
        }
Example #3
0
        public UnitShopBox(UnitShop parent, GraphicsDevice graphicsDevice, int capacity, Vector2 pos)
        {
            this.pos = pos;

            textBox = new RectBox(graphicsDevice,
                                  this.pos,
                                  width, textBoxHeight);

            divisorA = new Line(graphicsDevice,
                                new Vector2(pos.X, textBox.GetBottom()),
                                new Vector2(pos.X + width, textBox.GetBottom()),
                                5, Color.White);

            unitBoxes = new UnitShopButton[capacity];

            for (int i = 0; i < capacity; i++)
            {
                unitBoxes[i] = new UnitShopButton(i, graphicsDevice,
                                                  new Vector2(
                                                      pos.X,
                                                      (i == 0) ? textBox.GetBottom() : unitBoxes[i - 1].GetBottom()),
                                                  width, unitBoxHeight);
                unitBoxes[i].buttonPressed += parent.SellEntry;
            }

            dimensions = new Vector2(width,
                                     textBox.GetHeight() + capacity * unitBoxHeight);
        }
Example #4
0
        public StageViewBox(GraphicsDevice graphicsDevice, Stage stage, SpriteFont textFont, int stageNumber, int stageIndex, Vector2 pos)
        {
            this.stage      = stage;
            this.pos        = pos;
            this.textFont   = textFont;
            this.stageIndex = stageIndex;
            text            = $"Stage {stageNumber} : {stageIndex}";

            textBox = new RectBox(graphicsDevice,
                                  this.pos,
                                  width, textBoxHeight);

            divisorA = new Line(graphicsDevice,
                                new Vector2(pos.X, textBox.GetBottom()),
                                new Vector2(pos.X + width, textBox.GetBottom()),
                                5, Color.White);

            stageIconBoxes = new RectBox[stage.Length];

            for (int i = 0; i < stage.Length; i++)
            {
                stageIconBoxes[i] = new RectBox(graphicsDevice,
                                                new Vector2(
                                                    pos.X,
                                                    (i == 0)? textBox.GetBottom() : stageIconBoxes[i - 1].GetBottom()),
                                                width, stageIconBoxHeight);
            }
        }
Example #5
0
        /// <summary>
        /// 判断指定大小的两组像素是否相交
        /// </summary>
        ///
        /// <param name="rectA"></param>
        /// <param name="dataA"></param>
        /// <param name="rectB"></param>
        /// <param name="dataB"></param>
        /// <returns></returns>
        public static bool Intersect(RectBox rectA, int[] dataA, RectBox rectB,
                                     int[] dataB)
        {
            int top    = (int)Loon.Utils.MathUtils.Max(rectA.GetY(), rectB.GetY());
            int bottom = (int)Loon.Utils.MathUtils.Min(rectA.GetBottom(), rectB.GetBottom());
            int left   = (int)Loon.Utils.MathUtils.Max(rectA.GetX(), rectB.GetX());
            int right  = (int)Loon.Utils.MathUtils.Min(rectA.GetRight(), rectB.GetRight());

            for (int y = top; y < bottom; y++)
            {
                for (int x = left; x < right; x++)
                {
                    int colorA = dataA[(int)((x - rectA.x) + (y - rectA.y)
                                             * rectA.width)];
                    int colorB = dataB[(int)((x - rectB.x) + (y - rectB.y)
                                             * rectB.width)];
                    if ((int)(((uint)colorA) >> 24) != 0 && (int)(((uint)colorB) >> 24) != 0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #6
0
        public void AddObject(Actor actor)
        {
            RectBox bounds = this.GetActorBounds(actor);
            float   by;

            if (this.bspTree == null)
            {
                byte treeArea;
                if (bounds.width > bounds.height)
                {
                    treeArea = 0;
                    by       = bounds.GetMiddleX();
                }
                else
                {
                    treeArea = 1;
                    by       = bounds.GetMiddleY();
                }

                this.bspTree = GetBSPNode();
                this.bspTree.GetArea().Copy(bounds);
                this.bspTree.SetSplitAxis(treeArea);
                this.bspTree.SetSplitPos(by);
                this.bspTree.AddActor(actor);
            }
            else
            {
                int     idx       = 0;
                RectBox treeArea1 = this.bspTree.GetArea();
                RectBox result1   = new RectBox();
                RectBox result2   = new RectBox();
                for (; !treeArea1.Contains(bounds) && idx < MAX_SIZE;)
                {
                    RectBox          newArea;
                    BSPCollisionNode newTop;
                    if (bounds.GetX() < treeArea1.GetX())
                    {
                        by      = (treeArea1.GetX() - treeArea1.width);
                        newArea = new RectBox(by, treeArea1.GetY(),
                                              treeArea1.GetRight() - by, treeArea1.height);
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(0);
                        newTop.SetSplitPos(treeArea1.GetX());
                        newTop.SetChild(1, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1    = newArea;
                    }
                    if (bounds.GetRight() > treeArea1.GetRight())
                    {
                        by      = (treeArea1.GetRight() + treeArea1.width);
                        newArea = new RectBox(treeArea1.GetX(), treeArea1.GetY(),
                                              by - treeArea1.GetX(), treeArea1.height);
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(0);
                        newTop.SetSplitPos(treeArea1.GetRight());
                        newTop.SetChild(0, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1    = newArea;
                    }
                    if (bounds.GetY() < treeArea1.GetY())
                    {
                        by      = (treeArea1.GetY() - treeArea1.height);
                        newArea = new RectBox(treeArea1.GetX(), by,
                                              treeArea1.width, treeArea1.GetBottom() - by);
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(1);
                        newTop.SetSplitPos(treeArea1.GetY());
                        newTop.SetChild(1, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1    = newArea;
                    }
                    if (bounds.GetBottom() > treeArea1.GetBottom())
                    {
                        by      = (treeArea1.GetBottom() + treeArea1.height);
                        newArea = new RectBox(treeArea1.GetX(), treeArea1.GetY(),
                                              treeArea1.width, by - treeArea1.GetY());
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(1);
                        newTop.SetSplitPos(treeArea1.GetBottom());
                        newTop.SetChild(0, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1    = newArea;
                    }
                    idx++;
                }

                this.InsertObject(actor, bounds, bounds, treeArea1, this.bspTree,
                                  result1, result2);
            }
        }