public static void TurnTowardsDirection(Node node, Vector2R direction, bool flip, float lerpPercent) { if (direction == Vector2R.Zero) { return; } if (flip) { direction *= new Vector2R(-1, -1); } float oldAngle = VMath.VectorToAngle(node.body.velocity); float newAngle = VMath.VectorToAngle(direction); float lerpedAngle = GMath.AngleLerp(oldAngle, newAngle, lerpPercent / 100f); Vector2R finalDir = VMath.AngleToVector(lerpedAngle); node.body.velocity = VMath.Redirect(node.body.velocity, finalDir); }
public void DrawLines(LineSpinner lineSpinner, Color newColor) { for (int o = 0; o < copyCount; o++) { for (int i = 0; i < lineCount; i++) { float dirAngle = angleIncrement * i; dirAngle = (dirAngle + totalRotation) % GMath.TwoPI; Vector2R dir = VMath.AngleToVector(dirAngle); dir *= dist; float rotationAngle = dirAngle + GMath.PIbyTwo; //) % GMath.TwoPI; rotationAngle = (rotationAngle + rotation + copyOffset * o) % GMath.TwoPI; float length = dist * distLengthRatio; //symmetry.room.camera.Draw(textures.whitepixel, dir + symmetry.parent.body.pos, color ?? symmetry.parent.body.color, new Vector2(1f, length), rotationAngle, Layers.Under1); //lineSpinner.room.Camera.AddPermanentDraw(Textures.Whitepixel, dir + lineSpinner.parent.body.pos, newColor, // new Vector2(1f, length), rotationAngle, permDraw); //Todo:drawLines } } }
public void RandomizeSymmetry() { Group group = room.Groups.General.childGroups.Values.ElementAt(0); Color color = Utils.randomColor(); Vector2R center = parent.body.pos; float dist = (float)Utils.random.NextDouble() * 100f + 20f; float angle = (float)Utils.random.NextDouble() * GMath.TwoPI; float speed = (float)Utils.random.NextDouble() * 5f + 1f; int numberOfNodes = Utils.random.Next(10) + 2; float angleIncrement = GMath.TwoPI / numberOfNodes; Node centerNode = room.DefaultNode.CreateClone(room); centerNode.body.color = color; centerNode.collision.active = false; centerNode.body.pos = center; room.SpawnNode(centerNode, lifetime: -1, g: group); HashSet <Node> outerNodes = new HashSet <Node>(); for (int i = 0; i < numberOfNodes; i++) { Node n = centerNode.CreateClone(room); float angleFromCenter = angleIncrement * i; Vector2R spawnPosition = (VMath.AngleToVector(angleFromCenter) * dist) + center; Vector2R spawnVelocity = VMath.AngleToVector(angleFromCenter + angle) * speed; room.SpawnNode(n, lifetime: -1, g: group); n.body.pos = spawnPosition; n.body.velocity = spawnVelocity; n.body.radius = 5f; n.body.mass = 10f; n.body.color = color * 0.5f; n.movement.mode = movemode.free; outerNodes.Add(n); //n.addComponent<PhaseOrb>(true); //n.Comp<PhaseOrb>().phaserLength = 200; //n.addComponent<Laser>(true); //n.Comp<Laser>().laserLength = 200; n.addComponent <Waver>(true); n.Comp <Waver>().Length = 200; n.Comp <Waver>().reflective = true; n.addComponent <ColorChanger>(true); } centerNode.movement.active = false; centerNode.basicdraw.active = false; Gravity grav = new Gravity(); grav.multiplier = 20f; grav.radius = float.MaxValue; Spring spring = new Spring(); spring.restdist = 100; spring.radius = float.MaxValue; Follow follow = new Follow(); RelativeMotion rel = new RelativeMotion(); Link link = new Link(parent, outerNodes, grav); //Link link = new Link(outerNodes, parent, follow); //link.AddLinkComponent(rel, true); //link.AddLinkComponent(follow, true); link.active = true; link.DrawLinkLines = false; links.Enqueue(link); }
public override void OnSpawn() { collisionAction = (s, t) => { if (t.IsPlayer) { if (damageMode == DamageMode.Players || damageMode == DamageMode.Both) { t.meta.CalculateDamage(s, damageMultiplier); } if (pushBack.enabled) { Vector2R f = (t.body.pos - s.body.pos); VMath.NormalizeSafe(ref f); f *= pushBack.value; t.body.velocity += f; } if (stunSeconds.enabled) { if (t.movement.active) { t.movement.active = false; Action <Node> ad = (n) => { t.movement.active = true; }; room.Scheduler.AddAppointment(new Appointment(ad, (int)(stunSeconds.value * 1000))); } } } else { if (damageMode == DamageMode.Nodes || damageMode == DamageMode.Both) { t.meta.CalculateDamage(s, damageMultiplier); } if (pushBack.enabled) { Vector2R f = (t.body.pos - s.body.pos); VMath.NormalizeSafe(ref f); f *= pushBack.value; t.body.velocity += f; } if (stunSeconds.enabled) { if (t.movement.active) { t.movement.active = false; Action <Node> ad = (n) => t.movement.active = true; t.scheduler.AddAppointment(new Appointment(ad, (int)(stunSeconds.value * 1000))); } } } }; Polygon poly = new Polygon(); poly.body = parent.body; float dist = parent.body.radius * 1.3f; Vector2R[] verts = new Vector2R[3]; for (int i = 0; i < 3; i++) { verts[i] = VMath.AngleToVector(GMath.TwoPI / 3f * i) * dist; } parent.body.shape = poly; poly.Set(verts, 3); parent.body.DrawPolygonCenter = true; parent.body.orient = parent.body.orient; //todo:set this every init of polys parent.body.OnCollisionEnter += collisionAction; parent.body.ExclusionCheck += (s, t) => { return(Vector2R.Distance(s.pos, t.pos) > dist); }; }
public Vector2R getOrientV2() { return(VMath.AngleToVector(orient)); }