private bool IsWithinBounds(Position2D position) { int x = position.GetX(); int y = position.GetY(); if (x >= _sizeX || y >= _sizeY) { return(false); } return(true); }
public bool Place(IPlaceable placeable, Position position) { Position2D position2D = position.AsPosition2D(); if (!CanPlace(placeable, position, position2D)) { return(false); } List <IPlaceable> contents = _content [position2D.GetX(), position2D.GetY()]; if (contents == null) { contents = new List <IPlaceable>(); _content [position2D.GetX(), position2D.GetY()] = contents; } contents.Add(placeable); placeable.Place(position); return(true); }
//TODO maybe replace this with an arbitrary query instead of searching just by position //for example we might search for a list of all sources of danger within some distance public List <IPlaceable> GetContent(Position position) { Position2D position2D = GetPosition2D(position); if (position2D == null) { Debug.Log("2D pos is null"); return(null); } List <IPlaceable> content = _content [position2D.GetX(), position2D.GetY()]; return(content == null ? new List <IPlaceable> () : content); }
public Transform CreateRepresentation(IPlaceable placeable) { //TODO replace this with good code if (!(placeable is GroundTile)) { return(null); } GroundTile.GroundTileType type = ((GroundTile)placeable).GetTileType(); Position pos = placeable.GetPosition(); Position2D pos2D = pos.AsPosition2D(); tileTypes [(int)type].transform.position = new Vector3(pos2D.GetX(), pos2D.GetY(), 0); Transform newTile = GameObject.Instantiate(tileTypes [(int)type]); activeTiles.Add(newTile); return(newTile); }
/// <summary> /// Returns null if the position is not valid /// </summary> private Position2D GetPosition2D(Position position) { Position2D position2D = position.AsPosition2D(); if (position2D == null) { Debug.Log("is not a 2D position"); return(null); } int x = position2D.GetX(); int y = position2D.GetY(); if (x >= _sizeX || y >= _sizeY) { return(null); } return(position2D); }