Ejemplo n.º 1
0
        public void LoadLevel()
        {
            using (StreamReader sr = new StreamReader("Content/testmap.txt"))
            {
                List<string> lines = new List<string>();
                while (!sr.EndOfStream)
                {
                    lines.Add(sr.ReadLine());
                }
                xDimension = lines[0].Length;
                yDimension = lines.Count;
                tiles = new Tile[xDimension, yDimension];
                for (int i = 0; i < xDimension; i++)
                {
                    for (int j = 0; j < yDimension; j++)
                    {

                        switch (lines[j][i])
                        {
                            case '#':
                                tiles[i, j] = new Tile(i, j, new Rectangle((int)(i * TileSize), (int)(j * TileSize), (int)TileSize, (int)TileSize));
                                tiles[i, j].passable = false;
                                Body body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(TileSize), ConvertUnits.ToSimUnits(TileSize), 10, ConvertUnits.ToSimUnits(GetWindowCenterPos(tiles[i, j])));
                                body.BodyType = BodyType.Static;
                                body.CollidesWith = Category.All;
                                body.CollisionCategories = Category.All;
                                tileBodies.Add(body);
                                break;
                            case 'r':
                                tiles[i, j] = new ResourceTile(i, j, new Rectangle((int)(i * TileSize), (int)(j * TileSize), (int)TileSize, (int)TileSize),2000);
                                tiles[i, j].resourceTile = true;
                                break;
                            case 's':
                                tiles[i, j] = new Tile(i, j, new Rectangle((int)(i * TileSize), (int)(j * TileSize), (int)TileSize, (int)TileSize));
                                break;
                            default:
                                tiles[i, j] = new Tile(i, j, new Rectangle((int)(i * TileSize), (int)(j * TileSize), (int)TileSize, (int)TileSize));
                                break;
                        }

                    }
                }

                //Go through again for spawning locations
                for (int i = 0; i < xDimension; i++)
                {
                    for (int j = 0; j < yDimension; j++)
                    {
                        switch (lines[j][i])
                        {
                            case 's':
                                gm.SpawnBase(i, j, factionIndex++);
                                break;
                            default:
                                break;
                        }

                    }
                }

            }

            AssignNeighbours();
        }
Ejemplo n.º 2
0
        public void LoadLevel()
        {
            using (StreamReader sr = new StreamReader("Content/testmap.txt"))
            {
                List <string> lines = new List <string>();
                while (!sr.EndOfStream)
                {
                    lines.Add(sr.ReadLine());
                }
                xDimension = lines[0].Length;
                yDimension = lines.Count;
                tiles      = new Tile[xDimension, yDimension];
                for (int i = 0; i < xDimension; i++)
                {
                    for (int j = 0; j < yDimension; j++)
                    {
                        switch (lines[j][i])
                        {
                        case '#':
                            tiles[i, j]          = new Tile(i, j, new Rectangle((int)(i * TileSize), (int)(j * TileSize), (int)TileSize, (int)TileSize));
                            tiles[i, j].passable = false;
                            Body body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(TileSize), ConvertUnits.ToSimUnits(TileSize), 10, ConvertUnits.ToSimUnits(GetWindowCenterPos(tiles[i, j])));
                            body.BodyType            = BodyType.Static;
                            body.CollidesWith        = Category.All;
                            body.CollisionCategories = Category.All;
                            tileBodies.Add(body);
                            break;

                        case 'r':
                            tiles[i, j] = new ResourceTile(i, j, new Rectangle((int)(i * TileSize), (int)(j * TileSize), (int)TileSize, (int)TileSize), 2000);
                            tiles[i, j].resourceTile = true;
                            break;

                        case 's':
                            tiles[i, j] = new Tile(i, j, new Rectangle((int)(i * TileSize), (int)(j * TileSize), (int)TileSize, (int)TileSize));
                            break;

                        default:
                            tiles[i, j] = new Tile(i, j, new Rectangle((int)(i * TileSize), (int)(j * TileSize), (int)TileSize, (int)TileSize));
                            break;
                        }
                    }
                }

                //Go through again for spawning locations
                for (int i = 0; i < xDimension; i++)
                {
                    for (int j = 0; j < yDimension; j++)
                    {
                        switch (lines[j][i])
                        {
                        case 's':
                            gm.SpawnBase(i, j, factionIndex++);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            AssignNeighbours();
        }