void SetTilePositions(TilePositions targetTilePosition) { for (int i = 0; i < tiles.Count; i++) { switch (targetTilePosition) { case TilePositions.Start: tiles[i].tileController.target = new Vector3(tilePositions[i].Start.x, tilePositions[i].Start.y, 0); break; case TilePositions.FiveFour: tiles[i].tileController.target = new Vector3(tilePositions[i].FiveFour.x, tilePositions[i].FiveFour.y, 0); break; case TilePositions.Line: tiles[i].tileController.target = new Vector3(tilePositions[i].Line.x, tilePositions[i].Line.y, 0); break; case TilePositions.End: tiles[i].tileController.target = new Vector3(tilePositions[i].End.x, tilePositions[i].End.y, 0); break; } currentTilePosition = targetTilePosition; } }
private bool TrySetTile(Tilemap tilemap, DungeonTile tile, int tid, TilePositions neighbors) { if (GetNeighbors(tile) != neighbors) { return(false); } SetTile(tilemap, tile, tid); return(true); }
void CreateTiles() { tiles = new List <Tile>(); for (int i = 0; i < numberofTiles; i++) { Tile tile = new Tile(); GameObject tileObject = Instantiate(Resources.Load(tileObjectPath)) as GameObject; TextMesh letter = tileObject.GetComponentInChildren <TextMesh>(); SpriteRenderer sprite = tileObject.GetComponent <SpriteRenderer>(); TileController tileController = tileObject.GetComponent <TileController>(); float depth = tileDepthMultiplier * i; string name = tileObjectName + i.ToString("D2"); // Set starting position currentTilePosition = TilePositions.FiveFour; tileObject.transform.position = new Vector3(tilePositions[i].FiveFour.x, tilePositions[i].FiveFour.y, depth); tileController.target = tileObject.transform.position; tileController.smoothTime = tileSmoothTime; // Set object name tileObject.name = name; // Set letter letter.text = letterList[i].ToString(); // Set color sprite.color = tileUnselectedColor; // Assign components to Tile struct tile.tileObject = tileObject; tile.letter = letter; tile.sprite = sprite; tile.tileController = tileController; // Add struct to list; tiles.Add(tile); } }
public virtual async Task <Tuple <Tile, MapDirection> > GetTargetTile(Point?target, MapDirection requesteDirection) { MapDirection invertMessageDirection = requesteDirection; if (target == null) { return(null); } await tileInitialized.Task; Tile tile = null; TilePositions.TryGetValue(target.Value, out tile); if (tile == null) { var targetTileData = CurrentMap.GetTileData(target.Value); if (targetTileData.Actuators.Any() && targetTileData.Actuators.All(x => x.ActuatorType == 5 || x.ActuatorType == 6)) { throw new InvalidOperationException("this should not be possible"); } else if (targetTileData.Actuators.Any() && !targetTileData.Actuators.All(x => x.ActuatorType != 5 && x.ActuatorType != 6)) { throw new InvalidOperationException("mixture of wall and virtual actuators"); } else {//find floor tile where is wall actuator put & thus invert message direction invertMessageDirection = requesteDirection.Opposite; TilePositions.TryGetValue(target.Value + requesteDirection.RelativeShift, out tile); if (tile == null) { throw new InvalidOperationException(); } } } return(Tuple.Create(tile, invertMessageDirection)); }
private void ProcessMapData() { var offset = new Point(CurrentMap.OffsetX, CurrentMap.OffsetY); for (int y = 0; y < CurrentMap.Height; y++) { for (int x = 0; x < CurrentMap.Width; x++) { var pos = new Point(x, y) + offset; var tile = TileCreator.GetTile(new TileInfo <TileData> { Position = pos, Tile = CurrentMap.GetTileData(pos) }); if (tile != null) { TilePositions.Add(pos, tile); } } } }
private TilePositions GetNeighbors(DungeonTile tile) { TilePositions result = TilePositions.None; if (GetTileTypeAt(tile.X - 1, tile.Y) == tile.Type) { result |= TilePositions.Left; } if (GetTileTypeAt(tile.X + 1, tile.Y) == tile.Type) { result |= TilePositions.Right; } if (GetTileTypeAt(tile.X, tile.Y - 1) == tile.Type) { result |= TilePositions.Up; } if (GetTileTypeAt(tile.X, tile.Y + 1) == tile.Type) { result |= TilePositions.Down; } return(result); }
// paramters: // obj - obj to create // dest - if true, destroy middle object, if false create obj public void AddObject(int obj, ObjectTypes objType, TilePositions pos, bool attachToSide) { //mMiddleObject = obj; GameObject tempObj = null; Vector3 objPos = new Vector3(0, (float)World.TILE_HEIGHT / 2, 0) + transform.position; float posFactor = 5; if (attachToSide) { posFactor = 10f; } // Instantitate correctly by tyoe switch (objType) { case ObjectTypes.Decals: tempObj = Instantiate(World.Instance.mDecalsPrefabList[obj]) as GameObject; tempObj.name = gameObject.name + "_" + World.Instance.mDecalsPrefabNameList[obj]; break; case ObjectTypes.Items: tempObj = Instantiate(World.Instance.mItemsPrefabList[obj]) as GameObject; tempObj.name = gameObject.name + "_" + World.Instance.mItemsPrefabNameList[obj]; break; case ObjectTypes.Triggerables: tempObj = Instantiate(World.Instance.mTriggerablesPrefabList[obj]) as GameObject; tempObj.name = gameObject.name + "_" + World.Instance.mTriggerablesPrefabNameList[obj]; break; case ObjectTypes.Enemies: tempObj = Instantiate(World.Instance.mEnemiesPrefabList[obj]) as GameObject; tempObj.name = gameObject.name + "_" + World.Instance.mEnemiesPrefabNameList[obj]; break; } // attach to wall and get name AttachedToWall attachObj = tempObj.GetComponent <AttachedToWall>(); // calculate position in world and wall attachment switch (pos) { case TilePositions.NorthWest: objPos += new Vector3(-posFactor, 0, posFactor); break; case TilePositions.North: objPos += new Vector3(0, 0, posFactor); if (attachObj != null) { attachObj.mWallAttachedTo = WallNorth; attachObj.mFacing = LookingDirection.South; } break; case TilePositions.NorthEast: objPos += new Vector3(posFactor, 0, posFactor); break; case TilePositions.West: objPos += new Vector3(-posFactor, 0, 0); tempObj.transform.Rotate(Vector3.up * -90); if (attachObj != null) { attachObj.mWallAttachedTo = WallWest; attachObj.mFacing = LookingDirection.East; } break; case TilePositions.East: objPos += new Vector3(posFactor, 0, 0); tempObj.transform.Rotate(Vector3.up * 90); if (attachObj != null) { attachObj.mWallAttachedTo = WallEast; attachObj.mFacing = LookingDirection.West; } break; case TilePositions.SouthWest: objPos += new Vector3(-posFactor, 0, -posFactor); break; case TilePositions.South: objPos += new Vector3(0, 0, -posFactor); tempObj.transform.Rotate(Vector3.up * 180); if (attachObj != null) { attachObj.mWallAttachedTo = WallSouth; attachObj.mFacing = LookingDirection.North; } break; case TilePositions.SouthEast: objPos += new Vector3(posFactor, 0, -posFactor); break; case TilePositions.RandomPos: float posXRandom = Random.Range(-1f, 1f); float posYRandom = Random.Range(-1f, 1f); objPos += new Vector3(posFactor * posXRandom, 0, -posFactor * posYRandom); break; case TilePositions.Middle: objPos += new Vector3(0, 0, 0); break; } // Place in world and attach to correct anchor switch (objType) { case ObjectTypes.Decals: tempObj.transform.localPosition = objPos; tempObj.transform.parent = mLevelPartBelongingTo.mDecalObjectsAnchor; break; case ObjectTypes.Items: if (mItemPlaced) { DestroyImmediate(mItemPlaced.gameObject); } ItemObject itemObj = tempObj.GetComponent <ItemObject>(); itemObj.mTilePlacedOn = this; tempObj.transform.localPosition = objPos; tempObj.transform.parent = mLevelPartBelongingTo.mItemObjectsAnchor; mItemPlaced = tempObj.GetComponent <ItemObject>(); break; case ObjectTypes.Triggerables: tempObj.transform.localPosition = objPos; tempObj.transform.parent = mLevelPartBelongingTo.mTriggableListAnchor; break; case ObjectTypes.Enemies: tempObj.transform.localPosition = objPos; tempObj.transform.parent = mLevelPartBelongingTo.mEnemiesAnchor; tempObj.GetComponent <MovableActor>().mStartingTile = this; break; } // add to AttachedObjects List AttachedObjects.Add(tempObj); }
/* * with the tile array created, this will instantiate all the different tile types on the screen * */ void GenerateMapVisuals() { mapGenerator.generateMap(tiles); GameObject mapParent = (GameObject)Instantiate(new GameObject("MapParent")); for (int x = 0; x < mapSizeX; x++) { for (int y = 0; y < mapSizeY; y++) { TileType tt = tileTypes [tiles [x, y]]; GameObject go = (GameObject)Instantiate(tt.tilePrefab, new Vector3(x, y, 0), Quaternion.identity); go.name = tt.name + " " + x + " " + y; go.transform.parent = mapParent.transform; TilePositions tp = go.GetComponent <TilePositions> (); tp.tileX = x; tp.tileY = y; } } // add the newly generated map to the list of the total map MapCoordinates newMap = new MapCoordinates(mapParent, playerTotalPositionX, playerTotalPositionY); mapCoordinates.Add(newMap); System.Random rand = new System.Random(); // spawn all enemies here // instantiate the enemy and save as game object for (int i = 0; i < maxEnemies; i++) { for (int j = 0; j < enemyArray.Length; j++) { int randomX = rand.Next(0, mapSizeX); int randomY = rand.Next(0, mapSizeY); // enemies will spawn on a random tile in the map if (tileTypes [tiles [randomX, randomY]].isWalkable && (randomX != player.transform.position.x && randomY != player.transform.position.y)) { GameObject enemySpawn = (GameObject)Instantiate(enemyArray [j], new Vector3(randomX, randomY, 0), Quaternion.identity); enemy.Add(enemySpawn); enemySpawn.transform.parent = mapParent.transform; } else { j--; } } } numberOfEnemies = enemy.Count; GeneratePathfindingGraph(); for (int i = 0; i < pickupList.Count(); i++) { int randomX = rand.Next(0, mapSizeX); int randomY = rand.Next(0, mapSizeY); if (tileTypes [tiles [randomX, randomY]].isWalkable && (randomX != player.transform.position.x && randomY != player.transform.position.y)) { GameObject item = (GameObject)Instantiate(pickupList.ElementAt(i), new Vector3(randomX, randomY, -0.5f), Quaternion.identity); item.transform.parent = mapParent.transform; } else { i--; } } }