public bool TilesAdjecent(RoomTile targetTile) { int dx = this.Position.X - targetTile.Position.X; int dy = this.Position.Y - targetTile.Position.Y; return((dx * dx) + (dy * dy) <= 2); }
public RoomTile GetTileInFront(RoomTile tile, int rotation, int offset = 0) { int offsetX = 0; int offsetY = 0; switch (rotation) { case 0: offsetY--; break; case 1: offsetX++; offsetY--; break; case 2: offsetX++; break; case 3: offsetX++; offsetY++; break; case 4: offsetY++; break; case 5: offsetX--; offsetY++; break; case 6: offsetX--; break; case 7: offsetX--; offsetY--; break; } int x = tile.Position.X; int y = tile.Position.Y; for (int i = 0; i <= offset; i++) { x += offsetX; y += offsetY; } return(this.Tiles[x, y]); }
public void RegenerateEntityCollision() { foreach (RoomTile tile in this.Tiles) { tile.Entities.Clear(); } foreach (RoomEntity entity in this.room.EntityManager.Entities) { RoomTile tile = Tiles[entity.Position.X, entity.Position.Y]; if (tile == null) { continue; } tile.AddEntity(entity); } }
public void RegenerateCollisionMap() { string[] split = room.Model.Map.Replace("\n", "").Split('\r'); this.SizeY = split.Length; this.SizeX = split[0].Length; this.Tiles = new RoomTile[this.SizeX, this.SizeY]; for (int y = 0; y < this.SizeY; y++) { for (int x = 0; x < this.SizeX; x++) { char position = split[y][x]; RoomTile tile = new RoomTile(room, new TilePosition(x, y, this.ParseChar(position))); if (position == 'x') { tile.State = RoomTileState.CLOSED; } this.Tiles[x, y] = tile; } } this.RegenerateEntityCollision(); this.RegenerateItemsCollision(); }