private static void AddBillboard(ref QuadBoard qb, ref MyQuadD quad)
                {
                    MyTransparentGeometry.AddTriangleBillboard
                    (
                        quad.Point0,
                        quad.Point1,
                        quad.Point2,
                        Vector3.Zero, Vector3.Zero, Vector3.Zero,
                        qb.texCoords.Min,
                        (qb.texCoords.Min + new Vector2(0f, qb.texCoords.Size.Y)),
                        qb.texCoords.Max,
                        qb.textureID, 0,
                        Vector3D.Zero,
                        qb.bbColor,
                        BlendTypeEnum.PostPP
                    );

                    MyTransparentGeometry.AddTriangleBillboard
                    (
                        quad.Point0,
                        quad.Point2,
                        quad.Point3,
                        Vector3.Zero, Vector3.Zero, Vector3.Zero,
                        qb.texCoords.Min,
                        qb.texCoords.Max,
                        (qb.texCoords.Min + new Vector2(qb.texCoords.Size.X, 0f)),
                        qb.textureID, 0,
                        Vector3D.Zero,
                        qb.bbColor,
                        BlendTypeEnum.PostPP
                    );
                }
Beispiel #2
0
                    /// <summary>
                    /// Sets the formatting for the given range of characters in the line
                    /// </summary>
                    public void SetFormatting(int start, int end, GlyphFormat format, bool onlyChangeColor)
                    {
                        Vector4 bbColor = QuadBoard.GetQuadBoardColor(format.Data.Item4);

                        for (int n = start; n <= end; n++)
                        {
                            if (onlyChangeColor)
                            {
                                var quadBoard = glyphBoards[n];
                                quadBoard.bbColor = bbColor;

                                glyphBoards[n]     = quadBoard;
                                formattedGlyphs[n] = new FormattedGlyph(formattedGlyphs[n].glyph, format);
                            }
                            else if (!formattedGlyphs[n].format.Equals(format))
                            {
                                IFontStyle fontStyle = FontManager.GetFontStyle(format.Data.Item3);
                                float      scale     = format.Data.Item2 * fontStyle.FontScale;
                                Glyph      glyph     = fontStyle[chars[n]];
                                Vector2    glyphSize = new Vector2(glyph.advanceWidth, fontStyle.Height) * scale;

                                formattedGlyphs[n] = new FormattedGlyph(glyph, format);
                                locData[n]         = new GlyphLocData(glyph.MatFrame.Material.size * scale, glyphSize);
                                glyphBoards[n]     = glyph.GetQuadBoard(format, bbColor);
                            }
                        }
                    }
                private static void AddBillboard(ref QuadBoard qb, ref CroppedQuad crop)
                {
                    MyTransparentGeometry.AddTriangleBillboard
                    (
                        crop.quad.Point0,
                        crop.quad.Point1,
                        crop.quad.Point2,
                        Vector3.Zero, Vector3.Zero, Vector3.Zero,
                        crop.matBounds.Min,
                        (crop.matBounds.Min + new Vector2(0f, crop.matBounds.Size.Y)),
                        crop.matBounds.Max,
                        qb.textureID, 0,
                        Vector3D.Zero,
                        qb.bbColor,
                        BlendTypeEnum.PostPP
                    );

                    MyTransparentGeometry.AddTriangleBillboard
                    (
                        crop.quad.Point0,
                        crop.quad.Point2,
                        crop.quad.Point3,
                        Vector3.Zero, Vector3.Zero, Vector3.Zero,
                        crop.matBounds.Min,
                        crop.matBounds.Max,
                        (crop.matBounds.Min + new Vector2(crop.matBounds.Size.X, 0f)),
                        qb.textureID, 0,
                        Vector3D.Zero,
                        qb.bbColor,
                        BlendTypeEnum.PostPP
                    );
                }
Beispiel #4
0
                /// <summary>
                /// Initializes a new matboard with a size of 0 and a blank, white material.
                /// </summary>
                public MatBoard()
                {
                    matFrame = new MaterialFrame();
                    minBoard = QuadBoard.Default;

                    color        = Color.White;
                    updateMatFit = true;
                }
            /// <summary>
            /// Builds a list of <see cref="Line.RichChar"/>s from RichString data.
            /// </summary>
            protected static void GetRichChars(RichStringMembers richString, Line charBuffer, bool allowSpecialChars)
            {
                StringBuilder      text       = richString.Item1;
                GlyphFormatMembers formatData = richString.Item2;
                Color   lastColor             = default(Color);
                Vector4 bbColor = default(Vector4);

                charBuffer.EnsureCapacity(charBuffer.Count + text.Length);

                for (int n = 0; n < text.Length; n++)
                {
                    if (formatData.Item4 != lastColor)
                    {
                        lastColor = formatData.Item4;
                        bbColor   = QuadBoard.GetQuadBoardColor(formatData.Item4);
                    }

                    if (text[n] >= ' ' || allowSpecialChars && (text[n] == '\n' || text[n] == '\t'))
                    {
                        charBuffer.InsertNew(charBuffer.Chars.Count, text[n], new GlyphFormat(formatData), bbColor);
                    }
                }
            }
