void SetupTutorialPanel() { if (GameObject.FindGameObjectWithTag("GameController") != null) { var manager = GameObject.FindGameObjectWithTag("GameController"); grid = manager.GetComponent <GridGeneration>(); code = manager.GetComponent <CodeInput>(); } if (grid != null) { level = grid.level; } playerDead = false; tutTextCount = 0; pauseMenu.SetActive(false); instructionsMenu.SetActive(false); inGameMenu.SetActive(false); tutorialUIHolder.SetActive(true); tutorialUIBackground.SetActive(true); tutorialUIText.SetActive(true); mainMenu.SetActive(false); mainmenuPanel.SetActive(true); optionsMenu.SetActive(false); optionsmenupanel.SetActive(false); restart.gameObject.SetActive(false); hints.SetActive(false); ChangeTutorialText(); }
// runs interface menu and checks if buttons are clicked void Update() { createPath.interactable = !(PathfinderManager.type.isSearching && PathfinderManager.type.PathLocatingStyle == pathLocatingProp.completeSpawn); moveForward.interactable = PathfinderManager.type.isSearching && PathfinderManager.type.isPause && PathfinderManager.type.PathLocatingStyle != pathLocatingProp.completeSpawn; resetButton.interactable = true; selectSize.interactable = !PathfinderManager.type.isSearching; areaValue.interactable = !PathfinderManager.type.isSearching; pathfinderType.interactable = !PathfinderManager.type.isSearching; lineThickness.interactable = !PathfinderManager.type.isSearching; sidewayMovement.interactable = !PathfinderManager.type.isSearching; avoidObstaclesSideway.interactable = !PathfinderManager.type.isSearching; lineThickness.gameObject.SetActive(PathfinderManager.type.algorithmType == PathDecisionAlgorithm.AStarStyleAlgorithm); sidewayMovement.gameObject.SetActive(GridManager.type.shapeOfBlock == BlockGrid.SquareShape); avoidObstaclesSideway.gameObject.SetActive(GridManager.type.shapeOfBlock == BlockGrid.SquareShape && PathfinderManager.type.blockSidewayWall); //checks if mouse one is pressed and generates obstacles if (Input.GetMouseButtonUp(0)) { isAddingObstacle = false; isUndoingObstacle = false; selectedBlockType = null; isStartBlock = false; isEndBlock = false; } }
public void FindPath(GridGeneration StartPosition, GridGeneration EndPosition) { //checks the origin and destination of the tiles and findes the path this.StartPosition = StartPosition; this.EndPosition = EndPosition; GeneratePathfinding(); }
void CloseTutorial() { if (GameObject.FindGameObjectWithTag("GameController") != null) { var manager = GameObject.FindGameObjectWithTag("GameController"); grid = manager.GetComponent <GridGeneration>(); code = manager.GetComponent <CodeInput>(); } if (grid != null) { level = grid.level; } //pController.HasControl = true; inGameMenu.SetActive(true); instructionsMenu.SetActive(false); tutorialUIHolder.SetActive(false); tutorialUIBackground.SetActive(false); tutorialUIText.SetActive(false); commandList.gameObject.SetActive(true); HUD.SetActive(true); if (!codeInputHolder.activeInHierarchy) { openCodeWindow.gameObject.SetActive(true); } instructions.gameObject.SetActive(true); hints.SetActive(false); playerDead = false; tutTextCount = 0; }
private void Start() { _savedTimeBetweenTraps = timeBetweenTraps; _gridReference = GameObject.Find("GridGenerator").GetComponent <GridGeneration>(); //set timmers _trapTimer = timeBetweenTraps; _increaseSpeedTimer = timeBetweenSpeedIncrease; }
// Start is called before the first frame update void Start() { lives = PlayerPrefs.GetInt("PlayerLife", lives); currentScene = SceneManager.GetActiveScene(); // Get Rigidbody2D of the player rb = GetComponent <Rigidbody2D>(); gridInfo = GameObject.Find("Background").GetComponent <GridGeneration>(); }
public override void GenerateOnEditor() { GridGeneration generate = target as GridGeneration; if (generate == null) { return; } generate.SetupGeneratedObject(generate.GenerateObject(generate.prefab)); }
private Player playerInfo; // Player information // Start is called before the first frame update void Start() { // Set the initial properties isCollide = false; isDown = true; isRight = true; direction = Vector3.right; // Get the components rb = GetComponent <Rigidbody2D>(); gridInfo = GameObject.Find("Background").GetComponent <GridGeneration>(); playerInfo = GameObject.Find("Player").GetComponent <Player>(); }
private void ReturnToGridOptions() { grid = null; gridTiles = null; gridWalls = null; gridTilesList.Clear(); gridWallsList.Clear(); tileAreas.Clear(); wallAreas.Clear(); materials.Clear(); _gridDesign = false; _reset = false; }
void Start() { var Manager = GameObject.FindGameObjectWithTag("GameController"); grid = Manager.GetComponent <GridGeneration>(); curX = grid.gridSquares[grid.startingTileEnemy].x; curY = grid.gridSquares[grid.startingTileEnemy].y; transform.rotation = Quaternion.Euler(0, 0, -90); moveTrace.Add(grid.startingTileEnemy); moveTrace.Add(grid.startingTileEnemy + grid.numberOfXGrid); moveTrace.Add(grid.startingTileEnemy - grid.numberOfXGrid); }
public void StartingPosition() { if (GridManager.type.shapeOfBlock == BlockGrid.SquareShape) { StartPosition = GridManager.type.getBlocks(Mathf.RoundToInt(GridManager.type.blockNumber / 4.0f) - 1, Mathf.FloorToInt(GridManager.type.blockNumber / 2.0f)); StartPosition.currentSit = blockEnum.startBlock; EndPosition = GridManager.type.getBlocks(Mathf.RoundToInt(GridManager.type.blockNumber / 4.0f * 3.0f), Mathf.FloorToInt(GridManager.type.blockNumber / 2.0f)); EndPosition.currentSit = blockEnum.endBlock; } else if (GridManager.type.shapeOfBlock == BlockGrid.HexagonShape) { StartPosition = GridManager.type.getBlocks(-Mathf.RoundToInt(GridManager.type.blockNumber / 2.0f), 0); StartPosition.currentSit = blockEnum.startBlock; EndPosition = GridManager.type.getBlocks(Mathf.RoundToInt(GridManager.type.blockNumber / 2.0f), 0); EndPosition.currentSit = blockEnum.endBlock; } }
//Gets the grid and sets up player ready for movement void Start() { var Manager = GameObject.FindGameObjectWithTag("GameController"); grid = Manager.GetComponent <GridGeneration>(); codeInput = Manager.GetComponent <CodeInput>(); camManager = GetComponent <CameraManager>(); pShoot = GetComponent <PlayerShoot>(); pHealth = GetComponent <PlayerHealth>(); GameObject.FindGameObjectWithTag("UITag").GetComponent <UI>().GetPlayer(this, pShoot, pHealth); xMax = grid.numberOfXGrid; yMax = grid.numberOfYGrid; currentX = grid.gridSquares[grid.startingTile].x; currentY = grid.gridSquares[grid.startingTile].y; nextGridSquare = 0; curRot = 0; }
void recreatePath() { List <GridGeneration> locateInitialList = new List <GridGeneration>(); List <Vector3> LocateList = new List <Vector3>(); GridGeneration LocatePrevoiusBlock = EndPosition; while (LocatePrevoiusBlock != null) { if (LocatePrevoiusBlock.currentSit != blockEnum.startBlock && LocatePrevoiusBlock.currentSit != blockEnum.endBlock) //Colour of the Tiles are not replaced { LocatePrevoiusBlock.currentSit = blockEnum.pathTrack; } locateInitialList.Add(LocatePrevoiusBlock); LocateList.Add(LocatePrevoiusBlock.transform.position); if (LocatePrevoiusBlock == StartPosition) { break; } LocatePrevoiusBlock = LocatePrevoiusBlock.groupBlock; } //retrace line is drawn if (LocateList.Count <= 1) //if there is no solution { locatePath.gameObject.SetActive(false); } else { locatePath.positionCount = LocateList.Count; locatePath.SetPositions(LocateList.ToArray()); locatePath.gameObject.SetActive(true); } //Pathfinder is set to go to next stage PathLocatingStyle = (pathLocatingProp)((int)PathLocatingStyle + 1); }
void GetCamera() { g = GameObject.FindGameObjectWithTag("GameController").gameObject.GetComponent <GridGeneration>(); cam = GameObject.FindGameObjectWithTag("MainCamera"); Camera mainCam = cam.gameObject.GetComponent <Camera>(); if (g.level == 0) { mainCam.orthographicSize = 5; } if (g.level == 1) { mainCam.orthographicSize = 9.5f; } if (g.level == 2) { mainCam.orthographicSize = 5; } }
private void Awake() { instance = this; }
private void OnGUI() { if (!_guiInit) // GUI Variables have not been initialized { textCenteringStyle = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter }; _guiInit = true; } // Variables that can change during use screenMiddle = new Vector2(position.width / 2.0f, position.height / 2.0f); leftMiddle = new Vector2(100, position.height / 2.0f + 50); rightMiddle = new Vector2(position.width - 75, position.height / 2.0f + 50); if (!_gridDesign) // Paint grid generation menu { DrawGridOptionsPanel(); } else if (grid == null) // Paint grid editor { grid = new GridGeneration(gridDimensions.x, gridDimensions.y, cellSize, 0f, 0.01f); materials = new List <Material>(); tileSize = cellSize * 100; tileSizeVector = new Vector2(tileSize, tileSize); if (baseMaterialContainer != null) { for (int i = 0; i < baseMaterialContainer.materials.Length; i++) { if (baseMaterialContainer.materials[i] != null) { materials.Add(baseMaterialContainer.materials[i]); } } Material randomMat = materials[Random.Range(0, materials.Count)]; if (gridTiles == null) { gridTiles = grid.GetAllTiles(); gridWalls = grid.GetAllWalls(); } int wallY = 0; for (int y = 0; y < gridTiles.GetLength(1); y++) { for (int x = 0; x < gridTiles.GetLength(0); x++) { gridTilesList.Add(gridTiles[x, y]); gridTiles[x, y].AssignMaterial(randomMat); gridWallsList.Add(gridWalls[x, wallY]); gridWallsList.Add(gridWalls[x, wallY + 1]); if (x == gridTiles.GetLength(0) - 1) { gridWallsList.Add(gridWalls[x + 1, wallY + 1]); } if (y == gridTiles.GetLength(1) - 1) { gridWallsList.Add(gridWalls[x, wallY + 2]); } } wallY += 2; } } else { Debug.Log("No material container assigned!"); } } else { DrawGrid(); } }
public void GetGameManager(GridGeneration g, int x, int y) { grid = g; xPos = x; yPos = y; }
void GetAccess() { //If open list count is empty if (generationList.Count > 0 && !EndPosition._isScannedArea) { //It sets the current block as first on the list GridGeneration currentTile = generationList[0]; //The Block with the smallest movement cost is found for (int i = 1; i < generationList.Count; i++) { float newHeuristic = 0.0f; float curHeuristic = 0.0f; if (algorithmType == PathDecisionAlgorithm.AStarStyleAlgorithm) { if (BlockStyle == BlockGrid.SquareShape) { SquareShape newSquareShape = ((SquareShapeScript)generationList[i]).transformValue; SquareShape curSquareShape = ((SquareShapeScript)currentTile).transformValue; newHeuristic = newSquareShape.GetHeuristic(EndPosition.a, EndPosition.b); curHeuristic = curSquareShape.GetHeuristic(EndPosition.a, EndPosition.b); } else if (BlockStyle == BlockGrid.HexagonShape) { HexagonShape newHexagonShape = ((HexagonShapeScript)generationList[i]).transformValueHexagon; HexagonShape curHexagonShape = ((HexagonShapeScript)currentTile).transformValueHexagon; newHeuristic = newHexagonShape.GetHeuristic(EndPosition.a, EndPosition.b); curHeuristic = curHexagonShape.GetHeuristic(EndPosition.a, EndPosition.b); } newHeuristic *= weight; curHeuristic *= weight; } if (generationList[i].trackPos + newHeuristic < currentTile.trackPos + curHeuristic) { currentTile = generationList[i]; } } //It removes the current Block from open list currentTile._isScannedArea = true; generationList.Remove(currentTile); if (BlockStyle == BlockGrid.SquareShape) { //Neighbours of current block are taken SquareShape s = ((SquareShapeScript)currentTile).transformValue; SquareShape[] neighbours = s.getClosestBlock(); for (int i = 0; i < neighbours.Length; i++) { //Coordinate valid or not if ( neighbours[i].b < 0 || neighbours[i].b >= blockGrid.GetLength(0) || neighbours[i].a < 0 || neighbours[i].a >= blockGrid.GetLength(1) ) { continue; } //The coordinaes are transformed to grid piece script GridGeneration closestBlock = GridManager.type.getBlocks(neighbours[i].a, neighbours[i].b); //If neighbour does not exist, then skip if (closestBlock == null) { continue; } //If neighbour is obstacle, then skip if (closestBlock.isWall) { continue; } //If crossing diagonal gaps exist, then skip if (blockSidewayWall && !ignoreSidewayWall && i % 2 != 0) { GridGeneration prevNeighbour = GridManager.type.getBlocks(s.getClosestBlock(i - 1).a, s.getClosestBlock(i - 1).b); GridGeneration nextNeighbour = GridManager.type.getBlocks(s.getClosestBlock(i + 1).a, s.getClosestBlock(i + 1).b); if (prevNeighbour.isWall && nextNeighbour.isWall) //If diagonal gap, then do not cross { continue; } } //If neighbour is checked, then skip if (closestBlock._isScannedArea) { continue; } //Setting the new cost to the neighbour's mevement cost float newCost = currentTile.trackPos + s.GetCost(i); //If the new cost is smaller than the neighbour movement cost, then replace it and set it as parent tile if (newCost < closestBlock.trackPos) { closestBlock.trackPos = newCost; closestBlock.groupBlock = currentTile; if (!generationList.Contains(closestBlock)) { generationList.Add(closestBlock); } } } } else if (BlockStyle == BlockGrid.HexagonShape) { //Getting the neighbours of the current tile for the hexagon shape HexagonShape Hexagon = ((HexagonShapeScript)currentTile).transformValueHexagon; HexagonShape[] neighbours = Hexagon.GetNeighbours(); for (int i = 0; i < neighbours.Length; i++) { //Coordinates valid or not if ( neighbours[i].ToArrayPos(GridManager.type.blockNumber).b < 0 || neighbours[i].ToArrayPos(GridManager.type.blockNumber).b >= blockGrid.GetLength(0) || neighbours[i].ToArrayPos(GridManager.type.blockNumber).a < 0 || neighbours[i].ToArrayPos(GridManager.type.blockNumber).a >= blockGrid.GetLength(1) ) { continue; } //Coordinates a transfromed to grid piece script GridGeneration neighbour = GridManager.type.getBlocks(neighbours[i].a, neighbours[i].b); //If the neighbour does not exist, then skip if (neighbour == null) { continue; } //If the neighbour is an obstacle, then skip if (neighbour.isWall) { continue; } //also if is checked if (neighbour._isScannedArea) { continue; } //Setting the new cost to neighbour's movement cost float newCost = currentTile.trackPos + Hexagon.GetCost(i); // If the new cost is smaller, then replace it and set it as the parent tile if (newCost < neighbour.trackPos) { neighbour.trackPos = newCost; neighbour.groupBlock = currentTile; if (!generationList.Contains(neighbour)) { generationList.Add(neighbour); } } } } } else { //else, pathfinder is finding the next stage PathLocatingStyle = (pathLocatingProp)((int)PathLocatingStyle + 1); } }
public TileGrid(Tile tile, int[,] map, Vector2 margin, Transform parent) { // Initialize a grid tiles = GridGeneration.GenerateTileGrid(tile, map, margin, parent); }
private void Start() { Instance = this; GenerateGrid(); }