public void PlaceDiode() { Vector2R mousePos = UserInterface.WorldMousePos; if (firstclick) { firstclick = false; firstPos = mousePos; } else { firstclick = true; var dict = new Dictionary <dynamic, dynamic>() { { typeof(Diode), true }, { nodeE.texture, Textures.Gradient1 } }; lastSpawnedDiode = Node.ContructLineWall(room, firstPos, mousePos, diodeThickness, dict, false); room.MasterGroup.IncludeEntity(lastSpawnedDiode); lastSpawnedDiode.OnSpawn(); lastSpawnedDiode.SetColor(new Color(255, 255, 255, 255)); lastSpawnedDiode.Comp <Diode>().start = firstPos; lastSpawnedDiode.Comp <Diode>().end = mousePos; Console.WriteLine(lastSpawnedDiode.body.orient); } }
public void InitializePlayers() { for (int i = 0; i < 8; i++) { //Player p = Player.GetNew(i); Player p = new Player(i); if (p == null) { break; } Vector2R spawnPos = Vector2R.Zero; double angle = Utils.random.NextDouble() * Math.PI * 2; angle -= Math.PI; float dist = 200; float x = dist * (float)Math.Cos(angle); float y = dist * (float)Math.Sin(angle); spawnPos = new Vector2R(room.WorldWidth / 2, room.WorldHeight / 2) - new Vector2R(x, y); //add //{ nodeE.position, spawnPos }, p.node = room.SpawnNode(playerProps); p.node.name = "player" + p.playerIndex; Collider collider = new Collider(new Circle(25)); p.node.collision.AddCollider("trigger", collider); collider.OnCollisionEnter += onCollisionEnter; collider.OnCollisionExit += onCollisionExit; p.node.addComponent <Swap>(true); p.node.Comp <Swap>().OnSwapBefore += before; p.node.Comp <Swap>().OnSwapAfter += after; } }
public static float Defaultered(string id, ModifierInfo mi, float defaultval) { float ret; if (mi.fpInfos.ContainsKey(id)) { var val = mi.fpInfos[id].GetValue(); if (val.GetType() == typeof(float)) { //Console.WriteLine(val.GetType()); return((float)val); } else if (val.GetType() == typeof(int)) { return((int)val); } else if (val.GetType() == typeof(Vector2R)) { Vector2R vect = (Vector2R)(val); ret = (vect.X + vect.Y) / 10; } else { ret = defaultval; } } else { ret = defaultval; } return(ret); }
public void DrawRect(Vector2R min, Vector2R max, Color borderColor) { DrawLine(min, new Vector2R(max.X, min.Y), 2, borderColor, (int)Layers.Under5); DrawLine(min, new Vector2R(min.X, max.Y), 2, borderColor, (int)Layers.Under5); DrawLine(new Vector2R(min.X, max.Y), max, 2, borderColor, (int)Layers.Under5); DrawLine(new Vector2R(max.X, min.Y), max, 2, borderColor, (int)Layers.Under5); }
public static bool isWithin(this Vector2R v, Vector2R TopLeft, Vector2R BottomRight) { var fromTL = v - TopLeft; var fromBR = v - BottomRight; return(fromTL.X > 0 && fromTL.Y < 0 && fromBR.X < 0 && fromBR.Y > 0); }
public override void PlayerControl(Input input) { swordNode.movement.active = false; //sword.body.velocity = Utils.AngleToVector(sword.body.orient + (float)Math.PI/2) * 100; swordNode.body.velocity = swordNode.body.effvelocity * nodeKnockback; Vector2R rightstick = input.GetRightStick().toV2R(); if (rightstick.LengthSquared() > 0.9 * 0.9) { movingStick = true; target = rightstick; //enabled = true; target.Normalize(); target *= distance; target += parent.body.pos; swordNode.body.pos = Vector2R.Lerp(swordNode.body.pos, target, 0.1f); //sword.body.pos = target + parent.body.pos; Vector2R result = swordNode.body.pos - parent.body.pos; swordNode.body.SetOrientV2(result); } else { movingStick = false; //enabled = false; Vector2R restPos = new Vector2R(parent.body.radius, 0).Rotate(parent.body.orient) + parent.body.pos; swordNode.body.pos = Vector2R.Lerp(swordNode.body.pos, restPos, 0.1f); swordNode.body.orient = GMath.AngleLerp(swordNode.body.orient, parent.body.orient, 0.1f); } //sword.body.pos = position; }
public Tuple <int, int> getIndexs(Collider collider) { Vector2R pos = new Vector2R(collider.pos.X, collider.pos.Y); int x = (int)collider.pos.X; int y = (int)collider.pos.Y; int gridx = (int)pos.X - ((int)pos.X % cellWidth); x = gridx / cellWidth; //if ((int)pos.X - gridx > gridx + cellwidth - (int)node.transform.radius) x++; int gridy = (int)pos.Y - ((int)pos.Y % cellHeight); y = gridy / cellHeight; //if ((int)pos.Y - gridy > gridy + cellheight - (int)node.transform.radius) y++; if (x > cellsX - 1) { x = cellsX - 1; } if (y > cellsY - 1) { y = cellsY - 1; } if (x < 0) { x = 0; } if (y < 0) { y = 0; } //Console.WriteLine("{0} + {1}", x, y); return(new Tuple <int, int>(x, y)); }
static public void startFill(Vector2R pos) { if (!spawnPoints.Keys.Contains(pos)) { spawnPoints[pos] = new int[2]; } }
public void SetOrientV2(Vector2R direction) { float radians = VMath.VectorToAngle(direction); orient = radians; shape.SetOrient(radians); }
public override void AIControl(AIMode aiMode) { //if (aiMode == AIMode.) tempTurretTimer += OrbIt.Game.Time.ElapsedGameTime.Milliseconds; if (tempTurretTimer > TurretTimerSeconds * 1000) { float nearest = float.MaxValue; Node nearNode = null; foreach (Node n in room.Groups.Player.entities) { float dist = Vector2R.Distance(parent.body.pos, n.body.pos); if (dist < nearest) { nearNode = n; nearest = dist; } } if (nearNode != null) { Vector2R dir = nearNode.body.pos - parent.body.pos; VMath.NormalizeSafe(ref dir); dir.Y *= -1; FireNode(dir); tempTurretTimer = 0; } } }
public void AddToOutgoing(Node node) { if (node != parent && node.HasComp <Tether>()) { if (outgoing.Contains(node)) { outgoing.Remove(node); node.Comp <Tether>().incoming.Remove(parent); if (lockedAngle && confiningVects.ContainsKey(node)) { confiningVects.Remove(node); } if (lockedDistance && lockedVals.ContainsKey(node)) { lockedVals.Remove(node); } } else { outgoing.Add(node); node.Comp <Tether>().incoming.Add(parent); if (lockedAngle && !confiningVects.ContainsKey(node)) { Vector2R v = (node.body.pos - parent.body.pos); VMath.NormalizeSafe(ref v); confiningVects.Add(node, v); } if (lockedDistance && !lockedVals.ContainsKey(node)) { lockedVals.Add(node, (int)(node.body.pos - parent.body.pos).Length()); } } } }
public static void FindIncidentFace(ref Vector2R[] v, Polygon RefPoly, Polygon IncPoly, int referenceIndex) { Vector2R referenceNormal = RefPoly.normals[referenceIndex]; // Calculate normal in incident's frame of reference referenceNormal = RefPoly.u * referenceNormal; // To world space referenceNormal = IncPoly.u.Transpose() * referenceNormal; // To incident's model space // Find most anti-normal face on incident polygon int incidentFace = 0; double minDot = float.MaxValue; for (int i = 0; i < IncPoly.vertexCount; ++i) { double dot = Vector2R.Dot(referenceNormal, IncPoly.normals[i]); if (dot < minDot) { minDot = dot; incidentFace = i; } } // Assign face vertices for incidentFace v[0] = IncPoly.u * IncPoly.vertices[incidentFace] + IncPoly.body.pos; incidentFace = incidentFace + 1 >= IncPoly.vertexCount ? 0 : incidentFace + 1; v[1] = IncPoly.u * IncPoly.vertices[incidentFace] + IncPoly.body.pos; }
public static bool CircletoCircle(Manifold m, Collider a, Collider b) { Circle ca = (Circle)a.shape; Circle cb = (Circle)b.shape; Vector2R normal = b.pos - a.pos; float distSquared = normal.LengthSquared(); double radius = a.radius + b.radius; if (distSquared >= (float)(radius * radius)) { m.contact_count = 0; return(false); } double distance = Math.Sqrt(distSquared); m.contact_count = 1; if (distance == 0) { m.penetration = ca.radius; m.normal = new Vector2R(1, 0); m.contacts[0] = a.pos; } else { m.penetration = radius - distance; m.normal = VMath.MultVectDouble(normal, 1.0 / distance); //normal / distance; m.contacts[0] = VMath.MultVectDouble(m.normal, ca.radius) + a.pos; //m.normal * ca.radius + a.body.position; } return(true); }
public void ChangeDiodeMode() { Vector2R pos = UserInterface.WorldMousePos; Node found = null; float shortedDistance = Int32.MaxValue; for (int i = room.MasterGroup.fullSet.Count - 1; i >= 0; i--) { Node n = (Node)room.MasterGroup.fullSet.ElementAt(i); if (!n.HasComp <Diode>()) { continue; } // find node that has been clicked, starting from the most recently placed nodes float distsquared = Vector2R.DistanceSquared(n.body.pos, pos); //if (distsquared < n.body.radius * n.body.radius) //{ if (distsquared < shortedDistance) { found = n; shortedDistance = distsquared; } //} } if (found != null) { Diode d = found.Comp <Diode>(); //int mode = (int)d.mode; //int countModes = Enum.GetValues(typeof(Diode.Mode)).Length; //d.mode = (Diode.Mode)((mode + 1) % countModes); found.body.orient += GMath.PI; } }
public void CreateRandomPolygon() { Vector2R mp = UserInterface.WorldMousePos; List <Vector2R> randVerts = new List <Vector2R>(); int count = Utils.random.Next(7) + 3; for (int i = 0; i < count; i++) { Vector2R v = new Vector2R(Utils.random.Next(200) - 100, Utils.random.Next(200) - 100); randVerts.Add(v); } Vector2R[] vertices = randVerts.ToArray(); //Node newNode = new Node(ShapeType.ePolygon); Node newNode = room.ActiveDefaultNode.CreateClone(); //Node.cloneNode(OrbIt.ui.sidebar.ActiveDefaultNode, newNode); Polygon poly = new Polygon(); poly.body = newNode.body; poly.SetCenterOfMass(vertices); //poly.Set(vertices, vertices.Length); newNode.body.shape = poly; newNode.body.pos = mp; room.SpawnNode(newNode); verts = new List <Vector2R>(); }
public void FireNode(Vector2R dir) { if (currentGroup == null) { return; } Node n = room.SpawnNode(currentGroup); if (n == null) { return; } n.body.velocity = dir * nodeSpeed; n.body.pos = parent.body.pos + parent.body.velocity * Math.Sign(nodeSpeed); n.body.radius = nodeRadius; Func <Collider, Collider, bool> excludeParent = (c1, c2) => c2.parent == n; parent.body.ExclusionCheckResolution += excludeParent; Action <Node, Node> onExit = null; onExit = (n1, n2) => { parent.body.OnCollisionExit -= onExit; parent.body.ExclusionCheckResolution -= excludeParent; }; parent.body.OnCollisionExit += onExit; lastFired = n; }
public static void ShowFloatGraph() { min = new Vector2R(float.MaxValue, float.MaxValue); max = new Vector2R(-float.MaxValue, -float.MaxValue); foreach (float f in floatData.Keys) { if (f < min.X) { min.X = f; } if (f > max.X) { max.X = f; } if (floatData[f] < min.Y) { min.Y = floatData[f]; } if (floatData[f] > max.Y) { max.Y = floatData[f]; } } drawing = true; }
public override void AffectOther(Node other) { if (!active) { return; } float dist = Vector2R.Distance(parent.body.pos, other.body.pos); //if (dist > radius) return; if (springMode == mode.PullOnly && dist < restdist) { return; } if (springMode == mode.PushOnly && dist > restdist) { return; } //if (dist > restdist * 2) return; if (deadzone.enabled && dist < deadzone.value) { dist = deadzone.value; } float stretch = dist - restdist; float strength = -stretch * multiplier / 10000f; Vector2R force = other.body.pos - parent.body.pos; VMath.NormalizeSafe(ref force); force *= strength; other.body.ApplyForce(force); }
public GridSystem(Room room, int cellsX, Vector2R position, int?GridWidth = null, int?GridHeight = null) { linesToDraw = new List <Line>(); this.position = position; this.room = room; this.gridWidth = GridWidth ?? room.WorldWidth; this.gridHeight = GridHeight ?? room.WorldHeight; this.cellsX = cellsX; //this.cellReach = cellReach; cellWidth = (int)Math.Ceiling((double)gridWidth / (double)cellsX); cellHeight = cellWidth; this.cellsY = (gridHeight - 1) / cellHeight + 1; //cellheight = gridheight / cellsY; grid = new List <Collider> [cellsX, cellsY]; for (int i = 0; i < cellsX; i++) { for (int j = 0; j < cellsY; j++) { grid[i, j] = new List <Collider>(); } } // arrayGrid = new IndexArray <Collider> [cellsX][]; for (int i = 0; i < cellsX; i++) { arrayGrid[i] = new IndexArray <Collider> [cellsY]; for (int j = 0; j < cellsY; j++) { arrayGrid[i][j] = new IndexArray <Collider>(100); } } bucketBags = new IndexArray <IndexArray <Collider> > [cellsX][]; for (int i = 0; i < cellsX; i++) { bucketBags[i] = new IndexArray <IndexArray <Collider> > [cellsY]; for (int j = 0; j < cellsY; j++) { bucketBags[i][j] = new IndexArray <IndexArray <Collider> >(20); } } // distToOffsets = GenerateReachOffsetsDictionary(); //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); int generateReach = gridWidth / 3; //GenerateAllReachOffsetsPerCoord(generateReach); //takes a shitload of time.. but only for the temproom? //stopwatch.Stop(); //string taken = stopwatch.Elapsed.ToString(); //Console.WriteLine("gridsystem generation time taken: " + taken); bucketLists = new List <List <Collider> > [cellsX, cellsY]; ///new attempt GenerateReachOffsetsArray(); }
/// <summary> Returns a non-unit vector up to the radius specified.</summary> public override Vector2 GetRightStick(float radius, bool drawRing = false) { Vector2 mousePos = new Vector2(newMouseState.X, newMouseState.Y); Vector2R playerPos = (player.node.body.pos - player.room.Camera.virtualTopLeft) * player.room.Camera.zoom + player.room.Camera.CameraOffsetVect; Vector2R dir = new Vector2R(mousePos.X, mousePos.Y) - playerPos; float lensqr = dir.LengthSquared(); if (lensqr > radius * radius) { VMath.NormalizeSafe(ref dir); //dir = dir.NormalizeSafe() * radius; } else { dir /= radius; } if (drawRing) { float scale = (radius * 2f) / 128;//Todo:Assets.TextureDict[Textures.Ring].Width; float alpha = (((float)Math.Sin(OrbIt.Game.Time.TotalGameTime.TotalMilliseconds / 300f) + 1f) / 4f) + 0.25f; player.room.Camera.Draw(Textures.Ring, player.node.body.pos, player.pColor * alpha, scale, (int)Layers.Under2); } return(new Vector2(dir.X, dir.Y)); }
public override void Draw(Textures texture, Vector2R position, Color color, Vector2 scalevect, float rotation, float depth) { var v = new SpriteVertex(new Vector3(position.X, position.Y, depth), scalevect * 128, rotation, (int)texture, color); //Mesh.SetData(ref v); pendingVertices.Add(v); }
public void RandomizeSpinningLines() { Color color = Utils.randomColor(); Vector2R center = parent.body.pos; float maxDist = (float)Utils.random.NextDouble() * distRange; //float angle = (float)Utils.random.NextDouble() * GMath.TwoPI; float speed = (float)Utils.random.NextDouble() * speedRange; float rotationSpeed = (float)Utils.random.NextDouble() * randRotationSpeed / 500f; float totalRotationSpeed = (float)Utils.random.NextDouble() * totalRotationSpeedRange / 500f; int numberOfLines = Utils.random.Next(numberOfLinesRange) + minNumberOfLines; int randmaxPermanentDraw = Utils.random.Next(maxPermanentDraw) + 1; //float angleIncrement = GMath.TwoPI / numberOfNodes; int copyCount = Utils.random.Next(maxCopyCount) + 1; float?copyOffset = Utils.random.Next(100) % 2 == 0 ? (float)Utils.random.NextDouble() * GMath.PIbyTwo : (null as float?); //as if int distCopyCount = Utils.random.Next(maxDistCopyCount) + 1; for (int i = 0; i < distCopyCount; i++) { SpinningLine spin = new SpinningLine(center, rotationSpeed, totalRotationSpeed, minDist, maxDist + minDist, speed, numberOfLines, copyCount, randmaxPermanentDraw, copyOffset, parent.body.color); spin.dist = maxDist / distCopyCount * i; spinningLines.Enqueue(spin); } }
public override void OnSpawn() { parent.collision.isSolid = false; parent.basicdraw.DrawLayer = Layers.Under4; parent.body.OnCollisionStay += (c1, c2) => { if (!active || c2 == null) { return; } if (directionMode == DirectionMode.Relative) { int sign = 1; if (slowdown) { sign = -1; } //float tempAngle = (float)Math.Atan2(c2.body.velocity.Y, c2.body.velocity.X); //todo:implement c2.body.velocity *= 1f + (multiplier / 100f * sign); } else if (directionMode == DirectionMode.Absolute) { Vector2R force = new Vector2R(absoluteX, absoulteY) * (multiplier / 100f); c2.body.velocity += force; } }; }
public override void PlayerControl(Input input) { Vector2R newstickpos = input.GetRightStick(torchReach, true).toV2R(); Vector2R pos = newstickpos * torchReach; torchNode.body.pos = parent.body.pos + pos; float positive = 0f; float negative = 0f; if (input is PcFullInput) { positive = (input.BtnDown(InputButtons.RightTrigger_Mouse1) ? 1f : 0f) * torchMultiplier; negative = (input.BtnDown(InputButtons.LeftTrigger_Mouse2) ? 1f : 0f) * torchMultiplier; } else { positive = input.newInputState.RightTriggerAnalog * torchMultiplier; negative = input.newInputState.LeftTriggerAnalog * torchMultiplier; } total = positive - negative; //torchNode.Comp<Gravity>().multiplier = total; if (torchNode != activeComp.parent) { System.Diagnostics.Debugger.Break(); } activeComp.multiplier = total; }
public BigTony() : base() { //OrbIt.ui.SetSidebarActive(false); onCollisionEnter = delegate(Node s, Node t) { if (t != null && !Player.players.Select(p => p.node).Contains(t)) { t.body.color = Add(s.body.color, new Color(colorChange, colorChange, colorChange)); //changed node to s } }; onCollisionExit = delegate(Node s, Node t) { if (t != null && !Player.players.Select(p => p.node).Contains(t)) { t.body.color = Color.White; } }; accel = new Vector2R(0, 0); absaccel = 0.2f; friction = 0.01f; before = (n) => { if (n != bigtony) { n.body.mass = smallmass; } }; after = (n) => { if (n != bigtony) { n.body.mass = bigmass; } }; InitializePlayers(); }
public override void Draw() { Color col = Color.White; if (total > 0) { col = Color.Lerp(Color.White, Color.Green, total / torchMultiplier); } else { col = Color.Lerp(Color.White, Color.Red, total / torchMultiplier * -1f); } Vector2R position = torchNode.body.pos; if (position == Vector2R.Zero) { position = parent.body.pos; } else { room.Camera.DrawLine(position, parent.body.pos, 2f, col, (int)Layers.Over3); } torchNode.body.color = col; room.Camera.Draw(Textures.Ring, position, Color.Black, torchNode.body.scale, torchNode.body.orient, (int)Layers.Over4); room.Camera.Draw(MagicToRune[magicType], position, col, torchNode.body.scale, VMath.VectorToAngle(position - parent.body.pos) + GMath.PIbyTwo, (int)Layers.Over3); }
//failed generic experiment -- for now /* * public T SuppliedOrDefault<T>(string id, ModifierInfo mi, T defaultval) * { * T ret; * if (mi.fpInfos.ContainsKey(id)) * { * var val = mi.fpInfos[id].GetValue(); * if (typeof(T) == val.GetType()) * { * return Convert.ChangeType(val, typeof(T)); * } * else * { * * } * } * else * { * ret = defaultval; * } * return ret; * * } */ public static float Defaultered(string id, Dictionary <string, dynamic> args, float defaultval) { float ret; if (args.ContainsKey(id)) { var val = args[id]; if (val.GetType() == typeof(float) || val.GetType() == typeof(int)) { return((float)val); } else if (val.GetType() == typeof(Vector2R)) { Vector2R vect = (Vector2R)(val); ret = (vect.X + vect.Y) / 10; } else { ret = defaultval; } } else { ret = defaultval; } return(ret); }
public void ResizeBeam(float size) { float halfheight = (int)(size / 2f); float halfwidth = beamThickness / 2f; float angle = VMath.VectorToAngle(stick); Polygon p = (Polygon)beamNode.body.shape; p.SetBox(halfwidth, halfheight, false); Vector2R endpos = parent.body.pos + (stick.NormalizeSafe() * halfheight); beamNode.body.pos = endpos; p.SetOrient(angle); Vector2R normal = new Vector2R(-stick.Y, stick.X).NormalizeSafe(); if (normal == Vector2R.Zero) { return; } Color c = Color.Blue; int r = Math.Sign(128 - c.R) * 10; int g = Math.Sign(128 - c.G) * 10; int b = Math.Sign(128 - c.B) * 10; for (int i = 0; i < beamThickness; i++) { Vector2R offset = normal * (i - beamThickness / 2); Vector2R start = parent.body.pos + offset; Vector2R end = start + (stick.NormalizeSafe() * size); int seed = (int)DelegateManager.Triangle((i + tempColorVal), maxColorVal); Color newcol = new Color(c.R + r * seed, c.G + g * seed, c.B + g * seed); // *0.5f; room.Camera.DrawLine(start, end, 1f, newcol, (int)Layers.Under2); } tempColorVal += colorValSpeed; }
public static void VectorSineComposite(Dictionary <string, dynamic> args, ModifierInfo mi) { Vector2R vector = ((Vector2R)mi.fpInfos["v1"].GetValue()); float timer = (Defaultered("m1", mi, -9999)); float amp = (Defaultered("amp", args, (OrbIt.ScreenHeight / 5))); float period = (Defaultered("period", args, (OrbIt.ScreenWidth / 4))); float vshift = (Defaultered("vshift", args, (OrbIt.ScreenHeight / 2))); int times = (int)(Defaultered("composite", args, 2)); //float min = (Defaultered("min", args, 0.1f)); //float highest = (Defaultered("highest", args, 20f)); //float o1 = velocity.Length() / highest; //o1 = o1 * (max - min) + min; //vector.Y = (float)Math.Sin(vector.X / (period / (Math.PI * 2))) * amp + Game1.sHeight / 2; //vector.Y = SineComposite(vector.X, amp, period, vshift, times); //float test = args["test"]; //test++; //args["test"] = test; float x = timer; if (x == -9999) { x = vector.X; } args["yval"] = SineComposite(x, amp, period, vshift, times); mi.fpInfos["v1"].SetValue(vector); }
public override void AffectOther(Node other) { if (onlyObstructors && !other.HasActiveComponent <Obstructor>()) { return; } if (onlyAvailableObs && other.HasActiveComponent <Obstructor>() && !other.Comp <Obstructor>().Available) { return; } float dist = Vector2R.Distance(other.body.pos, parent.body.pos); if (dist < radius) { if (nodeDistances.Count < maxWalls) { nodeDistances.Add(new KeyValuePair <float, Node>(dist, other)); nodeDistances.Sort((a, b) => a.Key.CompareTo(b.Key)); } else if (nodeDistances.Count > 0 && dist < nodeDistances.Last().Key) { nodeDistances.Add(new KeyValuePair <float, Node>(dist, other)); nodeDistances.Sort((a, b) => a.Key.CompareTo(b.Key)); nodeDistances.RemoveAt(nodeDistances.Count - 1); } } }