Ejemplo n.º 1
0
        public void DeclanMethod()
        {
            // Check if ball has collided with any blocks
            foreach (Block b in blocks)
            {
                if (ball.BlockCollision(b)) // block health decreases when hit by ball
                {
                    b.hp--;

                    if (b.hp > 0)                            // player score increases when the ball hits a block
                    {
                        playerScore     = playerScore + 50;  // update score
                        scoreLabel.Text = playerScore + "";  // display updated score
                    }
                    else if (b.hp == 0)                      // remove block from screen if its health is zero
                    {
                        playerScore     = playerScore + 100; // update score
                        scoreLabel.Text = playerScore + "";  // display updated score
                        blocks.Remove(b);
                    }

                    if (blocks.Count == 0) // go to next level if player finishes current level
                    {
                        gameTimer.Enabled = false;
                        OnEnd();
                    }

                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            // Move the paddle
            if (leftArrowDown && paddle.x > 0)
            {
                paddle.Move("left");
            }
            if (rightArrowDown && paddle.x < (this.Width - paddle.width))
            {
                paddle.Move("right");
            }

            // Moves ball
            ball.Move();

            // Check for collision with top and side walls
            ball.WallCollision(this);

            // Check for collision of ball with paddle, (incl. paddle movement)
            ball.PaddleCollision(paddle, leftArrowDown, rightArrowDown);

            // Check if ball has collided with any blocks
            foreach (Block b in blocks)
            {
                if (ball.BlockCollision(b))
                {
                    blocks.Remove(b);

                    if (blocks.Count == 0)
                    {
                        gameTimer.Enabled = false;

                        OnEnd();
                    }

                    break;
                }
            }

            // Check for ball hitting bottom of screen
            if (ball.BottomCollision(this))
            {
                lives--;

                // Moves the ball back to origin
                ball.x = ((paddle.x - (ball.size / 2)) + (paddle.width / 2));
                ball.y = (this.Height - paddle.height) - 85;

                if (lives == 0)
                {
                    gameTimer.Enabled = false;

                    OnEnd();
                }
            }

            //redraw the screen
            Refresh();
        }
Ejemplo n.º 3
0
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            //swaps controls when shrooms is active for p1
            if (isShroomsControls)
            {
                if (leftArrowDown && paddle.x < (this.Width - paddle.width))
                {
                    paddle.Move("right");
                }
                if (rightArrowDown && paddle.x > 0)
                {
                    paddle.Move("left");
                }
            }

            if (isShroomsControls)//for p2
            {
                if (aKeyDown && paddle2.x < (this.Width - paddle2.width))
                {
                    paddle2.Move("right");
                }
                if (dKeyDown && paddle.x > 0)
                {
                    paddle2.Move("left");
                }
            }

            // Move the paddle for p1
            if (leftArrowDown && paddle.x > 0)
            {
                paddle.Move("left");
            }
            if (rightArrowDown && paddle.x < (this.Width - paddle.width))
            {
                paddle.Move("right");
            }

            //move the paddle for p2
            if (aKeyDown && paddle2.x > 0)
            {
                paddle2.Move("left");
            }
            if (dKeyDown && paddle2.x < (this.Width - paddle2.width))
            {
                paddle2.Move("right");
            }

            #region Stefan and Jacks PowerUps

            if (MagnetTimer > 0 && isMagnet == true)
            {
                MagnetTimer--;
            }
            else if (MagnetTimer <= 0 && isMagnet == true)
            {
                isMagnet = false;
            }

            if (longPaddle == true)
            {
                longPaddleTimer++;
                if (longPaddleTimer >= 14 && paddle.width > 80)
                {
                    longPaddleTimer = 0;
                    paddle.x++;
                    paddle.width -= 2;
                }
                else if (paddle.width <= 80 && longPaddleTimer >= 14)
                {
                    longPaddleTimer = 0;
                    longPaddle      = false;
                }
            }
            else if (longPaddle == true && paddle.width != 80)
            {
                paddle.width = 80;
            }

            if (isFloor == true && floorTimer <= 0)
            {
                isFloor = false;
            }
            else if (isFloor == true && floorTimer > 0)
            {
                floorTimer--;
                foreach (Ball ba in balls)
                {
                    if (ba.PaddleCollision(floorPaddle, false, false, 100) == 0)
                    {
                        floorTimer = 0;
                    }
                }
                CollidePowerUps(floorPaddle);
            }

            if (strongBallTimer > 0 && isStrongball == true)
            {
                strongBallTimer--;
            }
            else if (strongBallTimer <= 0 && isStrongball == true)
            {
                isStrongball = false;

                ballBrush.Color = Color.White;
            }

            if (shroomsTimer > 0 && isShrooms == true)
            {
                ballBrush.Color   = Color.FromArgb(randomNum.Next(0, 255), randomNum.Next(0, 255), randomNum.Next(0, 255));
                paddleBrush.Color = Color.FromArgb(randomNum.Next(0, 255), randomNum.Next(0, 255), randomNum.Next(0, 255));

                if (shroomsControlTimer >= 80 && isShroomsControls == false)
                {
                    isShroomsControls = true;
                }

                shroomsControlTimer++;
                shroomsTimer--;
            }
            else if (shroomsTimer <= 0 && isShrooms == true)
            {
                isShrooms         = isShroomsControls = false;
                paddleBrush.Color = ballBrush.Color = Color.White;
            }

            if (blindfoldTimer > 0 && isBlindfold == true)
            {
                blindfoldTimer--;
            }
            else if (blindfoldTimer <= 0 && isBlindfold == true)
            {
                isBlindfold = false;
            }


            // Moves powerups
            MovePowerups(powerUps);

            // Check for collision with powerups and paddle
            CollidePowerUps(paddle);
            CollidePowerUps(paddle2);

            #endregion

            // Moves ball
            ball.Move();

            // Check for collision with top and side walls
            ball.WallCollision(this);

            // Check for collision of ball with paddle, (incl. paddle movement)

            ticksSinceHit = ball.PaddleCollision(paddle, leftArrowDown, rightArrowDown, ticksSinceHit);
            ticksSinceHit = ball.PaddleCollision(paddle2, aKeyDown, dKeyDown, ticksSinceHit);

            // Check if ball has collided with any of player 1 blocks
            foreach (Block b in blocks1p)
            {
                if (ball.BlockCollision(b))
                {
                    b.hp--;
                    if (b.hp == 0)
                    {
                        blocks1p.Remove(b);
                    }
                    //reduce life of player
                    p1HP--;

                    Random n = new Random();
                    if (n.Next(0, 1) == 0)
                    {
                        PowerUp p = new PowerUp(b.x, b.y, 20, -3, n.Next(0, 7));
                        powerUps.Add(p);
                    }

                    hpLabelp1.Text = "Player 1 HP: " + p1HP.ToString();
                    if (blocks1p.Count == 0 && p1HP <= 0)//if player 1 runs out of blocks
                    {
                        gameTimer.Enabled = false;
                        player1Won        = false;
                        player2Won        = true;
                        OnEnd();
                    }

                    break;
                }
            }
            // Check if ball has collided with any of player 2 blocks
            foreach (Block b in blocks2p)
            {
                if (ball.BlockCollision(b))
                {
                    b.hp--;
                    if (b.hp == 0)
                    {
                        blocks2p.Remove(b);
                    }

                    p2HP--;

                    Random n = new Random();
                    if (n.Next(0, 1) == 0)
                    {
                        PowerUp p = new PowerUp(b.x, b.y, 20, 3, n.Next(0, 7));
                        powerUps.Add(p);
                    }

                    hpLabelp2.Text = "Player 2 HP: " + p2HP.ToString();
                    if (blocks2p.Count == 0 && p2HP <= 0)
                    {
                        gameTimer.Enabled = false;
                        player2Won        = false;
                        player1Won        = true;
                        OnEnd();
                    }

                    break;
                }
            }

            // Check for ball hitting bottom of screen
            if (ball.BottomCollision(this))
            {
                // Moves the ball back to origin
                ball.ySpeed *= -1;
            }

            //redraw the screen
            Refresh();
        }
Ejemplo n.º 4
0
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            BreannaPowerUp();

            // Move the paddle
            if (leftArrowDown && paddle.x > 0)
            {
                paddle.Move("left");

                if (ballStart == false)
                {
                    ball.MoveWithPaddle("left", paddle);
                }
            }
            if (rightArrowDown && paddle.x < (this.Width - paddle.width))
            {
                paddle.Move("right");

                if (ballStart == false)
                {
                    ball.MoveWithPaddle("right", paddle);
                }
            }

            // Move ball
            if (ballStart)
            {
                ball.Move();
            }


            // Check for collision with top and side walls
            ball.WallCollision(this);

            // Check for ball hitting bottom of screen
            if (ball.BottomCollision(this))
            {
                lives--;
                if (paddle.width != 80)
                {
                    paddle.width = 80;
                }

                if (ball.xSpeed != 6 && ball.ySpeed != 6)
                {
                    ball.xSpeed = 6;
                    ball.ySpeed = 6;
                }

                // Moves the ball back to origin
                paddle.x = (this.Width / 2);

                ball.x = ((paddle.x - (ball.size / 2)) + (paddle.width / 2));
                ball.y = (this.Height - paddle.height) - 85;

                Refresh();
                Thread.Sleep(1500);


                if (lives == 0)
                {
                    gameTimer.Enabled = false;
                    OnEnd();
                }
            }
            // Check for collision of ball with paddle, (incl. paddle movement)
            ball.PaddleCollision(paddle);
            // Check if ball has collided with any blocks
            foreach (Block b in blocks)
            {
                if (ball.BlockCollision(b))
                {
                    b.hp--;
                    score++;
                    if (b.hp == 0)
                    {
                        blocks.Remove(b);
                    }
                    if (blocks.Count == 0)
                    {
                        gameTimer.Enabled = false;
                        Win();
                    }
                    break;
                }
            }

            //redraw the screen
            Refresh();
            if (gameStart)
            {
                Thread.Sleep(1500);
                gameStart = false;
            }
        }
