Exemple #1
0
        public TrackSwitchBox(Vector2 position, bool global, bool canFloat, bool canBounce)
            : base(position, 32f, 32f, safe: true)
        {
            colorLerp = (LocalTrackSwitchState = CommunalHelperModule.Session.TrackInitialState) == TrackSwitchState.On ? 0f : 1f;

            this.global    = global;
            this.canFloat  = canFloat;
            this.canBounce = canBounce;

            SurfaceSoundIndex  = SurfaceIndex.ZipMover;
            start              = Position;
            sprite             = CommunalHelperModule.SpriteBank.Create("trackSwitchBox");
            sprite.Position    = new Vector2(Width, Height) / 2f;
            sprite.OnLastFrame = anim => {
                if (anim == "switch")
                {
                    canSwitch = true;
                }
            };

            Add(Sfx = new SoundSource()
            {
                Position = new Vector2(Width / 2, Height / 2)
            });

            Add(sprite);
            Add(sine         = new SineWave(0.5f, 0f));
            bounce           = Wiggler.Create(1f, 0.5f);
            bounce.StartZero = false;
            Add(bounce);
            Add(shaker    = new Shaker(on: false));
            OnDashCollide = Dashed;
        }
Exemple #2
0
 private void Switch(TrackSwitchState state)
 {
     if (initialSwitchState == TrackSwitchState.None)
     {
         return;
     }
     switchState = initialSwitchState == state ? TrackSwitchState.On : TrackSwitchState.Off;
 }
        // METHOD: TrackSwitch
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Primary constructor with initial state
        /// </summary>
        /// 
        /// <param name="name">Track switch name</param>
        /// <param name="controllerID">ID of the TrackController assigned to the switch</param>
        /// <param name="trunkID">ID of the trunk block connecting to the switch</param>
        /// <param name="branchClosedID">ID of the branch blocks connecting to the switch when closed</param>
        /// <param name="branchOpenID">ID of the branch blocks connecting to the switch when open</param>
        //--------------------------------------------------------------------------------------
        public TrackSwitch(string name, string controllerID, string trunkID, string branchClosedID, string branchOpenID)
        {
            Name = name;
            ControllerId = controllerID;
            TrunkId = trunkID;
            BranchClosedId = branchClosedID;
            BranchOpenId = branchOpenID;

            m_state = TrackSwitchState.Closed;
        }
Exemple #4
0
 public static void SwitchTracks(Scene scene, TrackSwitchState state)
 {
     foreach (StationBlockTrack track in scene.Tracker.GetEntities <StationBlockTrack>())
     {
         if (track.MasterOfGroup)
         {
             foreach (StationBlockTrack child in track.Group)
             {
                 child.Switch(state);
             }
         }
     }
 }
Exemple #5
0
 public static bool Switch(Scene scene, TrackSwitchState state, bool global = false)
 {
     if (state == LocalTrackSwitchState)
     {
         return(false);
     }
     LocalTrackSwitchState = state;
     SwitchTracks(scene, state);
     if (global)
     {
         CommunalHelperModule.Session.TrackInitialState = state;
     }
     return(true);
 }
