// Start is called before the first frame update void Start() { zoneIndex = 0; activeGrid = _GridController.gridZones[zoneIndex]; generateLevel(1, levelDataSet[0].dataSet); NextStageCallBack += nextStage; NextZoneCallback += moveToNextZone; NextZoneEntranceCallback += activateSwipe; }
private void generateIndicators(StageCubeData _cubeData, GridZone _zone) { foreach (Vector2Int _coord in _cubeData.cubePlacements) { GameObject _tmp = _pool.getIndicator(); _zone.indicators.Add(_tmp); _tmp.transform.SetParent(_zone.transform); _tmp.transform.rotation = Quaternion.identity; } }
//gets swipe data from swipemanager and decides what to do public void setSwipe(SwipeData _data) { if (isSwipeAvailable) { deactivateSwipe(); GridZone _zone = activeGrid; List <Cube> _cubeGrid = new List <Cube>(_zone.getMovableCubes()); Cube[] _orderedCubes = orderCubeList(_data, _cubeGrid); //Order cubes decideMovement(_data, _orderedCubes); //Calculate coordinate to move for each cube } }
public void SetIndicators(StageCubeData _cubeData, GridZone _zone) { foreach (GameObject item in _zone.indicators) { _pool.retireIndicator(item); } generateIndicators(_cubeData, _zone); for (int i = 0; i < _cubeData.cubePlacements.Length; i++) { _zone.indicators[i].transform.localPosition = _GridController.calculateCoord(_cubeData.cubePlacements[i]); } }
public void GenerateLevel(Texture2D _mapdata, GridZone _zone, LevelController _levelControllerDependency) { offsetX = _GridController.getOffset().x; offsetY = _GridController.getOffset().y; liningSpace = _GridController.getLiningSpace(); for (int x = 0; x < _mapdata.width; x++) { for (int y = 0; y < _mapdata.height; y++) { GenerateTile(x, y, _mapdata, _zone, _levelControllerDependency); } } }
private void moveToNextZone() { if (zoneIndex == 3) { _GameManager.winCondition(); } else { zoneIndex++; stageIndex = 0; _CameraController.moveToZoneByIndex(zoneIndex); activeGrid = _GridController.gridZones[zoneIndex]; _LevelGenerator.SetIndicators(levelStageDatas[levelNo - 1].GetCubeDatas(stageIndex, activeGrid), activeGrid); sequenceIndex = 0; Invoke("zoneEntrenceSequence", 2f); } }
void detectNewDestination() { if (Input.GetMouseButtonDown(1)) //Right click { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100)) { if (hit.transform.gameObject.tag == ("GridZone")) { targetGridZone = hit.transform.gameObject.GetComponent <GridZone>(); latestDestination = targetGridZone.transform.position; } } isAtDestination = false; } }
void Update() { detectNewDestination(); if (!isAtDestination) { //Turn to look at latest Destination Vector3 targetDir = latestDestination - transform.position; Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, maxTurnSpeed * Time.deltaTime, 0.0f); transform.rotation = Quaternion.LookRotation(newDir); //Move towards destination float distanceToDestination = Vector3.Distance(transform.position, latestDestination); if (distanceToDestination < maxMoveSpeed * Time.deltaTime) { transform.position = latestDestination; currentZone = targetGridZone; isAtDestination = true; } else { transform.Translate(Vector3.forward * maxMoveSpeed * Time.deltaTime); } } if (Input.GetKey(KeyCode.UpArrow)) { transform.Translate(Vector3.forward * maxMoveSpeed * Time.deltaTime); } if (Input.GetKey(KeyCode.DownArrow)) { transform.Translate(-Vector3.forward * maxMoveSpeed * Time.deltaTime); } if (Input.GetKey(KeyCode.LeftArrow)) { transform.Rotate(Vector3.up, -maxTurnSpeed * Time.deltaTime); } if (Input.GetKey(KeyCode.RightArrow)) { transform.Rotate(Vector3.up, maxTurnSpeed * Time.deltaTime); } }
public Zone CreateNewZone(int iIndexX, int iIndexY) { string name = string.Format("{0}_{1}_{2}", ZoneNames, iIndexX, iIndexY); Zone z = new GridZone(name, iIndexX, iIndexY); z.LoadedDistance = LoadedRadius; z.CacheInMargin = CacheInMargin; z.CacheOutMargin = CacheOutMargin; Vector3F vStep = new Vector3F(_area.SizeX / (float)SubdivisionsX, _area.SizeY / (float)SubdivisionsY, _area.SizeZ); Vector3F vOrigin = _area.vMin + new Vector3F(vStep.X * (float)iIndexX, vStep.Y * (float)iIndexY, 0.0f); BoundingBox bbox = new BoundingBox(vOrigin, vOrigin + vStep); z.AssignmentBoundingBox = bbox; z.DebugColor = ZoneColors; return(z); }
// Use this for initialization void Awake() { gridZones = new GridZone[gridRows][]; for (int i = 0; i < gridRows; i++) { gridZones[i] = new GridZone[gridCols]; for (int j = 0; j < gridCols; j++) { float xPos = i * (gridZoneObj.GetComponent <Renderer>().bounds.size.x + zonePadding); float yPos = 0.01f; float zPos = j * (gridZoneObj.GetComponent <Renderer>().bounds.size.z + zonePadding); Vector3 zoneTranslate = new Vector3(xPos, yPos, zPos); Quaternion zoneRotation = Quaternion.Euler(new Vector3(90, 0, 0)); gridZones[i][j] = (GridZone)Instantiate(gridZoneObj, zoneTranslate, zoneRotation); gridZones[i][j].zoneX = i; gridZones[i][j].zoneY = j; } } }
//Color Codes //0 is WALL //1 is MOVABLE CUBE //2 is DOOR void GenerateTile(int x, int y, Texture2D _mapdata, GridZone _zone, LevelController _levelControllerDependency) { Color32 pixelColor = _mapdata.GetPixel(x, y); if (colorMappings[0].color.Equals(pixelColor)) { GameObject _tmpWall = _pool.getWall(); _tmpWall.transform.SetParent(_zone.transform); _tmpWall.transform.localPosition = new Vector2(x * liningSpace + offsetX, y * liningSpace + offsetY); Cube _cubeScript = _tmpWall.GetComponent <Cube>(); _cubeScript.gridCoord = new Vector2Int(x, y); _cubeScript.setSkin(wallSprites[Random.Range(0, 4)]); _tmpWall.transform.rotation = Quaternion.identity; } else if (colorMappings[1].color.Equals(pixelColor)) { GameObject _tmpMovable = _pool.getMovableCube(); _tmpMovable.transform.SetParent(_zone.transform); _tmpMovable.transform.localPosition = new Vector2(x * liningSpace + offsetX, y * liningSpace + offsetY); Cube _cubeScript = _tmpMovable.GetComponent <Cube>(); _cubeScript.cubeSetup(_levelControllerDependency, new Vector2Int(x, y)); _zone.addMovable(_cubeScript); _cubeScript.transform.rotation = Quaternion.identity; } else if (colorMappings[2].color.Equals(pixelColor)) { GameObject _tmpGate = Instantiate(colorMappings[2].prefab); _tmpGate.transform.SetParent(_zone.transform); _tmpGate.transform.localPosition = new Vector2(x * liningSpace + offsetX, y * liningSpace + offsetY); Cube _cubeScript = _tmpGate.GetComponent <Cube>(); _cubeScript.cubeSetup(_levelControllerDependency, new Vector2Int(x, y)); _cubeScript.transform.rotation = Quaternion.identity; } }
public StageCubeData GetCubeDatas(int _stageIndex, GridZone _zone) { if (_zone.zoneIndex == 0) { return(stageDatas1[_stageIndex]); } else if (_zone.zoneIndex == 1) { return(stageDatas2[_stageIndex]); } else if (_zone.zoneIndex == 2) { return(stageDatas3[_stageIndex]); } else if (_zone.zoneIndex == 3) { return(stageDatas4[_stageIndex]); } else { return(null); } }
public MovementSequence getSequence(int _index, GridZone _zone) { if (_zone.zoneIndex == 0) { return(stage1Sequence[_index]); } else if (_zone.zoneIndex == 1) { return(stage2Sequence[_index]); } else if (_zone.zoneIndex == 2) { return(stage3Sequence[_index]); } else if (_zone.zoneIndex == 3) { return(stage4Sequence[_index]); } else { return(null); } }
public int GetStageLength(GridZone _zone) { if (_zone.zoneIndex == 0) { return(stageDatas1.Length); } else if (_zone.zoneIndex == 1) { return(stageDatas2.Length); } else if (_zone.zoneIndex == 2) { return(stageDatas3.Length); } else if (_zone.zoneIndex == 3) { return(stageDatas4.Length); } else { return(0); } }
//Compare all cube coordinates by true positions of stage //return true if all cube coordinates match by true positions which means stage completed //else return false which means stage is not completed private bool checkCubeStatus(StageCubeData _cubeData, GridZone _zone) { int _trueCount = 0; foreach (Vector2Int _trueCoord in _cubeData.cubePlacements) { foreach (var _cube in _zone.getMovableCubes()) { if (_trueCoord == _cube.gridCoord) { _trueCount++; } } } if (_trueCount == _cubeData.cubePlacements.Length) { return(true); } else { return(false); } }
/// <summary> /// Finds the shortest surface distance in the case of the points being on opposing faces. /// This method is separate from CalculateShortestSurfaceDistance only for readability purposes. /// </summary> private static int OpposingFaceDistance(GridPoint start, GridPoint end) { List <int> distances = new List <int>(); GridZone gz = start.DetermineGridZone(); ExtendedGrid[] grids; switch (gz) { case GridZone.TopLeft: grids = new[] { ExtendedGrid.TopMiddle, ExtendedGrid.TopRight, ExtendedGrid.RightMiddle, ExtendedGrid.BotMiddle, ExtendedGrid.LeftBot, ExtendedGrid.LeftMiddle }; distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end))); break; case GridZone.TopMiddle: grids = new[] { ExtendedGrid.TopLeft, ExtendedGrid.TopMiddle, ExtendedGrid.TopRight, ExtendedGrid.RightMiddle, ExtendedGrid.RightBot, ExtendedGrid.BotMiddle, ExtendedGrid.LeftBot, ExtendedGrid.LeftMiddle }; distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end))); break; case GridZone.TopRight: grids = new[] { ExtendedGrid.TopLeft, ExtendedGrid.TopMiddle, ExtendedGrid.RightMiddle, ExtendedGrid.RightBot, ExtendedGrid.BotMiddle, ExtendedGrid.LeftMiddle }; distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end))); break; case GridZone.BottomLeft: grids = new[] { ExtendedGrid.TopMiddle, ExtendedGrid.RightMiddle, ExtendedGrid.BotRight, ExtendedGrid.BotMiddle, ExtendedGrid.LeftMiddle, ExtendedGrid.LeftTop }; distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end))); break; case GridZone.BottomMiddle: grids = new[] { ExtendedGrid.TopMiddle, ExtendedGrid.RightTop, ExtendedGrid.RightMiddle, ExtendedGrid.BotRight, ExtendedGrid.BotMiddle, ExtendedGrid.BotLeft, ExtendedGrid.LeftMiddle, ExtendedGrid.LeftTop }; distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end))); break; case GridZone.BottomRight: grids = new[] { ExtendedGrid.TopMiddle, ExtendedGrid.RightTop, ExtendedGrid.RightMiddle, ExtendedGrid.BotMiddle, ExtendedGrid.BotLeft, ExtendedGrid.LeftMiddle }; distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end))); break; case GridZone.LeftMiddle: grids = new[] { ExtendedGrid.TopMiddle, ExtendedGrid.TopRight, ExtendedGrid.RightMiddle, ExtendedGrid.BotRight, ExtendedGrid.BotMiddle, ExtendedGrid.LeftBot, ExtendedGrid.LeftMiddle, ExtendedGrid.LeftTop }; distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end))); break; case GridZone.RightMiddle: grids = new[] { ExtendedGrid.TopLeft, ExtendedGrid.TopMiddle, ExtendedGrid.RightTop, ExtendedGrid.RightMiddle, ExtendedGrid.RightBot, ExtendedGrid.BotMiddle, ExtendedGrid.BotLeft, ExtendedGrid.LeftMiddle }; distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end))); break; default: throw new Exception("uh oh..."); } return(distances.Min()); }
public void setCharacterToZone(GridZone _zone, SequenceNode _startNode) { character.transform.rotation = _zone.transform.rotation; character.transform.position = _startNode.transform.position; zoneNumber = _zone.zoneIndex; }
public Zone CreateNewZone(int iIndexX, int iIndexY) { string name = string.Format("{0}_{1}_{2}", ZoneNames, iIndexX, iIndexY); Zone z = new GridZone(name, iIndexX, iIndexY); z.LoadedDistance = LoadedRadius; z.CacheInMargin = CacheInMargin; z.CacheOutMargin = CacheOutMargin; Vector3F vStep = new Vector3F(_area.SizeX/(float)SubdivisionsX,_area.SizeY/(float)SubdivisionsY,_area.SizeZ); Vector3F vOrigin = _area.vMin + new Vector3F(vStep.X*(float)iIndexX,vStep.Y*(float)iIndexY,0.0f); BoundingBox bbox = new BoundingBox(vOrigin, vOrigin + vStep); z.AssignmentBoundingBox = bbox; z.DebugColor = ZoneColors; return z; }
void Start() { currentZone = gridMan.gridZones[startGridX][startGridY]; transform.position = new Vector3(currentZone.transform.position.x, transform.position.y, currentZone.transform.position.z); isAtDestination = true; }