public override void DoAction(IEventArgs args) { int minX = FreeUtil.ReplaceInt(MinX, args); int maxX = FreeUtil.ReplaceInt(MaxX, args); int minY = FreeUtil.ReplaceInt(MinY, args); int maxY = FreeUtil.ReplaceInt(MaxY, args); int stopX = FreeUtil.ReplaceInt(StopX, args); int stopY = FreeUtil.ReplaceInt(StopY, args); int stopR = FreeUtil.ReplaceInt(StopR, args); int random = RandomUtil.Random(1, 4); // 飞机航线 if (stopR == 0) { FlyLine line = SelectStart(random, minX, minY, maxX, maxY); Set(args, (int)line.from.x, (int)line.from.y, (int)line.to.x, (int)line.to.y); } else { FlyLine line = SelectStart(random, minX, minY, maxX, maxY); Set(args, (int)line.from.x, (int)line.from.y, (int)line.to.x, (int)line.to.y); } }
private void SetToLine(FlyLine line, Vector2 p, int min, int max, bool useX) { if ((useX && p.x <= max && p.x >= min) || (!useX && p.y <= max && p.y >= min)) { if (line.from == null) { line.from = p; } else { line.to = p; } } }
private FlyLine FindCirclePosotion(bool useX, int minX, int minY, int maxX, int maxY, int stopX, int stopY) { FlyLine line = new FlyLine(); Vector2 to = new Vector2(stopX, stopY); int angle = RandomUtil.Random(0, 360); if (angle == 90 || angle == 270) { angle = angle + RandomUtil.Random(5, 10); } double d = Math.Tan(angle * Math.PI / 180); Vector2 p1 = new Vector2(minX, GetY(to, d, minX)); Vector2 p2 = new Vector2(maxX, GetY(to, d, maxX)); Vector2 p3 = new Vector2(GetX(to, d, minY), minY); Vector2 p4 = new Vector2(GetX(to, d, maxY), maxY); SetToLine(line, p1, minY, maxY, false); SetToLine(line, p2, minY, maxY, false); SetToLine(line, p3, minX, maxX, true); SetToLine(line, p4, minX, maxX, true); return(line); }