Example #1
0
    void OnDrawGizmos()
    {
#if UNITY_EDITOR
        var size = GetComponent <SpriteRenderer>().size;
        var rot  = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z);
        var mat  = Gizmos.matrix;
        Gizmos.matrix = transform.localToWorldMatrix;
        if (Application.isPlaying)
        {
            size = OriginalSize;
        }
        Gizmos.color = Color.yellow;
        Gizmos.DrawWireCube(Vector3.zero, new Vector3(size.x, size.y, 0));
        Gizmos.color = Color.red;
        Gizmos.DrawWireCube(Vector3.zero + new Vector3(0, -size.y / 2, 0f), new Vector3(size.x, 0.05f, 0));

        if (transform.parent != null)
        {
            ParentPiston = transform.parent.GetComponent <Piston>();
        }
        if (ParentPiston != null)
        {
            Gizmos.matrix = mat;
            Gizmos.DrawLine(transform.position, ParentPiston.transform.position);
        }
#endif
    }
Example #2
0
        public override void OnInspectorGUI()
        {
            if (target == null)
            {
                return;
            }

            Piston myTarget = (Piston)target;

            InitShared();

            myTarget.Direction = EditorGUILayout.Vector2Field("Direction", myTarget.Direction);
            myTarget.Distance  = EditorGUILayout.FloatField("Distance", myTarget.Distance);



            myTarget.SpeedAB = EditorGUILayout.FloatField("SpeedAB", myTarget.SpeedAB);
            myTarget.SpeedBA = EditorGUILayout.FloatField("SpeedBA", myTarget.SpeedBA);

            myTarget.StartOffset = EditorGUILayout.FloatField("StartDelay", myTarget.StartOffset);

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }
Example #3
0
        private void MovePiston(Piston piston)
        {
            if (piston.y - piston.Height > 0 || piston.y + piston.Height < panel1.Height) //if on the screen (can't remove inside foreach)
            {
                if (qt == null)                                                           //make new qt
                {
                    qt = new QuadTree(new Rectangle(panel1.Width / 2, panel1.Height / 2, panel1.Width, panel1.Height), (int)accuracy.Value);
                    foreach (Ball ball in balls)
                    {
                        qt.Insert(ball);
                    }
                }
                List <Ball> ballz = qt.Query(new Rectangle(panel1.Width / 2, piston.y, panel1.Width, piston.Height), new List <Ball>()); //get all balls contacting piston
                foreach (Ball ball in ballz)
                {
                    if (ball.v.y < 0)
                    {
                        //ball.B = new SolidBrush(Color.White); //make ball white
                        ball.v.y *= -1; //flip ball

                        ball.p.y += 20;
                    }
                    else
                    {
                        //ball.B = new SolidBrush(Color.Purple); //make ball white
                        ball.v.y *= -1; //flip ball

                        ball.p.y -= 20;
                    }
                    piston.ySpeed += (int)(ball.v.y * 0.5); //add half the balls speed to piston
                }
                piston.y += piston.ySpeed;                  //move piston
                gbuff.FillRectangle(piston.B, 0, piston.y, panel1.Width, piston.Height);
            }
        }
Example #4
0
    // public method to invole the MoveRoutine
    public void Move(Vector3 destinationPos, float delayTime = 0.25f)
    {
        if (isMoving)
        {
            return;
        }

        if (m_board != null)
        {
            Node targetNode = m_board.FindNodeAt(destinationPos);

            if (targetNode != null && m_currentNode != null)
            {
                if (m_currentNode.LinkedNodes.Contains(targetNode))
                {
                    Door   door   = m_board.FindDoorAt(destinationPos);
                    Piston piston = m_board.FindPistonAt(destinationPos);
                    if ((door != null && !door.IsOpen) || (piston != null && !piston.IsDown))
                    {
                        return;
                    }
                    // start the coroutine MoveRoutine
                    StartCoroutine(MoveRoutine(destinationPos, delayTime));
                }
                else
                {
                    Debug.Log("Mover: " + m_currentNode.name + " not connected " + targetNode.name);
                }
            }
        }
    }
Example #5
0
    public int CompareTo(object _rhs)
    {
        Piston rhs = _rhs as Piston;

        Debug.Assert(rhs != null);
        return(transform.IsChildOf(rhs.transform) ? 1 : -1);
    }
 void CreatePistons(int pistonCount)
 {
     Piston[] pistons = new Piston[pistonCount];
     for (int i = 0; i < pistons.Length; i++)
     {
         pistons[i] = new Piston();
     }
 }
