Example #1
0
        public void SetProjectedPosition()
        {
            Ball testBall = new Ball();

            testBall.CurrentTop  = CurrentTop;
            testBall.CurrentLeft = CurrentLeft;
            testBall.HDirection  = HDirection;
            testBall.VDirection  = VDirection;

            if (testBall.HDirection == Horizantal.RIGHT)
            {
                while (testBall.CurrentLeft < ((widthOfConsole - 1) - marginFromSideOfScreenToPaddle))
                {
                    testBall.Move(1);
                }

                ProjectedColumn = testBall.CurrentLeft;
                ProjectedRow    = testBall.CurrentTop;
            }

            else if (testBall.HDirection == Horizantal.LEFT)
            {
                while (testBall.CurrentLeft > marginFromSideOfScreenToPaddle)
                {
                    testBall.Move(1);
                }

                ProjectedColumn = testBall.CurrentLeft;
                ProjectedRow    = testBall.CurrentTop;
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            // set up console
            SetWindowSize(widthOfConsole, heightOfConsole); // set up console dimensions
            ForegroundColor = textColor;
            BackgroundColor = backgroundColor;
            CursorVisible   = false; // make the cursor invisible
            SetScreenSquaresToNull();
            GameOver += GameOverHandler;

            SetUpNewGame();  // set up the new game

            // main game loop
            while (true)
            {
                SetCursorPosition(0, 0);

                if (KeyAvailable)
                {
                    ConsoleKey keyPressed = ReadKey().Key;

                    if (keyPressed == ConsoleKey.UpArrow)
                    {
                        rPaddle.Move(0);
                    }

                    else if (keyPressed == ConsoleKey.DownArrow)
                    {
                        rPaddle.Move(1);
                    }
                }

                lPaddle.Move();

                ball.Move();
            }
        }
Example #3
0
        private void timer_Tick(object sender, EventArgs e)
        {
            Double ticks = Environment.TickCount;

            ball.Move(ticks - ticks_old, ball.speed);
            ball.Collision(RectFeld, tbCountLeft, tbCountRight);

            //Player 1 - paddle on the left
            if (Keyboard.IsKeyDown(Key.S))
            {
                paddle1.move(ticks - ticks_old, paddleSpeed);
            }
            else if (Keyboard.IsKeyDown(Key.W))
            {
                paddle1.move(ticks - ticks_old, -paddleSpeed);
            }

            //Player 2 - paddle on the right
            if (dlg.autoMode == false)
            {
                p2CanMove = true;
            }
            else
            {
                p2CanMove = false;
            }
            if (p2CanMove == true)
            {
                if (Keyboard.IsKeyDown(Key.Down))
                {
                    paddle2.move(ticks - ticks_old, paddleSpeed);
                }
                else if (Keyboard.IsKeyDown(Key.Up))
                {
                    paddle2.move(ticks - ticks_old, -paddleSpeed);
                }
            }

            ball.collisionPaddle(paddle1.Rect);
            ball.collisionPaddle(paddle2.Rect);

            paddle1.collision(RectFeld);
            paddle2.collision(RectFeld);

            getFPS(ticks);

            slider();

            SecBerechnung(ticks);

            //Automatischer Paddle
            if (dlg.autoMode == true && ball.Vx > 0)
            {
                double t  = Canvas.GetLeft(paddle2.Rect) - ball.X / ball.Vx;
                double yt = ball.Y + ball.Vy / t;

                if (yt < Canvas.GetTop(paddle2.Rect) + paddle2.Rect.Height / 2 && Canvas.GetTop(paddle2.Rect) > Canvas.GetTop(RectFeld) + 10)
                {
                    paddle2.move(ticks - ticks_old, -paddleSpeed * ball.speed * extraSpeed);
                }
                else if (yt > Canvas.GetTop(paddle2.Rect) + paddle2.Rect.Height / 2 && Canvas.GetTop(paddle2.Rect) + paddle2.Rect.Height < Canvas.GetTop(RectFeld) + RectFeld.Height - 10)
                {
                    paddle2.move(ticks - ticks_old, paddleSpeed * ball.speed * extraSpeed);
                }
            }

            ticks_old = ticks;
        }