private void PlaceSprite(PointInt32 location, byte type, PointShort size, PointShort upperLeft = new PointShort()) { for (int x = 0; x < size.X; x++) { for (int y = 0; y < size.Y; y++) { var curTile = _world.Tiles[location.X + x, location.Y + y]; curTile.IsActive = true; curTile.Type = type; curTile.Frame = new PointShort((short)(upperLeft.X + (x * 18)), (short)(upperLeft.Y + (y * 18))); _renderer.UpdateWorldImage(new PointInt32(location.X + x, location.Y + y)); } } if (type == 21) { _world.Chests.Add(new Chest { Location = location }); } else if (type == 55 || type == 85) { _world.Signs.Add(new Sign { Location = location }); } }
public TileProperty(byte id) { // ID + Default values ID = id; Name = "UNKNOWN"; Color = Colors.Magenta; Size = new PointShort(1, 1); }
public Tile() { IsActive = false; Type = 0; Frame = new PointShort(-1, -1); Wall = 0; IsLighted = false; Liquid = 0; IsLava = false; }
private void SetTileSprite(PointInt32 point, PointShort frame, byte type) { var curTile = _world.Tiles[point.X, point.Y]; if (curTile != null) { curTile.IsActive = true; curTile.Type = type; curTile.Frame = frame; _renderer.UpdateWorldImage(point); } }
public PointShort XMLConvert(PointShort v, XAttribute attr) { if (attr == null) { return(v); } var ps = PointShort.TryParseInline((string)attr); if (attr.Name == "size" && ps == new PointShort()) { ps = new PointShort(1, 1); } return(ps); }
private static bool WRITE_BY_ROW = true; // Построчная запись public PicImage(Stream stream) : base(0x01) { _coord = stream.ReadPicAbsCoord(); ushort size = stream.ReadUShortBE(); var startPos = stream.Position; Width = stream.ReadUShortBE(); Height = stream.ReadUShortBE(); stream.Seek(2, SeekOrigin.Current); _transpCol = stream.ReadB(); stream.Seek(1, SeekOrigin.Current); Image = new byte[Width * Height]; ReadImageData(stream); var readSize = stream.Position - startPos; if (size != readSize) { throw new FormatException(); } }
private bool ValidatePlacement(PointInt32 location, PointShort size, FramePlacement frame) // using FP = FramePlacement; { // TODO: Support for attachesTo with placement // quick short-circuits if (frame.Is(FP.None)) { return(false); // hey, if it can't attach to anything, it's invalid } if (frame.Is(FP.Any)) { return(true); } if (frame.Has(FP.Float)) { return(true); // ...for now; this behavior may change if we actually get a "float only" object } /// Look at surrounding area for objects /// FramePlacement area = FP.Float; RectI areaRect = new RectI(location - 1, location + size); // (only used for x/y loop) RectI areaRectBnd = new RectI(areaRect); // skip tests that don't apply // (frame = multiples) if (frame.HasNo(FP.Ceiling)) { areaRectBnd.Top++; } if (frame.HasNo(FP.FloorSurface)) { areaRectBnd.Bottom--; } if (frame.HasNo(FP.Wall)) { areaRectBnd.Left++; areaRectBnd.Right--; } // (shorter cuts for singular terms; using HasNoneOf to factor in MustHaveAll) if (frame.HasNoneOf(FP.WallCeiling)) { areaRectBnd.Top = areaRect.Bottom; // Floor/Surface/both } if (frame.HasNoneOf(FP.WallFloorSurface)) { areaRectBnd.Bottom = areaRect.Top; // Ceiling } // Wall already covered in multiples checks // boundary checks if (areaRectBnd.Left < 0) { areaRectBnd.Left = 0; } if (areaRectBnd.Top < 0) { areaRectBnd.Top = 0; } if (areaRectBnd.Right > Header.WorldBounds.Right) { areaRectBnd.Right = Header.WorldBounds.Right; } if (areaRectBnd.Bottom > Header.WorldBounds.Bottom) { areaRectBnd.Bottom = Header.WorldBounds.Bottom; } for (int y = areaRectBnd.Top; y <= areaRectBnd.Bottom; y++) { for (int x = areaRectBnd.Left; x <= areaRectBnd.Right; x++) { // skip dead zone (the item itself) & corners (wow, xor use...) bool valid = (x == areaRect.Left || x == areaRect.Right) ^ (y == areaRect.Top || y == areaRect.Bottom); if (!valid) { continue; } var t = Tiles[x, y]; var w = WorldSettings.Tiles[t.Type]; // skip non-solid objects if (!(t.IsActive && w.IsSolid || w.IsSolidTop)) { continue; } // FIXME: Assuming that a single tile will hold the object // // (Maybe this is true in Terraria as well....) // at this point, only one of these will hit if (y == areaRect.Top) { area = area.Add(FP.Ceiling); break; // done with this Y-axis } else if (x == areaRect.Left || x == areaRect.Right) { area = area.Add(FP.Wall); y = areaRect.Bottom - 1; // -1 = for loop will re-adjust, or kick out if LRB was truncated break; // done with all except bottom } else if (y == areaRect.Bottom) // special case for floor/surface { if (w.IsSolidTop) { area = area.Add(FP.Surface); } else { area = area.Add(FP.Floor); } if (area.HasAllOf(FP.FloorSurface)) { break; // done with everything else } } } } // Now let's compare the object in question if (frame.Has(FP.MustHaveAll)) { area = area.Add(FP.MustHaveAll); // add bit for bitwise math to work if (area.Filter(frame) != frame) { return(false); } } else { if (frame.HasNoneOf(area)) { return(false); } } return(true); }