Ejemplo n.º 5
0
        public void IanMethod()
        {
            string type = "";
            Color  c    = Color.White;

            int ballX    = this.Width / 2;
            int ballY    = this.Height - paddle.height - 80;
            int ballSize = 20;

            Random powerGen = new Random();

            foreach (Block b in blocks)
            {
                if (ball.BlockCollision(b))
                {
                    int powerupChance = powerGen.Next(1, 4);
                    int powerupType   = powerGen.Next(1, 6);
                    if (b.hp == 1)
                    {
                        if (powerupChance == 1)
                        {
                            if (powerupType == 1) // add 300 points
                            {
                                type = "points";

                                c = Color.Blue;
                            }
                            else if (powerupType == 2) // add another ball
                            {
                                type = "ball";
                                c    = Color.Yellow;
                            }
                            else if (powerupType == 3) // add extra life
                            {
                                type = "life";
                                c    = Color.Red;
                            }
                            else if (powerupType == 4) // bigger paddle
                            {
                                type = "big";
                                c    = Color.Green;
                            }
                            else if (powerupType == 5) // makes paddle faster
                            {
                                type = "fast";
                                c    = Color.Pink;
                            }
                            SolidBrush powerBrush = new SolidBrush(c);
                            Powerups   newPowerup = new Powerups(b.x + b.width / 2 - 5, b.y + b.height / 2 - 5, 10, type, powerBrush);
                            Powerup.Add(newPowerup);
                        }
                    }
                }
            }
            foreach (Powerups p in Powerup)
            {
                p.Move(3);
            }
            foreach (Powerups d in Powerup)
            {
                Rectangle powerRec  = new Rectangle(d.x, d.y, d.size, d.size);
                Rectangle paddleRec = new Rectangle(paddle.x, paddle.y, paddle.width, paddle.height);

                if (powerRec.IntersectsWith(paddleRec))
                {
                    if (d.type == "points")
                    {
                        score += 300;
                    }
                    else if (d.type == "ball")
                    {
                        Rectangle ballRec = new Rectangle(ball.x, ball.y, ball.size, ball.size);
                        if (powerupBall.Count == 0)
                        {
                            Ball powerball = new Ball(this.Width / 2 - 10, this.Height / 2 + 80, -6, -6, ballSize);
                            powerupBall.Add(powerball);
                        }
                    }
                    else if (d.type == "life")
                    {
                        lives++;
                    }
                    else if (d.type == "big")
                    {
                        paddle.width += 100;
                    }
                    else if (d.type == "fast")
                    {
                        paddle.speed += 1;
                    }
                    d.y = this.Height + 1;
                }
            }
            int index = Powerup.FindIndex(b => b.y > this.Height);

            if (index >= 0 && Powerup.Count() > 0)
            {
                Powerup.RemoveAt(index);
            }
        }
