예제 #1
0
 public TileRenderer(Tile data)
 {
     this.data = data;
     rectangleShape = new RectangleShape();
     rectangleShape.Size = this.data.Size;
     rectangleShape.FillColor = data.FillColor;
 }
예제 #2
0
파일: Tile.cs 프로젝트: Cellmon95/WarGames
        public Tile(TileType tileType)
        {
            Size = new Vector2f(32, 32);
            Children = new Tile[8];
            Type = tileType;

            setTileType(tileType);
        }
예제 #3
0
파일: Map.cs 프로젝트: Cellmon95/WarGames
        public Map(Vector2i mapSize)
        {
            //need to make the map one unit bigger for the void frame
            mapSize.X++;
            mapSize.Y++;
            Size = new Vector2f(mapSize.X * 32, mapSize.Y * 32);
            Position = new Vector2f(-32, -32);

            tiles = new Tile[mapSize.X + 2, mapSize.Y + 2];
            rand = new Random();

            randomiseMap();
            setTileChildren();
        }
예제 #4
0
        public int calculateSmallestPath(Tile start, Tile target)
        {
            reset();

            if (target == start)
                return 0;

            StartingTile = start;
            TargetTile = target;
            CheckingTile = StartingTile;

            while (!FoundTarget)
            {
                findPath();
            }

            //Console.WriteLine(TargetTile.FValue);
            return traceBack();
        }
예제 #5
0
파일: Map.cs 프로젝트: Cellmon95/WarGames
        /// <summary>
        /// Makes the map random.
        /// </summary>
        private void randomiseMap()
        {
            int tmpNum = 0;
            for (int x = 0; x < tiles.GetLength(0); x++)
            {
                for (int y = 0; y < tiles.GetLength(1); y++)
                {
                    if (x == 0 || x == tiles.GetLength(0) - 1)
                    {
                        tiles[x, y] = null;
                    }

                    else if (y == 0 || y == tiles.GetLength(1) - 1)
                    {
                        tiles[x, y] = null;
                    }

                    else
                    {
                        tmpNum = rand.Next(0, 100);

                        if (tmpNum <= 80)
                            tiles[x, y] = new Tile(Tile.TileType.GRASS);
                        else if (tmpNum >= 80 && tmpNum <= 100)
                            tiles[x, y] = new Tile(Tile.TileType.DIRT);
                        //set the position
                        tiles[x, y].Position = new SFML.Window.Vector2f(x * 32 + Position.X, y * 32 + Position.Y);
                    }
                }
            }
        }
예제 #6
0
        private void determenTileValue(Tile currentTile, Tile testingTile)
        {
            if (testingTile == null)
            {
                return;
            }

            if (testingTile == TargetTile)
            {
                testingTile.Parent = currentTile;
                FoundTarget = true;
                return;
            }

            if (!closeList.Contains(testingTile))
            {
                if (openList.Contains(testingTile))
                {
                    int newGCost = currentTile.GValue + currentTile.BaseGvalue;

                    if (newGCost < testingTile.GValue)
                    {
                        testingTile.Parent = currentTile;
                        testingTile.GValue = newGCost;
                        testingTile.calculateFValue();
                    }
                }

                else
                {
                    testingTile.Parent = currentTile;
                    testingTile.GValue = currentTile.GValue + currentTile.BaseGvalue;
                    testingTile.calculateFValue();
                    openList.Add(testingTile);
                }
            }
        }
예제 #7
0
 /// <summary>
 /// Resets everything.
 /// </summary>
 private void reset()
 {
     map.resetTiles();
     openList.Clear();
     closeList.Clear();
     FoundTarget = false;
     TargetTile = null;
 }