//Make the tiles public void StartNewGame(int gridDimension) { _gridDimension = gridDimension; _edgeOfMapdimesion = _gridDimension * MapTile.TileSideLength; _tiles = new MapTile[_gridDimension, _gridDimension]; for (int y = 0; y < _gridDimension; y++) { for (int x = 0; x < _gridDimension; x++) { _tiles[x, y] = new MapTile(MapTile.WorldPositionForGridCoordinates(x, y), DoorDirections.RandomDoors(), false); } } //initially set the overlays UpdateOverlays(); }
internal static Vector2 RandomPositionInTile(int x, int y) { return(MapTile.WorldPositionForGridCoordinates(x, y) + Utilities.randomVector() * 0.7f * MapTile.TileSideLength); }
//shift the row/col of tiles private void shiftTiles(int index, ShiftDirection dir, DoorDirections newTileDoors) { if (_isShifting) { //should never happen with the queueing now in place, but still check it to be safe return; } //check if the index is valid if (index < 0 || index >= _gridDimension) { throw new Exception("Invalid grid index passed to shiftTiles()"); } //set current shift direction _currShiftDir = dir; _currShiftIndex = index; Program.Objects.MainCamera.shake(); //spawn extra enemies Program.Objects.EnemyDirector.OnShift(); bool isPositiveShift = (dir == ShiftDirection.RIGHT || dir == ShiftDirection.DOWN); int shiftStart = isPositiveShift ? _gridDimension - 1 : 0; int shiftEnd = isPositiveShift ? 0 : _gridDimension - 1; int shiftInc = isPositiveShift ? -1 : 1; if (dir == ShiftDirection.LEFT || dir == ShiftDirection.RIGHT) { //Set all the tiles to start moving for (int x = 0; x < _gridDimension; x++) { shiftTile(x, index, x - shiftInc, index); } //store the tile that is getting shifted out _shiftedOutTile = _tiles[shiftStart, index]; //shift the tiles in our array to represent the new arrangement for (int x = shiftStart; x != shiftEnd; x += shiftInc) { _tiles[x, index] = _tiles[x + shiftInc, index]; } //set the location of the tile that was pushed in a move it into place //TODO: don't reassign this. pass it in. MapTile pushingTile = new MapTile(MapTile.WorldPositionForGridCoordinates(shiftEnd + shiftInc, index), newTileDoors, false); _tiles[shiftEnd, index] = pushingTile; shiftTile(pushingTile, shiftEnd, index); } else //UP or DOWN //Set all the tiles to start moving { for (int y = 0; y < _gridDimension; y++) { shiftTile(index, y, index, y - shiftInc); } //store the tile that is getting shifted out _shiftedOutTile = _tiles[index, shiftStart]; //shift the tiles in our array to represent the new arrangement for (int y = shiftStart; y != shiftEnd; y += shiftInc) { _tiles[index, y] = _tiles[index, y + shiftInc]; } //set the location of the tile that was pushed in a move it into place //TODO: don't reassign this. pass it in. MapTile pushingTile = new MapTile(MapTile.WorldPositionForGridCoordinates(index, shiftEnd + shiftInc), newTileDoors, false); _tiles[index, shiftEnd] = pushingTile; shiftTile(pushingTile, index, shiftEnd); } _shiftedOutTile.flagForDestruction(tileFinishedShifting); //update the overlays UpdateOverlays(); _isShifting = true; }
internal void shiftTo(int destX, int destY) { //go setTarget(MapTile.WorldPositionForGridCoordinates(destX, destY)); }