public bool FindMapObjectInBounds(out IGameMapObject foundObject, int mapX, int mapY) { foreach (var mapObject in MapObjects) { // Simple check: Object is not visible or hidden then skip checking this item if (mapObject.TileWidth < 1 || mapObject.TileHeight < 1) { continue; } // Simple check: The unit is 1x1 if (mapObject.TileWidth == 1 && mapObject.TileHeight == 1 && mapObject.MapX == mapX && mapObject.MapY == mapY) { foundObject = mapObject; return(true); } // The map object has dimensions, we need to see if our target X/Y falls within its bounds var leftBounds = mapObject.MapX; var rightBounds = leftBounds + (mapObject.TileWidth - 1); var topBounds = mapObject.MapY + (mapObject.TileHeight - 1); var bottomBounds = mapObject.MapY; if (mapX >= leftBounds && mapX <= rightBounds && mapY <= topBounds && mapY >= bottomBounds) { foundObject = mapObject; return(true); } } // Fallthrough: No units were found foundObject = null; return(false); }
public void RemoveMapUnit(IGameMapObject mapObject) { if (MapObjects.Contains(mapObject)) { MapObjects.Remove(mapObject); mapObject.WorldPosition = new Vector3(-100, -100, -100); } }
public IGameMap GameMap; // The game map reference public AbilityExecuteParameters(IGameUnit unit, IAbility ability, IGameMapObject target, IEnumerable <IGameMapObject> targets, MapPoint targetPoint, IGameMap gameMap) { UnitExecuting = unit; AbilityExecuting = ability; Target = target; AllTargets = targets; TargetPoint = targetPoint; GameMap = gameMap; }
public IGameMapObject[,] ReadLevel(string fileName) { var levelText = File.ReadAllLines(fileName); var level = new IGameMapObject[levelText.GetLength(0), levelText[0].Length]; for (var i = 0; i < levelText.GetLength(0); i++) { var str = levelText[i].ToCharArray(); for (var j = 0; j < str.Length; j++) { if (!objectsDictionary.ContainsKey(str[j])) { level[i, j] = null; } else { level[i, j] = objectsDictionary[str[j]]; } } } return(level); }
public void GenerateDirectionalPoints(IGameMapObject mapObject, IAbility ability) { }