public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f) { if (connection.Name == "velocity_in") { currVelocity = XMLExtensions.ParseVector2(signal, false); } else { base.ReceiveSignal(stepsTaken, signal, connection, source, sender, power); } }
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f) { if (connection.Name == "velocity_in") { TargetVelocity = XMLExtensions.ParseVector2(signal, errorMessages: false); } else { base.ReceiveSignal(stepsTaken, signal, connection, source, sender, power, signalStrength); } }
public override void ReceiveSignal(Signal signal, Connection connection) { if (connection.Name == "velocity_in") { steeringAdjustSpeed = DefaultSteeringAdjustSpeed; steeringInput = XMLExtensions.ParseVector2(signal.value, errorMessages: false); steeringInput.X = MathHelper.Clamp(steeringInput.X, -100.0f, 100.0f); steeringInput.Y = MathHelper.Clamp(-steeringInput.Y, -100.0f, 100.0f); } else { base.ReceiveSignal(signal, connection); } }
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power) { switch (connection.Name) { case "position_in": Vector2 receivedPos = XMLExtensions.ParseVector2(signal, false); Vector2 centerPos = new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y); Vector2 offset = receivedPos - centerPos; offset.Y = -offset.Y; targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset)); IsActive = true; break; case "trigger_in": item.Use((float)Timing.Step, sender); break; } }
public CustomDeformation(XElement element) : base(element, new CustomDeformationParams(element)) { phase = Rand.Range(0.0f, MathHelper.TwoPi); if (element == null) { deformRows.Add(new Vector2[] { Vector2.Zero, Vector2.Zero }); deformRows.Add(new Vector2[] { Vector2.Zero, Vector2.Zero }); } else { for (int i = 0; ; i++) { string row = element.GetAttributeString("row" + i, ""); if (string.IsNullOrWhiteSpace(row)) { break; } string[] splitRow = row.Split(' '); Vector2[] rowVectors = new Vector2[splitRow.Length]; for (int j = 0; j < splitRow.Length; j++) { rowVectors[j] = XMLExtensions.ParseVector2(splitRow[j]); } deformRows.Add(rowVectors); } } if (deformRows.Count() == 0 || deformRows.First() == null || deformRows.First().Length == 0) { return; } var configDeformation = new Vector2[deformRows.First().Length, deformRows.Count]; for (int x = 0; x < configDeformation.GetLength(0); x++) { for (int y = 0; y < configDeformation.GetLength(1); y++) { configDeformation[x, y] = deformRows[y][x]; } } //construct an array for the desired resolution, //interpolating values if the resolution configured in the xml is smaller //deformation = new Vector2[Resolution.X, Resolution.Y]; float divX = 1.0f / Resolution.X, divY = 1.0f / Resolution.Y; for (int x = 0; x < Resolution.X; x++) { float normalizedX = x / (float)(Resolution.X - 1); for (int y = 0; y < Resolution.Y; y++) { float normalizedY = y / (float)(Resolution.Y - 1); Point indexTopLeft = new Point( Math.Min((int)Math.Floor(normalizedX * (configDeformation.GetLength(0) - 1)), configDeformation.GetLength(0) - 1), Math.Min((int)Math.Floor(normalizedY * (configDeformation.GetLength(1) - 1)), configDeformation.GetLength(1) - 1)); Point indexBottomRight = new Point( Math.Min(indexTopLeft.X + 1, configDeformation.GetLength(0) - 1), Math.Min(indexTopLeft.Y + 1, configDeformation.GetLength(1) - 1)); Vector2 deformTopLeft = configDeformation[indexTopLeft.X, indexTopLeft.Y]; Vector2 deformTopRight = configDeformation[indexBottomRight.X, indexTopLeft.Y]; Vector2 deformBottomLeft = configDeformation[indexTopLeft.X, indexBottomRight.Y]; Vector2 deformBottomRight = configDeformation[indexBottomRight.X, indexBottomRight.Y]; Deformation[x, y] = Vector2.Lerp( Vector2.Lerp(deformTopLeft, deformTopRight, (normalizedX % divX) / divX), Vector2.Lerp(deformBottomLeft, deformBottomRight, (normalizedX % divX) / divX), (normalizedY % divY) / divY); } } }
public Holdable(Item item, XElement element) : base(item, element) { body = item.body; Pusher = null; if (element.GetAttributeBool("blocksplayers", false)) { Pusher = new PhysicsBody(item.body.width, item.body.height, item.body.radius, item.body.Density) { BodyType = BodyType.Dynamic, CollidesWith = Physics.CollisionCharacter, CollisionCategories = Physics.CollisionItemBlocking, Enabled = false }; Pusher.FarseerBody.OnCollision += OnPusherCollision; Pusher.FarseerBody.FixedRotation = false; Pusher.FarseerBody.IgnoreGravity = true; } handlePos = new Vector2[2]; scaledHandlePos = new Vector2[2]; Vector2 previousValue = Vector2.Zero; for (int i = 1; i < 3; i++) { int index = i - 1; string attributeName = "handle" + i; var attribute = element.Attribute(attributeName); // If no value is defind for handle2, use the value of handle1. var value = attribute != null?ConvertUnits.ToSimUnits(XMLExtensions.ParseVector2(attribute.Value)) : previousValue; handlePos[index] = value; previousValue = value; } canBePicked = true; if (attachable) { prevMsg = DisplayMsg; prevPickKey = PickKey; prevRequiredItems = new Dictionary <RelatedItem.RelationType, List <RelatedItem> >(requiredItems); if (item.Submarine != null) { if (item.Submarine.Loading) { AttachToWall(); Attached = false; } else //the submarine is not being loaded, which means we're either in the sub editor or the item has been spawned mid-round { if (Screen.Selected == GameMain.SubEditorScreen) { //in the sub editor, attach AttachToWall(); } else { //spawned mid-round, deattach DeattachFromWall(); } } } } }