private void Start() { shootTimer = firstShotOffset + shootCooldown; player = Player.instance; point = GetComponent <PolygonalPoint>(); body = point.body; }
void RemovePolygon(PolygonalBody body) { if (--number <= 0) { Activate(); } }
private RigidBodyBase MakeBodyFromClosedStroke(Stroke stroke, Point[] vertices) { // Form a new body -- ellipse or polygon? RigidBodyBase newbody = null; Point[] points = stroke.GetPoints(); Ellipse elli = Ellipse.FromRegression(points); if (!elli.IsEmpty && elli.IsFit(points)) { dbg.WriteLine("new EllipticalBody"); newbody = new EllipticalBody(); EllipticalBody body = newbody as EllipticalBody; body.CenterPoint = elli.Center; body.MajorAxis = elli.MajorAxis; body.MinorAxis = elli.MinorAxis; body.Orientation = elli.Orientation; // Close to circle? Snap to it. if ((float)elli.MajorAxis / (float)elli.MinorAxis < 1.25) { int r = (elli.MajorAxis + elli.MinorAxis) / 2; body.MajorAxis = body.MinorAxis = r; body.Orientation = 0; } } else { dbg.WriteLine("new PolygonalBody"); newbody = new PolygonalBody(); PolygonalBody body = newbody as PolygonalBody; body.Vertices = vertices; } dbg.WriteLine(String.Format("Mass={0}, I={1}", newbody.Mass, newbody.I)); newbody.strokeid = stroke.Id; doc.Bodies.Add(newbody); return(newbody); }
static MagicDocument CreateDocumentFixture() { MagicDocument doc = new MagicDocument(); RigidBodyBase body; body = new EllipticalBody(); body.strokeid = 1; doc.Bodies.Add(body); body = new EllipticalBody(); body.strokeid = 2; doc.Bodies.Add(body); body = new PolygonalBody(); body.strokeid = 3; doc.Bodies.Add(body); ((PolygonalBody)body).Vertices = new Point[] { new Point(120,340), new Point(560,340), new Point(560,780), new Point(120,780) }; BindingMechanismBase mech; mech = new RodMech(); mech.EndpointA = BodyRef.For((RigidBodyBase)doc.Bodies[0],Point.Empty); mech.EndpointB = BodyRef.For((RigidBodyBase)doc.Bodies[1],Point.Empty); doc.Mechanisms.Add(mech); mech = new RopeMech(); mech.EndpointA = BodyRef.For((RigidBodyBase)doc.Bodies[1],Point.Empty); mech.EndpointB = BodyRef.For((RigidBodyBase)doc.Bodies[2],Point.Empty); doc.Mechanisms.Add(mech); mech = new SpringMech(); mech.EndpointA = BodyRef.For((RigidBodyBase)doc.Bodies[2],Point.Empty); mech.EndpointB = BodyRef.For((RigidBodyBase)doc.Bodies[0],Point.Empty); doc.Mechanisms.Add(mech); return doc; }
static MagicDocument CreateDocumentFixture() { MagicDocument doc = new MagicDocument(); RigidBodyBase body; body = new EllipticalBody(); body.strokeid = 1; doc.Bodies.Add(body); body = new EllipticalBody(); body.strokeid = 2; doc.Bodies.Add(body); body = new PolygonalBody(); body.strokeid = 3; doc.Bodies.Add(body); ((PolygonalBody)body).Vertices = new Point[] { new Point(120, 340), new Point(560, 340), new Point(560, 780), new Point(120, 780) }; BindingMechanismBase mech; mech = new RodMech(); mech.EndpointA = BodyRef.For((RigidBodyBase)doc.Bodies[0], Point.Empty); mech.EndpointB = BodyRef.For((RigidBodyBase)doc.Bodies[1], Point.Empty); doc.Mechanisms.Add(mech); mech = new RopeMech(); mech.EndpointA = BodyRef.For((RigidBodyBase)doc.Bodies[1], Point.Empty); mech.EndpointB = BodyRef.For((RigidBodyBase)doc.Bodies[2], Point.Empty); doc.Mechanisms.Add(mech); mech = new SpringMech(); mech.EndpointA = BodyRef.For((RigidBodyBase)doc.Bodies[2], Point.Empty); mech.EndpointB = BodyRef.For((RigidBodyBase)doc.Bodies[0], Point.Empty); doc.Mechanisms.Add(mech); return(doc); }
internal override RigidBodyBase Clone(int newstrokeid) { // Instantiate a clone as the most-derived type. PolygonalBody clone = (PolygonalBody)this.MemberwiseClone(); // Sever ties to the original's gp and rgn caches. clone.gp = null; clone.rgncache = null; // Make value-copies of reference types. clone.Vertices = (Point[])Vertices.Clone(); // Set the new stroke id. clone.strokeid = newstrokeid; // Move it down, and to the right a bit. using (Matrix m = new Matrix()) { m.Translate(1000f, 1000f); clone.Transform(m); } return(clone); }
void Died(PolygonalBody deadBody) { OutcomeController.instance.RemovePolygon(); Destroy(gameObject); }
void Start() { body = GetComponent <PolygonalBody>(); body.onDie.AddListener(Died); }
private RigidBodyBase MakeBodyFromClosedStroke(Stroke stroke, Point[] vertices) { // Form a new body -- ellipse or polygon? RigidBodyBase newbody = null; Point[] points = stroke.GetPoints(); Ellipse elli = Ellipse.FromRegression(points); if (!elli.IsEmpty && elli.IsFit(points)) { dbg.WriteLine("new EllipticalBody"); newbody = new EllipticalBody(); EllipticalBody body = newbody as EllipticalBody; body.CenterPoint = elli.Center; body.MajorAxis = elli.MajorAxis; body.MinorAxis = elli.MinorAxis; body.Orientation = elli.Orientation; // Close to circle? Snap to it. if ((float)elli.MajorAxis/(float)elli.MinorAxis < 1.25) { int r = (elli.MajorAxis+elli.MinorAxis)/2; body.MajorAxis = body.MinorAxis = r; body.Orientation = 0; } } else { dbg.WriteLine("new PolygonalBody"); newbody = new PolygonalBody(); PolygonalBody body = newbody as PolygonalBody; body.Vertices = vertices; } dbg.WriteLine(String.Format("Mass={0}, I={1}",newbody.Mass,newbody.I)); newbody.strokeid = stroke.Id; doc.Bodies.Add(newbody); return newbody; }
protected virtual void Start() { body = GetComponent <PolygonalBody>(); Modify(body.points.ToArray()); }