示例#1
0
文件: Ball.cs 项目: i2um1/VolleyBall
 void HitTheGround(double x, double y, double width, double height, Score score)
 {
     if (y + this.RealHeight() > height)
         if (2.0 * x + this.RealWidth() < width)
             ++score.Player2;
         else
             ++score.Player1;
 }
示例#2
0
文件: Ball.cs 项目: i2um1/VolleyBall
        public void Move(double width, double height, Score score, Fence fence, Player[] players)
        {
            Velocity.Y = PowerOfAttraction();

            double x = this.Left() + Speed * Velocity.X, y = this.Top() + Speed * Velocity.Y;
            ImpactOnTheBorder(x, y, width, height);
            HitTheGround(x, y, width, height, score);

            this.SetLeft(x);
            this.SetTop(y);

            double nextX = this.Left() + Speed * Velocity.X, nextY = this.Top() + Speed * PowerOfAttraction();
            CollisionWithTheFence(nextX, nextY, fence);
            for (int i = 0; i < players.Length; ++i)
                CollisionWithThePlayer(nextX, nextY, players[i]);
        }
示例#3
0
文件: Game.cs 项目: i2um1/VolleyBall
        void Reset(bool isNewGame = true, bool queueFirstPlayer = true)
        {
            if (isNewGame)
                score = new Score();
            UpdateResult();

            players[0].SetLeft((fence.Left() - players[0].RealWidth()) / 2.0);
            players[0].SetTop(canvas.RealHeight() - players[0].RealHeight());
            players[1].SetLeft(fence.Left() * 1.5 + fence.Width - players[1].RealWidth() / 2.0);
            players[1].SetTop(canvas.RealHeight() - players[1].RealHeight());
            ball.SetLeft(players[0].RealWidth() + (queueFirstPlayer ? fence.Left() / 2.0 - ball.RealWidth() : fence.Left() + ball.RealWidth()));
            ball.SetTop(canvas.RealHeight() - players[1].RealHeight() - ball.RealHeight() * 1.5);
            players[0].Floor = players[0].Top();
            players[1].Floor = players[1].Top();

            players[0].VelocityJump = players[1].VelocityJump = 0;
            players[0].IsJump = players[1].IsJump = false;
            players[0].Direction = players[1].Direction = Direction.None;

            ball.Velocity = new Vector(0, 0);
        }