Beispiel #6
0
        protected override void Initialize()
        {
            if (nDirections == 8)
            {
                isOctaboard = true;
            }

            playsCount = lossCount = winCount = 0;
            Board  board;
            Player player;

            new RNG(4);
            lossCount = winCount = 0;
            //setting first keyboard states
            state         = Keyboard.GetState();
            previousState = state;

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            if (fileON)
            {
                board = LoadLevel(out player);
                foreach (Obstacle obs in board.obstacles)
                {
                    obs.board = board;
                }
            }
            else
            {
                //Create a game board
                if (nDirections == 6) //Hexaboard
                {
                    board = new HexaBoard(width, height, nHoles, nBoxes, nCollectibles, nEnemies, nPortals, nLasers, nDirections, this);
                }
                else if (nDirections == 4) //Quadboard
                {
                    board = new QuadBoard(width, height, nHoles, nBoxes, nCollectibles, nEnemies, nPortals, nLasers, nDirections, this);
                }
                else //Octaboard
                {
                    board = new OctaBoard(width, height, nHoles, nBoxes, nCollectibles, nEnemies, nPortals, nLasers, nDirections, this);
                }

                //player is placed on the first tile if it isn't a hole
                if (board[0, 0] != null)
                {
                    //create a player
                    player = new Player(board, board[0, 0].position);
                }
                else
                {
                    player = new Player(board, board[1, 0].position);
                }
                currentGameState = new GameState(board, player);
            }

            Moves = board.GetKeysDirection(BoardInfo.nDirections);

            if (MCTSPlayer)
            {
                treeRootMTCS = new NodeMCTS(currentGameState);
            }

            baseObstaclePos = new Vector2[board.obstacles.Count];

            for (int i = 0; i < board.obstacles.Count; i++)
            {
                baseObstaclePos[i] = board.obstacles[i].position;
            }

            base.Initialize();
        }
