示例#1
0
    // Resets the ball
    public void ResetBall()
    {
        // initialize variables
        myRigidBody2D = GetComponent <Rigidbody2D>();

        // initialize directional velocities
        upperRightVel = new Vector2(1, 0.5f);
        upperLeftVel  = new Vector2(-1, 0.5f);
        lowerLeftVel  = new Vector2(-1, -0.5f);
        lowerRightVel = new Vector2(1, -0.5f);

        // reset position and velocity of ball
        transform.position     = BallSpawn.transform.position;
        myRigidBody2D.velocity = Vector2.zero;

        if (DebugDirection != BallDirection.NoDebugDirection)
        {
            direction = DebugDirection;
        }
        else
        {
            direction = randomizeBallDirection();
        }
        SetVelocityDirection();
        velocity *= MovementSpeed;
    }
示例#2
0
        private void ResetPositions(PlayerEnum playerEnum)
        {
            ballX     = 39;
            ballY     = 11;
            holdTicks = 10;
            PlayerClass player1 = FindPlayerEnum(PlayerEnum.Player1);
            PlayerClass player2 = FindPlayerEnum(PlayerEnum.Player2);

            ballDirection = BallDirection.UpLeft;
            if (player1 != null)
            {
                player1.paddle = 8;
                if (playerEnum == PlayerEnum.Player2)
                {
                    ballDirection = BallDirection.UpLeft;
                }
            }
            if (player2 != null)
            {
                player2.paddle = 8;
                if (playerEnum == PlayerEnum.Player1)
                {
                    ballDirection = BallDirection.UpRight;
                }
            }
        }
示例#3
0
文件: Ball.cs 项目: VitGanchuk/Lines
 private void OnJumpTimerTick(object sender, EventArgs e)
 {
     if (_direction == BallDirection.Up)
     {
         if (pbBall.Location.Y == -2)
         {
             _size      = _size == BallSize.Initial ? BallSize.HalfSqueezed : (_size == BallSize.HalfSqueezed ? BallSize.FullSqueezed : BallSize.FullSqueezed);
             _direction = _size == BallSize.FullSqueezed ? BallDirection.Down : BallDirection.Up;
         }
         else
         {
             pbBall.Location = _size == BallSize.Initial ? new Point(pbBall.Location.X, pbBall.Location.Y - 1) : new Point(pbBall.Location.X, pbBall.Location.Y - 2);
             _size           = _size == BallSize.FullSqueezed ? BallSize.HalfSqueezed : (_size == BallSize.HalfSqueezed ? BallSize.Initial : BallSize.Initial);
         }
     }
     else if (_direction == BallDirection.Down)
     {
         if (pbBall.Location.Y == 2 || pbBall.Location.Y == 4 || pbBall.Location.Y == 6)
         {
             _size           = _size == BallSize.Initial ? BallSize.HalfSqueezed : (_size == BallSize.HalfSqueezed ? BallSize.FullSqueezed : BallSize.FullSqueezed);
             pbBall.Location = _size == BallSize.HalfSqueezed || _size == BallSize.FullSqueezed ? new Point(pbBall.Location.X, pbBall.Location.Y + 2) : pbBall.Location;
             _direction      = _size == BallSize.FullSqueezed ? BallDirection.Up : BallDirection.Down;
         }
         else
         {
             _size           = _size == BallSize.FullSqueezed ? BallSize.HalfSqueezed : (_size == BallSize.HalfSqueezed ? BallSize.Initial : BallSize.Initial);
             pbBall.Location = _size == BallSize.Initial ? new Point(pbBall.Location.X, pbBall.Location.Y + 1) : pbBall.Location;
         }
     }
 }
示例#4
0
文件: Ball.cs 项目: VitGanchuk/Lines
 private void StartJump()
 {
     _direction      = BallDirection.Up;
     _timer          = new System.Windows.Forms.Timer();
     _timer.Interval = 40;
     _timer.Tick    += OnJumpTimerTick;
     _timer.Start();
 }
示例#5
0
 public Settings()
 {
     GameOver      = false;
     Points        = 10;
     Score         = 0;
     Speed         = 14;
     Width         = 14;
     Height        = 14;
     direction     = Direction.Stop;
     ballDirection = BallDirection.Stop;
 }
示例#6
0
        public static BallDirection ReflectedVertically(this BallDirection direction)
        {
            switch (direction)
            {
            case BallDirection.DownLeft:
                return(BallDirection.UpLeft);

            case BallDirection.DownRight:
                return(BallDirection.UpRight);

            case BallDirection.UpLeft:
                return(BallDirection.DownLeft);

            case BallDirection.UpRight:
                return(BallDirection.DownRight);
            }

            return(BallDirection.DownLeft);
        }
示例#7
0
        public BallDirection(BallDirection a)
        {
            if (a._x > 0)
            {
                X = 1;
            }
            else
            {
                X = -1;
            }

            if (a._y > 0)
            {
                Y = 1;
            }
            else
            {
                Y = -1;
            }
        }
