コード例 #1
0
        public bool CompareTextures(GameTexture t)
        {
            bool result = true;

            if (this.TextureType != t.TextureType)
            {
                result = false;
            }

            // Coparing the source texture
            if (!this.SourceTexture.Equals(t.SourceTexture))
            {
                result = false;
            }

            // Comparing the sub texture
            if (this.StartX != t.StartX || this.StartY != t.StartY)
            {
                result = false;
            }

            return(result);
        }
コード例 #2
0
        public SaveClass LoadGame(FileStream file)
        {
            StreamReader reader = new StreamReader(file);

            try
            {
                Game g = new Game();
                Dictionary <string, Texture> textures = new Dictionary <string, Texture>();

                // Number of textures
                int num = int.Parse(reader.ReadLine());

                // For each texture
                for (int i = 0; i < num; i++)
                {
                    string  key   = reader.ReadLine();
                    Texture value = StringToTexture(reader.ReadLine());

                    textures.Add(key, value);
                }

                // Number of rooms
                num = int.Parse(reader.ReadLine());

                // For each room
                for (int q = 0; q < num; q++)
                {
                    string name = reader.ReadLine();

                    int tile_x = int.Parse(reader.ReadLine());
                    int tile_y = int.Parse(reader.ReadLine());

                    Room r = new Room(name, tile_x, tile_y);

                    // For each tile
                    for (int j = 0; j < tile_y; j++)
                    {
                        for (int i = 0; i < tile_x; i++)
                        {
                            // For each layer
                            for (int f = 0; f < 2; f++)
                            {
                                string      sourceTexture = reader.ReadLine();
                                string      textureTypeS  = reader.ReadLine();
                                TextureType textureType;

                                switch (textureTypeS)
                                {
                                case "None":
                                    textureType = TextureType.None;
                                    break;

                                case "Base":
                                    textureType = TextureType.Base;
                                    break;

                                case "AutoTile":
                                    textureType = TextureType.AutoTile;
                                    break;

                                case "Wall":
                                    textureType = TextureType.Wall;
                                    break;

                                default:
                                    textureType = TextureType.None;
                                    break;
                                }

                                string        animationTypeS = reader.ReadLine();
                                AnimationType animationType;

                                switch (animationTypeS)
                                {
                                case "None":
                                    animationType = AnimationType.None;
                                    break;

                                case "AutoTile":
                                    animationType = AnimationType.AutoTile;
                                    break;

                                case "Waterfall":
                                    animationType = AnimationType.Waterfall;
                                    break;

                                default:
                                    animationType = AnimationType.None;
                                    break;
                                }

                                int startX = int.Parse(reader.ReadLine());
                                int startY = int.Parse(reader.ReadLine());
                                int sizeX  = int.Parse(reader.ReadLine());
                                int sizeY  = int.Parse(reader.ReadLine());

                                Rectangle[] rects = new Rectangle[4];
                                for (int h = 0; h < 4; h++)
                                {
                                    int rect_x      = int.Parse(reader.ReadLine());
                                    int rect_y      = int.Parse(reader.ReadLine());
                                    int rect_size_x = int.Parse(reader.ReadLine());
                                    int rect_size_y = int.Parse(reader.ReadLine());

                                    rects[h] = new Rectangle(rect_x, rect_y, rect_size_x, rect_size_y);
                                }

                                GameTexture gameTexture = new GameTexture(sourceTexture, textureType, startX, startY, sizeX, sizeY, rects);
                                r.Tiles[i, j].SetLayer(f, (GameTexture)(gameTexture.Clone()));
                            }
                        }
                    }

                    g.AddRoom(r);
                }

                reader.Close();
                reader.Dispose();

                SaveClass save = new SaveClass(g, textures);
                return(save);
            }
            catch (Exception e)
            {
                reader.Close();
                reader.Dispose();

                return(null);
            }
        }
コード例 #3
0
 public void Resetbrush()
 {
     this.texture = new GameTexture(String.Empty, TextureType.None);
     this.layer   = 0;
 }
コード例 #4
0
        public void SetLayer(int layer, GameTexture texture)
        {
            GameTexture t = (GameTexture)texture.Clone();

            this.layers[layer].GameTexture = t;
        }
コード例 #5
0
 public TileLayer(GameTexture texture)
 {
     this.texture = texture;
 }