Example #7
0
 public void PistonWarning(Piston piston)
 {
     EffectsAudioSource.PlayOneShot(PistonWarningSound);
     CameraShake.ShakeCamera(0.5f);
     PistonWarningParticles.transform.position   = piston.transform.position + Quaternion.Euler(0, 0, piston.transform.rotation.eulerAngles.z) * new Vector3(0f, 0f, 0);
     PistonWarningParticles.transform.rotation   = piston.transform.rotation;
     PistonWarningParticles.transform.localScale = new Vector3(piston.OriginalSize.x, 1f, 1f);
     PistonWarningParticles.Emit(100);
 }
Example #8
0
    public void OnSceneGUI()
    {
        reference = this.target as Piston;


        Handles.color = Color.red;

        Handles.DrawLine(reference.transform.position, reference.transform.position + (reference.transform.right * reference.extendedDistance));
    }
 public Engine()
 {
     Crankshaft = new Crankshaft();
     Pistons    = new Piston[8];
     Pistons[0] = new Piston();
     Pistons[1] = new Piston();
     Pistons[2] = new Piston();
     Pistons[3] = new Piston();
 }
Example #10
0
    void ButtonPushed(EButton.ColorType color)
    {
        if (clickCount >= 3)
        {
            return;
        }

        clickCount++;

        if (phase == Phase.FIRST)
        {
            Piston piston = firstPistons[clickCount - 1];
            if (piston)
            {
                piston.color = color;
            }


            if (firstCombination[clickCount - 1] != color)
            {
                first_failed = true;
            }

            if (clickCount >= 3)
            {
                resetDelay.Start();
                if (!first_failed)
                {
                    OnFirstPhase.Invoke();
                }
            }
        }
        else if (phase == Phase.SECOND)
        {
            Piston piston = secondPistons[clickCount - 1];
            if (piston)
            {
                piston.color = color;
            }


            if (secondCombination[clickCount - 1] != color)
            {
                second_failed = true;
            }

            if (clickCount >= 3)
            {
                resetDelay.Start();
                if (!second_failed)
                {
                    OnSecondPhase.Invoke();
                }
            }
        }
    }
Example #11
0
 public void PistonActivated(Piston piston)
 {
     ActivePistons.Add(piston);
     EffectsAudioSource.PlayOneShot(PistonActivationSound);
     CameraShake.ShakeCamera(2f);
     PistonActivationParticles.transform.position   = piston.transform.position + Quaternion.Euler(0, 0, piston.transform.rotation.eulerAngles.z) * new Vector3(0f, 0.1f, 0);
     PistonActivationParticles.transform.rotation   = piston.transform.rotation;
     PistonActivationParticles.transform.localScale = new Vector3(piston.OriginalSize.x, 1f, 1f);
     PistonActivationParticles.Emit(200);
 }
Example #12
0
        protected void OnSceneGUI()
        {
            Piston myTarget = (Piston)target;


            Vector3 dstPos = myTarget.transform.position + new Vector3(myTarget.Direction.x, myTarget.Direction.y).normalized *myTarget.Distance;

            Handles.DrawLine(myTarget.transform.position, dstPos);
            Handles.SphereCap(0, dstPos, Quaternion.identity, 1.0f);
        }
Example #13
0
        public Engine()
        {
            Crankshaft = new Crankshaft();
            Pistons    = new Piston[8];

            for (int i = 0; i < 4; i++)
            {
                Pistons[i] = new Piston();
            }
        }
Example #14
0
 public void HandlePiston(bool isEnabled, Piston piston)
 {
     if (isEnabled)
     {
         piston.enabled = isEnabled;
     }
     else
     {
         piston.StopWorking();
     }
 }
Example #15
0
 public void HandlePiston(bool isEnabled, Piston piston)
 {
     if (isEnabled)
     {
         piston.enabled = isEnabled;
     }
     else
     {
         piston.StopWorking();
     }
 }
Example #16
0
    public void StandingOn(Piston piston)
    {
        if (_standingOn != piston)
        {
            _standingOn = piston;

            foreach (var p in ChildPistons(_standingOn))
            {
                p.AllowedToActivate = true;
            }
        }
    }