示例#8
0
文件: FootBall.cs 项目: PKode/Kinect
 public override void Initialize(Vector3 startDirection, float speed, BallDirection bd)
 {
     base.Initialize(startDirection, speed, bd);
     this.ballDirection = bd;
     //this.speed = startDirection * speed;
 }
示例#9
0
文件: Ball.cs 项目: PKode/Kinect
 public virtual void Initialize(Vector3 direction, float speed, BallDirection bd)
 {
 }
示例#10
0
 // Use this for initialization
 void Start()
 {
     initPosition_Ball = new Vector3(0, -17.69f, 0);
     ballDir           = BallDirection.UP;
 }
示例#11
0
 public static Vector2 ToVector2(this BallDirection direction)
 {
     return(VECTOR2S[(int)direction]);
 }
示例#12
0
 private void InitializationState()
 {
     x             = 60;
     y             = 15;
     moveDirection = (BallDirection) new Random().Next(0, 6);
 }
示例#13
0
 public Ball(int size, float speed, float defaultBallBumpSpeedIncreaseFactor) : base(size, size)
 {
     Speed = speed;
     BumpSpeedIncreaseFactor = defaultBallBumpSpeedIncreaseFactor;
     Direction = new BallDirection(1, 1);
 }
示例#14
0
 public void Initialize(Vector2 startPosition, BallDirection direction)
 {
     rigidbody2D.position = startPosition;
     rigidbody2D.velocity = direction.ToVector2() * Game.BallSpeed;
 }
示例#15
0
文件: Ball.cs 项目: VitGanchuk/Lines
 public Ball()
 {
     InitializeComponent();
     __size     = BallSize.Initial;
     _direction = BallDirection.Stop;
 }
示例#16
0
 public void SetBallData(byte[] data)
 {
     x             = data[0];
     y             = data[1];
     moveDirection = (BallDirection)data[2];
 }
示例#17
0
        public char[,] Move(char[,] playingField)
        {
            switch (moveDirection)
            {
            case BallDirection.leftUp:
                x -= 1;
                y += 1;
                break;

            case BallDirection.left:
                x -= 1;
                break;

            case BallDirection.leftDown:
                x -= 1;
                y -= 1;
                break;

            case BallDirection.rightUp:
                x += 1;
                y += 1;
                break;

            case BallDirection.right:
                x += 1;
                break;

            case BallDirection.rightDown:
                x += 1;
                y -= 1;
                break;
            }
            if (y.IsOneOf(1, 28))
            {
                moveDirection = wallRebound[moveDirection];
            }
            else if ('#'.IsOneOf(GamePerformer.playingField[y, x - 3], GamePerformer.playingField[y, x + 3]))
            {
                if (moveDirection == BallDirection.left)
                {
                    if (IsLeftMiddle())
                    {
                        moveDirection = BallDirection.right;
                    }
                    else if (GamePerformer.playingField[y + 3, x - 3] == ' ')
                    {
                        moveDirection = BallDirection.rightUp;
                    }
                    else if (GamePerformer.playingField[y - 3, x - 3] == ' ')
                    {
                        moveDirection = BallDirection.rightDown;
                    }
                }
                else if (moveDirection == BallDirection.right)
                {
                    if (IsRightMiddle())
                    {
                        moveDirection = BallDirection.left;
                    }
                    else if (GamePerformer.playingField[y + 3, x + 3] == ' ')
                    {
                        moveDirection = BallDirection.rightUp;
                    }
                    else if (GamePerformer.playingField[y - 3, x + 3] == ' ')
                    {
                        moveDirection = BallDirection.rightDown;
                    }
                }
                else
                {
                    if (moveDirection.IsOneOf(BallDirection.leftUp, BallDirection.leftDown) && IsLeftMiddle())
                    {
                        moveDirection = BallDirection.right;
                    }
                    else if (moveDirection.IsOneOf(BallDirection.rightUp, BallDirection.rightDown) && IsRightMiddle())
                    {
                        moveDirection = BallDirection.left;
                    }
                    else
                    {
                        moveDirection = plateRebound[moveDirection];
                    }
                }
            }
            else if (x - 3 == 0 || x + 3 == 119)
            {
                InitializationState();
            }
            return(RenderingBall(playingField));
        }