Exemple #6
0
        // METHOD: TrackSwitch
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Primary constructor with initial state
        /// </summary>
        ///
        /// <param name="name">Track switch name</param>
        /// <param name="controllerID">ID of the TrackController assigned to the switch</param>
        /// <param name="trunk">the trunk of the switch</param>
        /// <param name="branch1">the first branch of the switch</param>
        /// <param name="branch2">the second branch of the switch</param>
        /// <remarks>
        /// The TrackBlock that you pass as trunk should be connected to Branch
        /// The TrackBlock that you pass as branch1 should be connected to Trunk1
        /// The TrackBlock that you pass as branch2 should be connected to Trunk2
        /// </remarks>
        //--------------------------------------------------------------------------------------
        public TrackSwitch(string name, string controllerID, TrackBlock trunk, TrackBlock branchClosed, TrackBlock branchOpen)
        {
            Name         = name;
            ControllerId = controllerID;

            TrunkId        = trunk.Name;
            BranchClosedId = branchClosed.Name;
            BranchOpenId   = branchOpen.Name;

            // initial state
            BranchClosed = branchClosed;
            BranchOpen   = branchOpen;
            Trunk        = trunk;

            m_state = TrackSwitchState.Closed;
        }
        // METHOD: TrackSwitch
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Primary constructor with initial state
        /// </summary>
        /// 
        /// <param name="name">Track switch name</param>
        /// <param name="controllerID">ID of the TrackController assigned to the switch</param>
        /// <param name="trunk">the trunk of the switch</param>
        /// <param name="branch1">the first branch of the switch</param>
        /// <param name="branch2">the second branch of the switch</param>
        /// <remarks>
        /// The TrackBlock that you pass as trunk should be connected to Branch
        /// The TrackBlock that you pass as branch1 should be connected to Trunk1
        /// The TrackBlock that you pass as branch2 should be connected to Trunk2
        /// </remarks>
        //--------------------------------------------------------------------------------------
        public TrackSwitch(string name, string controllerID, TrackBlock trunk, TrackBlock branchClosed, TrackBlock branchOpen)
        {
            Name = name;
            ControllerId = controllerID;

            TrunkId = trunk.Name;
            BranchClosedId = branchClosed.Name;
            BranchOpenId = branchOpen.Name;

            // initial state
            BranchClosed = branchClosed;
            BranchOpen = branchOpen;
            Trunk = trunk;

            m_state = TrackSwitchState.Closed;
        }
Exemple #8
0
        // METHOD: Switch
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Changes the state of the switch
        /// </summary>
        //--------------------------------------------------------------------------------------
        public void Switch()
        {
            // if closed, open
            if (m_state == TrackSwitchState.Closed)
            {
                m_state = TrackSwitchState.Open;

                if (BranchOpen.PreviousBlock == null)
                {
                    BranchOpen.PreviousBlock   = Trunk;
                    Trunk.NextBlock            = BranchOpen;
                    BranchClosed.PreviousBlock = null;
                }
                else
                {
                    BranchOpen.NextBlock   = Trunk;
                    Trunk.PreviousBlock    = BranchOpen;
                    BranchClosed.NextBlock = null;
                }
            }
            else
            {
                m_state = TrackSwitchState.Closed;

                if (BranchClosed.NextBlock == null)
                {
                    BranchClosed.NextBlock = Trunk;
                    Trunk.PreviousBlock    = BranchClosed;
                    BranchOpen.NextBlock   = null;
                }
                else
                {
                    BranchClosed.PreviousBlock = Trunk;
                    Trunk.NextBlock            = BranchClosed;
                    BranchOpen.PreviousBlock   = null;
                }
            }
        }