Beispiel #7
0
        Board LoadLevel(out Player player)
        {
            string[] file = File.ReadAllLines(Content.RootDirectory + "/level.txt");
            width  = file[0].Length;
            height = file.Length;
            List <Obstacle>    obstacles = new List <Obstacle>();
            List <WinObject>   winObjects = new List <WinObject>();
            List <EnemyObject> enemyObjects = new List <EnemyObject>();
            Vector2            playerPos = new Vector2();
            int holesCount = 0, boxCount = 0, enemyCount = 0, collectibleCount = 0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    // Hole
                    if (file[i][j] == '#')
                    {
                        holesCount++;
                    }
                    //Box
                    else if (file[i][j] == 'B')
                    {
                        boxCount++;
                    }
                    //Enemy
                    else if (file[i][j] == 'E')
                    {
                        enemyCount++;
                    }
                    //Collectible
                    else if (file[i][j] == 'C')
                    {
                        collectibleCount++;
                    }
                }
            }

            Board tempBoard = new HexaBoard(width, height, holesCount, boxCount, enemyCount, nPortals, nLasers, nCollectibles, nDirections, this);

            Vector2[] holesPosition = new Vector2[holesCount];
            holesCount = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // Player
                    if (file[y][x] == 'P')
                    {
                        playerPos = new Vector2(x, y);
                    }
                    //Box
                    else if (file[y][x] == 'B')
                    {
                        Box box = new Box(tempBoard, this)
                        {
                            position = new Vector2(x, y)
                        };
                        obstacles.Add(box);
                    }
                    //Toggle
                    else if (file[y][x] == 'T')
                    {
                        Toggle toggle = new Toggle(this);
                        toggle.position = new Vector2(x, y);
                        winObjects.Add(toggle);
                    }
                    //Collectible
                    else if (file[y][x] == 'C')
                    {
                        Collectible collectible = new Collectible(this);
                        collectible.position = new Vector2(x, y);
                        winObjects.Add(collectible);
                    }
                    //Hole
                    else if (file[y][x] == '#')
                    {
                        holesPosition[holesCount] = new Vector2(x, y);
                        holesCount++;
                    }
                    //Enemy
                    else if (file[y][x] == 'E')
                    {
                        Spike spike = new Spike(this);
                        spike.position = new Vector2(x, y);
                        enemyObjects.Add(spike);
                    }
                }
            }

            Board board = new HexaBoard(width, height, holesPosition, obstacles, enemyObjects, winObjects, nDirections, this);

            if (nDirections == 4)
            {
                board = new QuadBoard(width, height, holesPosition, obstacles, enemyObjects, winObjects, nDirections, this);
            }

            player           = new Player(board, playerPos);
            currentGameState = new GameState(board, player);
            return(board);
        }
                static QuadBoard()
                {
                    var matFit = new BoundingBox2(new Vector2(0f, 0f), new Vector2(0f, 1f));

                    Default = new QuadBoard(Material.Default.TextureID, matFit, Color.White);
                }
                /// <summary>
                /// Generates underlines for underlined text
                /// </summary>
                private void UpdateUnderlines()
                {
                    int visRange = endLine - startLine;

                    underlines.Clear();
                    underlines.EnsureCapacity(visRange);

                    for (int ln = startLine; ln <= endLine; ln++)
                    {
                        Line line = lines[ln];

                        if (line.Count > 0)
                        {
                            GlyphFormatMembers?formatData = line.FormattedGlyphs[0].format.Data;
                            int startCh = 0;

                            for (int ch = 0; ch < lines[ln].Count; ch++)
                            {
                                GlyphFormatMembers?nextFormat = null;

                                if (ch != line.Count - 1)
                                {
                                    nextFormat = line.FormattedGlyphs[ch + 1].format.Data;
                                }

                                bool formatEqual = nextFormat != null &&
                                                   formatData.Value.Item1 == nextFormat.Value.Item1 &&
                                                   formatData.Value.Item2 == nextFormat.Value.Item2 &&
                                                   formatData.Value.Item3 == nextFormat.Value.Item3 &&
                                                   formatData.Value.Item4 == nextFormat.Value.Item4;

                                if (!formatEqual)
                                {
                                    if (((FontStyles)formatData.Value.Item3.Y & FontStyles.Underline) > 0)
                                    {
                                        GlyphLocData start = line.LocData[startCh], end = line.LocData[ch];
                                        Vector2      pos = new Vector2
                                                           (
                                            (start.bbOffset.X + end.bbOffset.X) * .5f,
                                            end.bbOffset.Y - (end.chSize.Y * .5f - (1f * formatData.Value.Item2))
                                                           );

                                        Vector2 size = new Vector2
                                                       (
                                            (end.bbOffset.X - start.bbOffset.X) + (end.chSize.X + start.chSize.X) * .5f,
                                            Math.Max((int)formatData.Value.Item2, 1)
                                                       );

                                        Vector4 color = QuadBoard.GetQuadBoardColor(formatData.Value.Item4) * .9f;
                                        underlines.Add(new UnderlineBoard(size, pos, color));
                                    }

                                    startCh    = ch;
                                    formatData = nextFormat;
                                }
                            }
                        }
                    }

                    if (visRange > 9 && underlines.Capacity > 3 * underlines.Count && underlines.Capacity > visRange)
                    {
                        underlines.TrimExcess();
                    }
                }
                /// <summary>
                /// Draws the text board in world space on the XY plane of the matrix, facing in the +Z
                /// direction.
                /// </summary>
                public void Draw(BoundingBox2 box, BoundingBox2 mask, MatrixD[] matrix)
                {
                    ContainmentType containment;

                    mask.Contains(ref box, out containment);

                    if (containment != ContainmentType.Disjoint)
                    {
                        if (offsetsAreStale)
                        {
                            UpdateOffsets();
                        }
                        else if (lineRangeIsStale || (endLine == -1 && lines.Count > 0))
                        {
                            UpdateLineRange();
                        }

                        if (AutoResize)
                        {
                            _textOffset = Vector2.Zero;
                        }

                        if (updateEvent && (eventTimer.ElapsedTicks / TimeSpan.TicksPerMillisecond) > 500)
                        {
                            TextChanged?.Invoke();
                            eventTimer.Restart();
                            updateEvent = false;
                        }

                        BoundingBox2 textMask = box.Intersect(mask);
                        Vector2      offset   = box.Center + _textOffset * Scale;

                        IReadOnlyList <Line> lineList = lines.PooledLines;
                        CroppedBox           bb       = default(CroppedBox);
                        bb.mask = textMask;

                        // Draw glyphs
                        for (int ln = startLine; ln <= endLine && ln < lines.Count; ln++)
                        {
                            Line line = lineList[ln];

                            for (int ch = 0; ch < line.Count; ch++)
                            {
                                GlyphLocData locData  = line.LocData[ch];
                                Vector2      halfSize = locData.bbSize * Scale * .5f,
                                             pos      = offset + locData.bbOffset * Scale;

                                bb.bounds = new BoundingBox2(pos - halfSize, pos + halfSize);
                                bb.mask.Value.Contains(ref bb.bounds, out containment);

                                if (containment == ContainmentType.Contains)
                                {
                                    line.GlyphBoards[ch].Draw(ref bb, ref matrix[0]);
                                }
                                else if (containment != ContainmentType.Disjoint)
                                {
                                    line.GlyphBoards[ch].DrawCroppedTex(ref bb, ref matrix[0]);
                                }
                            }
                        }

                        QuadBoard underlineBoard = QuadBoard.Default;

                        // Draw underlines
                        for (int n = 0; n < underlines.Count; n++)
                        {
                            Vector2 halfSize = underlines[n].size * Scale * .5f,
                                    pos      = offset + underlines[n].offset * Scale;

                            bb.bounds = new BoundingBox2(pos - halfSize, pos + halfSize);
                            bb.mask.Value.Contains(ref bb.bounds, out containment);
                            underlineBoard.bbColor = underlines[n].color;

                            if (containment == ContainmentType.Contains)
                            {
                                underlineBoard.Draw(ref bb, ref matrix[0]);
                            }
                            else if (containment != ContainmentType.Disjoint)
                            {
                                underlineBoard.DrawCropped(ref bb, ref matrix[0]);
                            }
                        }
                    }
                }