public static void ApplySetPieces(World world) { var map = world.Map; int w = map.Width, h = map.Height; Random rand = new Random(); HashSet<Rect> rects = new HashSet<Rect>(); foreach (var dat in setPieces) { int size = dat.Item1.Size; int count = rand.Next(dat.Item2, dat.Item3); for (int i = 0; i < count; i++) { IntPoint pt = new IntPoint(); Rect rect; int max = 50; do { pt.X = rand.Next(0, w); pt.Y = rand.Next(0, h); rect = new Rect() { x = pt.X, y = pt.Y, w = size, h = size }; max--; } while ((Array.IndexOf(dat.Item4, map[pt.X, pt.Y].Terrain) == -1 || rects.Any(_ => Rect.Intersects(rect, _))) && max > 0); if (max <= 0) continue; dat.Item1.RenderSetPiece(world, pt); rects.Add(rect); } } }
public void RenderSetPiece(World world, IntPoint pos) { Entity boss = Entity.Resolve(world.Manager, "shtrs Bridge Sentinel"); boss.Move(pos.X, pos.Y); Entity chestSpawner = Entity.Resolve(world.Manager, "shtrs encounterchestspawner"); chestSpawner.Move(pos.X, pos.Y + 5f); Entity blobombSpawner1 = Entity.Resolve(world.Manager, "shtrs blobomb maker"); blobombSpawner1.Move(pos.X, pos.Y + 5f); Entity blobombSpawner2 = Entity.Resolve(world.Manager, "shtrs blobomb maker"); blobombSpawner2.Move(pos.X + 5f, pos.Y + 5f); Entity blobombSpawner3 = Entity.Resolve(world.Manager, "shtrs blobomb maker"); blobombSpawner3.Move(pos.X - 5f, pos.Y + 5f); world.EnterWorld(boss); world.EnterWorld(chestSpawner); world.EnterWorld(blobombSpawner1); world.EnterWorld(blobombSpawner2); world.EnterWorld(blobombSpawner3); }
public void RenderSetPiece(World world, IntPoint pos) { var deepWaterRadius = 1f; var border = new List<IntPoint>(); var t = new int[Size, Size]; for (var y = 0; y < Size; y++) //Replace Deep Water With NWater for (var x = 0; x < Size; x++) { var dx = x - (Size/2.0); var dy = y - (Size/2.0); var r = Math.Sqrt(dx*dx + dy*dy); if (r <= deepWaterRadius) { t[x, y] = 1; } } for (var x = 0; x < Size; x++) for (var y = 0; y < Size; y++) { if (t[x, y] == 1) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Water; tile.ObjType = 0; world.Obstacles[x + pos.X, y + pos.Y] = 0; world.Map[x + pos.X, y + pos.Y] = tile; } } }
public void RenderSetPiece(World world, IntPoint pos) { var cooledRadius = 15; var t = new int[Size, Size]; for (var y = 0; y < Size; y++) for (var x = 0; x < Size; x++) { var dx = x - Size / 2.0; var dy = y - Size / 2.0; var r = Math.Sqrt(dx * dx + dy * dy); if (r <= cooledRadius) t[x, y] = 1; } for (var x = 0; x < Size; x++) for (var y = 0; y < Size; y++) { if (t[x, y] == 1) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Cooled; tile.ObjType = 0; if (world.Obstacles[x + pos.X, y + pos.Y] == 0) world.Map[x + pos.X, y + pos.Y] = tile; } } }
public void RenderSetPiece(World world, IntPoint pos) { for (int x = 0; x < Size; x++) for (int y = 0; y < Size; y++) { double dx = x - (Size / 2.0); double dy = y - (Size / 2.0); double r = Math.Sqrt(dx * dx + dy * dy) + rand.NextDouble() * 4 - 2; if (r <= 10) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Floor; tile.ObjType = 0; world.Obstacles[x + pos.X, y + pos.Y] = 0; world.Map[x + pos.X, y + pos.Y] = tile; } } Entity lord = Entity.Resolve(0x675); lord.Move(pos.X + 15.5f, pos.Y + 15.5f); world.EnterWorld(lord); Container container = new Container(0x0501, null, false); int count = rand.Next(5, 8); List<Item> items = new List<Item>(); while (items.Count < count) { Item item = chest.GetRandomLoot(rand); if (item != null) items.Add(item); } for (int i = 0; i < items.Count; i++) container.Inventory[i] = items[i]; container.Move(pos.X + 15.5f, pos.Y + 15.5f); world.EnterWorld(container); }
public void RenderSetPiece(World world, IntPoint pos) { int[,] t = new int[5, 5]; t[0, 2] = 1; t[1, 2] = 1; t[2, 2] = 1; t[3, 2] = 1; t[4, 2] = 1; t[2, 0] = 1; t[2, 1] = 1; t[2, 3] = 1; t[2, 4] = 1; t[1, 1] = 1; t[1, 3] = 1; t[3, 3] = 1; t[3, 1] = 1; for (int x = 0; x < 5; x++) //Rendering for (int y = 0; y < 5; y++) { if (t[x, y] == 1) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Lava; tile.ObjType = 0; if (world.Obstacles[x + pos.X, y + pos.Y] == 0) world.Map[x + pos.X, y + pos.Y] = tile; } } }
protected internal override void Resolve(State parent) { parent.Death += (sender, e) => { var dat = e.Host.Manager.GameData; var w = e.Host.Owner; var pos = new IntPoint((int) e.Host.X - (dist/2), (int) e.Host.Y - (dist/2)); if (w == null) return; for (int x = 0; x < dist; x++) { for (int y = 0; y < dist; y++) { WmapTile tile = w.Map[x + pos.X, y + pos.Y].Clone(); if (groundToChange != null) { foreach (string type in groundToChange) { int r = Random.Next(targetType.Length); if (tile.TileId == dat.IdToTileType[type]) { tile.TileId = dat.IdToTileType[targetType[r]]; w.Map[x + pos.X, y + pos.Y] = tile; } } } else { int r = Random.Next(targetType.Length); tile.TileId = dat.IdToTileType[targetType[r]]; w.Map[x + pos.X, y + pos.Y] = tile; } } } }; }
/// <summary> /// Shift cloud by adding specified value to all points in the collection. /// </summary> /// /// <param name="cloud">Collection of points to shift their coordinates.</param> /// <param name="shift">Point to shift by.</param> /// public static void Shift( List<IntPoint> cloud, IntPoint shift ) { for ( int i = 0, n = cloud.Count; i < n; i++ ) { cloud[i] = cloud[i] + shift; } }
public void RenderSetPiece(World world, IntPoint pos) { int heatedRadius = 15; int[,] t = new int[Size, Size]; for (int y = 0; y < Size; y++) for (int x = 0; x < Size; x++) { double dx = x - (Size / 2.0); double dy = y - (Size / 2.0); double r = Math.Sqrt(dx * dx + dy * dy); if (r <= heatedRadius) t[x, y] = 1; } for (int x = 0; x < Size; x++) for (int y = 0; y < Size; y++) { if (t[x, y] == 1) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Heated; tile.ObjType = 0; if (world.Obstacles[x + pos.X, y + pos.Y] == 0) world.Map[x + pos.X, y + pos.Y] = tile; } } }
public void RenderSetPiece(World world, IntPoint pos) { var dat = world.Manager.GameData; for (int x = 0; x < Size; x++) for (int y = 0; y < Size; y++) { double dx = x - (Size / 2.0); double dy = y - (Size / 2.0); double r = Math.Sqrt(dx * dx + dy * dy) + rand.NextDouble() * 4 - 2; if (r <= 10) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } } Entity lord = Entity.Resolve(world.Manager, "Phoenix Lord"); lord.Move(pos.X + 15.5f, pos.Y + 15.5f); world.EnterWorld(lord); Container container = new Container(world.Manager, 0x0501, null, false); Item[] items = chest.GetLoots(world.Manager, 5, 8).ToArray(); for (int i = 0; i < items.Length; i++) container.Inventory[i] = items[i]; container.Move(pos.X + 15.5f, pos.Y + 15.5f); world.EnterWorld(container); }
// called for each visible tile protected override void UpdateTile(UIElement _tile, IntPoint ml) { MapControlTile tile = (MapControlTile)_tile; BitmapSource bmp; if (m_map.Bounds.Contains(ml)) { byte b = m_map.MapArray[ml.Y, ml.X]; if (b < 100) bmp = m_symbolBitmapCache.GetBitmap(SymbolID.Wall, Colors.Black, false); else bmp = m_symbolBitmapCache.GetBitmap(SymbolID.Floor, Colors.Black, false); } else { bmp = null; } if (bmp != tile.Bitmap) { tile.Bitmap = bmp; } }
public void RoundTest( float x, float y, int expectedX, int expectedY ) { Point point = new Point( x, y ); IntPoint iPoint = new IntPoint( expectedX, expectedY ); Assert.AreEqual( iPoint, point.Round( ) ); }
public void InequalityOperatorTest( int x1, int y1, int x2, int y2, bool areNotEqual ) { IntPoint point1 = new IntPoint( x1, y1 ); IntPoint point2 = new IntPoint( x2, y2 ); Assert.AreEqual( point1 != point2, areNotEqual ); }
/// <summary> /// Get bounding rectangle of the specified list of points. /// </summary> /// /// <param name="cloud">Collection of points to get bounding rectangle for.</param> /// <param name="minXY">Point comprised of smallest X and Y coordinates.</param> /// <param name="maxXY">Point comprised of biggest X and Y coordinates.</param> /// public static void GetBoundingRectangle( List<IntPoint> cloud, out IntPoint minXY, out IntPoint maxXY ) { if ( cloud.Count == 0 ) throw new ArgumentException( "List of points can not be empty." ); // take first point as min and max int minX = cloud[0].X; int maxX = cloud[0].X; int minY = cloud[0].Y; int maxY = cloud[0].Y; for ( int i = 1, n = cloud.Count; i < n; i++ ) { int x = cloud[i].X; int y = cloud[i].Y; // check X coordinate if ( x < minX ) minX = x; if ( x > maxX ) maxX = x; // check Y coordinate if ( y < minY ) minY = y; if ( y > maxY ) maxY = y; } minXY = new IntPoint( minX, minY ); maxXY = new IntPoint( maxX, maxY ); }
/// <summary> /// Calculate minimum angle between two lines measured in [0, 90] degrees range. /// </summary> /// /// <param name="line1start">Starting point of the first line.</param> /// <param name="line1end">Ending point of the first line.</param> /// <param name="line2start">Starting point of the second line.</param> /// <param name="line2end">Ending point of the second line.</param> /// /// <returns>Returns minimum angle between two lines.</returns> /// public static double GetAngleBetweenLines( IntPoint line1start, IntPoint line1end, IntPoint line2start, IntPoint line2end ) { double k1, k2; if ( line1start.X != line1end.X ) { k1 = (double) ( line1end.Y - line1start.Y ) / ( line1end.X - line1start.X ); } else { k1 = double.PositiveInfinity; } if ( line2start.X != line2end.X ) { k2 = (double) ( line2end.Y - line2start.Y ) / ( line2end.X - line2start.X ); } else { k2 = double.PositiveInfinity; } // check if lines are parallel if ( k1 == k2 ) return 0; double angle = 0; if ( ( k1 != double.PositiveInfinity ) && ( k2 != double.PositiveInfinity ) ) { double tanPhi = ( ( k2 > k1 ) ? ( k2 - k1 ) : ( k1 - k2 ) ) / ( 1 + k1 * k2 ); angle = Math.Atan( tanPhi ); } else { // one of the lines is parallel to Y axis if ( k1 == double.PositiveInfinity ) { angle = Math.PI / 2 - Math.Atan( k2 ) * Math.Sign( k2 ); } else { angle = Math.PI / 2 - Math.Atan( k1 ) * Math.Sign( k1 ); } } // convert radians to degrees angle *= ( 180.0 / Math.PI ); if ( angle < 0 ) { angle = -angle; } return angle; }
/// <summary> /// Calculate angle between to vectors measured in [0, 180] degrees range. /// </summary> /// /// <param name="startPoint">Starting point of both vectors.</param> /// <param name="vector1end">Ending point of the first vector.</param> /// <param name="vector2end">Ending point of the second vector.</param> /// /// <returns>Returns angle between specified vectors measured in degrees.</returns> /// public static double GetAngleBetweenVectors( IntPoint startPoint, IntPoint vector1end, IntPoint vector2end ) { int x1 = vector1end.X - startPoint.X; int y1 = vector1end.Y - startPoint.Y; int x2 = vector2end.X - startPoint.X; int y2 = vector2end.Y - startPoint.Y; return Math.Acos( ( x1 * x2 + y1 * y2 ) / ( Math.Sqrt( x1 * x1 + y1 * y1 ) * Math.Sqrt( x2 * x2 + y2 * y2 ) ) ) * 180.0 / Math.PI; }
/// <summary> /// (Re)initialize with a fresh test case. /// Returns the target point (center of large box). /// </summary> public IntPoint InitTestCase(int largeBoxRelativePos) { // Get small and large box center positions. IntPoint[] boxPosArr = GenerateRandomTestCase(largeBoxRelativePos); _smallBoxTopLeft = boxPosArr[0]; _largeBoxTopLeft = boxPosArr[1]; _largeBoxTopLeft.X--; _largeBoxTopLeft.Y--; return boxPosArr[1]; }
private void TilePlacementHandler() { IntPoint nD = ExtendedMath.DistanceIntervals(new Vector2(Cam1.position.x, Cam1.position.z), new Vector2(_chunkCenter.x, _chunkCenter.z), _chunkSize/2); if ((nD.x > 0 ^ nD.x < 0) | (nD.y > 0 ^ nD.y < 0)) { _chunkCenter = new Vector2(_chunkCenter.x + (nD.x * _chunkSize.x), _chunkCenter.z + (nD.y * _chunkSize.y)); IntPoint negaDir = new IntPoint((int)ExtendedMath.InvertValue((nD.x != 0 ? nD.x : nD.y)), (nD.y != 0 ? nD.y : (int)ExtendedMath.InvertValue(nD.x))); ShuffleTiles(negaDir); } }
public static void ApplyTranslation(this Polygons polygons, IntPoint translation) { for (int i = 0; i < polygons.Count; i++) { for (int j = 0; j < polygons[i].Count; j++) { polygons[i][j] = polygons[i][j] + translation; } } }
public void RenderSetPiece(World world, IntPoint pos) { var radius = rand.Next(Size - 5, Size + 1)/2; var border = new List<IntPoint>(); var t = new int[Size, Size]; for (var y = 0; y < Size; y++) for (var x = 0; x < Size; x++) { var dx = x - (Size/2.0); var dy = y - (Size/2.0); var r = Math.Sqrt(dx*dx + dy*dy); if (r <= radius) { t[x, y] = 1; if (radius - r < 1.5) border.Add(new IntPoint(x, y)); } } var trees = new HashSet<IntPoint>(); while (trees.Count < border.Count*0.5) trees.Add(border[rand.Next(0, border.Count)]); foreach (var i in trees) t[i.X, i.Y] = 2; for (var x = 0; x < Size; x++) for (var y = 0; y < Size; y++) { if (t[x, y] == 1) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Floor; tile.ObjType = 0; world.Obstacles[x + pos.X, y + pos.Y] = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 2) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Floor; tile.ObjType = Tree; tile.Name = "size:" + (rand.Next()%2 == 0 ? 120 : 140); if (tile.ObjId == 0) tile.ObjId = world.GetNextEntityId(); world.Obstacles[x + pos.X, y + pos.Y] = 2; world.Map[x + pos.X, y + pos.Y] = tile; } } var ent = Entity.Resolve(0x091f); ent.Size = 140; ent.Move(pos.X + Size/2 + 1, pos.Y + Size/2 + 1); world.EnterWorld(ent); }
public bool Select(Vector3 wordPos) { IntPoint p = new IntPoint(wordPos.x * clipScalling, wordPos.z * clipScalling); List<IntPoint> poly = GetArea(mMesh); if(Clipper.PointInPolygon(p, poly) == 1){ return true; } return false; }
public void RenderSetPiece(World world, IntPoint pos) { int radius = rand.Next(Size - 5, Size + 1) / 2; List<IntPoint> border = new List<IntPoint>(); int[,] t = new int[Size, Size]; for (int y = 0; y < Size; y++) for (int x = 0; x < Size; x++) { double dx = x - (Size / 2.0); double dy = y - (Size / 2.0); double r = Math.Sqrt(dx * dx + dy * dy); if (r <= radius) { t[x, y] = 1; if (radius - r < 1.5) border.Add(new IntPoint(x, y)); } } HashSet<IntPoint> trees = new HashSet<IntPoint>(); while (trees.Count < border.Count * 0.5) trees.Add(border[rand.Next(0, border.Count)]); foreach (IntPoint i in trees) t[i.X, i.Y] = 2; XmlData dat = world.Manager.GameData; for (int x = 0; x < Size; x++) for (int y = 0; y < Size; y++) { if (t[x, y] == 1) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 2) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor]; tile.ObjType = dat.IdToObjectType[Tree]; tile.Name = "size:" + (rand.Next() % 2 == 0 ? 120 : 140); if (tile.ObjId == 0) tile.ObjId = world.GetNextEntityId(); world.Map[x + pos.X, y + pos.Y] = tile; } } Entity ent = Entity.Resolve(world.Manager, "Ent Ancient"); ent.Size = 140; ent.Move(pos.X + Size / 2 + 1, pos.Y + Size / 2 + 1); world.EnterWorld(ent); }
public bool Equals(IntPoint p) { // If parameter is null return false: if ((object)p == null) { return false; } // Return true if the fields match: return ((x == p.x) & (y == p.y)); }
private double diffEval(int[][] input, IntPoint p) { double output = 1; double refEval; if (HashedResults.ContainsKey(Ref.Eval)) { refEval = HashedResults[Ref.Eval]; } else { refEval = Ref.Eval(input); } output = (refEval) / (refEval + input[p.X][p.Y] + .00001); HashedResults[Eval] = output; return output; }
private double prodEval(int[][] input, IntPoint p) { double output = 1; double refEval; if (HashedResults.ContainsKey(Ref.Eval)) { refEval = HashedResults[Ref.Eval]; } else { refEval = Ref.Eval(input); } output = refEval * input[p.X][p.Y]; HashedResults[Eval] = output; return output; }
public void InsideOutsidePoints() { { // a square with a hole (outside is ccw inside is cw) // __________ // | _____ | // | | | | // | |____| | // |________| string partOutlineString = "x:0, y:0,x:1000, y:0,x:1000, y:1000,x:0, y:1000,|x:100, y:100,x:0, y:900,x:900, y:900,x:900, y:0,|"; Polygons bounderyPolygons = PolygonsHelper.CreateFromString(partOutlineString); AvoidCrossingPerimeters testHarness = new AvoidCrossingPerimeters(bounderyPolygons); Assert.IsTrue(testHarness.PointIsInsideBoundary(new IntPoint(1, 1))); } // Here is a test case that was failing. { // Looks a little like this // _____ // | | // | O | // | O | // |___| string partOutlineString = "x:90501, y:80501,x:109500, y:80501,x:109500, y:119500,x:90501, y:119500,|x:97387, y:104041,x:95594, y:105213,x:94278, y:106903,x:93583, y:108929,x:93583, y:111071,x:94278, y:113097,x:95594, y:114787,x:97387, y:115959,x:99464, y:116485,x:101598, y:116307,x:103559, y:115447,x:105135, y:113996,x:106154, y:112113,x:106507, y:110000,x:106154, y:107887,x:105135, y:106004,x:103559, y:104553,x:101598, y:103693,x:99464, y:103515,|x:97387, y:84042,x:95594, y:85214,x:94278, y:86904,x:93583, y:88930,x:93583, y:91072,x:94278, y:93098,x:95594, y:94788,x:97387, y:95960,x:99464, y:96486,x:101598, y:96308,x:103559, y:95448,x:105135, y:93997,x:106154, y:92114,x:106507, y:90001,x:106154, y:87888,x:105135, y:86005,x:103559, y:84554,x:101598, y:83694,x:99464, y:83516,|"; Polygons bounderyPolygons = PolygonsHelper.CreateFromString(partOutlineString); IntPoint startPoint = new IntPoint(95765, 114600); IntPoint endPoint = new IntPoint(99485, 96234); AvoidCrossingPerimeters testHarness = new AvoidCrossingPerimeters(bounderyPolygons); { IntPoint startPointInside = startPoint; testHarness.MovePointInsideBoundary(ref startPointInside); IntPoint endPointInside = endPoint; testHarness.MovePointInsideBoundary(ref endPointInside); Assert.IsTrue(testHarness.PointIsInsideBoundary(startPointInside)); Assert.IsTrue(testHarness.PointIsInsideBoundary(endPointInside)); Polygon insidePath = new Polygon(); testHarness.CreatePathInsideBoundary(startPointInside, endPointInside, insidePath); Assert.IsTrue(insidePath.Count > 10); // It needs to go around the cicle so it needs many points (2 is a definate fail). } { Polygon insidePath = new Polygon(); testHarness.CreatePathInsideBoundary(startPoint, endPoint, insidePath); Assert.IsTrue(insidePath.Count > 12); // two more than the last test to get the points in the right place } } }
public void RenderSetPiece(World world, IntPoint pos) { var t = new int[41, 41]; for (var i = 0; i < 5; i++) { double angle = (360/5*i)*(float) Math.PI/180; var x_ = (int) (Math.Cos(angle)*15 + 20 - 3); var y_ = (int) (Math.Sin(angle)*15 + 20 - 3); for (var x = 0; x < 7; x++) for (var y = 0; y < 7; y++) { t[x_ + x, y_ + y] = Circle[x, y]; } t[x_ + 3, y_ + 3] = 2; } t[20, 20] = 3; for (var x = 0; x < 40; x++) for (var y = 0; y < 40; y++) { if (t[x, y] == 1) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Floor; tile.ObjType = 0; world.Obstacles[x + pos.X, y + pos.Y] = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 2) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Floor; tile.ObjType = 0; world.Obstacles[x + pos.X, y + pos.Y] = 0; world.Map[x + pos.X, y + pos.Y] = tile; var penta = Entity.Resolve(0x0d5e); penta.Move(pos.X + x + .5f, pos.Y + y + .5f); world.EnterWorld(penta); } else if (t[x, y] == 3) { var penta = Entity.Resolve(0x0d5f); penta.Move(pos.X + x + .5f, pos.Y + y + .5f); world.EnterWorld(penta); } } }
public void RenderSetPiece(World world, IntPoint pos) { int[,] t = new int[41, 41]; for (int i = 0; i < 5; i++) { double angle = (360/5*i)*(float) Math.PI/180; int x_ = (int) (Math.Cos(angle)*15 + 20 - 3); int y_ = (int) (Math.Sin(angle)*15 + 20 - 3); for (int x = 0; x < 7; x++) for (int y = 0; y < 7; y++) { t[x_ + x, y_ + y] = Circle[x, y]; } t[x_ + 3, y_ + 3] = 2; } t[20, 20] = 3; XmlData data = world.Manager.GameData; for (int x = 0; x < 40; x++) for (int y = 0; y < 40; y++) { if (t[x, y] == 1) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = data.IdToTileType[Floor]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 2) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = data.IdToTileType[Floor]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; Entity penta = Entity.Resolve(world.Manager, 0x0d5e); penta.Move(pos.X + x + .5f, pos.Y + y + .5f); world.EnterWorld(penta); } else if (t[x, y] == 3) { Entity penta = Entity.Resolve(world.Manager, "Pentaract"); penta.Move(pos.X + x + .5f, pos.Y + y + .5f); world.EnterWorld(penta); } } }
public void Calculate(Polygons polys) { min = new IntPoint(long.MaxValue, long.MaxValue); max = new IntPoint(long.MinValue, long.MinValue); for (int i = 0; i < polys.Count; i++) { for (int j = 0; j < polys[i].Count; j++) { if (min.X > polys[i][j].X) min.X = polys[i][j].X; if (min.Y > polys[i][j].Y) min.Y = polys[i][j].Y; if (max.X < polys[i][j].X) max.X = polys[i][j].X; if (max.Y < polys[i][j].Y) max.Y = polys[i][j].Y; } } }
public void RenderSetPiece(World world, IntPoint pos) { XmlData dat = world.Manager.GameData; for (int x = 0; x < Size; x++) { for (int y = 0; y < Size; y++) { if (SetPiece[y, x] == 1) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Ground[0]]; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 2) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Ground[1]]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 7) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Ground[0]]; tile.ObjType = dat.IdToObjectType[Pillars[0]]; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 8) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Ground[0]]; tile.ObjType = dat.IdToObjectType[Pillars[1]]; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 9) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Ground[0]]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; Entity hermit = Entity.Resolve(world.Manager, "Hermit God"); hermit.Move(pos.X + x + 0.5f, pos.Y + y + 0.5f); world.EnterWorld(hermit); } } } }
/// <summary> /// Checks if the point is outside of polygon /// </summary> /// <param name="val">Polygon to check</param> /// <param name="point">Point to check</param> /// <returns>true if point is outside of polygon</returns> public static bool IsOutside(this Geometry.Polygon val, Vector2 point) { var p = new IntPoint(point.X, point.Y); return(Clipper.PointInPolygon(p, val.ToClipperPath()) != 1); }
/// <summary> /// Set pixel with the specified coordinates to the specified color. /// </summary> /// /// <param name="point">Point's coordiates to set color for.</param> /// <param name="color">Color to set for the pixel.</param> /// /// <remarks><para>See <see cref="SetPixel(int, int, Color)"/> for more information.</para></remarks> /// public void SetPixel(IntPoint point, Color color) { SetPixel(point.X, point.Y, color); }
public IEnumerable <Entity> InstantiateEntities(RealmManager manager, IntPoint offset = new IntPoint()) { foreach (var i in _entities) { var entity = Entity.Resolve(manager, i.Item2); entity.Move(i.Item1.X + 0.5f + offset.X, i.Item1.Y + 0.5f + offset.Y); if (i.Item3 != null) { foreach (var item in i.Item3.Split(';')) { string[] kv = item.Split(':'); switch (kv[0]) { case "hp": (entity as Enemy).HP = Utils.FromString(kv[1]); (entity as Enemy).MaximumHP = (entity as Enemy).HP; break; case "name": entity.Name = kv[1]; break; case "size": entity.SetDefaultSize(Math.Min(500, Utils.FromString(kv[1]))); break; case "eff": entity.ConditionEffects = (ConditionEffects)ulong.Parse(kv[1]); break; case "conn": (entity as ConnectedObject).Connection = ConnectionInfo.Infos[(uint)Utils.FromString(kv[1])]; break; case "mtype": (entity as Merchant).Item = (ushort)Utils.FromString(kv[1]); break; case "mcost": (entity as SellableObject).Price = Math.Max(0, Utils.FromString(kv[1])); break; case "mcur": (entity as SellableObject).Currency = (CurrencyType)Utils.FromString(kv[1]); break; case "mamnt": (entity as Merchant).Count = Utils.FromString(kv[1]); break; case "mtime": (entity as Merchant).TimeLeft = Utils.FromString(kv[1]); break; case "mdisc": // not implemented break; case "mrank": case "stars": // provided for backwards compatibility with older maps (entity as SellableObject).RankReq = Utils.FromString(kv[1]); break; case "mtax": (entity as SellableObject).Tax = Utils.FromString(kv[1]); break; case "xOffset": var xo = float.Parse(kv[1]); entity.Move(entity.X + xo, entity.Y); break; case "yOffset": var yo = float.Parse(kv[1]); entity.Move(entity.X, entity.Y + yo); break; } } } yield return(entity); } }
public static void Bake(GameObject go, bool forced) { var sc = go.GetComponent <SpriteShapeController>(); var lc = go.GetComponent <LegacyCollider>(); if (sc != null) { List <IntPoint> path = new List <IntPoint>(); int splinePointCount = sc.spline.GetPointCount(); int pathPointCount = splinePointCount; ColliderCornerType cct = ColliderCornerType.Square; float co = 1.0f; if (lc != null) { int hashCode = sc.spline.GetHashCode() + lc.m_ColliderCornerType.GetHashCode() + lc.m_ColliderOffset.GetHashCode(); if (lc.m_HashCode == hashCode && !forced) { return; } lc.m_HashCode = hashCode; cct = lc.m_ColliderCornerType; co = lc.m_ColliderOffset; } if (sc.spline.isOpenEnded) { pathPointCount--; } for (int i = 0; i < pathPointCount; ++i) { int nextIndex = SplineUtility.NextIndex(i, splinePointCount); SampleCurve(sc.colliderDetail, sc.spline.GetPosition(i), sc.spline.GetRightTangent(i), sc.spline.GetPosition(nextIndex), sc.spline.GetLeftTangent(nextIndex), ref path); } if (co != 0f) { List <List <IntPoint> > solution = new List <List <IntPoint> >(); ClipperOffset clipOffset = new ClipperOffset(); EndType endType = EndType.etClosedPolygon; if (sc.spline.isOpenEnded) { endType = EndType.etOpenSquare; if (cct == ColliderCornerType.Round) { endType = EndType.etOpenRound; } } clipOffset.ArcTolerance = 200f / sc.colliderDetail; clipOffset.AddPath(path, (ExtrasClipperLib.JoinType)cct, endType); clipOffset.Execute(ref solution, s_ClipperScale * co); if (solution.Count > 0) { path = solution[0]; } } List <Vector2> pathPoints = new List <Vector2>(path.Count); for (int i = 0; i < path.Count; ++i) { IntPoint ip = path[i]; pathPoints.Add(new Vector2(ip.X / s_ClipperScale, ip.Y / s_ClipperScale)); } var pc = go.GetComponent <PolygonCollider2D>(); if (pc) { pc.pathCount = 0; pc.SetPath(0, pathPoints.ToArray()); } var ec = go.GetComponent <EdgeCollider2D>(); if (ec) { if (co > 0f || co < 0f && !sc.spline.isOpenEnded) { pathPoints.Add(pathPoints[0]); } ec.points = pathPoints.ToArray(); } } }
public double GetDistance(IntPoint p1, IntPoint p2) { double distance = Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2)); return(distance); }
private Bitmap CheckCheckbox(Bitmap image) { //Mittelpunkt der Checkmarks IntPoint[] points = new IntPoint[] { new IntPoint { X = 75, Y = 175 }, new IntPoint { X = 300, Y = 175 }, new IntPoint { X = 75, Y = 191 }, new IntPoint { X = 300, Y = 191 }, new IntPoint { X = 75, Y = 207 }, new IntPoint { X = 300, Y = 207 }, new IntPoint { X = 75, Y = 223 }, new IntPoint { X = 300, Y = 223 }, new IntPoint { X = 300, Y = 239 }, new IntPoint { X = 75, Y = 255 }, new IntPoint { X = 300, Y = 255 }, new IntPoint { X = 75, Y = 271 }, }; int checkBoxID = 0; foreach (IntPoint p in points) { IntPoint middle = new IntPoint { X = p.X, Y = p.Y }; int halfBoxSize = int.Parse(tbCheckBoxSize.Text) / 2; IntPoint topLeft = new IntPoint { X = middle.X - halfBoxSize, Y = middle.Y + halfBoxSize }; IntPoint topRight = new IntPoint { X = middle.X + halfBoxSize, Y = middle.Y + halfBoxSize }; IntPoint bottomLeft = new IntPoint { X = middle.X - halfBoxSize, Y = middle.Y - halfBoxSize }; IntPoint bottomRight = new IntPoint { X = middle.X + halfBoxSize, Y = middle.Y - halfBoxSize }; int totalA = 0; //bereich um den Kasten for (int i = topLeft.X; i < topRight.X; i++) { for (int j = bottomLeft.Y; j < topRight.Y; j++) { Color c = image.GetPixel(i, j); //Farbwerte im Feld addieren totalA = totalA + c.A; if (cbShowCheckedArea.IsChecked ?? true) { image.SetPixel(i, j, Color.FromArgb(255, 255, 0, 0)); } } } //Totalen Farbwert durch Anzahl an Pixeln teilen int cAverage = totalA / ((halfBoxSize * 2) * (halfBoxSize * 2)); if (cAverage > int.Parse(tbUncheckedUnder.Text) && cAverage < int.Parse(tbCheckedUnder.Text)) { isChecked.Add(true); } else { isChecked.Add(false); } cAverageValue.Add(cAverage); checkBoxID++; } return(image); }
public void CorrectSeamPlacement() { // coincident points return 0 angle { IntPoint p1 = new IntPoint(10, 0); IntPoint p2 = new IntPoint(0, 0); IntPoint p3 = new IntPoint(0, 0); Assert.IsTrue(PathOrderOptimizer.GetTurnAmount(p1, p2, p3) == 0); } // no turn returns a 0 angle { IntPoint p1 = new IntPoint(10, 0); IntPoint p2 = new IntPoint(0, 0); IntPoint p3 = new IntPoint(-10, 0); Assert.IsTrue(PathOrderOptimizer.GetTurnAmount(p1, p2, p3) == 0); } // 90 turn works { IntPoint p1 = new IntPoint(0, 0); IntPoint p2 = new IntPoint(10, 0); IntPoint p3 = new IntPoint(10, 10); Assert.AreEqual(PathOrderOptimizer.GetTurnAmount(p1, p2, p3), Math.PI / 2, .001); IntPoint p4 = new IntPoint(0, 10); IntPoint p5 = new IntPoint(0, 0); IntPoint p6 = new IntPoint(10, 0); Assert.AreEqual(PathOrderOptimizer.GetTurnAmount(p4, p5, p6), Math.PI / 2, .001); } // -90 turn works { IntPoint p1 = new IntPoint(0, 0); IntPoint p2 = new IntPoint(10, 0); IntPoint p3 = new IntPoint(10, -10); Assert.AreEqual(PathOrderOptimizer.GetTurnAmount(p1, p2, p3), -Math.PI / 2, .001); } // 45 turn works { IntPoint p1 = new IntPoint(0, 0); IntPoint p2 = new IntPoint(10, 0); IntPoint p3 = new IntPoint(15, 5); Assert.AreEqual(Math.PI / 4, PathOrderOptimizer.GetTurnAmount(p1, p2, p3), .001); IntPoint p4 = new IntPoint(0, 0); IntPoint p5 = new IntPoint(-10, 0); IntPoint p6 = new IntPoint(-15, -5); Assert.AreEqual(Math.PI / 4, PathOrderOptimizer.GetTurnAmount(p4, p5, p6), .001); } // -45 turn works { IntPoint p1 = new IntPoint(0, 0); IntPoint p2 = new IntPoint(10, 0); IntPoint p3 = new IntPoint(15, -5); Assert.AreEqual(-Math.PI / 4, PathOrderOptimizer.GetTurnAmount(p1, p2, p3), .001); } // find the right point wound ccw { // 4________3 // | / // | /2 // | \ // |0______\1 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(0, 0), new IntPoint(100, 0), new IntPoint(70, 50), new IntPoint(100, 100), new IntPoint(0, 100) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 2); } // find the right point wound ccw { // 3________2 // | | // | | // | | // |0______|1 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(0, 0), new IntPoint(100, 0), new IntPoint(100, 100), new IntPoint(0, 100) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 3); } // find the right point wound ccw { // 1________0 // | | // | | // | | // |2______|3 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(100, 100), new IntPoint(0, 100), new IntPoint(0, 0), new IntPoint(100, 0) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 1); } // find the right point wound cw { // 1________2 // | | // | | // | | // |0______|3 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(0, 0), new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(100, 0) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 1); } // find the right point wound cw { // 0________1 // | | // | | // | | // |3______|2 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(100, 0), new IntPoint(0, 0) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 0); } // find the right point wound ccw { // 4________3 // | / // | /2 // | \ // |0______\1 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(0, 0), new IntPoint(1000, 0), new IntPoint(900, 500), new IntPoint(1000, 1000), new IntPoint(0, 1000) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 2); } // ccw { // 2________1 // | / // | /0 // | \ // |3______\4 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(90, 50), new IntPoint(100, 100), new IntPoint(0, 100), new IntPoint(0, 0), new IntPoint(100, 0) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 0); } // ccw { // 2________1 // \ / // \3 /0 // / \ // /4_____\5 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(90, 50), new IntPoint(100, 100), new IntPoint(0, 100), new IntPoint(10, 50), new IntPoint(0, 0), new IntPoint(100, 0) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 3); } // ccw { // 2________1 // \ / // \3 /0 less angle // / \ // /4_____\5 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(950, 500), new IntPoint(1000, 1000), new IntPoint(0, 1000), new IntPoint(100, 500), new IntPoint(0, 0), new IntPoint(1000, 0) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 3); } // ccw { // 2________1 // \ / // \3 /0 more angle // / \ // /4_____\5 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(550, 500), new IntPoint(1000, 1000), new IntPoint(0, 1000), new IntPoint(100, 500), new IntPoint(0, 0), new IntPoint(1000, 0) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 0); } // ccw { // 5________4 // \ / // \0 /3 // / \ // /1_____\2 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(10, 50), new IntPoint(0, 0), new IntPoint(100, 0), new IntPoint(90, 50), new IntPoint(100, 100), new IntPoint(0, 100), }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 0); } // find the right point wound cw (inside hole loops) { // 1________2 // | / // | /3 // | \ // |0______\4 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(0, 0), new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(90, 50), new IntPoint(100, 0) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 1); } // find the right point wound cw { // 2________3 // | / // | /4 // | \ // |1______\0 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(100, 0), new IntPoint(0, 0), new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(90, 50) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 2); } // cw { // 4________5 // \ / // \3 /0 // / \ // /2_____\1 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(90, 50), new IntPoint(100, 0), new IntPoint(0, 0), new IntPoint(10, 50), new IntPoint(0, 100), new IntPoint(100, 100) }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 4); } // cw { // 1________2 // \ / // \0 /3 // / \ // /5_____\4 List <IntPoint> testPoints = new List <IntPoint> { new IntPoint(10, 50), new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(90, 50), new IntPoint(100, 0), new IntPoint(0, 0), }; int bestPoint = PathOrderOptimizer.GetBestIndex(testPoints); Assert.IsTrue(bestPoint == 1); } }
public static void GenerateHexLinePaths(Polygons in_outline, ref Polygons result, int lineSpacing, int infillExtendIntoPerimeter_um, double rotationDegrees, int layerIndex) { int extraRotationAngle = 0; if (in_outline.Count > 0) { Polygons outlines = in_outline.Offset(infillExtendIntoPerimeter_um); if (outlines.Count > 0) { int perIncrementOffset = (int)(lineSpacing * Math.Sqrt(3) / 2 + .5); PointMatrix matrix = new PointMatrix(-(rotationDegrees + extraRotationAngle)); // we are rotating the part so we rotate by the negative so the lines go the way we expect outlines.applyMatrix(matrix); AABB boundary = new AABB(outlines); boundary.min.X = ((boundary.min.X / lineSpacing) - 1) * lineSpacing; boundary.min.Y = ((boundary.min.Y / perIncrementOffset) - 1) * perIncrementOffset; boundary.max.X += lineSpacing; boundary.max.Y += perIncrementOffset; Polygons unclipedPatern = new Polygons(); foreach (IntPoint startPoint in StartPositionIterator(boundary, lineSpacing, layerIndex)) { Polygon attachedLine = new Polygon(); foreach (IntPoint center in IncrementPositionIterator(startPoint, boundary, lineSpacing, layerIndex)) { // what we are adding are the little plusses that define the points // | top // | // /\ center // left/ \ right // IntPoint left = center + new IntPoint(-lineSpacing / 2, -perIncrementOffset / 3); IntPoint right = center + new IntPoint(lineSpacing / 2, -perIncrementOffset / 3); IntPoint top = center + new IntPoint(0, perIncrementOffset * 2 / 3); switch (layerIndex % 3) { case 0: // left to right attachedLine.Add(left); attachedLine.Add(center); attachedLine.Add(center); attachedLine.Add(right); unclipedPatern.Add(new Polygon() { top, center }); break; case 1: // left to top attachedLine.Add(left); attachedLine.Add(center); attachedLine.Add(center); attachedLine.Add(top); unclipedPatern.Add(new Polygon() { center, right }); break; case 2: // top to right attachedLine.Add(top); attachedLine.Add(center); attachedLine.Add(center); attachedLine.Add(right); unclipedPatern.Add(new Polygon() { left, center }); break; } } if (attachedLine.Count > 0) { unclipedPatern.Add(attachedLine); } } PolyTree ret = new PolyTree(); Clipper clipper = new Clipper(); clipper.AddPaths(unclipedPatern, PolyType.ptSubject, false); clipper.AddPaths(outlines, PolyType.ptClip, true); clipper.Execute(ClipType.ctIntersection, ret, PolyFillType.pftPositive, PolyFillType.pftEvenOdd); Polygons newSegments = Clipper.OpenPathsFromPolyTree(ret); PointMatrix inversematrix = new PointMatrix((rotationDegrees + extraRotationAngle)); newSegments.applyMatrix(inversematrix); result.AddRange(newSegments); } } }
private static IEnumerable <IntPoint> StartPositionIterator(AABB boundary, int lineSpacing, int layerIndex) { int perIncrementOffset = (int)(lineSpacing * Math.Sqrt(3) / 2 + .5); int yLineCount = (int)((boundary.max.Y - boundary.min.Y + perIncrementOffset) / perIncrementOffset) + 1; switch (layerIndex % 3) { case 0: // left to right for (int yIndex = 0; yIndex < yLineCount; yIndex++) { long yPosition = boundary.min.Y + yIndex * perIncrementOffset; bool removeXOffset = ((yPosition / perIncrementOffset) % 2) == 0; long xOffsetForY = lineSpacing / 2; if (removeXOffset) // if we are at every other y { xOffsetForY = 0; } long firstX = boundary.min.X + xOffsetForY; yield return(new IntPoint(firstX, yPosition)); } break; case 1: // left to top { IntPoint nextPoint = new IntPoint(); for (int yIndex = yLineCount; yIndex >= 0; yIndex--) { long yPosition = boundary.min.Y + yIndex * perIncrementOffset; bool createLineSegment = ((yPosition / perIncrementOffset) % 2) == 0; if (createLineSegment) { nextPoint = new IntPoint(boundary.min.X, yPosition); yield return(nextPoint); } } IntPoint positionAdd = new IntPoint(lineSpacing, 0); nextPoint += positionAdd; while (nextPoint.X > boundary.min.X && nextPoint.X < boundary.max.X) { yield return(nextPoint); nextPoint += positionAdd; } } break; case 2: // top to right { IntPoint nextPoint = new IntPoint(); for (int yIndex = 0; yIndex < yLineCount; yIndex++) { long yPosition = boundary.min.Y + yIndex * perIncrementOffset; bool createLineSegment = ((yPosition / perIncrementOffset) % 2) == 0; if (createLineSegment) { nextPoint = new IntPoint(boundary.min.X, yPosition); yield return(nextPoint); } } IntPoint positionAdd = new IntPoint(lineSpacing, 0); nextPoint += positionAdd; while (nextPoint.X > boundary.min.X && nextPoint.X < boundary.max.X) { yield return(nextPoint); nextPoint += positionAdd; } } break; } }
private int RenderBlock(int leftPos, int rightPos, Color?selectedTextColor, Color bgColor, IntRect rectContent, IFastGridCellBlock block, FastGridCellAddress cellAddr, bool leftAlign, bool isHoverCell) { bool renderBlock = true; if (block.MouseHoverBehaviour == MouseHoverBehaviours.HideWhenMouseOut && !isHoverCell) { renderBlock = false; } int width = 0, top = 0, height = 0; switch (block.BlockType) { case FastGridBlockType.Text: var font = GetFont(block.IsBold, block.IsItalic); int textHeight = font.GetTextHeight(block.TextData); width = font.GetTextWidth(block.TextData, _columnSizes.MaxSize); height = textHeight; top = rectContent.Top + (int)Math.Round(rectContent.Height / 2.0 - textHeight / 2.0); break; case FastGridBlockType.Image: top = rectContent.Top + (int)Math.Round(rectContent.Height / 2.0 - block.ImageHeight / 2.0); height = block.ImageHeight; width = block.ImageWidth; break; } if (renderBlock && block.CommandParameter != null) { var activeRect = new IntRect(new IntPoint(leftAlign ? leftPos : rightPos - width, top), new IntSize(width, height)).GrowSymmetrical(1, 1); var region = new ActiveRegion { CommandParameter = block.CommandParameter, Rect = activeRect, Tooltip = block.ToolTip, }; CurrentCellActiveRegions.Add(region); if (_mouseCursorPoint.HasValue && activeRect.Contains(_mouseCursorPoint.Value)) { _drawBuffer.FillRectangle(activeRect, ActiveRegionHoverFillColor); CurrentHoverRegion = region; } bool renderRectangle = true; if (block.MouseHoverBehaviour == MouseHoverBehaviours.HideButtonWhenMouseOut && !isHoverCell) { renderRectangle = false; } if (renderRectangle) { _drawBuffer.DrawRectangle(activeRect, ActiveRegionFrameColor); } } switch (block.BlockType) { case FastGridBlockType.Text: if (renderBlock) { var textOrigin = new IntPoint(leftAlign ? leftPos : rightPos - width, top); var font = GetFont(block.IsBold, block.IsItalic); var fontcolor = selectedTextColor ?? block.FontColor ?? ((cellAddr.IsColumnHeader) ? (cellAddr.IsColumnFilter) ? HeaderFilterFontColor : HeaderFontColor : CellFontColor); _drawBuffer.DrawString(textOrigin.X, textOrigin.Y, rectContent, fontcolor, UseClearType ? bgColor : (Color?)null, font, block.TextData); } break; case FastGridBlockType.Image: if (renderBlock) { var imgOrigin = new IntPoint(leftAlign ? leftPos : rightPos - block.ImageWidth, top); var image = GetImage(block.ImageSource); _drawBuffer.Blit(new Point(imgOrigin.X, imgOrigin.Y), image.Bitmap, new Rect(0, 0, block.ImageWidth, block.ImageHeight), image.KeyColor, image.BlendMode); } break; } return(width); }
public AABB() { min = new IntPoint(long.MinValue, long.MinValue); max = new IntPoint(long.MinValue, long.MinValue); }
public AABB(Polygons polys) { min = new IntPoint(long.MinValue, long.MinValue); max = new IntPoint(long.MinValue, long.MinValue); calculate(polys); }
public void RenderSetPiece(World world, IntPoint pos) { var t = new int[23, 35]; for (var x = 0; x < 23; x++) //Floor { for (var y = 0; y < 35; y++) { t[x, y] = rand.Next() % 3 == 0 ? 0 : 1; } } for (var y = 0; y < 35; y++) //Perimeters { t[0, y] = t[22, y] = 2; } for (var x = 0; x < 23; x++) { t[x, 0] = t[x, 34] = 2; } var pts = new List <IntPoint>(); for (var y = 0; y < 11; y++) //Crosses { for (var x = 0; x < 7; x++) { if (rand.Next() % 3 > 0) { t[2 + 3 * x, 2 + 3 * y] = 4; } else { pts.Add(new IntPoint(2 + 3 * x, 2 + 3 * y)); } } } for (var x = 0; x < 23; x++) //Corruption { for (var y = 0; y < 35; y++) { if (t[x, y] == 1 || t[x, y] == 0 || t[x, y] == 4) { continue; } var p = rand.NextDouble(); if (p < 0.1) { t[x, y] = 1; } else if (p < 0.4) { t[x, y]++; } } } //Boss & Chest var pt = pts[rand.Next(0, pts.Count)]; t[pt.X, pt.Y] = 5; t[pt.X + 1, pt.Y] = 6; var r = rand.Next(0, 4); for (var i = 0; i < r; i++) //Rotation { t = SetPieces.rotateCW(t); } int w = t.GetLength(0), h = t.GetLength(1); for (var x = 0; x < w; x++) //Rendering { for (var y = 0; y < h; y++) { if (t[x, y] == 1) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Floor; tile.ObjType = 0; world.Obstacles[x + pos.X, y + pos.Y] = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 2) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Floor; tile.ObjType = WallA; if (tile.ObjId == 0) { tile.ObjId = world.GetNextEntityId(); } world.Obstacles[x + pos.X, y + pos.Y] = 2; world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 3) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Floor; world.Obstacles[x + pos.X, y + pos.Y] = 2; world.Map[x + pos.X, y + pos.Y] = tile; var wall = Entity.Resolve(WallB); wall.Move(x + pos.X + 0.5f, y + pos.Y + 0.5f); world.EnterWorld(wall); } else if (t[x, y] == 4) { var tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = Floor; tile.ObjType = Cross; if (tile.ObjId == 0) { tile.ObjId = world.GetNextEntityId(); } world.Obstacles[x + pos.X, y + pos.Y] = 2; world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 5) { var container = new Container(0x0501, null, false); var count = rand.Next(3, 8); var items = new List <Item>(); while (items.Count < count) { var item = chest.GetRandomLoot(rand); if (item != null) { items.Add(item); } } for (var i = 0; i < items.Count; i++) { container.Inventory[i] = items[i]; } container.Move(pos.X + x + 0.5f, pos.Y + y + 0.5f); world.EnterWorld(container); } else if (t[x, y] == 6) { var mage = Entity.Resolve(0x0925); mage.Move(pos.X + x, pos.Y + y); world.EnterWorld(mage); } } } //Boss & Chest }
public override void OnInspectorGUI() { serializedObject.Update(); int origid = npcId.intValue; EditorGUILayout.PropertyField(npcId, new GUIContent("Npc ID")); if (origid != npcId.intValue) { if (!changeNpc(npcId.intValue)) { npcId.intValue = origid; } } EditorGUILayout.PropertyField(propLevel, new GUIContent("等级")); if (aiLabels == null) { readAiData(); } if (aiLabels != null) { curSelAi = EditorGUILayout.Popup("AI类型:", curSelAi, aiLabels); propAi.intValue = int.Parse(aiRows[curSelAi]["id"].ToString()); } // EditorGUILayout.PrefixLabel("模型ID:"); MapNpcView view = (MapNpcView)target; //string info = ""; //info += "模型ID:" + propModelId.stringValue + "\n"; //info += "名字:" + view.data.npcName + "\n"; //info +="x:"+logic.x+",y:"+logic.y+"\n"; EditorGUILayout.LabelField("模型ID:\t" + propModelId.stringValue); EditorGUILayout.LabelField("名字:\t" + view.data.npcName); if (view.gameObject.transform.hasChanged) { Vector3 pos = view.gameObject.transform.localPosition; IntPoint logic = PathUtilEdit.Real2Logic(pos); Quaternion rotat = view.gameObject.transform.localRotation; if (logic.x != propX.intValue || logic.y != propY.intValue) { //Debug.Log("npc pos changed:" + logic.x + " != " + propX.intValue + "," + logic.y+" != "+propY.intValue); if (EditorData.terrainMan != null) { pos.y = EditorData.terrainMan.GetHeight(pos.x, pos.z); view.gameObject.transform.localPosition = pos; } } propX.intValue = logic.x; propY.intValue = logic.y; propDirection.intValue = (int)(rotat.eulerAngles.y / 360 * 2 * Mathf.PI * 1000); } EditorGUILayout.PropertyField(propHeight, new GUIContent("出生范围 宽度")); EditorGUILayout.LabelField("X:\t" + propX.intValue); EditorGUILayout.LabelField("Y:\t" + propY.intValue); EditorGUILayout.LabelField("朝向direction:\t" + propDirection.intValue); EditorGUILayout.PropertyField(propScope, new GUIContent("活动范围")); EditorGUILayout.PropertyField(propChase, new GUIContent("追击范围")); EditorGUILayout.PropertyField(propNum, new GUIContent("数目")); EditorGUILayout.PropertyField(propInterval, new GUIContent("重生间隔")); EditorGUILayout.PropertyField(propWidth, new GUIContent("出生范围 长度")); EditorGUILayout.PropertyField(propHeight, new GUIContent("出生范围 宽度")); //EditorGUILayout.HelpBox("test", MessageType.Info); //Debug.Log("npc name:" + view.data.npcName+",hash:"+view.data.GetHashCode()); //string curModelId = propModelId.stringValue; // EditorGUILayout.PropertyField(propModelId, new GUIContent("模型ID")); // if (curModelId != propModelId.stringValue) // { // Debug.Log("prop changed:" + propModelId.stringValue); // changeModel(propModelId.stringValue,curModelId); // } // EditorGUILayout.PrefixLabel("模型:"); //Object prefab = EditorGUILayout.ObjectField(curPrefab, typeof(GameObject)); //if (curPrefab != prefab) //{ // Debug.Log("add new prefab:" + curPrefab); // curPrefab = prefab; // changePrefab(curPrefab); //} serializedObject.ApplyModifiedProperties(); }
public void RenderSetPiece(World world, IntPoint pos) { int[,] t = new int[27, 27]; int[,] q = (int[, ])quarter.Clone(); for (int y = 0; y < 14; y++) //Top left { for (int x = 0; x < 14; x++) { t[x, y] = q[x, y]; } } q = SetPieces.reflectHori(q); //Top right for (int y = 0; y < 14; y++) { for (int x = 0; x < 14; x++) { t[13 + x, y] = q[x, y]; } } q = SetPieces.reflectVert(q); //Bottom right for (int y = 0; y < 14; y++) { for (int x = 0; x < 14; x++) { t[13 + x, 13 + y] = q[x, y]; } } q = SetPieces.reflectHori(q); //Bottom left for (int y = 0; y < 14; y++) { for (int x = 0; x < 14; x++) { t[x, 13 + y] = q[x, y]; } } for (int y = 1; y < 4; y++) //Opening { for (int x = 8; x < 19; x++) { t[x, y] = 2; } } t[12, 0] = t[13, 0] = t[14, 0] = 2; int r = rand.Next(0, 4); //Rotation for (int i = 0; i < r; i++) { t = SetPieces.rotateCW(t); } t[13 + 6, 13] = 3; XmlData dat = world.Manager.GameData; for (int x = 0; x < 27; x++) //Rendering { for (int y = 0; y < 27; y++) { if (t[x, y] == 1) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor]; tile.ObjType = dat.IdToObjectType[Wall]; if (tile.ObjId == 0) { tile.ObjId = world.GetNextEntityId(); } world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 2) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 3) { Entity cyclops = Entity.Resolve(world.Manager, 0x0928); cyclops.Move(pos.X + x, pos.Y + y); world.EnterWorld(cyclops); } } } }
public void RenderSetPiece(World world, IntPoint pos) { var proto = world.Manager.Resources.Worlds["RockDragon"]; SetPieces.RenderFromProto(world, pos, proto); }
private Bitmap DistortImage(Bitmap bitmap, IntPoint p1, IntPoint p2, IntPoint p3, IntPoint p4) { if (p1.X != 0 && p2.Y != 0 && p3.Y != 0 && p4.X != 0) { using (MagickImage image = new MagickImage(bitmap)) { if (cbNormalize.IsChecked ?? true) { image.Normalize(); } if (cbAutoGamma.IsChecked ?? true) { image.AutoGamma(); } if (cbAutoLevel.IsChecked ?? true) { image.AutoLevel(); } image.Threshold(new Percentage(int.Parse(tbThreshold.Text))); image.Distort(DistortMethod.Perspective, new double[] { p1.X, p1.Y, 0, 0, p2.X, p2.Y, image.Width, 0, p3.X, p3.Y, 0, image.Height, p4.X, p4.Y, image.Width, image.Height }); MagickGeometry size = new MagickGeometry(561, 795) { IgnoreAspectRatio = true }; image.Resize(size); //image.Write("C:\\Users\\RLabonde\\Desktop\\test\\test.bmp"); return(image.ToBitmap()); } } else { System.Windows.Forms.MessageBox.Show("No point was detected!", "No points", MessageBoxButtons.OK, MessageBoxIcon.Error); return(bitmap); } }
public SimplifiedPic(List <BriefElecComp> Arr, MainWindow mainWindow) { mainWindow.SyncProgess(0, "处理图像"); PointArr = new List <IntPoint>(); FeatureArr = new List <ElecFeature>(); StructureArr = new List <ElecStructure>(); //第一步:只要找到导线,则把所有的第二节点变成第一节点 mainWindow.SyncProgess(5, "处理导线"); for (int i = 0; i < Arr.Count; i++) { if (Arr[i].Comp == BriefElecComp.Comp_Wire) { //把所有的A替换成B IntPoint A = Arr[i].Interfaces[0]; IntPoint B = new IntPoint(Arr[i].Interfaces[1]);//一定要新建 for (int j = 0; j < Arr.Count; j++) { Arr[j].ReplaceWith(B, A); } } } mainWindow.SyncProgess(10, "处理坐标"); //第二步:找到所有不同的坐标,存在PointArr里 for (int i = 0; i < Arr.Count; i++) { for (int j = 0; j < Arr[i].Interfaces.Count; j++) { if (!PointArr.Contains(Arr[i].Interfaces[j])) { PointArr.Add(new IntPoint(Arr[i].Interfaces[j])); } } } mainWindow.SyncProgess(15, "整理元件"); for (int i = 0; i < Arr.Count; i++) { if (Arr[i].Comp != BriefElecComp.Comp_Wire) { int Left = PointArr.IndexOf(Arr[i].Interfaces[0]); int Right = PointArr.IndexOf(Arr[i].Interfaces[1]); ElecFeature elecFeature = Arr[i].elecComp.GetElecFeature(); elecFeature.SetFoot(Left, Right); elecFeature.SetFather(Arr[i]); //生成了elecFeature的序列,和对应的Structure序列 FeatureArr.Add(elecFeature); StructureArr.Add(elecFeature.GetStructure()); } } //显示所有的Feature信息 /*String str1 = ""; * for (int i=0; i< FeatureArr.Count; i++) * { * str1 += FeatureArr[i] + "\r\n"; * } * MessageBox.Show(str1);*/ //显示所有的节点信息 String str = ""; for (int i = 0; i < PointArr.Count; i++) { str += "Point " + i + ":" + PointArr[i].X + "," + PointArr[i].Y + "\n"; } MessageBox.Show(str); //显示所有的结构信息 /*String str2 = ""; * for (int i=0; i<StructureArr.Count; i++) * { * str2 += StructureArr[i] + "\n"; * } * MessageBox.Show(str2);*/ //下面开始处理结构,获得结构矩阵 mainWindow.SyncProgess(20, "处理结构"); ComputeA(mainWindow); }
/// <summary> /// Apply filter to an image. /// </summary> /// /// <param name="imageData">Source image to get biggest blob from.</param> /// /// <returns>Returns image of the biggest blob.</returns> /// /// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the source image.</exception> /// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the original image.</exception> /// <exception cref="InvalidImagePropertiesException">Source and original images must have the same size.</exception> /// <exception cref="ArgumentException">The source image does not contain any blobs.</exception> /// public Bitmap Apply(BitmapData imageData) { // check pixel format of the source image if (!FormatTranslations.ContainsKey(imageData.PixelFormat)) { throw new UnsupportedImageFormatException("Source pixel format is not supported by the filter."); } // locate blobs in the source image BlobCounter blobCounter = new BlobCounter(imageData); // get information about blobs Blob[] blobs = blobCounter.GetObjectsInformation( ); // find the biggest blob int maxSize = 0; Blob biggestBlob = null; for (int i = 0, n = blobs.Length; i < n; i++) { int size = blobs[i].Rectangle.Width * blobs[i].Rectangle.Height; if (size > maxSize) { maxSize = size; biggestBlob = blobs[i]; } } // check if any blob was found if (biggestBlob == null) { throw new ArgumentException("The source image does not contain any blobs."); } blobPosition = new IntPoint(biggestBlob.Rectangle.Left, biggestBlob.Rectangle.Top); // extract biggest blob's image if (originalImage == null) { blobCounter.ExtractBlobsImage(new UnmanagedImage(imageData), biggestBlob, false); } else { // check original image's format if ( (originalImage.PixelFormat != PixelFormat.Format24bppRgb) && (originalImage.PixelFormat != PixelFormat.Format32bppArgb) && (originalImage.PixelFormat != PixelFormat.Format32bppRgb) && (originalImage.PixelFormat != PixelFormat.Format32bppPArgb) && (originalImage.PixelFormat != PixelFormat.Format8bppIndexed) ) { throw new UnsupportedImageFormatException("Original image may be grayscale (8bpp indexed) or color (24/32bpp) image only."); } // check its size if ((originalImage.Width != imageData.Width) || (originalImage.Height != imageData.Height)) { throw new InvalidImagePropertiesException("Original image must have the same size as passed source image."); } blobCounter.ExtractBlobsImage(originalImage, biggestBlob, false); } Bitmap managedImage = biggestBlob.Image.ToManagedImage( ); // dispose unmanaged image of the biggest blob biggestBlob.Image.Dispose( ); return(managedImage); }
public static void Generate(ConfigSettings config, Polygons in_outline, Polygons result_lines, bool zigZag, int layerIndex) { // generate infill based on the gyroid equation: sin_x * cos_y + sin_y * cos_z + sin_z * cos_x = 0 // kudos to the author of the Slic3r implementation equation code, the equation code here is based on that Polygons outline = in_outline.Offset(config.ExtrusionWidth_um / 2); var aabb = outline.GetBounds(); var accelerator = new Pathfinding.PathingData(outline, config.ExtrusionWidth_um * 3, true); var linespacing_um = (int)(config.ExtrusionWidth_um / (config.InfillPercent / 100)); var z = layerIndex * config.LayerThickness_um; int pitch = (int)(linespacing_um * 2.41); // this produces similar density to the "line" infill pattern int num_steps = 4; int step = pitch / num_steps; while (step > 500 && num_steps < 16) { num_steps *= 2; step = pitch / num_steps; } pitch = step * num_steps; // recalculate to avoid precision errors double z_rads = 2 * Math.PI * z / pitch; double cos_z = Math.Cos(z_rads); double sin_z = Math.Sin(z_rads); var odd_line_coords = new List <double>(); var even_line_coords = new List <double>(); var result = new Polygons(); var chains = new Polygon[] { new Polygon(), new Polygon() }; // [start_points[], end_points[]] var connected_to = new List <int>[] { new List <int>(), new List <int>() }; // [chain_indices[], chain_indices[]] var line_numbers = new List <int>(); // which row/column line a chain is part of if (Math.Abs(sin_z) <= Math.Abs(cos_z)) { // "vertical" lines double phase_offset = ((cos_z < 0) ? Math.PI : 0) + Math.PI; for (long y = 0; y < pitch; y += step) { double y_rads = 2 * Math.PI * y / pitch; double a = cos_z; double b = Math.Sin(y_rads + phase_offset); double odd_c = sin_z * Math.Cos(y_rads + phase_offset); double even_c = sin_z * Math.Cos(y_rads + phase_offset + Math.PI); double h = Math.Sqrt(a * a + b * b); double odd_x_rads = ((h != 0) ? Math.Asin(odd_c / h) + Math.Asin(b / h) : 0) - Math.PI / 2; double even_x_rads = ((h != 0) ? Math.Asin(even_c / h) + Math.Asin(b / h) : 0) - Math.PI / 2; odd_line_coords.Add(odd_x_rads / Math.PI * pitch); even_line_coords.Add(even_x_rads / Math.PI * pitch); } int num_coords = odd_line_coords.Count; int num_columns = 0; for (long x = (long)((Math.Floor(aabb.minX / (double)pitch) - 2.25) * pitch); x <= aabb.maxX + pitch / 2; x += pitch / 2) { bool is_first_point = true; IntPoint last = default(IntPoint); bool last_inside = false; int chain_end_index = 0; var chain_end = new IntPoint[2]; for (long y = (long)((Math.Floor(aabb.minY / (double)pitch) - 1) * pitch); y <= aabb.maxY + pitch; y += pitch) { for (int i = 0; i < num_coords; ++i) { var current = new IntPoint(x + (((num_columns & 1) == 1) ? odd_line_coords[i] : even_line_coords[i]) / 2 + pitch, y + (long)(i * step)); bool current_inside = accelerator.PointIsInside(current) == QTPolygonsExtensions.InsideState.Inside; if (!is_first_point) { if (last_inside && current_inside) { // line doesn't hit the boundary, add the whole line result.AddLine(last, current); } else if (last_inside != current_inside) { // line hits the boundary, add the part that's inside the boundary var line = new Polygons(); line.AddLine(last, current); line = outline.CreateLineIntersections(line); if (line.Count > 0) { // some of the line is inside the boundary result.AddLine(line[0][0], line[0][1]); var end = line[0][(line[0][0] != last && line[0][0] != current) ? 0 : 1]; var lineNumber = num_columns; if (zigZag) { chain_end[chain_end_index] = end; if (++chain_end_index == 2) { chains[0].Add(chain_end[0]); chains[1].Add(chain_end[1]); chain_end_index = 0; connected_to[0].Add(int.MaxValue); connected_to[1].Add(int.MaxValue); line_numbers.Add(lineNumber); } } } else { // none of the line is inside the boundary so the point that's actually on the boundary // is the chain end var end = last_inside ? last : current; var lineNumber = num_columns; if (zigZag) { chain_end[chain_end_index] = end; if (++chain_end_index == 2) { chains[0].Add(chain_end[0]); chains[1].Add(chain_end[1]); chain_end_index = 0; connected_to[0].Add(int.MaxValue); connected_to[1].Add(int.MaxValue); line_numbers.Add(lineNumber); } } } } } last = current; last_inside = current_inside; is_first_point = false; } } ++num_columns; } } else { // "horizontal" lines double phase_offset = (sin_z < 0) ? Math.PI : 0; for (long x = 0; x < pitch; x += step) { double x_rads = 2 * Math.PI * x / pitch; double a = sin_z; double b = Math.Cos(x_rads + phase_offset); double odd_c = cos_z * Math.Sin(x_rads + phase_offset + Math.PI); double even_c = cos_z * Math.Sin(x_rads + phase_offset); double h = Math.Sqrt(a * a + b * b); double odd_y_rads = ((h != 0) ? Math.Asin(odd_c / h) + Math.Asin(b / h) : 0) + Math.PI / 2; double even_y_rads = ((h != 0) ? Math.Asin(even_c / h) + Math.Asin(b / h) : 0) + Math.PI / 2; odd_line_coords.Add(odd_y_rads / Math.PI * pitch); even_line_coords.Add(even_y_rads / Math.PI * pitch); } int num_coords = odd_line_coords.Count; int num_rows = 0; for (long y = (long)((Math.Floor(aabb.minY / (double)pitch) - 1) * pitch); y <= aabb.maxY + pitch / 2; y += pitch / 2) { bool is_first_point = true; IntPoint last = default(IntPoint); bool last_inside = false; int chain_end_index = 0; var chain_end = new IntPoint[2]; for (long x = (long)((Math.Floor(aabb.minX / (double)pitch) - 1) * pitch); x <= aabb.maxX + pitch; x += pitch) { for (int i = 0; i < num_coords; ++i) { var current = new IntPoint(x + (long)(i * step), y + (((num_rows & 1) == 1) ? odd_line_coords[i] : even_line_coords[i]) / 2); bool current_inside = accelerator.PointIsInside(current) == QTPolygonsExtensions.InsideState.Inside; if (!is_first_point) { if (last_inside && current_inside) { // line doesn't hit the boundary, add the whole line result.AddLine(last, current); } else if (last_inside != current_inside) { // line hits the boundary, add the part that's inside the boundary var line = new Polygons(); line.AddLine(last, current); line = outline.CreateLineIntersections(line); if (line.Count > 0) { // some of the line is inside the boundary result.AddLine(line[0][0], line[0][1]); var end = line[0][(line[0][0] != last && line[0][0] != current) ? 0 : 1]; var lineNumber = num_rows; if (zigZag) { chain_end[chain_end_index] = end; if (++chain_end_index == 2) { chains[0].Add(chain_end[0]); chains[1].Add(chain_end[1]); chain_end_index = 0; connected_to[0].Add(int.MaxValue); connected_to[1].Add(int.MaxValue); line_numbers.Add(lineNumber); } } } else { // none of the line is inside the boundary so the point that's actually on the boundary // is the chain end var end = (last_inside) ? last : current; var lineNumber = num_rows; if (zigZag) { chain_end[chain_end_index] = end; if (++chain_end_index == 2) { chains[0].Add(chain_end[0]); chains[1].Add(chain_end[1]); chain_end_index = 0; connected_to[0].Add(int.MaxValue); connected_to[1].Add(int.MaxValue); line_numbers.Add(lineNumber); } } } } } last = current; last_inside = current_inside; is_first_point = false; } } ++num_rows; } } if (zigZag && chains[0].Count > 0) { // zig-zag connecting consists of joining alternate chain ends to make a chain of chains // the basic algorithm is that we follow the infill area boundary and as we progress we are either drawing a connector or not // whenever we come across the end of a chain we toggle the connector drawing state // things are made more complicated by the fact that we want to avoid generating loops and so we need to keep track // of the identity of the first chain in a connected sequence int chain_ends_remaining = chains[0].Count * 2; foreach (var outline_poly in outline) { var connector_points = new Polygon(); // the points that make up a connector line // we need to remember the first chain processed and the path to it from the first outline point // so that later we can possibly connect to it from the last chain processed int first_chain_chain_index = int.MaxValue; var path_to_first_chain = new Polygon(); bool drawing = false; // true when a connector line is being (potentially) created // keep track of the chain+point that a connector line started at int connector_start_chain_index = int.MaxValue; int connector_start_point_index = int.MaxValue; IntPoint cur_point = default(IntPoint); // current point of interest - either an outline point or a chain end // go round all of the region's outline and find the chain ends that meet it // quit the loop early if we have seen all the chain ends and are not currently drawing a connector for (int outline_point_index = 0; (chain_ends_remaining > 0 || drawing) && outline_point_index < outline_poly.Count; ++outline_point_index) { var op0 = outline_poly[outline_point_index]; var op1 = outline_poly[(outline_point_index + 1) % outline_poly.Count()]; var points_on_outline_chain_index = new List <int>(); var points_on_outline_point_index = new List <int>(); // collect the chain ends that meet this segment of the outline for (int chain_index = 0; chain_index < chains[0].Count; ++chain_index) { for (int point_index = 0; point_index < 2; ++point_index) { // don't include chain ends that are close to the segment but are beyond the segment ends int beyond = 0; if (GetDist2FromLineSegment(op0, chains[point_index][chain_index], op1, ref beyond) < 10 && beyond != 0) { points_on_outline_point_index.Add(point_index); points_on_outline_chain_index.Add(chain_index); } } } if (outline_point_index == 0 || (op0 - cur_point).Length() > 100) { // this is either the first outline point or it is another outline point that is not too close to cur_point if (first_chain_chain_index == int.MaxValue) { // include the outline point in the path to the first chain path_to_first_chain.Add(op0); } cur_point = op0; if (drawing) { // include the start point of this outline segment in the connector connector_points.Add(op0); } } // iterate through each of the chain ends that meet the current outline segment while (points_on_outline_chain_index.Count > 0) { // find the nearest chain end to the current point int nearest_point_index = 0; var nearest_point_dist_squared = double.MaxValue; for (int pi = 0; pi < points_on_outline_chain_index.Count; ++pi) { var first = chains[points_on_outline_point_index[pi]][points_on_outline_chain_index[pi]]; var dist_squared = (first - cur_point).LengthSquared(); if (dist_squared < nearest_point_dist_squared) { nearest_point_dist_squared = dist_squared; nearest_point_index = pi; } } int point_index = points_on_outline_point_index[nearest_point_index]; int chain_index = points_on_outline_chain_index[nearest_point_index]; // make the chain end the current point and add it to the connector line cur_point = chains[point_index][chain_index]; if (drawing && connector_points.Count > 0 && (cur_point - connector_points.Last()).Length() < 100) { // this chain end will be too close to the last connector point so throw away the last connector point connector_points.RemoveAt(connector_points.Count - 1); } connector_points.Add(cur_point); if (first_chain_chain_index == int.MaxValue) { // this is the first chain to be processed, remember it first_chain_chain_index = chain_index; path_to_first_chain.Add(cur_point); } if (drawing) { // add the connector line segments but only if // 1 - the start/end points are not the opposite ends of the same chain // 2 - the other end of the current chain is not connected to the chain the connector line is coming from if (chain_index != connector_start_chain_index && connected_to[(point_index + 1) % 2][chain_index] != connector_start_chain_index) { for (int pi = 1; pi < connector_points.Count; ++pi) { result.AddLine(connector_points[pi - 1], connector_points[pi]); } drawing = false; connector_points.Clear(); // remember the connection connected_to[point_index][chain_index] = connector_start_chain_index; connected_to[connector_start_point_index][connector_start_chain_index] = chain_index; } else { // start a new connector from the current location connector_points.Clear(); connector_points.Add(cur_point); // remember the chain+point that the connector started from connector_start_chain_index = chain_index; connector_start_point_index = point_index; } } else { // we have just jumped a gap so now we want to start drawing again drawing = true; // if this connector is the first to be created or we are not connecting chains from the same row/column, // remember the chain+point that this connector is starting from if (connector_start_chain_index == int.MaxValue || line_numbers[chain_index] != line_numbers[connector_start_chain_index]) { connector_start_chain_index = chain_index; connector_start_point_index = point_index; } } // done with this chain end if (points_on_outline_chain_index.Count > 0) { points_on_outline_chain_index.RemoveAt(Math.Min(points_on_outline_chain_index.Count - 1, points_on_outline_chain_index[0] + nearest_point_index)); } if (points_on_outline_chain_index.Count > 0) { points_on_outline_chain_index.RemoveAt(Math.Min(points_on_outline_chain_index.Count - 1, points_on_outline_chain_index[0] + nearest_point_index)); } // decrement total amount of work to do --chain_ends_remaining; } } // we have now visited all the points in the outline, if a connector was (potentially) being drawn // check whether the first chain is already connected to the last chain and, if not, draw the // connector between if (drawing && first_chain_chain_index != int.MaxValue && first_chain_chain_index != connector_start_chain_index && connected_to[0][first_chain_chain_index] != connector_start_chain_index && connected_to[1][first_chain_chain_index] != connector_start_chain_index) { // output the connector line segments from the last chain to the first point in the outline connector_points.Add(outline_poly[0]); for (int pi = 1; pi < connector_points.Count; ++pi) { result.AddLine(connector_points[pi - 1], connector_points[pi]); } // output the connector line segments from the first point in the outline to the first chain for (int pi = 1; pi < path_to_first_chain.Count; ++pi) { result.AddLine(path_to_first_chain[pi - 1], path_to_first_chain[pi]); } } if (chain_ends_remaining < 1) { break; } } } result_lines.AddRange(result); }
public Tuple <IntPoint, IntPoint, IntPoint, IntPoint> SortCorners(List <IntPoint> cornerPoints, Bitmap image) { IntPoint topLeft = new IntPoint(0, 0); IntPoint topRight = new IntPoint(image.Width, 0); IntPoint bottomLeft = new IntPoint(0, image.Height); IntPoint bottomRight = new IntPoint(image.Width, image.Height); IntPoint p1 = new IntPoint(0, 0); IntPoint p2 = new IntPoint(0, 0); IntPoint p3 = new IntPoint(0, 0); IntPoint p4 = new IntPoint(0, 0); if (GetDistance(topLeft, cornerPoints[0]) < GetDistance(topLeft, cornerPoints[1]) && GetDistance(topLeft, cornerPoints[0]) < GetDistance(topLeft, cornerPoints[2]) && GetDistance(topLeft, cornerPoints[0]) < GetDistance(topLeft, cornerPoints[3])) { p1 = cornerPoints[0]; } else if (GetDistance(topLeft, cornerPoints[1]) < GetDistance(topLeft, cornerPoints[2]) && GetDistance(topLeft, cornerPoints[1]) < GetDistance(topLeft, cornerPoints[3]) && GetDistance(topLeft, cornerPoints[1]) < GetDistance(topLeft, cornerPoints[0])) { p1 = cornerPoints[1]; } else if (GetDistance(topLeft, cornerPoints[2]) < GetDistance(topLeft, cornerPoints[3]) && GetDistance(topLeft, cornerPoints[2]) < GetDistance(topLeft, cornerPoints[0]) && GetDistance(topLeft, cornerPoints[2]) < GetDistance(topLeft, cornerPoints[1])) { p1 = cornerPoints[2]; } else { p1 = cornerPoints[3]; } //oben rechts if (GetDistance(topRight, cornerPoints[0]) < GetDistance(topRight, cornerPoints[1]) && GetDistance(topRight, cornerPoints[0]) < GetDistance(topRight, cornerPoints[2]) && GetDistance(topRight, cornerPoints[0]) < GetDistance(topRight, cornerPoints[3])) { p2 = cornerPoints[0]; } else if (GetDistance(topRight, cornerPoints[1]) < GetDistance(topRight, cornerPoints[2]) && GetDistance(topRight, cornerPoints[1]) < GetDistance(topRight, cornerPoints[3]) && GetDistance(topRight, cornerPoints[1]) < GetDistance(topRight, cornerPoints[0])) { p2 = cornerPoints[1]; } else if (GetDistance(topRight, cornerPoints[2]) < GetDistance(topRight, cornerPoints[3]) && GetDistance(topRight, cornerPoints[2]) < GetDistance(topRight, cornerPoints[0]) && GetDistance(topRight, cornerPoints[2]) < GetDistance(topRight, cornerPoints[1])) { p2 = cornerPoints[2]; } else { p2 = cornerPoints[3]; } //unten links if (GetDistance(bottomLeft, cornerPoints[0]) < GetDistance(bottomLeft, cornerPoints[1]) && GetDistance(bottomLeft, cornerPoints[0]) < GetDistance(bottomLeft, cornerPoints[2]) && GetDistance(bottomLeft, cornerPoints[0]) < GetDistance(bottomLeft, cornerPoints[3])) { p3 = cornerPoints[0]; } else if (GetDistance(bottomLeft, cornerPoints[1]) < GetDistance(bottomLeft, cornerPoints[2]) && GetDistance(bottomLeft, cornerPoints[1]) < GetDistance(bottomLeft, cornerPoints[3]) && GetDistance(bottomLeft, cornerPoints[1]) < GetDistance(bottomLeft, cornerPoints[0])) { p3 = cornerPoints[1]; } else if (GetDistance(bottomLeft, cornerPoints[2]) < GetDistance(bottomLeft, cornerPoints[3]) && GetDistance(bottomLeft, cornerPoints[2]) < GetDistance(bottomLeft, cornerPoints[0]) && GetDistance(bottomLeft, cornerPoints[2]) < GetDistance(bottomLeft, cornerPoints[1])) { p3 = cornerPoints[2]; } else { p3 = cornerPoints[3]; } //unten rechts if (GetDistance(bottomRight, cornerPoints[0]) < GetDistance(bottomRight, cornerPoints[1]) && GetDistance(bottomRight, cornerPoints[0]) < GetDistance(bottomRight, cornerPoints[2]) && GetDistance(bottomRight, cornerPoints[0]) < GetDistance(bottomRight, cornerPoints[3])) { p4 = cornerPoints[0]; } else if (GetDistance(bottomRight, cornerPoints[1]) < GetDistance(bottomRight, cornerPoints[2]) && GetDistance(bottomRight, cornerPoints[1]) < GetDistance(bottomRight, cornerPoints[3]) && GetDistance(bottomRight, cornerPoints[1]) < GetDistance(bottomRight, cornerPoints[0])) { p4 = cornerPoints[1]; } else if (GetDistance(bottomRight, cornerPoints[2]) < GetDistance(bottomRight, cornerPoints[3]) && GetDistance(bottomRight, cornerPoints[2]) < GetDistance(bottomRight, cornerPoints[0]) && GetDistance(bottomRight, cornerPoints[2]) < GetDistance(bottomRight, cornerPoints[1])) { p4 = cornerPoints[2]; } else { p4 = cornerPoints[3]; } return(Tuple.Create(p1, p2, p3, p4)); }
public void RenderSetPiece(World world, IntPoint pos) { XmlData dat = world.Manager.GameData; for (int x = 0; x < Size; x++) { for (int y = 0; y < Size; y++) { if (SetPiece[y, x] == 1) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor1]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 2) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor2]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 3) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor3]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 4) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor4]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 5) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Middle]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 6) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Air]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 7) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Air2]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 8) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Air3]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 9) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Air4]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (SetPiece[y, x] == 10) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Middle]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; Entity elemental = Entity.Resolve(world.Manager, "Elemental Phantom"); elemental.Move(pos.X + Size / 2f, pos.Y + Size / 2f); world.EnterWorld(elemental); } } } }
public bool needSupportAt(IntPoint pointToCheckIfNeedsSupport, int currentZHeight_um) { if (pointToCheckIfNeedsSupport.X < 1 || pointToCheckIfNeedsSupport.Y < 1 || pointToCheckIfNeedsSupport.X >= supportStorage.gridWidth - 1 || pointToCheckIfNeedsSupport.Y >= supportStorage.gridHeight - 1 || done[pointToCheckIfNeedsSupport.X + pointToCheckIfNeedsSupport.Y * supportStorage.gridWidth]) { return(false); } int gridIndex = (int)(pointToCheckIfNeedsSupport.X + pointToCheckIfNeedsSupport.Y * supportStorage.gridWidth); if (generateInternalSupport) { // We add 2 each time as we are wanting to look at the bottom face (even faces), and the intersections are bottom - top - bottom - top - etc. for (int zIndex = 0; zIndex < supportStorage.xYGridOfSupportPoints[gridIndex].Count; zIndex += 2) { SupportPoint currentBottomSupportPoint = supportStorage.xYGridOfSupportPoints[gridIndex][zIndex]; bool angleNeedsSupport = currentBottomSupportPoint.angleFromHorizon >= supportedAngleFromHorizon; if (angleNeedsSupport) { bool zIsBelowBottomSupportPoint = currentZHeight_um <= currentBottomSupportPoint.z - interfaceZDistance_um - supportZDistance_um - extraErrorGap; if (zIndex == 0) { if (zIsBelowBottomSupportPoint) { return(true); } } else { SupportPoint previousTopSupportPoint = supportStorage.xYGridOfSupportPoints[gridIndex][zIndex - 1]; bool zIsAbovePrevSupportPoint = currentZHeight_um > previousTopSupportPoint.z + supportZDistance_um; if (zIsBelowBottomSupportPoint && zIsAbovePrevSupportPoint) { return(true); } } } } return(false); } else // we only ever look up to the first point needing support (the 0th index) { if (supportStorage.xYGridOfSupportPoints[gridIndex].Count == 0) { // there are no points needing support here return(false); } if (supportStorage.xYGridOfSupportPoints[gridIndex][0].angleFromHorizon < supportedAngleFromHorizon) { // The angle does not need support return(false); } if (currentZHeight_um >= supportStorage.xYGridOfSupportPoints[gridIndex][0].z - interfaceZDistance_um - supportZDistance_um - extraErrorGap) { // the spot is above the place we need to support return(false); } } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="CanvasMove"/> class. /// </summary> /// /// <param name="movePoint">Point to move the canvas.</param> /// <param name="fillColorGray">Gray color to use for filling empty areas in grayscale images.</param> /// public CanvasMove(IntPoint movePoint, byte fillColorGray) : this() { this.movePoint = movePoint; this.fillGray = fillColorGray; }
public void RenderSetPiece(World world, IntPoint pos) { int[,] t = new int[23, 35]; for (int x = 0; x < 23; x++) //Floor { for (int y = 0; y < 35; y++) { t[x, y] = rand.Next() % 3 == 0 ? 0 : 1; } } for (int y = 0; y < 35; y++) //Perimeters { t[0, y] = t[22, y] = 2; } for (int x = 0; x < 23; x++) { t[x, 0] = t[x, 34] = 2; } List <IntPoint> pts = new List <IntPoint>(); for (int y = 0; y < 11; y++) //Crosses { for (int x = 0; x < 7; x++) { if (rand.Next() % 3 > 0) { t[2 + 3 * x, 2 + 3 * y] = 4; } else { pts.Add(new IntPoint(2 + 3 * x, 2 + 3 * y)); } } } for (int x = 0; x < 23; x++) //Corruption { for (int y = 0; y < 35; y++) { if (t[x, y] == 1 || t[x, y] == 0 || t[x, y] == 4) { continue; } double p = rand.NextDouble(); if (p < 0.1) { t[x, y] = 1; } else if (p < 0.4) { t[x, y]++; } } } //Boss & Chest IntPoint pt = pts[rand.Next(0, pts.Count)]; t[pt.X, pt.Y] = 5; t[pt.X + 1, pt.Y] = 6; int r = rand.Next(0, 4); for (int i = 0; i < r; i++) //Rotation { t = SetPieces.rotateCW(t); } int w = t.GetLength(0), h = t.GetLength(1); XmlData dat = world.Manager.GameData; for (int x = 0; x < w; x++) //Rendering { for (int y = 0; y < h; y++) { if (t[x, y] == 1) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor]; tile.ObjType = 0; world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 2) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor]; tile.ObjType = dat.IdToObjectType[WallA]; if (tile.ObjId == 0) { tile.ObjId = world.GetNextEntityId(); } world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 3) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor]; world.Map[x + pos.X, y + pos.Y] = tile; Entity wall = Entity.Resolve(world.Manager, dat.IdToObjectType[WallB]); wall.Move(x + pos.X + 0.5f, y + pos.Y + 0.5f); world.EnterWorld(wall); } else if (t[x, y] == 4) { WmapTile tile = world.Map[x + pos.X, y + pos.Y].Clone(); tile.TileId = dat.IdToTileType[Floor]; tile.ObjType = dat.IdToObjectType[Cross]; if (tile.ObjId == 0) { tile.ObjId = world.GetNextEntityId(); } world.Map[x + pos.X, y + pos.Y] = tile; } else if (t[x, y] == 5) { Container container = new Container(world.Manager, 0x0501, null, false); Item[] items = chest.GetLoots(world.Manager, 3, 8).ToArray(); for (int i = 0; i < items.Length; i++) { container.Inventory[i] = items[i]; } container.Move(pos.X + x + 0.5f, pos.Y + y + 0.5f); world.EnterWorld(container); } else if (t[x, y] == 6) { Entity mage = Entity.Resolve(world.Manager, "Deathmage"); mage.Move(pos.X + x, pos.Y + y); world.EnterWorld(mage); } } } }
/// <summary> /// Initializes a new instance of the <see cref="CanvasMove"/> class. /// </summary> /// /// <param name="movePoint">Point to move the canvas to.</param> /// public CanvasMove(IntPoint movePoint) : this() { this.movePoint = movePoint; }
/// <summary> /// Get color of the pixel with the specified coordinates. /// </summary> /// /// <param name="point">Point's coordiates to get color of.</param> /// /// <returns>Return pixel's color at the specified coordinates.</returns> /// /// <remarks><para>See <see cref="GetPixel(int, int)"/> for more information.</para></remarks> /// public Color GetPixel(IntPoint point) { return(GetPixel(point.X, point.Y)); }
public override void RenderSetPiece(World world, IntPoint pos) { var t = new int[Size, Size]; var o = new int[Size, Size]; for (int x = 0; x < 60; x++) //Flooring { for (int y = 0; y < 60; y++) { if (Math.Abs(x - Size / 2) / (Size / 2.0) + rand.NextDouble() * 0.3 < 0.9 && Math.Abs(y - Size / 2) / (Size / 2.0) + rand.NextDouble() * 0.3 < 0.9) { double dist = Math.Sqrt(((x - Size / 2) * (x - Size / 2) + (y - Size / 2) * (y - Size / 2)) / ((Size / 2.0) * (Size / 2.0))); t[x, y] = rand.NextDouble() < (1 - dist) * (1 - dist) ? 2 : 1; } } } for (int x = 0; x < Size; x++) //Corruption { for (int y = 0; y < Size; y++) { if (rand.Next() % 50 == 0) { t[x, y] = 0; } } } const int bas = 16; //Walls for (int x = 0; x < 23; x++) { if (x > 9 && x < 13) { continue; } o[bas + x, bas] = 2; o[bas + x, bas + 1] = 2; o[bas + x, bas + 21] = 2; o[bas + x, bas + 22] = 2; } for (int y = 0; y < 23; y++) { if (y > 9 && y < 13) { continue; } o[bas, bas + y] = 2; o[bas + 1, bas + y] = 2; o[bas + 21, bas + y] = 2; o[bas + 22, bas + y] = 2; } o[bas - 1, bas + 7] = o[bas - 1, bas + 8] = o[bas - 1, bas + 9] = o[bas - 1, bas + 13] = o[bas - 1, bas + 14] = o[bas - 1, bas + 15] = 1; o[bas + 23, bas + 7] = o[bas + 23, bas + 8] = o[bas + 23, bas + 9] = o[bas + 23, bas + 13] = o[bas + 23, bas + 14] = o[bas + 23, bas + 15] = 1; o[bas + 7, bas - 1] = o[bas + 8, bas - 1] = o[bas + 9, bas - 1] = o[bas + 13, bas - 1] = o[bas + 14, bas - 1] = o[bas + 15, bas - 1] = 1; o[bas + 7, bas + 23] = o[bas + 8, bas + 23] = o[bas + 9, bas + 23] = o[bas + 13, bas + 23] = o[bas + 14, bas + 23] = o[bas + 15, bas + 23] = 1; for (int y = 0; y < 4; y++) //Columns { for (int x = 0; x < 4; x++) { o[bas + 5 + x * 4, bas + 5 + y * 4] = 3; } } for (int x = 0; x < Size; x++) //Plants { for (int y = 0; y < Size; y++) { if (((x > 5 && x < bas) || (x < Size - 5 && x > Size - bas) || (y > 5 && y < bas) || (y < Size - 5 && y > Size - bas)) && o[x, y] == 0 && t[x, y] == 1) { double r = rand.NextDouble(); if (r > 0.6) //0.4 { o[x, y] = 4; } else if (r > 0.35) //0.25 { o[x, y] = 5; } else if (r > 0.33) //0.02 { o[x, y] = 6; } } } } int rotation = rand.Next(0, 4); //Rotation for (int i = 0; i < rotation; i++) { t = SetPieces.rotateCW(t); o = SetPieces.rotateCW(o); } Render(this, world, pos, t, o); //Boss & Chest var container = new Container(world.Manager, 0x0501, null, false); Item[] items = chest.GetLoots(world.Manager, 3, 8).ToArray(); for (int i = 0; i < items.Length; i++) { container.Inventory[i] = items[i]; } container.Move(pos.X + bas + 11.5f, pos.Y + bas + 11.5f); world.EnterWorld(container); Entity snake = Entity.Resolve(world.Manager, 0x0dc2); snake.Move(pos.X + bas + 11.5f, pos.Y + bas + 11.5f); world.EnterWorld(snake); }
private static ConvolutionColor GetColor(DataSource dataSource, int[] pixels, IntPoint coordinate, Point point) { int x = coordinate.X; int y = coordinate.Y; var x0 = dataSource.XCoordinates[x]; var x1 = dataSource.XCoordinates[x + 1]; var y0 = dataSource.YCoordinates[y]; var y1 = dataSource.YCoordinates[y + 1]; double xRatio = GetRatio(x0, x1, point.X); double yRatio = GetRatio(y0, y1, point.Y); int width = dataSource.Width; var v00 = pixels[x + y * width]; var v01 = pixels[x + 1 + y * width]; var v10 = pixels[x + (y + 1) * width]; var v11 = pixels[x + 1 + (y + 1) * width]; //var result = (int)(((1 - xRatio) * v00 + xRatio * v10 + // (1 - xRatio) * v01 + xRatio * v11 + // (1 - yRatio) * v00 + yRatio * v01 + // (1 - yRatio) * v10 + yRatio * v11) * 0.25); var result = v00; return(ConvolutionColor.FromArgb(result)); }
public bool IsOutside(Vector2 point) { var p = new IntPoint(point.X, point.Y); return(Clipper.PointInPolygon(p, ToClipperPath()) != 1); }