示例#18
0
        private void MoveBall()
        {
            // move ball
            switch (dir)
            {
                case BallDirection.RightTop:
                    this.ballLeft += BallStep;
                    this.ballTop -= BallStep;
                    break;
                case BallDirection.RightBottom:
                    this.ballLeft += BallStep;
                    this.ballTop += BallStep;
                    break;
                case BallDirection.LeftTop:
                    this.ballLeft -= BallStep;
                    this.ballTop -= BallStep;
                    break;
                case BallDirection.LeftBottom:
                    this.ballLeft -= BallStep;
                    this.ballTop += BallStep;
                    break;
            }

            if (this.isGameOver)
            {
                // has ball left canvas
                if (this.ballLeft + BallWidth < 0)
                {
                    // stop current game
                    this.Stop();

                    // ask user for another game
                    MessageBoxResult result = MessageBox.Show(
                        "Game Over!\nAnother Game?", "Another Pong Game",
                        MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.Yes)
                        this.Start();
                }

                return;
            }

            // collision detection
            if (this.ballLeft <= (BallWidth + PaddleMargin))
            {
                if (this.IsLeftPaddleDefending())
                {
                    if (dir == BallDirection.LeftTop)
                        dir = BallDirection.RightTop;
                    else if (dir == BallDirection.LeftBottom)
                        dir = BallDirection.RightBottom;
                }
                else
                {
                    // game is over ... let ball move out of the window
                    this.isGameOver = true;
                }
            }
            else if (this.ballLeft >= (this.ActualWidth - 2 * BallWidth - PaddleMargin))
            {
                if (dir == BallDirection.RightTop)
                    dir = BallDirection.LeftTop;
                else if (dir == BallDirection.RightBottom)
                    dir = BallDirection.LeftBottom;
            }

            if (this.ballTop <= PaddleMargin)
            {
                if (dir == BallDirection.RightTop)
                    dir = BallDirection.RightBottom;
                else if (dir == BallDirection.LeftTop)
                    dir = BallDirection.LeftBottom;
            }
            else if (this.ballTop >= (this.ActualHeight - BallHeight))
            {
                if (dir == BallDirection.RightBottom)
                    dir = BallDirection.RightTop;
                else if (dir == BallDirection.LeftBottom)
                    dir = BallDirection.LeftTop;
            }

            this.MoveRightPaddleIfNecessary();
        }
 void Start()
 {
     RandomizeForce(1);
     m_currentDirection = BallDirection.Forward;
 }
示例#20
0
        public void Start()
        {
            this.InitControls();

            this.isRightPaddleMoving = false;
            this.isRunning = true;
            this.isGameOver = false;

            this.dir = BallDirection.RightTop;

            this.timer.Start();
        }
示例#21
0
        private void ComputeLogic()
        {
            PlayerClass player1 = FindPlayerEnum(PlayerEnum.Player1);
            PlayerClass player2 = FindPlayerEnum(PlayerEnum.Player2);

            if (player1.paddle < 0)
            {
                player1.paddle = 0;
            }
            if (player1.paddle > 18)
            {
                player1.paddle = 18;
            }
            if (gameState == GameState.Normal)
            {
                if (player2.paddle < 0)
                {
                    player2.paddle = 0;
                }
                if (player2.paddle > 18)
                {
                    player2.paddle = 18;
                }
            }

            if (holdTicks > 0)
            {
                holdTicks--;
                return;
            }

            switch (ballDirection)
            {
            case BallDirection.UpRight:
                if (ballY == 0)
                {
                    ballDirection = BallDirection.DownRight;
                    ComputeLogic();
                    Bell();
                    break;
                }
                if (ballX == 77)
                {
                    if (gameState == GameState.Training || (player2.paddle - 1 <= ballY && ballY < player2.paddle + 5))
                    {
                        ballDirection = BallDirection.UpLeft;
                        ComputeLogic();
                        Bell();
                        break;
                    }
                }
                if (ballX == 78)
                {
                    ScorePoint(FindPlayerEnum(PlayerEnum.Player1));
                    break;
                }
                ballY--;
                ballX++;
                break;

            case BallDirection.DownRight:
                if (ballY == 21)
                {
                    ballDirection = BallDirection.UpRight;
                    ComputeLogic();
                    Bell();
                    break;
                }
                if (ballX == 77)
                {
                    if (gameState == GameState.Training || (player2.paddle - 1 <= ballY && ballY < player2.paddle + 5))
                    {
                        ballDirection = BallDirection.DownLeft;
                        ComputeLogic();
                        Bell();
                        break;
                    }
                }
                if (ballX == 78)
                {
                    ScorePoint(FindPlayerEnum(PlayerEnum.Player1));
                    break;
                }
                ballY++;
                ballX++;
                break;

            case BallDirection.DownLeft:
                if (ballY == 21)
                {
                    ballDirection = BallDirection.UpLeft;
                    ComputeLogic();
                    Bell();
                    break;
                }
                if (ballX == 1)
                {
                    if (player1.paddle - 1 <= ballY && ballY < player1.paddle + 5)
                    {
                        ballDirection = BallDirection.DownRight;
                        ComputeLogic();
                        Bell();
                        break;
                    }
                }
                if (ballX == 0)
                {
                    ScorePoint(FindPlayerEnum(PlayerEnum.Player2));
                    break;
                }
                ballY++;
                ballX--;
                break;

            case BallDirection.UpLeft:
                if (ballY == 0)
                {
                    ballDirection = BallDirection.DownLeft;
                    ComputeLogic();
                    Bell();
                    break;
                }
                if (ballX == 1)
                {
                    if (player1.paddle - 1 <= ballY && ballY < player1.paddle + 5)
                    {
                        ballDirection = BallDirection.UpRight;
                        ComputeLogic();
                        Bell();
                        break;
                    }
                }
                if (ballX == 0)
                {
                    ScorePoint(FindPlayerEnum(PlayerEnum.Player2));
                    break;
                }
                ballY--;
                ballX--;
                break;
            }
        }
示例#22
0
    }    // End Update

    public void ChangeDirection(BallDirection _direction)
    {
        ballDir = _direction;
    }