예제 #1
0
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            var existingBall = system.GetBallAt(e.Location);

            if (existingBall != null)
            {
                ballEditor1.SetBall(existingBall);
                return;
            }

            var addBallDialog = new AddBallDialog(e.Location, pictureBox1.Width, pictureBox1.Height);
            var dialogResult  = addBallDialog.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                var newBall = new PhysicBall
                {
                    Location =
                    {
                        [0] = addBallDialog.Position.X,
                        [1] = addBallDialog.Position.Y
                    },
                    Speed =
                    {
                        [0] = addBallDialog.Speed.X,
                        [1] = addBallDialog.Speed.Y
                    },
                    Radius = addBallDialog.Radius,
                    Mass   = addBallDialog.Mass
                };

                system.Balls.Add(newBall);
            }
        }
예제 #2
0
        public void SetBall(PhysicBall ball)
        {
            if (_ball != null)
            {
                UnSubScribe();
            }

            _ball = ball;

            SetBallsPropertiesToEditor();
            SubScribe();
        }
예제 #3
0
    private void OnTriggerEnter(Collider other)
    {
        RaycasterBall b = other.GetComponent <RaycasterBall>();

        if (b != null)
        {
            b.velocity += b.velocity.normalized * increasedSpeed;
            effect.transform.position = b.transform.position;
            effect.Play();
        }

        PhysicBall pb = other.GetComponent <PhysicBall>();

        if (pb != null)
        {
            var r = pb.GetComponent <Rigidbody>();
            r.AddForce(r.velocity.normalized * increasedSpeed, ForceMode.Impulse);
            effect.transform.position = pb.transform.position;
            effect.Play();
        }
    }