コード例 #6
0
        /// <summary>
        /// Places an autotile
        /// </summary>
        /// <param name="brush"></param>
        /// <param name="checkTexture"></param>
        /// <param name="i"></param>
        /// <param name="y"></param>
        /// <param name="checkonly"></param>
        /// <param name="repeat"></param>
        public static void DoAutoTile(EditorBrush brush, GameTexture checkTexture, int i, int y, bool checkonly, bool repeat)
        {
            bool left  = false;
            bool right = false;
            bool up    = false;
            bool down  = false;

            bool leftup    = false;
            bool rightup   = false;
            bool leftdown  = false;
            bool rightdown = false;

            if (checkonly)
            {
                if (i != 0)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i - 1, y].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        left = true;
                    }
                }

                // Get tile to the right
                if (i != Engine.game.GetCurrentRoom().Tiles.GetLength(0) - 1)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i + 1, y].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        right = true;
                    }
                }

                // Get tile above
                if (y != 0)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i, y - 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        up = true;
                    }
                }

                // Get tile below
                if (y != Engine.game.GetCurrentRoom().Tiles.GetLength(1) - 1)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i, y + 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        down = true;
                    }
                }

                if (i != 0 && y != 0)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i - 1, y - 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        leftup = true;
                    }
                }

                if (i != Engine.game.GetCurrentRoom().Tiles.GetLength(0) - 1 && y != 0)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i + 1, y - 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        rightup = true;
                    }
                }

                if (i != 0 && y != Engine.game.GetCurrentRoom().Tiles.GetLength(1) - 1)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i - 1, y + 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        leftdown = true;
                    }
                }

                if (i != Engine.game.GetCurrentRoom().Tiles.GetLength(0) - 1 && y != Engine.game.GetCurrentRoom().Tiles.GetLength(1) - 1)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i + 1, y + 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        rightdown = true;
                    }
                }
            }
            else
            {
                if (i != 0)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i - 1, y].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        if (Engine.game.GetCurrentRoom().Tiles[i - 1, y].Layers[brush.Layer].GameTexture.CompareTextures(checkTexture))
                        {
                            left = true;
                        }
                    }
                }

                // Get tile to the right
                if (i != Engine.game.GetCurrentRoom().Tiles.GetLength(0) - 1)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i + 1, y].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        if (Engine.game.GetCurrentRoom().Tiles[i + 1, y].Layers[brush.Layer].GameTexture.CompareTextures(checkTexture))
                        {
                            right = true;
                        }
                    }
                }

                // Get tile above
                if (y != 0)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i, y - 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        if (Engine.game.GetCurrentRoom().Tiles[i, y - 1].Layers[brush.Layer].GameTexture.CompareTextures(checkTexture))
                        {
                            up = true;
                        }
                    }
                }

                // Get tile below
                if (y != Engine.game.GetCurrentRoom().Tiles.GetLength(1) - 1)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i, y + 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        if (Engine.game.GetCurrentRoom().Tiles[i, y + 1].Layers[brush.Layer].GameTexture.CompareTextures(checkTexture))
                        {
                            down = true;
                        }
                    }
                }

                if (i != 0 && y != 0)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i - 1, y - 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        if (Engine.game.GetCurrentRoom().Tiles[i - 1, y - 1].Layers[brush.Layer].GameTexture.CompareTextures(checkTexture))
                        {
                            leftup = true;
                        }
                    }
                }

                if (i != Engine.game.GetCurrentRoom().Tiles.GetLength(0) - 1 && y != 0)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i + 1, y - 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        if (Engine.game.GetCurrentRoom().Tiles[i + 1, y - 1].Layers[brush.Layer].GameTexture.CompareTextures(checkTexture))
                        {
                            rightup = true;
                        }
                    }
                }

                if (i != 0 && y != Engine.game.GetCurrentRoom().Tiles.GetLength(1) - 1)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i - 1, y + 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        if (Engine.game.GetCurrentRoom().Tiles[i - 1, y + 1].Layers[brush.Layer].GameTexture.CompareTextures(checkTexture))
                        {
                            leftdown = true;
                        }
                    }
                }

                if (i != Engine.game.GetCurrentRoom().Tiles.GetLength(0) - 1 && y != Engine.game.GetCurrentRoom().Tiles.GetLength(1) - 1)
                {
                    if (Engine.game.GetCurrentRoom().Tiles[i + 1, y + 1].Layers[brush.Layer].GameTexture.TextureType == TextureType.AutoTile)
                    {
                        if (Engine.game.GetCurrentRoom().Tiles[i + 1, y + 1].Layers[brush.Layer].GameTexture.CompareTextures(checkTexture))
                        {
                            rightdown = true;
                        }
                    }
                }

                Rectangle[] rects = new Rectangle[4];

                rects[0] = new Rectangle(brush.Texture.StartX, brush.Texture.StartY, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                rects[1] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH, brush.Texture.StartY, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                rects[2] = new Rectangle(brush.Texture.StartX, brush.Texture.StartY + Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                rects[3] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH, brush.Texture.StartY + Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);

                // Top left
                if (left && up)
                {
                    rects[0] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 2, brush.Texture.StartY + Default.SUBTILE_WIDTH * 0, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (left && !up)
                {
                    rects[0] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 2, brush.Texture.StartY + Default.SUBTILE_WIDTH * 2, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (!left && up)
                {
                    rects[0] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 0, brush.Texture.StartY + Default.SUBTILE_WIDTH * 4, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (left && up && leftup)
                {
                    rects[0] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 2, brush.Texture.StartY + Default.SUBTILE_WIDTH * 4, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }

                // Top Right
                if (up && right)
                {
                    rects[1] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 3, brush.Texture.StartY + Default.SUBTILE_WIDTH * 0, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (up && !right)
                {
                    rects[1] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 3, brush.Texture.StartY + Default.SUBTILE_WIDTH * 4, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (!up && right)
                {
                    rects[1] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 1, brush.Texture.StartY + Default.SUBTILE_WIDTH * 2, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (up && right && rightup)
                {
                    rects[1] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 1, brush.Texture.StartY + Default.SUBTILE_WIDTH * 4, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }

                // Bottom Left
                if (left && down)
                {
                    rects[2] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 2, brush.Texture.StartY + Default.SUBTILE_WIDTH * 1, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (left && !down)
                {
                    rects[2] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 2, brush.Texture.StartY + Default.SUBTILE_WIDTH * 5, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (!left && down)
                {
                    rects[2] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 0, brush.Texture.StartY + Default.SUBTILE_WIDTH * 3, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (left && down && leftdown)
                {
                    rects[2] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 2, brush.Texture.StartY + Default.SUBTILE_WIDTH * 3, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }

                // Bottom Right
                if (down && right)
                {
                    rects[3] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 3, brush.Texture.StartY + Default.SUBTILE_WIDTH * 1, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (down && !right)
                {
                    rects[3] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 3, brush.Texture.StartY + Default.SUBTILE_WIDTH * 4, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (!down && right)
                {
                    rects[3] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 1, brush.Texture.StartY + Default.SUBTILE_WIDTH * 5, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }
                if (down && right && rightdown)
                {
                    rects[3] = new Rectangle(brush.Texture.StartX + Default.SUBTILE_WIDTH * 1, brush.Texture.StartY + Default.SUBTILE_WIDTH * 3, Default.SUBTILE_WIDTH, Default.SUBTILE_WIDTH);
                }

                brush.Texture.Rects = rects;
                //GameTexture texture = new GameTexture(brush., TextureType.AutoTile, brush.Texture.StartX, brush.Texture.StartY, Default.TILE_WIDTH, Default.TILE_WIDTH, rects);
                Engine.game.GetCurrentRoom().Tiles[i, y].SetLayer(brush.Layer, brush.Texture);
            }

            if (repeat)
            {
                if (left)
                {
                    DoAutoTile(brush, Engine.game.GetCurrentRoom().Tiles[i - 1, y].Layers[brush.Layer].GameTexture, i - 1, y, false, false);
                }
                if (right)
                {
                    DoAutoTile(brush, Engine.game.GetCurrentRoom().Tiles[i + 1, y].Layers[brush.Layer].GameTexture, i + 1, y, false, false);
                }
                if (up)
                {
                    DoAutoTile(brush, Engine.game.GetCurrentRoom().Tiles[i, y - 1].Layers[brush.Layer].GameTexture, i, y - 1, false, false);
                }
                if (down)
                {
                    DoAutoTile(brush, Engine.game.GetCurrentRoom().Tiles[i, y + 1].Layers[brush.Layer].GameTexture, i, y + 1, false, false);
                }
                if (leftup)
                {
                    DoAutoTile(brush, Engine.game.GetCurrentRoom().Tiles[i - 1, y - 1].Layers[brush.Layer].GameTexture, i - 1, y - 1, false, false);
                }
                if (rightup)
                {
                    DoAutoTile(brush, Engine.game.GetCurrentRoom().Tiles[i + 1, y - 1].Layers[brush.Layer].GameTexture, i + 1, y - 1, false, false);
                }
                if (leftdown)
                {
                    DoAutoTile(brush, Engine.game.GetCurrentRoom().Tiles[i - 1, y + 1].Layers[brush.Layer].GameTexture, i - 1, y + 1, false, false);
                }
                if (rightdown)
                {
                    DoAutoTile(brush, Engine.game.GetCurrentRoom().Tiles[i + 1, y + 1].Layers[brush.Layer].GameTexture, i + 1, y + 1, false, false);
                }
            }
        }