Ejemplo n.º 6
0
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            // Move the paddle for p1
            if (leftArrowDown && paddle.x > 0)
            {
                paddle.Move("left");
            }
            if (rightArrowDown && paddle.x < (this.Width - paddle.width))
            {
                paddle.Move("right");
            }

            //move the paddle for p2
            if (aKeyDown && paddle2.x > 0)
            {
                paddle2.Move("left");
            }
            if (dKeyDown && paddle2.x < (this.Width - paddle2.width))
            {
                paddle2.Move("right");
            }

            // Moves ball
            ball.Move();

            // Check for collision with top and side walls
            ball.WallCollision(this);

            // Check for collision of ball with paddle, (incl. paddle movement)

            ticksSinceHit = ball.PaddleCollision(paddle, leftArrowDown, rightArrowDown, ticksSinceHit);
            ticksSinceHit = ball.PaddleCollision(paddle2, aKeyDown, dKeyDown, ticksSinceHit);

            // Check if ball has collided with any of player 1 blocks
            foreach (Block b in blocks1p)
            {
                if (ball.BlockCollision(b))
                {
                    b.hp--;
                    if (b.hp == 0)
                    {
                        blocks1p.Remove(b);
                    }
                    //reduce life of player
                    p1HP--;

                    hpLabelp1.Text = "HP: " + p1HP.ToString();
                    if (blocks1p.Count == 0 && p1HP >= 0)
                    {
                        gameTimer.Enabled = false;
                        //TODO say who won
                        OnEnd();
                    }

                    break;
                }
            }
            // Check if ball has collided with any of player 2 blocks
            foreach (Block b in blocks2p)
            {
                if (ball.BlockCollision(b))
                {
                    b.hp--;
                    if (b.hp == 0)
                    {
                        blocks2p.Remove(b);
                    }

                    p2HP--;

                    hpLabelp2.Text = "HP: " + p2HP.ToString();
                    if (blocks2p.Count == 0 && p2HP >= 0)
                    {
                        gameTimer.Enabled = false;

                        OnEnd();
                    }

                    break;
                }
            }

            // Check for ball hitting bottom of screen
            if (ball.BottomCollision(this))
            {
                // Moves the ball back to origin
                ball.ySpeed *= -1;
            }

            //redraw the screen
            Refresh();
        }
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            //pause the game
            if (gamePaused == true)
            {
                gameTimer.Enabled = false;
            }

            // Move the paddle
            if (leftArrowDown && paddle.x > 0)
            {
                paddle.Move("left");
            }
            if (rightArrowDown && paddle.x < (this.Width - paddle.width))
            {
                paddle.Move("right");
            }

            if (escDown == true)
            {
                gamePaused = !gamePaused;
            }

            // Move ball
            ball.Move();

            //Move powerups
            foreach (PowerUp p in powers)
            {
                p.Move();
            }

            // Check for collision with top and side walls
            ball.WallCollision(this);

            // Check for ball hitting bottom of screen
            foreach (Ball b in ballList)
            {
                if (ballList.Count() < 1)
                {
                    if (b.BottomCollision(this))
                    {
                        ballList.Remove(b);
                    }
                }

                if (ballList.Count() == 1)
                {
                    if (b.BottomCollision(this))
                    {
                        lives--;

                        // Moves the ball back to origin
                        b.x      = ((paddle.x - (ball.size / 2)) + (paddle.width / 2));
                        b.y      = (this.Height - paddle.height) - 85;
                        b.xSpeed = 6;
                        b.ySpeed = 6;
                        b.size   = 20;

                        Refresh();


                        if (lives == 0)
                        {
                            gameTimer.Enabled = false;
                            OnEnd();
                        }
                        Thread.Sleep(2000);
                    }
                }
            }


            if (ballList.Count() == 0)
            {
                lives--;

                // Moves the ball back to origin
                int ballX    = ((paddle.x - (ball.size / 2)) + (paddle.width / 2));
                int ballY    = (this.Height - paddle.height) - 85;
                int xSpeed   = 6;
                int ySpeed   = 6;
                int ballSize = 20;

                ball = new Ball(ballX, ballY, xSpeed, ySpeed, ballSize);
                ballList.Add(ball);

                if (lives == 0)
                {
                    gameTimer.Enabled = false;
                    OnEnd();
                }
            }

            // Check for collision of ball with paddle, (incl. paddle movement)
            ball.PaddleCollision(paddle, leftArrowDown, rightArrowDown);

            // Check if ball has collided with any blocks
            foreach (Block b in blocks)
            {
                if (ball.BlockCollision(b))
                {
                    --b.hp;
                    //blocks.Remove(b);
                    int blockX    = b.x;
                    int blockY    = b.y + b.height;
                    int blockSize = b.width;

                    if (b.hp == 0)
                    {
                        blocks.Remove(b);

                        score = score + 100 * scoreMult;
                        double d        = score / 500;
                        double scoreint = Math.Round(d);

                        if (scoreint > lastPower)
                        {
                            lastPower = scoreint;
                            NumberGen();
                            int powertype = powerValue;

                            PowerUp power = new PowerUp(blockSize / 2 + blockX, blockY, powerupSpeed, 15, powertype);
                            powers.Add(power);
                        }
                    }

                    if (blocks.Count == 0)
                    {
                        currentLevel++;
                        NewLevel();
                    }

                    break;
                }
            }

            //redraw the screen
            Refresh();
        }