void Die() { // Sets all to 0 pointCounter = 0; foodCount.text = pointCounter.ToString(); bodyInfo.speed = Tail.initialSpeed; // Creates a New Map mapInfo.SetupMap(); TilesGrid grid = mapInfo.gridGen.gridData; // Move snake to center if (grid != null) { bodyInfo.currentNode = grid.centerNode; bodyInfo.nextNode = null; bodyInfo.lastNode = null; transform.position = grid.NodeWorldPos(grid.centerNode); } else { Debug.LogError("Tail::Start -- GRID NOT CREATED YET"); } }
public void CreateGrid() { // Creates a grid instance gridData = new TilesGrid(mapData.worldSize); // Gets grid size float gridSize = gridData.gridSize; // Gets bottom left corner worldBottomLeft = (transform.position - Vector3.right * (gridSize) / 2 - Vector3.up * (gridSize) / 2); // Creates each tile on the grid for (int x = 0; x < gridSize; x++) { for (int y = 0; y < gridSize; y++) { // Current tile world position Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * gridData.nodeDiameter + gridData.nodeRadius) + Vector3.up * (y * gridData.nodeDiameter + gridData.nodeRadius); // Make border be unwalkable bool isBorder = false; if (x == gridSize - 1 || y == gridSize - 1 || x == 0 || y == 0) { isBorder = true; } int movementPenalty = 0; gridData.grid[x, y] = new Tile(x, y, movementPenalty, isBorder, worldPoint); } } }
// Start is called before the first frame update void Start() { grid = FindObjectOfType <GridGenerator>().gridData; }