Exemple #9
0
        public StationBlockTrack(EntityData data, Vector2 offset)
            : base(data.Position + offset)
        {
            Depth = Depths.SolidsBelow;

            initialSwitchState = switchState = data.Enum("trackSwitchState", TrackSwitchState.None);
            if (CommunalHelperModule.Session.TrackInitialState == TrackSwitchState.Off && initialSwitchState != TrackSwitchState.None)
            {
                Switch(TrackSwitchState.Off);
            }

            trackStatePercent = switchState is TrackSwitchState.On or TrackSwitchState.None ? 0f : 1f;

            Horizontal      = data.Bool("horizontal");
            multiBlockTrack = data.Bool("multiBlockTrack", false);
            Collider        = new Hitbox(Horizontal ? data.Width : 8, Horizontal ? 8 : data.Height);

            nodeRect1 = new Rectangle((int)X, (int)Y, 8, 8);
            nodeRect2 = new Rectangle((int)(X + Width - 8), (int)(Y + Height - 8), 8, 8);

            initialNodeData1 = new Node(nodeRect1.X, nodeRect1.Y);
            initialNodeData2 = new Node(nodeRect2.X, nodeRect2.Y);

            Color indicatorColor         = data.HexColorNullable("indicatorColor") ?? Color.White;
            Color indicatorIncomingColor = data.HexColorNullable("indicatorIncomingColor") ?? Color.White;
            bool  hasIndicator           = data.Bool("indicator", true);

            Vector2 dir = Horizontal ? Vector2.UnitX : Vector2.UnitY;

            switch (data.Enum("moveMode", MoveMode.None))
            {
            case MoveMode.ForwardForce:
                initialNodeData1.PushForce    = Horizontal ? Vector2.UnitX : Vector2.UnitY;
                initialNodeData1.HasIndicator = hasIndicator;
                if (hasIndicator)
                {
                    initialNodeData1.IndicatorColor         = indicatorColor;
                    initialNodeData1.IndicatorIncomingColor = indicatorIncomingColor;
                }
                OneWayDir = dir;
                break;

            case MoveMode.ForwardOneWay:
                OneWayDir = dir;
                break;

            case MoveMode.BackwardForce:
                initialNodeData2.PushForce    = Horizontal ? -Vector2.UnitX : -Vector2.UnitY;
                initialNodeData2.HasIndicator = hasIndicator;
                if (hasIndicator)
                {
                    initialNodeData2.IndicatorColor         = indicatorColor;
                    initialNodeData2.IndicatorIncomingColor = indicatorIncomingColor;
                }
                OneWayDir = -dir;
                break;

            case MoveMode.BackwardOneWay:
                OneWayDir = -dir;
                break;

            default:
                break;
            }

            if (Horizontal)
            {
                initialNodeData1.NodeRight  = initialNodeData2;
                initialNodeData1.TrackRight = this;

                initialNodeData2.NodeLeft  = initialNodeData1;
                initialNodeData2.TrackLeft = this;

                trackRect = new Rectangle((int)X + 8, (int)Y, (int)Width - 16, (int)Height);
                length    = Width - 8;
            }
            else
            {
                initialNodeData1.NodeDown  = initialNodeData2;
                initialNodeData1.TrackDown = this;

                initialNodeData2.NodeUp  = initialNodeData1;
                initialNodeData2.TrackUp = this;

                trackRect = new Rectangle((int)X, (int)Y + 8, (int)Width, (int)Height - 16);
                length    = Height - 8;
            }

            from     = initialNodeData1.Center;
            to       = initialNodeData2.Center;
            sparkAdd = (from - to).SafeNormalize(3f).Perpendicular();

            float num = (from - to).Angle();

            sparkDirFromA = num + (float)Math.PI / 8f;
            sparkDirFromB = num - (float)Math.PI / 8f;
            sparkDirToA   = num + (float)Math.PI - (float)Math.PI / 8f;
            sparkDirToB   = num + (float)Math.PI + (float)Math.PI / 8f;
        }
Exemple #10
0
        // METHOD: Switch
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Changes the state of the switch
        /// </summary>
        //--------------------------------------------------------------------------------------
        public void Switch()
        {
            // if closed, open
            if (m_state == TrackSwitchState.Closed)
            {
                m_state = TrackSwitchState.Open;

                if (BranchOpen.PreviousBlock == null)
                {
                    BranchOpen.PreviousBlock = Trunk;
                    Trunk.NextBlock = BranchOpen;
                    BranchClosed.PreviousBlock = null;
                }
                else
                {
                    BranchOpen.NextBlock = Trunk;
                    Trunk.PreviousBlock = BranchOpen;
                    BranchClosed.NextBlock = null;
                }
            }
            else
            {
                m_state = TrackSwitchState.Closed;

                if (BranchClosed.NextBlock == null)
                {
                    BranchClosed.NextBlock = Trunk;
                    Trunk.PreviousBlock = BranchClosed;
                    BranchOpen.NextBlock = null;
                }
                else
                {
                    BranchClosed.PreviousBlock = Trunk;
                    Trunk.NextBlock = BranchClosed;
                    BranchOpen.PreviousBlock = null;
                }
            }
        }