public Train(float x, float y, Rotation rotation, float speed = 0.05f) : base(x, y) { Direction = rotation; From = RailUtils.OppositeRotation(rotation); Rotate = RailUtils.RotationToAngle(Direction); this.speed = speed; this.radialSpeed = 90 * speed; }
static void panel_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right && _ghostObject != null) { _rotation = RailUtils.Rotate(_rotation); _ghostObject = _inputType == null ? null : GridObject.InstantiateObject(_inputType, 0, 0, 1, 1, _rotation); } if (OnClick != null) { OnClick(e.X, e.Y, e.Button); } }
private static void Grid_RailAdded(RailArgs railArgs) { IRail iRail = railArgs.Rail; if (iRail == null) { return; } Rotation[] sides = railArgs.Sides; TrainNetwork network = null; foreach (Rotation rot in sides) { GridObject go = _grid[RailUtils.GetOffsetForRotation(rot, railArgs.RawObject.Location)]; if (go == null || go == iRail) { continue; } IRail rail2 = go as IRail; if (rail2 == null) { continue; } TrainNetwork newNetwork = GetNetworkForRail(rail2); if (network == null) { if (RailUtils.DoRailsAttach(railArgs.RawObject, go)) { network = newNetwork; network.Add(iRail); } } else if (newNetwork != network) { network = CombineNetwork(network, newNetwork); } } if (network == null) { TrainNetwork newNetwork = new TrainNetwork(); //No need to register the object, it does so himself in its constructor newNetwork.Add(iRail); } Rail rail = iRail as Rail; if (rail != null) { rail.RailUpdated += rail_RailUpdated; } }
/// <summary> /// Gets the directions for the trains current location in the grid /// </summary> /// <param name="train">The train that you would like to check its directions for</param> /// <returns>An array with Rotation values that indicate where the train can go. Empty array if not successfull</returns> public static Rotation[] GetDirections(Train train) { Point location = train.Location; GridObject go = _grid[location]; if (go == null) { return(new Rotation[0]); } IRail rail = go as IRail; if (rail == null) { return(new Rotation[0]); } return(RailUtils.RailDirectionToRotation(rail.RailDirection, RailUtils.OppositeRotation(train.Direction))); }
static void rail_RailUpdated(RailArgs args) { Rotation[] sides = args.Sides; TrainNetwork network = GetNetworkForRail(args.Rail); foreach (Rotation side in sides) { GameObject go = _grid[RailUtils.GetOffsetForRotation(side, args.RawObject.Location)]; if (go == null) { continue; } IRail rail = go as IRail; if (rail == null) { continue; } TrainNetwork compareNetwork = GetNetworkForRail(rail); if (network != compareNetwork) { CombineNetwork(network, compareNetwork); } } }