void calibrate() { cellSizeY = height / linesNumber; cellSizeX = width / columnsNumber; //To check - Posibil memorylick. Ce era inainte in grid nu se sterge. grid = new VisualObject[linesNumber, columnsNumber]; spawnPoint = new gridPos((columnsNumber / 2 - 1), (linesNumber / 2 - 1)); }
// Start is called before the first frame update void Start() { gridArray = new gridPos [xSize, ySize]; for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { GameObject newTile = CreateTile(x, y, -1); gridArray[x, y] = new gridPos(newTile, newTile.transform.position); //our 2D array is an array of x that holds an array of y that holds an array of gameobjects. } } }
public static List <gridPos> getRange(gridPos A, gridPos B) { List <gridPos> ans = new List <gridPos>(); for (int X = A.X; X <= B.X; X++) { for (int Y = A.Y; Y <= B.Y; Y++) { ans.Add(new gridPos(X, Y)); } } return(ans); }
public void move(gridPos from, gridPos to) { grid[to.X, to.Y] = grid[from.X, from.Y]; grid[from.X, from.Y] = null; }
public void add(VisualObject obj, gridPos pos) { obj.setSize(cellSizeX, cellSizeY); grid[pos.X, pos.Y] = obj; print(); }
public void destroy(gridPos pos) { GameObject.Destroy(grid[pos.X, pos.Y].gameObject); }
public VisualObject getObject(gridPos pos) { return(grid[pos.X, pos.Y]); }
public Vector2 gridPosToRealPos(gridPos pos) { return(new Vector2(pos.X * cellSizeX, -pos.Y * cellSizeY)); }