Example #1
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                Application.Exit(); return;
            }
            if (e.KeyCode == Keys.Enter)
            {
                t.Enabled = true;
            }

            if (e.KeyCode == Keys.W)
            {
                left.setY(left.getY() - left.getSpeed());
            }

            if (e.KeyCode == Keys.S)
            {
                left.setY(left.getY() + left.getSpeed());
            }
            if (e.KeyCode == Keys.Up)
            {
                right.setY(right.getY() - right.getSpeed());
            }

            if (e.KeyCode == Keys.Down)
            {
                right.setY(right.getY() + right.getSpeed());
            }
        }
Example #2
0
        public void collision(Paddle pad)
        {
            //checks if a bullet has collided with another bullet
            int padx = pad.getX();
            int pady = pad.getY();
            int padw = pad.getWidth();
            int padh = pad.getHeight();
            // Console.WriteLine(padx + " " + pady + " " + ballx + " " + bally + " " + (padx <= ballx) + " " + (ballx <= padx + padw) + " " + (pady <= bally) + " " + (bally <= pady + padh));
            var bx = ballx + ballw / 2f;
            var by = bally + ballh / 2f;
            if (padx <= bx && bx <= padx + padw && pady <= by && by <= pady + padh)
            {
                dx *= -1;
                dy *= -1;
                /*if (pad.getPlayer() == 1)
                {
                    dx *= -1;
                    dy *= randomneg();
                }
                if (pad.getPlayer() == 2)
                {
                    dx *= -1;
                    dy *= randomneg();
                }
                if (pad.getPlayer() == 3)
                {
                    dx *= randomneg();
                    dy *= -1;
                }
                if (pad.getPlayer() == 4)
                {
                    dx *= randomneg();
                    dy *= -1;
                }*/

                //dx += 1;
                //dy += 1; */
            }
        }
Example #3
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            menuSprite = new Sprite();
            pointerSprite = new Sprite();
            creditSprite = new Sprite();
            gameOverSprite = new Sprite();

            gameball = new Ball(285, 285, 30, 30, 5, 5);
            paddle1 = new Paddle(1);
            paddle2 = new Paddle(2);
            paddle3 = new Paddle(3);
            paddle4 = new Paddle(4);
            ballsprite = new Sprite(gameball.getx(), gameball.gety());
            paddlesprite1 = new Sprite(paddle1.getX(), paddle1.getY());
            paddlesprite2 = new Sprite(paddle2.getX(), paddle2.getY());
            paddlesprite3 = new Sprite(paddle3.getX(), paddle3.getY());
            paddlesprite4 = new Sprite(paddle4.getX(), paddle4.getY());
            menu = new Menu();
        }