public bool AddTile(Tile tile) { if (!Tiles.Contains(tile)) { tile.BaseActor = this; Tiles.Add(tile); return true; } else { return false; } }
public void ActivateTile(Tile selectedBoardTile, TileType newTileType) { if (newTileType != TileType.Background) { //Remove any existing tiles Tile tileToRemove = null; foreach (Tile tile in ActiveTiles) { if (tile.BoardPosition == selectedBoardTile.BoardPosition) { tileToRemove = tile; } } if (tileToRemove != null) { ActiveTiles.Remove(tileToRemove); } //Add a new active tile Tile tileToAdd = new Tile(); if (LudimusGame.TileTypeLookup.ContainsKey(newTileType)) { tileToAdd.Type = newTileType; } tileToAdd.Initialize(selectedBoardTile.CurrentGlobalPosition, selectedBoardTile.Size, Graphics, LudimusGame.TileTypeLookup[newTileType]); tileToAdd.BoardPosition = selectedBoardTile.BoardPosition; ActiveTiles.Add(tileToAdd); } else if(newTileType == TileType.Background) { //Remove any current active tile at this position Tile tileToRemove = null; foreach(Tile tile in ActiveTiles) { if (tile.BoardPosition == selectedBoardTile.BoardPosition) { tileToRemove = tile; } } if (tileToRemove != null) ActiveTiles.Remove(tileToRemove); } }
public void Initialize(int boardWidth, int boardHeight, int tileWidth, int tileHeight, Point startlocation, GraphicsDeviceManager graphics) { StartLocation = startlocation; BoardTiles = new List<Tile>(); BoardWidth = boardWidth; BoardHeight = boardHeight; TileWidth = tileWidth; TileHeight = tileHeight; Graphics = graphics; for (int x = 0; x < BoardWidth; x++) { for (int y = 0; y < BoardHeight; y++) { Tile tileToAdd = new Tile(); tileToAdd.Initialize(new Point(StartLocation.X + TileWidth * x, StartLocation.Y + TileHeight * y), new Point(TileWidth, TileHeight), graphics); BoardTiles.Add(tileToAdd); } } }
public void Bounce(Tile selfTile, Tile otherTile) { Backup(); // Logic to decide when to switch directions if ((otherTile.CurrentRectCoords.X >= selfTile.CurrentRectCoords.X + selfTile.CurrentRectCoords.Width || otherTile.CurrentRectCoords.X + otherTile.CurrentRectCoords.Width <= selfTile.CurrentRectCoords.X) && !(otherTile.CurrentRectCoords.Y >= selfTile.CurrentRectCoords.Y + selfTile.CurrentRectCoords.Height || otherTile.CurrentRectCoords.Y + otherTile.CurrentRectCoords.Height <= selfTile.CurrentRectCoords.Y)) _velocity.X *= -1; else if ((otherTile.CurrentRectCoords.Y >= selfTile.CurrentRectCoords.Y + selfTile.CurrentRectCoords.Height || otherTile.CurrentRectCoords.Y + otherTile.CurrentRectCoords.Height <= selfTile.CurrentRectCoords.Y) && !(otherTile.CurrentRectCoords.X >= selfTile.CurrentRectCoords.X + selfTile.CurrentRectCoords.Width || otherTile.CurrentRectCoords.X + otherTile.CurrentRectCoords.Width <= selfTile.CurrentRectCoords.X)) _velocity.Y *= -1; else { // Without multiplying these by different numbers, can get caught in infinite bounce loop in static environments _velocity.X *= -1; _velocity.Y *= -1; } // Prevent stopping or stuck tiles by randomly adding a positive or negative small velocity if (_velocity.X == 0) { int rand = GameBoard.RandomGenerator.Next(0, 1); if (rand == 0) _velocity.X += 1; else _velocity.X -= 1; } if (_velocity.Y == 0) { int rand = GameBoard.RandomGenerator.Next(0, 1); if (rand == 0) _velocity.Y += 1; else _velocity.Y -= 1; } }
public List<Tile> FindNeighboringTiles(Tile tileToCheck) { List<Tile> neighboringTiles = new List<Tile>(); foreach(Tile tile in ActiveTiles) { if (tileToCheck.BoardPosition == new Point(tile.BoardPosition.X, tile.BoardPosition.Y - 1) || tileToCheck.BoardPosition == new Point(tile.BoardPosition.X, tile.BoardPosition.Y + 1) || tileToCheck.BoardPosition == new Point(tile.BoardPosition.X - 1, tile.BoardPosition.Y) || tileToCheck.BoardPosition == new Point(tile.BoardPosition.X + 1, tile.BoardPosition.Y)) { neighboringTiles.Add(tile); } } return neighboringTiles; }