Exemple #1
0
 public MovableSprite(Tileset tileset, Tile tile)
 {
     this.tileset = tileset;
     this.tile = tile;
     this.isRotating = true;
     this.rotationAngle = 0.0f;
     this.speed = DefaultSpeed;
     this.direction = Direction.Up;
     this.formerDirection = Direction.Up;
 }
Exemple #2
0
        public static Tile[,] Load(string path, int layerNumber)
        {
            List<int[]> layout = new List<int[]>();
            using (TextReader reader = new StreamReader(path))
            {
                string line = reader.ReadLine();
                bool read = false;
                bool triggerFound = false;

                while (line != null)
                {
                    if (read)
                    {
                        if (line == string.Empty)
                        {
                            read = false;
                            break;
                        }

                        string[] rowElements = line.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        layout.Add(rowElements.Select(x => int.Parse(x) - lastMaxValue).ToArray());
                    }

                    if (triggerFound && line.CompareTo("data=") == 0)
                    {
                        read = true;
                        triggerFound = false;
                    }

                    if (line.CompareTo("type=Tile Layer " + layerNumber) == 0)
                    {
                        triggerFound = true;
                    }
                    else if (Regex.IsMatch(line, @"\bwidth=\d+"))
                    {
                        width = FindDimension(line, @"width=");
                    }
                    else if (Regex.IsMatch(line, @"\bheight=\d+"))
                    {
                        height = FindDimension(line, @"height=");
                    }

                    line = reader.ReadLine();
                }
            }

            Tile[,] result = new Tile[width, height];

            ConvertMatrix(result, layout, layerNumber);

            return result;
        }
Exemple #3
0
        private static void ConvertMatrix(Tile[,] result, List<int[]> layout, int layerNumber)
        {
            int newMaxValue = int.MinValue;
            for (int row = 0; row < width; row++)
            {
                for (int col = 0; col < height; col++)
                {
                    result[row, col] = new Tile(layerNumber - 1, layout[row][col] - 1);

                    if (layout[row][col] > newMaxValue)
                    {
                        newMaxValue = layout[row][col];
                    }
                }
            }

            lastMaxValue += newMaxValue;
        }
Exemple #4
0
 public void SetTile(int x, int y, Tile tile)
 {
     this.map[y, x] = tile;
 }
Exemple #5
0
 public MapLayer(Tile[,] map)
 {
     this.map = (Tile[,])map.Clone();
 }
Exemple #6
0
 public void SetTile(int number, Tile tile)
 {
     this.tanks[number] = tile;
 }
Exemple #7
0
 public TanksSprite(Tile[] tanks)
 {
     this.tanks = tanks;
 }