protected virtual string TileName(DungeonTile val) { switch (val) { case DungeonTile.CeilingHole: return("ceiling hole"); case DungeonTile.FloorHole: return("floor hole"); case DungeonTile.PoisonGasVent: return("poison gas vent"); case DungeonTile.SlimeSplotch: return("slime splotch"); case DungeonTile.TripWire: return("trip wire"); case DungeonTile.GasVent: return("gas vent"); case DungeonTile.Chest: return("treasure chest"); case DungeonTile.Box: return("box"); case DungeonTile.Urn: return("urn"); default: return(""); } }
internal void DeploySecurity(EnemyProgram enemy, DungeonTile dungeonTile) { enemy.SetTile(dungeonTile); enemy.transform.position = dungeonTile.GetOccupyingCoordinates(enemy.IsFlying(), false); enemyPrograms.Add(enemy); dungeonTile.Occupy(enemy); }
// =================================================================================== // private void dieAsCreature() { // distribute xp points between alive party members foreach (Creature member in Party.Instance.Members) { if (member.IsAlive) { member.Stats[Stat.EXPERIENCE_POINTS] += _xPReward; TextDisplayer.Instance.AddToLogger("<color=red>" + Utils.GetCleanName(member.name) + "</color> got <color=yellow>" + _xPReward.ToString() + "</color> xp"); } } // get last stand tile DungeonTile tile = this.Position.DungeonTile; // put all carried items on the ground foreach (Item item in CarriedItems) { item.Show(); item.State = ItemState.GROUND; item.transform.position = tile.transform.position; item.transform.parent = tile.transform; } // destroy itself Destroy(gameObject); }
private void AddTiles() { tiles = new DungeonTileUnity[dungeon.SizeX * dungeon.SizeY]; //Create tiles for (int x = 0; x < dungeon.SizeX; x++) { for (int y = 0; y < dungeon.SizeY; y++) { DungeonTile tile = dungeon.GetTile(x, y); DungeonTileUnity tileUnity = tilesPool.GetTile(); tileUnity.transform.parent = tilesContainer; tileUnity.Init(this, new DungeonVector2(x, y), tile); tiles[x + y * dungeon.SizeX] = tileUnity; } } //Combine tiles CombineTiles(8); //Return tiles for (int i = 0; i < tiles.Length; i++) { if (tiles[i]) { tilesPool.ReturnTile(tiles[i]); tiles[i] = null; } } }
/// <summary> /// Parses the character array and determines which tile to use where /// </summary> private void SetTiles() { for (int z = 0; z < dungeonLayout.GetLength(0); z++) { for (int x = 0; x < dungeonLayout.GetLength(1); x++) { dungeonTiles[z, x] = new DungeonTile(); if (dungeonLayout[z, x] == emptySpaceChar) { continue; } GetSurroundingTiles(z, x); GetTileType(z, x); if (dungeonTiles[z, x].tileType == TileTypes.Empty) { continue; } switch (dungeonTiles[z, x].tileType) { case TileTypes.Room: case TileTypes.Entry: case TileTypes.Exit: DetermineRoomTile(z, x); break; // TODO Add functionality for doors and halls } } } }
private void PrintExamineObjectMessage() { Point faceDir = GameState.Player.FaceDirection.ToPoint(); DungeonTile tile = DungeonTile.Wall; int distance = 0; for (int i = 0; i < 5; i++) { Point loc = new Point(Player.X + faceDir.X * i, Player.Y + faceDir.Y * i); tile = DungeonAdapter.TileAt(loc.X, loc.Y); distance = i; if (tile != DungeonTile.Empty) { break; } } if (tile != DungeonTile.Wall && tile != DungeonTile.Empty) { XamineFormatter.DescribeTile(tile, distance); } else { XamineFormatter.PrintNothingUnusualInSight(); } }
internal bool IsInLineOfSight(Program observer, DungeonTile tile) { Vector3 direction = (tile.GetOccupyingCoordinates(true, false) - observer.myTile.GetOccupyingCoordinates(observer.IsFlying(), false)).normalized; float distance = (tile.GetOccupyingCoordinates(true, false) - observer.myTile.GetOccupyingCoordinates(observer.IsFlying(), false)).magnitude; return(!Physics.Raycast(observer.myTile.GetOccupyingCoordinates(observer.IsFlying(), false), direction, distance, LayerMask.GetMask("Ground"))); }
public void GenerateLevel() { int unixTimestamp = ((long)(System.DateTime.UtcNow.Subtract(new System.DateTime(1970, 1, 1))).TotalSeconds).GetHashCode(); LevelGenerator levelGenerator = new LevelGenerator(CurrentDungeon.numberOfTiles, 0.9f, unixTimestamp, CurrentDungeon.frequencyOfHallwayDiversions, CurrentDungeon.lengthOfHallways); levelGenerator.GenerateLevel(); foreach (var room in levelGenerator.AllRooms) { EncounterScriptableObject encounter = null; if (!(room.Position.x == 0 && room.Position.y == 0)) { encounter = (Random.Range(0, 2) == 1) ? CurrentDungeon.encounters[Random.Range(0, CurrentDungeon.encounters.Length)] : null; } DungeonTile dt = new DungeonTile(room, encounter); if (room.Position.x == 0 && room.Position.y == 0) { currentTile = dt; currentTile.TileVisited(); currentTile.TileSeen(); } dt.TileSeen(); Tiles.Add(dt); } }
private void DrawDungeon(Texture2D texture, DungeonMap dungeon) { System.Array.Copy(emptyPagePixels, tmpPagePixels, emptyPagePixels.Length); int tileWidth = texture.width / dungeon.SizeX; int tileHeight = texture.height / dungeon.SizeY; //Draw surrounding DrawSquare(tmpPagePixels, texture.width, texture.height, 0, 0, texture.width, texture.height, new Color32(0, 0, 0, 255)); for (int x = 0; x < dungeon.SizeX; x++) { for (int y = 0; y < dungeon.SizeY; y++) { DungeonTile tile = dungeon.GetTile(x, y); int px = x * tileWidth; int py = y * tileHeight; if (tile.type == DungeonTileType.Wall) { DrawSquare(tmpPagePixels, texture.width, texture.height, px + 1, py + 1, tileWidth - 2, tileHeight - 2, new Color32(0, 0, 0, 255)); } } } texture.SetPixels32(tmpPagePixels); texture.Apply(true); }
public DungeonTileInfo(DungeonTile dungeonTile) { Id = dungeonTile.Id; LandBlockId = dungeonTile.LandBlockId; TileId = dungeonTile.TileId; Origin = new Vector3(dungeonTile.X, dungeonTile.Y, dungeonTile.Z); }
public override void Init() { var ImgSizeX = DungeonWidth / DungeonSize; var ImgSizeY = DungeonHeight / DungeonSize; RoomSize = (int)Math.Round((float)(DungeonSize - Math.Round(DungeonSize * 0.35)) / 100 * RoomSizePercent); RoomDescription = new List <RoomDescription>(); DungeonSize += 2; // because of boundaries DungeonTiles = new DungeonTile[DungeonSize][]; for (var i = 0; i < DungeonSize; i++) { DungeonTiles[i] = new DungeonTile[DungeonSize]; } for (var i = 0; i < DungeonSize; i++) { for (var j = 0; j < DungeonSize; j++) { DungeonTiles[i][j] = new DungeonTile(i, j); } } for (var i = 1; i < DungeonSize - 1; i++) // set drawing area { for (var j = 1; j < DungeonSize - 1; j++) { DungeonTiles[i][j] = new DungeonTile((j - 1) * ImgSizeX, (i - 1) * ImgSizeY, i, j, ImgSizeX, ImgSizeY, Textures.MARBLE); } } }
// ================================================================================================== // public void Load(string dungeonName) { // clean all dungeon this.clear(); // find matching dungeon save data from player data by its name foreach (DungeonSaveData data in SaveAndLoad.Instance.PlayerSaveData.Dungeons) { if (data.Name == dungeonName) { _dungeonSaveData = data; } } // return if not exist if (_dungeonSaveData == null) { Debug.LogError(dungeonName + " dungeon doesn't exist in player save data"); return; } // TODO: in the meantime... show always first... ShowArea(Position.OriginPosition); // place the party if (dungeonName != Consts.WindowNames.VILLAGE) { DungeonTile tile = GetTile(new Position(0, 0)); // TODO: change that PutDungeonObjectInTile(Party.Instance.DungeonObject, tile); RevealPartySurroundings(); } // update the location of the party Party.Instance.Loaction = dungeonName; }
public DungeonType(string dungeonName, int roomCount, ref DungeonTile dungeonFloorTile, ref DungeonTile dungeonWallTile) { this.dungeonName = dungeonName; this.roomCount = roomCount; this.dungeonFloorTile = dungeonFloorTile; this.dungeonWallTile = dungeonWallTile; }
// ================================================================================================== // private void checkRightClickOnTile() { if (!Input.GetMouseButton(1)) { return; } LayerMask layerMask = (1 << LayerMask.NameToLayer("DungeonTile")); RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, 0.0F, layerMask); if (hit.collider == null) { return; } DungeonTile targetTile = hit.collider.GetComponent <DungeonTile>(); if (targetTile == null) { return; } targetTile.Clear(); updateCurrentAreaSaveData(); }
// ================================================================================================== // private GameObject createObjectInTile(string objectName, DungeonTile targetTile) { // get object from resources folder var allResources = Resources.LoadAll <GameObject>(""); GameObject prefabToCreate = null; foreach (GameObject obj in allResources) { if (obj.name == objectName) { prefabToCreate = obj; } } if (prefabToCreate == null) { Debug.LogError(objectName + " resource doesn't exist"); return(null); } // instantiate it in tile GameObject instance = Instantiate(prefabToCreate); instance.transform.position = targetTile.transform.position; instance.transform.parent = targetTile.transform; // if item, make it in ground state, so the sprite will change to icon if (instance.GetComponent <Item>() != null) { instance.GetComponent <Item>().State = ItemState.GROUND; } return(instance); }
void EditTile(int x, int y) { if (x < 0 || y < 0 || x >= Room.gridWidth || y >= Room.gridHeight) { return; } DungeonTile oldTile = loadedRoom.contents.GetTile(x, y); if (oldTile != null) { Destroy(oldTile.gameObject); } DungeonTile newTile = null; if (activeTile != null) { GameObject _newTile = PrefabUtility.InstantiatePrefab(activeTile.gameObject) as GameObject; newTile = _newTile.GetComponent <DungeonTile>(); newTile.transform.SetParent(loadedRoom.transform); newTile.x = x; newTile.y = y; Vector2 postion; postion.x = x - Room.gridWidth / 2f + .5f; postion.y = y - Room.gridHeight / 2f + .5f; newTile.transform.position = loadedRoom.transform.TransformPoint(postion); newTile.room = loadedRoom; newTile.EnableDebug(); } loadedRoom.contents.SetTile(newTile, x, y); }
// Start is called before the first frame update void Awake() { floor = FloorName.GARDEN; activeObjectType = DungeonObjectType.TILE; activeTile = tiles[0]; activeObject = objects[0]; }
private void SetDistanceRecursive(ref int[][] distances, int currentDistance, DungeonTile tile, int maxDistance, bool isFlying) { if (distances[tile.xCoord][tile.zCoord] > currentDistance) { distances[tile.xCoord][tile.zCoord] = currentDistance; if (currentDistance < maxDistance) { if (IsValidCoordinates(tile.xCoord + 1, tile.zCoord) && (isFlying || IsPassable(tileGrid[tile.xCoord + 1][tile.zCoord], tile))) { SetDistanceRecursive(ref distances, currentDistance + 1, tileGrid[tile.xCoord + 1][tile.zCoord], maxDistance, isFlying); } if (IsValidCoordinates(tile.xCoord - 1, tile.zCoord) && (isFlying || IsPassable(tileGrid[tile.xCoord - 1][tile.zCoord], tile))) { SetDistanceRecursive(ref distances, currentDistance + 1, tileGrid[tile.xCoord - 1][tile.zCoord], maxDistance, isFlying); } if (IsValidCoordinates(tile.xCoord, tile.zCoord + 1) && (isFlying || IsPassable(tileGrid[tile.xCoord][tile.zCoord + 1], tile))) { SetDistanceRecursive(ref distances, currentDistance + 1, tileGrid[tile.xCoord][tile.zCoord + 1], maxDistance, isFlying); } if (IsValidCoordinates(tile.xCoord, tile.zCoord - 1) && (isFlying || IsPassable(tileGrid[tile.xCoord][tile.zCoord - 1], tile))) { SetDistanceRecursive(ref distances, currentDistance + 1, tileGrid[tile.xCoord][tile.zCoord - 1], maxDistance, isFlying); } } } }
private void AddToOpen(DungeonTile node, List <DungeonTile> openList, List <DungeonTile> closedList) { AddToOpenList(node.I, node.J - 1, openList, closedList); // left AddToOpenList(node.I - 1, node.J, openList, closedList); // top AddToOpenList(node.I + 1, node.J, openList, closedList); // bottom AddToOpenList(node.I, node.J + 1, openList, closedList); // right }
public void SetTile(int x, int y, int sizeX, int sizeY, DungeonTile tile) { //if (!CheckValidBounds(x, y, sizeX, sizeY)) // throw new ArgumentException("Invalid tile position in room"); dungeon.SetTile(x + roomPositionX, y + roomPositionY, sizeX, sizeY, tile); }
private void AnimateMovement() { Vector3 motion = (myTile.GetOccupyingCoordinates(false, false) - gameObject.transform.position).normalized * animationSpeed * Time.deltaTime; if (motion == Vector3.zero || motion.magnitude > (myTile.GetOccupyingCoordinates(false, false) - gameObject.transform.position).magnitude) { gameObject.transform.position = myTile.GetOccupyingCoordinates(false, false); if (movePath.Count == 0) { HitTarget(); DungeonManager.instance.mode = DungeonManager.Mode.Move; Destroy(gameObject); } else { myTile = movePath[0]; movePath.Remove(myTile); } } else { gameObject.transform.position += motion; gameObject.transform.localScale = new Vector3(Mathf.Clamp(motion.x, 0.1f, 0.6f), Mathf.Clamp(motion.y, 0.1f, 0.6f), 0.1f); } }
public override async Task Execute() { DungeonTile tile = DungeonAdapter.TileAt(Player.X, Player.Y); if (tile == DungeonTile.Urn) { await OpenUrn(); } else if (tile == DungeonTile.Box) { await OpenBox(); } else if (tile == DungeonTile.Chest) { await OpenChest(DungeonAdapter.ChestValueAt(Player.X, Player.Y)); } else { await TextArea.PrintLine(); await TextArea.PrintLine(); await TextArea.PrintLine("Nothing to open."); await GameControl.WaitAsync(1000); } }
public void SpawnTiles() { foreach (var p in tilePoints) { DungeonTile d = Instantiate(TilePref, transform).GetComponent <DungeonTile>(); d.SetPosition(p); tiles.Add(d); } DungeonTile tile; do { tile = tiles[Random.Range(0, tiles.Count)]; } while (tile.generated); tile.GenerateRoom(tilePoints, TileType.spawn); do { tile = tiles[Random.Range(0, tiles.Count)]; } while (tile.generated); tile.GenerateRoom(tilePoints, TileType.exit); foreach (var t in tiles) { if (!t.generated) { t.GenerateRoom(tilePoints); } } }
private void RenderWalls() { var wallA = new DungeonTile { TileType = AbyssTemplate.Space, Object = new DungeonObject { ObjectType = AbyssTemplate.RedWall } }; var wallB = new DungeonTile { TileType = AbyssTemplate.Space, Object = new DungeonObject { ObjectType = AbyssTemplate.RedTorchWall } }; var buf = Rasterizer.Bitmap; var tmp = (DungeonTile[, ])buf.Clone(); int w = Rasterizer.Width, h = Rasterizer.Height; for (var x = 0; x < w; x++) { for (var y = 0; y < h; y++) { if (buf[x, y].TileType != AbyssTemplate.Space) { continue; } var notWall = true; if (x == 0 || y == 0 || x + 1 == w || y + 1 == h) { notWall = true; } else { for (var dx = -1; dx <= 1 && notWall; dx++) { for (var dy = -1; dy <= 1 && notWall; dy++) { if (tmp[x + dx, y + dy].TileType == AbyssTemplate.Space) { continue; } notWall = false; break; } } } if (!notWall) { buf[x, y] = Rand.NextDouble() < 0.9 ? wallA : wallB; } } } }
internal void SetTile(DungeonTile tile) { myTile = tile; if (isEnabled) { tile.isBlocked = true; } }
public override void Rasterize() { var tile = new DungeonTile { TileType = PirateCaveTemplate.ShallowWater }; Rasterizer.Clear(tile); }
public static DungeonTile[,] Load(string json) { var map = (JsonObject)SimpleJson.DeserializeObject(json); uint w = (uint)(long)map["width"], h = (uint)(long)map["height"]; var result = new DungeonTile[w, h]; var tiles = new Dictionary <ushort, DungeonTile>(); ushort id = 0; foreach (JsonObject tile in (JsonArray)map["dict"]) { var mapTile = new DungeonTile(); var tileType = (string)tile.GetValueOrDefault("ground", "Space"); mapTile.TileType = new TileType(tileType == "Space" ? 0xfe : (uint)tileType.GetHashCode(), tileType); mapTile.Region = tile.ContainsKey("regions") ? (string)((JsonObject)((JsonArray)tile["regions"])[0])["id"] : null; if (tile.ContainsKey("objs")) { var obj = (JsonObject)((JsonArray)tile["objs"])[0]; var tileObj = new DungeonObject(); tileObj.ObjectType = new ObjectType((uint)((string)obj["id"]).GetHashCode(), (string)obj["id"]); if (obj.ContainsKey("name")) { var attrs = (string)obj["name"]; tileObj.Attributes = attrs.Split(';') .Where(attr => !string.IsNullOrEmpty(attr)) .Select(attr => attr.Split(':')) .Select(attr => new KeyValuePair <string, string>(attr[0], attr[1])) .ToArray(); } else { tileObj.Attributes = Empty <KeyValuePair <string, string> > .Array; } mapTile.Object = tileObj; } else { mapTile.Object = null; } tiles[id++] = mapTile; } byte[] data = RotMG.Common.IO.Zlib.Decompress(Convert.FromBase64String((string)map["data"])); int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { result[x, y] = tiles[(ushort)((data[index++] << 8) | data[index++])]; } } return(result); }
public void SetWallTile(string[] ids) { //Changes the inner side of the walls surrounding the room to "id" //Circulates the room wall in clockwise order //Walls on the north (side pointing south) int idsLen = ids.Length; int idsOffset = 0; for (int x = 0; x < roomSizeX; x++) { DungeonTile wallTile = GetTile(x, SizeY); if (wallTile.type == DungeonTileType.Wall) { wallTile.wallSouth = ids[idsOffset % idsLen]; SetTile(x, SizeY, wallTile); } idsOffset++; } //Walls on the right (side pointing west) for (int y = 0; y < roomSizeY; y++) { DungeonTile wallTile = GetTile(SizeX, y); if (wallTile.type == DungeonTileType.Wall) { wallTile.wallWest = ids[idsOffset % idsLen]; SetTile(SizeX, y, wallTile); } idsOffset++; } //Walls on the south (side pointing north) for (int x = roomSizeX - 1; x >= 0; x--) { DungeonTile wallTile = GetTile(x, -1); if (wallTile.type == DungeonTileType.Wall) { wallTile.wallNorth = ids[idsOffset % idsLen]; SetTile(x, -1, wallTile); } idsOffset++; } //Walls on the left (side pointing east) for (int y = roomSizeY - 1; y >= 0; y--) { DungeonTile wallTile = GetTile(-1, y); if (wallTile.type == DungeonTileType.Wall) { wallTile.wallEast = ids[idsOffset % idsLen]; SetTile(-1, y, wallTile); } idsOffset++; } }
private bool CheckPossible(int vertical, int horizontal, DungeonTile door) { if (vertical == 0 || horizontal == 0) // its impossible to add room { DungeonTiles[door.I][door.J].Texture = Textures.ROOM_EDGE; // change the door to a room_edge return(false); } return(true); }
private void RandomFillUpDown(int x, int y, DungeonTile door) { var result = CheckArea(x, y, door); if (result[0] != 0 && result[1] != 0) { FillUpDown(x, y, result[0], result[1]); } }
public void AddDungeonTiles(DungeonTile pDungeonTiles) { dungeonTiles.Add(pDungeonTiles); }