예제 #1
0
파일: Ball.cs 프로젝트: i2um1/VolleyBall
 void CollisionWithThePlayer(double nextX, double nextY, Player player)
 {
     double left = player.Left() + player.RealWidth() / 2.0, top = player.Top() + player.RealWidth() / 2.0;
     double radius2 = this.RealWidth() * this.RealWidth();
     double centerX = nextX + this.RealWidth() / 2.0, centerY = nextY + this.RealHeight() / 2.0;
     double dx = left - centerX, dy = top - centerY;
     if (!isCollisionPlayer && Math.Pow(dx, 2) + Math.Pow(dy, 2) <= radius2)
     {
         Velocity.X = -dx * Physics.ImpactPlayer;
         Velocity.Y = -dy * Physics.ImpactPlayer;
         isCollisionPlayer = true;
     }
     else
         isCollisionPlayer = false;
 }
예제 #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
        public Game(Canvas canvas, Fence fence, Ball ball, Player[] players, TextBlock result)
        {
            this.canvas = canvas;
            this.fence = fence;
            this.ball = ball;
            this.players = players;
            this.result = result;

            timer = new DispatcherTimer();
            timer.Interval = new System.TimeSpan(speed);
            timer.Tick += new System.EventHandler(timer_Tick);

            wait = new DispatcherTimer();
            wait.Tick += new System.EventHandler(wait_Tick);
            wait.Interval = new TimeSpan(0, 0, 0, 0, timeWait);

            fence.SetLeft((canvas.RealWidth() - fence.Width) / 2.0);
            fence.SetTop(canvas.RealHeight() - fence.Height);

            Reset();
        }