Example #17
0
 public void PistonToevoegen(Piston piston)
 {
     if (this.pistons != null)
     {
         if (this.pistons.GetLength(0) < maxCrankshaft)
         {
             this.pistons[this.pistons.GetLength(0) + 1] = piston;
         }
         else
         {
             this.pistons[0] = piston;
         }
     }
 }
Example #18
0
        public AbstractEngine(int size, bool turbo)
        {
            this.size  = size;
            this.turbo = turbo;

            // Create a camshaft, piston and 4 spark plugs...
            camshaft   = new Camshaft();
            piston     = new Piston();
            sparkPlugs = new SparkPlug[]
            {
                new SparkPlug(), new SparkPlug(),
                new SparkPlug(), new SparkPlug()
            };
        }
Example #19
0
        public Piston[] AddPistons(int amount)
        {
            if (amount > maxPistons && amount < minPistons)
            {
                amount = minPistons;
            }
            Pistons = amount;

            Piston[] pistons = new Piston[amount];
            for (int i = 0; i < pistons.Length; i++)
            {
                pistons[i] = new Piston();
            }
            return(pistons);
        }
Example #20
0
    public void ShowArrows(bool state)
    {
        if (m_board == null)
        {
            Debug.LogWarning("PlayerCompass ShowArrows() ERROR: no Board found!");
        }
        if (m_arrows == null || m_arrows.Count != Board.directions.Length)
        {
            Debug.LogWarning("PlayerCompass ShowArrows() ERROR: no arrows found!");
        }

        if (m_board.PlayerNode != null)
        {
            for (int i = 0; i < Board.directions.Length; i++)
            {
                Node neighbor = m_board.PlayerNode.FindNeighborAt(Board.directions[i]);
                if (neighbor == null || !state)
                {
                    m_arrows[i].SetActive(false);
                }
                else
                {
                    Piston piston = null;
                    Door   door   = null;
                    if (neighbor != null)
                    {
                        door   = m_board.FindDoorAt(new Vector3(neighbor.Coordinate.x, 0f, neighbor.Coordinate.y));
                        piston = m_board.FindPistonAt(new Vector3(neighbor.Coordinate.x, 0f, neighbor.Coordinate.y));
                    }
                    if (door != null && !door.IsOpen)
                    {
                        m_arrows[i].SetActive(false);
                    }
                    else if (piston != null && !piston.IsDown)
                    {
                        m_arrows[i].SetActive(false);
                    }
                    else
                    {
                        bool activeState = m_board.PlayerNode.LinkedNodes.Contains(neighbor);
                        m_arrows[i].SetActive(activeState);
                    }
                }
            }
        }
        ResetArrows();
        MoveArrows();
    }
Example #21
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        reference = this.target as Piston;

        if (GUILayout.Button("Exend"))
        {
            reference.IsEnabled = true;
        }

        if (GUILayout.Button("Retract"))
        {
            reference.IsEnabled = false;
        }
    }
Example #22
0
 // Use this for initialization
 void Awake()
 {
     ChildPistons    = new List <Piston>();
     _boxCollider    = GetComponent <BoxCollider2D>();
     _spriteRenderer = GetComponent <SpriteRenderer>();
     ParentPiston    = null;
     if (transform.parent != null)
     {
         ParentPiston = transform.parent.GetComponent <Piston>();
     }
     transform.parent     = Level.Instance.transform;
     OriginalSize         = _spriteRenderer.size;
     OriginalPosition     = transform.position;
     _boxCollider.enabled = false;
     _timer = -Delay;
     Loaded = true;
     // UpdateSize();
 }
Example #23
0
        private void Panel1_Click(object sender, EventArgs e)
        {
            Point point = panel1.PointToClient(MousePosition);

            if (GoClicked && !AddPistons.Checked)
            {
                numericUpDown1.Value++;
                Ball newBall = new Ball(Color.Black, rnd.Next(panel1.Width - (int)Radius.Value * 2) + 1, rnd.Next(panel1.Height - (int)Radius.Value * 2) + 1, rnd.Next(-(int)Speed.Value, (int)Speed.Value), (int)Radius.Value);
                balls.Add(newBall);
                DrawBall(newBall);
            }
            else if (GoClicked)
            {
                Piston newPiston = new Piston(Color.Blue, point.Y, (int)numericUpDown2.Value);
                pistons.Add(newPiston);
                MovePiston(newPiston);
            }
        }
