public void timer1_Tick(object sender, EventArgs e) { //constantly updating the score when timer is enabled, and displaying them to the user labelLevelScore.Text = Level1Score.ToString(); labelOverallScore.Text = Options.OverallScore.ToString(); //setting up a list to hold the bricks in, so they can all be coded together List<PictureBox> bricksList = new List<PictureBox>(); bricksList.Add(pictureBoxBrick); bricksList.Add(pictureBoxBrick1); bricksList.Add(pictureBoxBrick2); bricksList.Add(pictureBoxBrick3); bricksList.Add(pictureBoxBrick4); bricksList.Add(pictureBoxBrick5); bricksList.Add(pictureBoxBrick6); bricksList.Add(pictureBoxBrick7); bricksList.Add(pictureBoxBrick8); bricksList.Add(pictureBoxBrick9); bricksList.Add(pictureBoxBrick10); //moving the ball pictureBoxBall.Top += BallSpeedTop; pictureBoxBall.Left += BallSpeedLeft; //if the ball collides with the edges of the panel if (pictureBoxBall.Top < PlayAreaTop) { //times by -1 reverses the direction BallSpeedTop *= -1; } if (pictureBoxBall.Left < PlayAreaLeft) { BallSpeedLeft *= -1; } if (pictureBoxBall.Left > PlayAreaRight) { BallSpeedLeft *= -1; } //if the ball goes below the bat if (pictureBoxBall.Top > PlayAreaBottom) { //resetting ball to middle of play area pictureBoxBall.Top = 210; pictureBoxBall.Left = 417; //deducting live, and updating lives lable which displays lives to the user lives = lives - 1; labelLives.Text = lives.ToString(); //playing the designated sound effect to the user when a life is lost SoundPlayer deathSound = new SoundPlayer("Powerup2.wav"); deathSound.Play(); } //using the collisions method //collision between ball and bat if (collide(pictureBoxBat, pictureBoxBall) == true) { SoundPlayer batSound = new SoundPlayer("Blip_Select.wav"); batSound.Play(); BallSpeedTop *= -1; //to stop the ball from glitching inside of the bat at high speeds pictureBoxBall.Top = pictureBoxBall.Top - 21; } foreach (PictureBox brick in bricksList) { //collision between ball and brick if (collide(pictureBoxBall, brick) == true) { //deflecting the ball and making sure it doesnt get stuck inside the brick BallSpeedTop *= -1; pictureBoxBall.Top = pictureBoxBall.Top + 30; brick.Top = 1000; Level1Score = Level1Score + 10; Options.OverallScore = Options.OverallScore + 10; SoundPlayer brickSound = new SoundPlayer("Jump.wav"); brickSound.Play(); } } if (lives == 0) { timer1.Enabled = false; GameOver GameOver = new GameOver(); this.Close(); GameOver.ShowDialog(); } if (Level1Score == 110) { this.Close(); Form2.Show(); } }
private void timer3_Tick_1(object sender, EventArgs e) { labelLevelScore.Text = Level3Score.ToString(); labelOverallScore.Text = Options.OverallScore.ToString(); List<PictureBox> bricksList = new List<PictureBox>(); bricksList.Add(pictureBoxBrick); bricksList.Add(pictureBoxBrick1); bricksList.Add(pictureBoxBrick2); bricksList.Add(pictureBoxBrick3); bricksList.Add(pictureBoxBrick4); bricksList.Add(pictureBoxBrick5); bricksList.Add(pictureBoxBrick6); bricksList.Add(pictureBoxBrick7); bricksList.Add(pictureBoxBrick8); bricksList.Add(pictureBoxBrick9); bricksList.Add(pictureBoxBrick10); bricksList.Add(pictureBoxBrick11); bricksList.Add(pictureBoxBrick12); bricksList.Add(pictureBoxBrick13); bricksList.Add(pictureBoxBrick14); bricksList.Add(pictureBoxBrick15); bricksList.Add(pictureBoxBrick16); bricksList.Add(pictureBoxBrick17); bricksList.Add(pictureBoxBrick18); List<PictureBox> bricksList1 = new List<PictureBox>(); bricksList1.Add(pictureBoxBrick19); bricksList1.Add(pictureBoxBrick20); bricksList1.Add(pictureBoxBrick21); bricksList1.Add(pictureBoxBrick22); bricksList1.Add(pictureBoxBrick23); bricksList1.Add(pictureBoxBrick24); bricksList1.Add(pictureBoxBrick25); bricksList1.Add(pictureBoxBrick26); List<PictureBox> bricksRedList = new List<PictureBox>(); bricksRedList.Add(pictureBoxBrickRed); bricksRedList.Add(pictureBoxBrickRed1); List<PictureBox> bricksGreenList = new List<PictureBox>(); bricksGreenList.Add(pictureBoxBrickGreen); List<PictureBox> bricksDeathList = new List<PictureBox>(); bricksDeathList.Add(pictureBoxBrickDeath); bricksDeathList.Add(pictureBoxBrickDeath1); bricksDeathList.Add(pictureBoxBrickDeath2); List<PictureBox> bricksBlockList = new List<PictureBox>(); bricksBlockList.Add(pictureBoxBrickBlock); bricksBlockList.Add(pictureBoxBrickBlock1); //moving the ball pictureBoxBall.Top += BallSpeedTop; pictureBoxBall.Left += BallSpeedLeft; //if the ball collides with the top of the panel if (pictureBoxBall.Top < PlayAreaTop) { BallSpeedTop *= -1; //times by -1 reverses the direction } //if ball goes below bottom of screen if (pictureBoxBall.Top > PlayAreaBottom) { pictureBoxBall.Top = 210; pictureBoxBall.Left = 417; lives3 = lives3 - 1; labelLives.Text = lives3.ToString(); SoundPlayer deathSound = new SoundPlayer("Powerup2.wav"); deathSound.Play(); } if (pictureBoxBall.Left < PlayAreaLeft) { BallSpeedLeft *= -1; } if (pictureBoxBall.Left > PlayAreaRight) { BallSpeedLeft *= -1; } //using the collisions method //collision between ball and bat if (collide(pictureBoxBat, pictureBoxBall) == true) { BallSpeedTop *= -1; SoundPlayer batSound = new SoundPlayer("Blip_Select.wav"); batSound.Play(); pictureBoxBall.Top = pictureBoxBall.Top - 21; } foreach (PictureBox brick in bricksList) { //collision between ball and brick if (collide(pictureBoxBall, brick) == true) { BallSpeedTop *= -1; pictureBoxBall.Top = pictureBoxBall.Top + 30; brick.Top = 1000; Level3Score = Level3Score + 10; Options.OverallScore = Options.OverallScore + 10; SoundPlayer brickSound = new SoundPlayer("Jump.wav"); brickSound.Play(); } } foreach (PictureBox brick in bricksList1) { if (collide(pictureBoxBall, brick) == true) { BallSpeedTop *= -1; pictureBoxBall.Top = pictureBoxBall.Top + 30; brick.Top = 1000; Level3Score = Level3Score + 10; Options.OverallScore = Options.OverallScore + 10; SoundPlayer brickSound = new SoundPlayer("Jump.wav"); brickSound.Play(); } } //when player hits red brick, power down, decreases bat size foreach (PictureBox brick in bricksRedList) { //collision between brick and ball if (collide(pictureBoxBall, brick) == true) { BallSpeedTop *= -1; pictureBoxBall.Top = pictureBoxBall.Top + 30; brick.Top = 1000; Level3Score = Level3Score + 10; Options.OverallScore = Options.OverallScore + 10; //decreasing bat size pictureBoxBat.Width = pictureBoxBat.Width / 2; SoundPlayer batDownSound = new SoundPlayer("Powerup2.wav"); batDownSound.Play(); } } //when player hits green brick, increases bat size foreach (PictureBox brick in bricksGreenList) { if (collide(pictureBoxBall, brick) == true) { BallSpeedTop *= -1; pictureBoxBall.Top = pictureBoxBall.Top + 30; brick.Top = 1000; Level3Score = Level3Score + 10; Options.OverallScore = Options.OverallScore + 10; //increasing bat size pictureBoxBat.Width = pictureBoxBat.Width * 2; SoundPlayer batUpSound = new SoundPlayer("Powerup.wav"); batUpSound.Play(); } } //when player hits a death brick foreach (PictureBox brick in bricksDeathList) { if (collide(pictureBoxBall, brick) == true) { BallSpeedTop *= -1; //pictureBoxBall.Top = pictureBoxBall.Top + 30; brick.Top = 1000; //deducting life lives3 = lives3 - 1; labelLives.Text = lives3.ToString(); SoundPlayer deathSound = new SoundPlayer("Powerup2.wav"); deathSound.Play(); } } //when player hits a block brick foreach (PictureBox brick in bricksBlockList) { if (collide(pictureBoxBall, brick) == true) { BallSpeedTop *= -1; SoundPlayer blockSound = new SoundPlayer("Blip_Select.wav"); blockSound.Play(); } } if (lives3 == 0) { timer3.Enabled = false; GameOver GameOver = new GameOver(); this.Close(); GameOver.ShowDialog(); } if (Level3Score == 300) { GameFinished GameFinished = new GameFinished(); timer3.Enabled = false; this.Close(); GameFinished.ShowDialog(); } }