/// <summary> /// /// </summary> /// <param name="id">The type of this tile.</param> /// <param name="solidityType"></param> /// <param name="textureSourceRectangle">The appropriate source rectangle to use. see <c>SourceRects</c>.</param> /// <param name="drawColor"></param> public Tile(TileId id, Solidity solidityType, Rectangle textureSourceRectangle, Color drawColor, TileSide tileSide) { this.Id = id; this.SolidityType = solidityType; this.SourceRectangle = textureSourceRectangle; this.DrawColor = drawColor; this.Side = tileSide; }
public int GetWeaponTextureId(TileSide side) { Item item = d_Inventory.RightHand[d_Viewport.ActiveMaterial]; if (item == null || IsCompass()) { //empty hand if (side == TileSide.Top) { return 129; } return 128; } if (item.ItemClass == ItemClass.Block) { return d_Data.TextureId[item.BlockId, (int)side]; } else { //todo return 0; } }
private int GetTilingCount(byte[, ,] currentChunk, int xx, int yy, int zz, byte tt, int x, int y, int z, float shadowratio, TileSide dir) { if (dir == TileSide.Top || dir == TileSide.Bottom) { int shadowz = dir == TileSide.Top ? 1 : -1; int newxx = xx + 1; for (; ; ) { if (newxx >= chunksize + 1) { break; } if (currentChunk[newxx, yy, zz] != tt) { break; } float shadowratio2 = GetShadowRatio(newxx, yy, zz + shadowz, x + (newxx - xx), y, z + shadowz); if (shadowratio != shadowratio2) { break; } currentChunkIgnore[newxx - 1, yy - 1, zz - 1, (int)dir] = true; newxx++; } return newxx - xx; } else if (dir == TileSide.Front || dir == TileSide.Back) { int shadowx = dir == TileSide.Front ? -1 : 1; int newyy = yy + 1; for (; ; ) { if (newyy >= chunksize + 1) { break; } if (currentChunk[xx, newyy, zz] != tt) { break; } float shadowratio2 = GetShadowRatio(xx + shadowx, newyy, zz, x + shadowx, y + (newyy - yy), z); if (shadowratio != shadowratio2) { break; } currentChunkIgnore[xx - 1, newyy - 1, zz - 1, (int)dir] = true; newyy++; } return newyy - yy; } else { int shadowy = dir == TileSide.Left ? -1 : 1; int newxx = xx + 1; for (; ; ) { if (newxx >= chunksize + 1) { break; } if (currentChunk[newxx, yy, zz] != tt) { break; } float shadowratio2 = GetShadowRatio(newxx, yy + shadowy, zz, x + (newxx - xx), y + shadowy, z); if (shadowratio != shadowratio2) { break; } currentChunkIgnore[newxx - 1, yy - 1, zz - 1, (int)dir] = true; newxx++; } return newxx - xx; } }
public BlockPosSide(int x, int y, int z, TileSide side) { this.pos = new Vector3(x, y, z); this.side = side; }
public int GetTileTextureId(int tileType, TileSide side) { if (side == TileSide.Top) { return data[tileType].TextureTop; } if (side == TileSide.Bottom) { return data[tileType].TextureBottom; } return data[tileType].TextureSide; }
public int GetWeaponTextureId(TileSide side) { return data.GetTileTextureId(viewport.MaterialSlots[viewport.activematerial], side); }
public int GetTileTextureId(int tileType, TileSide side) { if (CurrentSeason.CurrentSeason == 3) { if (tileType == (int)TileTypeMinecraft.Grass) { if (side == TileSide.Top) { return (7 * 16) + 3; } if (side == TileSide.Bottom) { goto standard; } return (7 * 16) + 5; } if (tileType == (int)TileTypeMinecraft.Water || tileType == (int)TileTypeMinecraft.StationaryWater || tileType == (int)TileTypeMinecraft.InfiniteWaterSource) { return (7 * 16) + 4; } if (tileType == (int)TileTypeMinecraft.Leaves) { return (7 * 16) + 6; } } standard: if (datanew[tileType] != null) { if (side == TileSide.Top) { return datanew[tileType].TextureTop; } if (side == TileSide.Bottom) { return datanew[tileType].TextureBottom; } return datanew[tileType].TextureSide; } if (IsRailTile(tileType)) { //return 1; if (side == TileSide.Top) { return tileType; } else { return data.GetTileTextureId((int)TileTypeMinecraft.Cobblestone, TileSide.Top); } } return data.GetTileTextureId(tileType, side); }
private TileCorner GetMatchingCorner(TileCorner thisCorner, TileSide neighboursTileSide) { var errorMessage = "There are no matching corners for this corner and tile side match"; switch (thisCorner) { case TileCorner.Top: if (neighboursTileSide == TileSide.TopLeft) { return(TileCorner.BottomLeft); } else if (neighboursTileSide == TileSide.TopRight) { return(TileCorner.BottomRight); } else { throw new InvalidOperationException(errorMessage); } case TileCorner.TopRight: if (neighboursTileSide == TileSide.TopRight) { return(TileCorner.Bottom); } else if (neighboursTileSide == TileSide.Right) { return(TileCorner.TopLeft); } else { throw new InvalidOperationException(errorMessage); } case TileCorner.BottomRight: if (neighboursTileSide == TileSide.Right) { return(TileCorner.BottomLeft); } else if (neighboursTileSide == TileSide.BottomRight) { return(TileCorner.Top); } else { throw new InvalidOperationException(errorMessage); } case TileCorner.Bottom: if (neighboursTileSide == TileSide.BottomRight) { return(TileCorner.TopLeft); } else if (neighboursTileSide == TileSide.BottomLeft) { return(TileCorner.TopRight); } else { throw new InvalidOperationException(errorMessage); } case TileCorner.BottomLeft: if (neighboursTileSide == TileSide.BottomLeft) { return(TileCorner.Top); } else if (neighboursTileSide == TileSide.Left) { return(TileCorner.BottomRight); } else { throw new InvalidOperationException(errorMessage); } case TileCorner.TopLeft: if (neighboursTileSide == TileSide.Left) { return(TileCorner.TopRight); } else if (neighboursTileSide == TileSide.TopLeft) { return(TileCorner.Bottom); } else { throw new InvalidOperationException(errorMessage); } default: throw new InvalidOperationException(errorMessage); } }
private void CreateEdgeColliders() { var sides = this.CreateTileSides(this.TilemapData); // todo: right now, all colliders are straight lines. they dont have to be. // todo>> make one collider for each closed shape. thus the amount of colliders is reduced greatly while (sides.Count > 0) { TileSide startSide = sides.First(); sides.Remove(startSide); Vector2f min = startSide.Min; Vector2f max = startSide.Max; TileSide previous = startSide.Previous; while (sides.Contains(previous)) { sides.Remove(previous); min = previous.Min; previous = previous.Previous; } TileSide next = startSide.Next; while (sides.Contains(next)) { sides.Remove(next); max = next.Max; next = next.Next; } this.Add <EdgeCollider2D>().points = new Vector2[] { min, max }; } #region !! TODO !! This is the optimized version (combines the colliders) which doesn't work with Unity 4.3, BUT it should work with Unity 4.5 (there is a bug with EdgeColliders and Physics2D.OverlapArea which broke crate collisions!!) /* * // create segments * HashSet<Segment2Di> segments = new HashSet<Segment2Di>(); * Dictionary<Vector2i, HashSet<Segment2Di>> pointToSegment = new Dictionary<Vector2i, HashSet<Segment2Di>>(); * while (sides.Count > 0) * { * TileSide startSide = sides.First(); * sides.Remove(startSide); * * Vector2i min = startSide.MinIndex; * Vector2i max = startSide.MaxIndex; * * TileSide previous = startSide.Previous; * while (sides.Contains(previous)) * { * sides.Remove(previous); * min = previous.MinIndex; * previous = previous.Previous; * } * * TileSide next = startSide.Next; * while (sides.Contains(next)) * { * sides.Remove(next); * max = next.MaxIndex; * next = next.Next; * } * * Segment2Di segment = new Segment2Di(min, max); * segments.Add(segment); * * pointToSegment.GetOrAddDefault(min).Add(segment); * pointToSegment.GetOrAddDefault(max).Add(segment); * } * * // FlaiDebug.LogWarning("S: " + string.Join(", ", segments.ToArray().Select(p => p.ToString()).ToArray())); * // combine segments and create edge colliders * while (segments.Count > 0) * { * Segment2Di current = segments.First(); * FlaiDebug.Log(current); * segments.Remove(current); * pointToSegment[current.Start].Remove(current); * pointToSegment[current.End].Remove(current); * * List<Vector2> points = new List<Vector2>() { current.Start * Tile.Size, current.End * Tile.Size }; * while (pointToSegment[current.End].Count != 0) * { * Segment2Di newSegment = pointToSegment[current.End].FirstOrDefault(segments.Contains); * if (newSegment == default(Segment2Di)) * { * break; * } * * segments.Remove(newSegment); * segments.Remove(newSegment.Flipped); * if (newSegment.End == current.End) * { * newSegment = newSegment.Flipped; * } * * FlaiDebug.Log(newSegment); * pointToSegment[newSegment.Start].Remove(newSegment); * pointToSegment[newSegment.End].Remove(newSegment); * points.Add(newSegment.End * Tile.Size); * current = newSegment; * } * * this.Add<EdgeCollider2D>().points = points.ToArray(); * } */ #endregion }
public Diode(TileSide outputSide) { this.outputSide = outputSide; inputOffset = Tile.SideToOffset(outputSide).Negate(); }
public bool IsSideEmpty(TileSide tileSide) { return(this._bridges[(int)tileSide] == null); }
public virtual IRenderer GetCeelingRenderer(TileSide ceeling, Texture2D wallTexture) { return(new TileWallSideRenderer <TileSide>(ceeling, wallTexture)); }
public virtual IRenderer GetWallSideRenderer(TileSide side, Texture2D wallTexture) { return(new TileWallSideRenderer <TileSide>(side, wallTexture)); }
public virtual IRenderer GetWallIllusionTileSideRenderer(TileSide tileSide, Texture2D wallTexture, Texture2D decoration) { return(new WallIllusionTileSideRenderer(tileSide, wallTexture, decoration)); }
public int GetTileTextureId(int tileType, TileSide side) { return TileTextureIds[new TileTypeSide() { tiletype = tileType, side = side }]; }
private CoverProvided CoverProvidedBetween(Vector2 aggressorVector, TileSide aggressorCorner, Vector2 victimVector, TileSide victimCorner) { var currentCover = new CoverProvided(); var currentX = _aggressor.Position.X * 2 + (int)aggressorCorner % 3 - 1; var currentY = _aggressor.Position.Y * 2 + ((int)aggressorCorner - 3 - (int)aggressorCorner % 3) / 3; var victimX = _victim.Position.X * 2 + (int)victimCorner % 3 - 1; var victimY = _victim.Position.Y * 2 + ((int)victimCorner - 3 - (int)victimCorner % 3) / 3; var victimCenterX = _victim.Position.X * 2; var victimCenterY = _victim.Position.Y * 2; var cover = CalculateDiagonalCover(currentX, currentY); if (cover.Cover == Cover.Heavy) { return(cover); } if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } if (currentX == victimX && currentY == victimY) { return(currentCover); } if (currentX == victimX) { var direction = Math.Sign(victimY - currentY); if (_aggressor.Position.X == _victim.Position.X) { for (var y = _aggressor.Position.Y; y != _victim.Position.Y; y += direction) { cover = new CoverProvided(GameWorld.Map[_aggressor.Position.X, y]); if (cover.Cover == Cover.Heavy) { return(cover); } if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } } } currentY += direction; if (currentY == victimCenterY) { return(currentCover); } while (currentY + direction != victimCenterY) { cover = CalculateCover(currentX, currentY); if (cover.Cover == Cover.Heavy) { return(cover); } if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } currentY += direction; } cover = CalculateDiagonalCoverIgnoring(currentX, currentY, _victim); if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } return(currentCover); } if (currentY == victimY) { var direction = Math.Sign(victimX - currentX); if (_aggressor.Position.Y == _victim.Position.Y) { for (var x = _aggressor.Position.X; x != _victim.Position.X; x += direction) { cover = new CoverProvided(GameWorld.Map[x, _aggressor.Position.Y]); if (cover.Cover == Cover.Heavy) { return(cover); } if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } } } currentX += direction; if (currentX == victimCenterX) { return(currentCover); } while (currentX != victimCenterX) { cover = CalculateCover(currentX, currentY); if (cover.Cover == Cover.Heavy) { return(cover); } if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } currentX += direction; } cover = CalculateDiagonalCoverIgnoring(currentX, currentY, _victim); if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } return(currentCover); } var currentPreciseX = aggressorVector.X; var currentPreciseY = aggressorVector.Y; var distanceX = (victimX - currentX) / 2; var distanceY = (victimY - currentY) / 2; var horizontalDirection = Math.Sign(distanceX); var verticalDirection = Math.Sign(distanceY); currentX += 1 * Math.Sign(distanceX); currentY += 1 * Math.Sign(distanceY); while (Math.Abs(currentX - victimCenterX) > 1 || Math.Abs(currentY - victimCenterY) > 1) { cover = new CoverProvided(GameWorld.Map[currentX / 2, currentY / 2]); if (cover.Cover == Cover.Heavy) { return(cover); } if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } var timeUntilCrossX = Math.Abs(((distanceX > 0 ? Math.Ceiling((currentPreciseX + 0.01) / TileData.RenderWidth) : Math.Floor((currentPreciseX - 0.01) / TileData.RenderWidth)) * TileData.RenderWidth - currentPreciseX) / distanceX); var timeUntilCrossY = Math.Abs(((distanceY > 0 ? Math.Ceiling((currentPreciseY + 0.01) / TileData.RenderHeight) : Math.Floor((currentPreciseY - 0.01) / TileData.RenderHeight)) * TileData.RenderHeight - currentPreciseY) / distanceY); if (Math.Abs(timeUntilCrossX - timeUntilCrossY) < EPSILON) { currentX += 1 * horizontalDirection; currentY += 1 * verticalDirection; if (Math.Abs(currentX - victimCenterX) <= 1 && Math.Abs(currentY - victimCenterY) <= 1) { cover = CalculateDiagonalCoverTraveling(currentX, currentY, horizontalDirection * verticalDirection > 0); if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } return(currentCover); } cover = CalculateDiagonalCover(currentX, currentY); if (cover.Cover == Cover.Heavy) { return(cover); } if ((int)cover.Cover > (int)currentCover.Cover) { currentCover = cover; } currentPreciseX += (float)timeUntilCrossX * distanceX; currentPreciseY += (float)timeUntilCrossX * distanceY; currentX += 1 * horizontalDirection; currentY += 1 * verticalDirection; } else if (timeUntilCrossX < timeUntilCrossY) { currentX += 2 * horizontalDirection; currentPreciseX += (float)timeUntilCrossX * distanceX; currentPreciseY += (float)timeUntilCrossX * distanceY; } else { currentY += 2 * verticalDirection; currentPreciseX += (float)timeUntilCrossY * distanceX; currentPreciseY += (float)timeUntilCrossY * distanceY; } } return(currentCover); }