Example #24
0
        protected virtual void InitShared()
        {
            Piston myTarget = (Piston)target;


            myTarget.CurrentMode = (Piston.Mode)EditorGUILayout.EnumPopup("Mode", myTarget.CurrentMode);
            myTarget.Trigger     = (Piston.TriggerType)EditorGUILayout.EnumPopup("TriggerType", myTarget.Trigger);


            if (myTarget.Trigger == Piston.TriggerType.CustomTrigger)
            {
                myTarget.TriggerObject = (Trigger)EditorGUILayout.ObjectField(myTarget.TriggerObject, typeof(Trigger));
            }

            if (myTarget.CurrentMode == Piston.Mode.Switching)
            {
                myTarget.StopDelayA = EditorGUILayout.FloatField("StopDurationA", myTarget.StopDelayA);
                myTarget.StopDelayB = EditorGUILayout.FloatField("StopDurationB", myTarget.StopDelayB);
            }
        }
Example #25
0
 // Use this for initialization
 void Start()
 {
     pistons = new Piston[width, height];
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             Vector2 mathPos = ToCoord(i, j);
             float   x       = mathPos.x,
                     y       = mathPos.y;
             pistons[i, j] = new Piston(pistonPrefab, toWorldSpace(i, j), speed, x, y);
             pistons[i, j].GoTo(Calc(x, y, Time.time));
         }
     }
     pistonPrefab.SetActive(false);
     if (Instance == null)
     {
         Instance = this;
     }
 }
Example #26
0
    public static void initPistons(MyGridProgram myGrid)
    {
        List <IMyPistonBase> blocks = new List <IMyPistonBase>();
        List <CustomData>    customData;
        Piston tmpPiston;

        myGrid.GridTerminalSystem.GetBlocksOfType <IMyPistonBase>(blocks);
        foreach (IMyPistonBase block in blocks)
        {
            if (block.CustomName.Contains("[Drone]"))
            {
                customData = CustomData.getCustomData(block.CustomData);
                if (customData.Count > 0)
                {
                    tmpPiston = new Piston(block, customData);
                    Piston.pistons.Add(tmpPiston);
                }
            }
        }
    }
Example #27
0
    public void assignAnchorsToConnector()
    {
        string connectorId = CustomData.findKeyFromList("connectorId", this.customData).value;

        if (!String.IsNullOrEmpty(connectorId))
        {
            this.connectorId  = int.Parse(connectorId);
            this.anchorTop    = Anchor.getAnchorByConnector(this.connectorId, "top");
            this.anchorBottom = Anchor.getAnchorByConnector(this.connectorId, "bottom");
            this.piston       = Piston.getPistonByConnector(this.connectorId);
            if (this.anchorTop != null && this.anchorBottom != null)
            {
                this.isAnchored = true;
            }
        }
        else
        {
            Display.printDebug("[WARN] Connector without a defined ID. Name: " + this.block.CustomName);
            this.isAnchored = false;
        }
    }
        static void Main(string[] args)
        {
            // Some configs for simulation
            double pistonStroke = 2;
            int    engineMaxRPM = 1000;

            int startCountDown = 3;

            // Below 2 values in reality should be the same, for demo purpose, make engine refresh rate slower so that piston moves slower
            int milSecPerFrame             = 300;
            int engineRefreshRatePerMilSec = 10;


            // Initialize all components
            IEngine    engine    = new Engine(engineMaxRPM);
            IPiston    piston    = new Piston(pistonStroke);
            ISparkPlug sparkPlug = new SparkPlug();

            // Initialize controller
            Controller controller = new Controller(engine, piston, sparkPlug);


            // Start engine
            controller.StartEngine();

            // Starting ...
            for (int i = 1; i <= startCountDown; i++)
            {
                Console.Write($"\r{startCountDown+1- i}");
                Thread.Sleep(1 * 1000);
            }


            // Simulate engine
            while (true)
            {
                Thread.Sleep(milSecPerFrame);
                controller.EngineOperate(engineRefreshRatePerMilSec);
            }
        }
Example #29
0
 public virtual void Visit(Piston piston)
 {
     pistonCount++;
 }
 public virtual void Visit(Piston piston)
 {
     Console.WriteLine("Diagnosing the piston");
 }
Example #31
0
 public void initiate()
 {
     AnchoredConnector.setAllConnectorState(false);
     Piston.setAllPistonState(false);
     this.type = "mothership";
 }