Пример #1
0
        public LevelFragment(LevelContent content, GraphicsDevice graphicsDevice)
        {
            grid = new LevelContent.LevelTile[content.levelWidth, content.levelHeight];
            for (int x = 0; x < content.grid.Length; x++)
            {
                int i = x % content.levelWidth;
                int j = x / content.levelWidth;
                grid[i, j] = content.grid[x];
            }

            name  = content.name;
            type  = content.type;
            id    = idCounter++;
            color = content.color;

            //create texture
            int texWidth  = content.levelWidth * Level.TILE_SIZE;
            int texHeight = content.levelHeight * Level.TILE_SIZE;

            levelTextureDebug = new Texture2D(graphicsDevice, texWidth, texHeight);
            Color[] data = new Color[texWidth * texHeight];
            for (int d = 0; d < data.Length; d++)
            {
                int i = (d % (texWidth)) / Level.TILE_SIZE;
                int j = (d / (texWidth)) / Level.TILE_SIZE;
                data[d] = LevelContent.TILE_TO_COLOR[grid[i, j]];
            }
            levelTextureDebug.SetData(data);
            levelTexture = new Texture2D(graphicsDevice, texWidth, texHeight);
            Color[] tileData = new Color[Level.TILE_SIZE * Level.TILE_SIZE];
            for (int i = 0; i < content.levelWidth; i++)
            {
                for (int j = 0; j < content.levelHeight; j++)
                {
                    if (Level.TILE_TO_TEXTURE[grid[i, j]] != null)
                    {
                        Level.TILE_TO_TEXTURE[grid[i, j]].GetData <Color>(tileData);
                        // tint texture
                        for (int d = 0; d < tileData.Length; d++)
                        {
                            tileData[d] = tileData[d].Tint(color, Level.COLOR_TINT_FACTOR);
                        }
                        levelTexture.SetData <Color>(0, new Rectangle(i * Level.TILE_SIZE, j * Level.TILE_SIZE, Level.TILE_SIZE, Level.TILE_SIZE), tileData, 0, Level.TILE_SIZE * Level.TILE_SIZE);
                    }

                    if (grid[i, j] == LevelContent.LevelTile.Gem)
                    {
                        collectableLocations.Add(new int[2] {
                            i, j
                        });
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Enemy)
                    {
                        enemyLocations.Add(new int[2] {
                            i, j
                        });
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Prisoner)
                    {
                        prisonerLocations.Add(new int[2] {
                            i, j
                        });
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Powerup)
                    {
                        powerupLocations.Add(new int[2] {
                            i, j
                        });
                    }
                    //special tiles
                    else if (grid[i, j] == LevelContent.LevelTile.Special1)
                    {
                        if (specialTiles[0][0] == null)
                        {
                            specialTiles[0][0] = new int[2] {
                                i, j
                            }
                        }
                        ;
                        else
                        {
                            specialTiles[1][0] = new int[2] {
                                i, j
                            }
                        };
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Special2)
                    {
                        if (specialTiles[0][1] == null)
                        {
                            specialTiles[0][1] = new int[2] {
                                i, j
                            }
                        }
                        ;
                        else
                        {
                            specialTiles[1][1] = new int[2] {
                                i, j
                            }
                        };
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Special3)
                    {
                        if (specialTiles[0][2] == null)
                        {
                            specialTiles[0][2] = new int[2] {
                                i, j
                            }
                        }
                        ;
                        else
                        {
                            specialTiles[1][2] = new int[2] {
                                i, j
                            }
                        };
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Special4)
                    {
                        if (specialTiles[0][3] == null)
                        {
                            specialTiles[0][3] = new int[2] {
                                i, j
                            }
                        }
                        ;
                        else
                        {
                            specialTiles[1][3] = new int[2] {
                                i, j
                            }
                        };
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Hero1)
                    {
                        heroTiles[0] = new int[2] {
                            i, j
                        }
                    }
                    ;
                    else if (grid[i, j] == LevelContent.LevelTile.Hero2)
                    {
                        heroTiles[1] = new int[2] {
                            i, j
                        }
                    }
                    ;
                }
            }
        }
