Example #1
0
File: Ball.cs Project: Suhvan/ppong
        void OnCollisionEnter2D(Collision2D col)
        {
            if (PongGame.Instance.IsClient)
            {
                return;
            }

            Racket racket = col.gameObject.GetComponent <Racket>();

            if (racket != null)
            {
                float sumX = 0;
                for (int i = 0; i < col.contactCount; i++)
                {
                    sumX += col.GetContact(i).point.x;
                }

                float forceX = sumX / col.contactCount - racket.transform.position.x;
                float forceY = CurrentFieldSide == PongGame.Side.A ? 1 : -1;

                if (Mathf.Abs(CachedTransform.position.y) > Mathf.Abs(racket.transform.position.y))
                {
                    forceY *= -1;
                }
                racket.OnBallHit();
                SetVelocity(new Vector2(forceX, forceY));
            }
        }
Example #2
0
 public PlayerAI(Racket racket, Difficulty dif) : base(racket)
 {
     m_dif            = dif;
     m_racketMaxSpeed = dif == Difficulty.Unreal ? AI_SPEED * 2 : AI_SPEED;
     m_accel          = dif == Difficulty.Unreal ? AI_ACCEL * 2 : AI_ACCEL;
     m_curSpeed       = 0;
     GenereateNewShift();
 }
Example #3
0
 public PlayerBase(Racket racket)
 {
     m_racket       = racket;
     m_racket.Owner = this;
     Score          = 0;
 }
Example #4
0
 public PlayerLocal(Racket racket) : base(racket)
 {
 }
Example #5
0
 public PlayerInterpolated(Racket racket) : base(racket)
 {
     InterpHelper = new InterpolatingHelper();
 }
Example #6
0
 public PlayerRemote(Racket racket) : base(racket)
 {
 }