示例#1
0
        //Collision ::
        //if (this.x + this.texture.Width * this.scale * HITBOXSCALE / 2 < otherSprite.x - otherSprite.texture.Width * otherSprite.scale / 2) return false;

        public static void UpdatePhysics(Sprites.Ball Ball, Controllables.Player Player, Incontrollables.AI AI)
        {
            #region Collision
            if (Player.Position.X + (Player.Texture.Width * Global.Scale.X) >= Ball.Position.X + (Ball.Texture.Width * Global.Scale.X) &&
                Player.Position.Y + (Player.Texture.Height * Global.Scale.Y) <= Ball.Position.Y + (Ball.Texture.Height * Global.Scale.Y) &&
                Player.Position.Y >= Ball.Position.Y)
            {
                Ball.Speed = -Ball.Speed;
            }
            else
            {
            }
            #endregion

            BallPhysics(Ball, Player, AI);
        }
示例#2
0
        public static void UpdateAI(Sprites.Ball Ball, Sprites.Racket AIRacket)
        {
            if (AIRacket.Position.Y + ((AIRacket.Texture.Height / 2) * Global.Scale.Y) < Ball.Position.Y)
            {
                AIRacket.Speed.Y = 0.3f;
            }

            if (AIRacket.Position.Y + ((AIRacket.Texture.Height / 2) * Global.Scale.Y) > Ball.Position.Y)
            {
                AIRacket.Speed.Y = -0.3f;
            }

            if (AIRacket.Position.Y + ((AIRacket.Texture.Height / 2) * Global.Scale.Y) == Ball.Position.Y)
            {
                AIRacket.Speed.Y = 0f;
            }
        }
示例#3
0
        private static void BallPhysics(Sprites.Ball Ball, Controllables.Player Player, Incontrollables.AI AI)
        {
            if (Ball.Position.Y <= 0)
            {
                Ball.Speed.Y = -Ball.Speed.Y;
            }

            if (Ball.Position.Y + Ball.Texture.Height >= Global.Resolution.Y)
            {
                Ball.Speed.Y = -Ball.Speed.Y;
            }

            if (Ball.Position.X + (Ball.Texture.Width * Global.Scale.X) / 2 < 0)
            {
                Ball.Reset();
                AI.Score++;
            }

            if (Ball.Position.X - (Ball.Texture.Width * Global.Scale.X) / 2 > Global.Resolution.X + Ball.Texture.Width)
            {
                Ball.Reset();
                Player.Score++;
            }
        }