Пример #2
0
        public LevelFragment(LevelContent content, GraphicsDevice graphicsDevice)
        {
            grid = new LevelContent.LevelTile[content.levelWidth, content.levelHeight];
            for (int x = 0; x < content.grid.Length; x++)
            {
                int i = x % content.levelWidth;
                int j = x / content.levelWidth;
                grid[i, j] = content.grid[x];
            }

            name = content.name;
            type = content.type;
            id = idCounter++;
            color = content.color;

            //create texture
            int texWidth = content.levelWidth * Level.TILE_SIZE;
            int texHeight = content.levelHeight * Level.TILE_SIZE;

            levelTextureDebug = new Texture2D(graphicsDevice, texWidth, texHeight);
            Color[] data = new Color[texWidth * texHeight];
            for (int d = 0; d < data.Length; d++)
            {
                int i = (d % (texWidth)) / Level.TILE_SIZE;
                int j = (d / (texWidth)) / Level.TILE_SIZE;
                data[d] = LevelContent.TILE_TO_COLOR[grid[i, j]];
            }
            levelTextureDebug.SetData(data);
            levelTexture = new Texture2D(graphicsDevice, texWidth, texHeight);
            Color[] tileData = new Color[Level.TILE_SIZE * Level.TILE_SIZE];
            for (int i = 0; i < content.levelWidth; i++)
                for (int j = 0; j < content.levelHeight; j++)
                {
                    if (Level.TILE_TO_TEXTURE[grid[i, j]] != null)
                    {
                        Level.TILE_TO_TEXTURE[grid[i, j]].GetData<Color>(tileData);
                        // tint texture
                        for (int d = 0; d < tileData.Length; d++)
                            tileData[d] = tileData[d].Tint(color, Level.COLOR_TINT_FACTOR);
                        levelTexture.SetData<Color>(0, new Rectangle(i * Level.TILE_SIZE, j * Level.TILE_SIZE, Level.TILE_SIZE, Level.TILE_SIZE), tileData, 0, Level.TILE_SIZE * Level.TILE_SIZE);
                    }

                    if (grid[i, j] == LevelContent.LevelTile.Gem)
                        collectableLocations.Add(new int[2] { i, j });
                    else if (grid[i, j] == LevelContent.LevelTile.Enemy)
                        enemyLocations.Add(new int[2] { i, j });
                    else if (grid[i, j] == LevelContent.LevelTile.Prisoner)
                        prisonerLocations.Add(new int[2] { i, j });
                    else if (grid[i, j] == LevelContent.LevelTile.Powerup)
                        powerupLocations.Add(new int[2] { i, j });
                    //special tiles
                    else if(grid[i, j] == LevelContent.LevelTile.Special1)
                    {
                        if (specialTiles[0][0] == null)
                            specialTiles[0][0] = new int[2] {i, j};
                        else
                            specialTiles[1][0] = new int[2] { i, j };
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Special2)
                    {
                        if (specialTiles[0][1] == null)
                            specialTiles[0][1] = new int[2] { i, j };
                        else
                            specialTiles[1][1] = new int[2] { i, j };
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Special3)
                    {
                        if (specialTiles[0][2] == null)
                            specialTiles[0][2] = new int[2] { i, j };
                        else
                            specialTiles[1][2] = new int[2] { i, j };
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Special4)
                    {
                        if (specialTiles[0][3] == null)
                            specialTiles[0][3] = new int[2] { i, j };
                        else
                            specialTiles[1][3] = new int[2] { i, j };
                    }
                    else if (grid[i, j] == LevelContent.LevelTile.Hero1)
                        heroTiles[0] = new int[2] { i, j };
                    else if (grid[i, j] == LevelContent.LevelTile.Hero2)
                        heroTiles[1] = new int[2] { i, j };
                }
        }
Пример #3
0
 public static LevelFragment getRandomLevelFragment(LevelContent.Type type)
 {
     switch (type)
     {
         case LevelContent.Type.Full:
             if (testFragmentsFull.Count > 0)
                 return testFragmentsFull[rand.Next(testFragmentsFull.Count)];
             return levelFragmentsFull.ElementAt(rand.Next(levelFragmentsFull.Keys.Count)).Value;
         case LevelContent.Type.HalfHorizontal:
             if (testFragmentsHalfHorizontal.Count > 0)
                 return testFragmentsHalfHorizontal[rand.Next(testFragmentsHalfHorizontal.Count)];
             return levelFragmentsHalfHorizontal.ElementAt(rand.Next(levelFragmentsHalfHorizontal.Keys.Count)).Value;
         case LevelContent.Type.HalfVertical:
             if (testFragmentsHalfVertical.Count > 0)
                 return testFragmentsHalfVertical[rand.Next(testFragmentsHalfVertical.Count)];
             return levelFragmentsHalfVertical.ElementAt(rand.Next(levelFragmentsHalfVertical.Keys.Count)).Value;
         case LevelContent.Type.Corner:
             if (testFragmentsCorner.Count > 0)
                 return testFragmentsCorner[rand.Next(testFragmentsCorner.Count)];
             return levelFragmentsCorner.ElementAt(rand.Next(levelFragmentsCorner.Keys.Count)).Value;
         default:
             throw new ArgumentException("Incompatible level fragment type: " + type.ToString(), "type");
     }
 }