public TileRenderer(Tile data) { this.data = data; rectangleShape = new RectangleShape(); rectangleShape.Size = this.data.Size; rectangleShape.FillColor = data.FillColor; }
public Tile(TileType tileType) { Size = new Vector2f(32, 32); Children = new Tile[8]; Type = tileType; setTileType(tileType); }
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(); }
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(); }
/// <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); } } } }
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); } } }
/// <summary> /// Resets everything. /// </summary> private void reset() { map.resetTiles(); openList.Clear(); closeList.Clear(); FoundTarget = false; TargetTile = null; }