Ejemplo n.º 1
0
        Levels levelNum = new Levels();             //create object of Levels class

        //https://www.mooict.com/c-tutorial-create-a-full-space-invaders-game-using-visual-studio/  //used this for reference on how to make objects move down screen and for keypresses

        public Form1()
        {
            InitializeComponent();

            LevelCount.Hide();                  //hides the level count

            //inverts the colors if over a certain score
            if (menuObject.specialImage == true)             //checks to see if property is true

            {
                this.BackColor       = Color.Black;
                playerCube.BackColor = Color.White;
                scoreCount.BackColor = Color.White;



                foreach (Control x in this.Controls)         //loops through each barrier
                {
                    if (x is PictureBox && x.Tag == "barriers")
                    {
                        x.BackColor = Color.White;
                    }
                }
            }
            else
            {
                //resets the colors back to normal
                this.BackColor       = Color.White;
                playerCube.BackColor = Color.Black;
                scoreCount.BackColor = Color.White;

                foreach (Control x in this.Controls)         //loops through each barrier
                {
                    if (x is PictureBox && x.Tag == "barriers")
                    {
                        x.BackColor = Color.Gray;
                    }
                }
            }

            countdown();
        }
Ejemplo n.º 2
0
        private void gameTime_Tick(object sender, EventArgs e)
        {
            if (score < 15)
            {
                Level = 1;
            }

            if (score == 15)                     //increases level when score is over certain number
            {
                speed = 15;
                LevelCountLabel.Text = "2";
                //Level = 2;
                levelNum.Level  = 2;
                LevelCount.Text = "Level 2! Speed up!";

                levelNum.displayLevelCount();               //call the function to disply the next level title

                if (levelNum.displayLevelTitle == true)
                {
                    LevelCount.Show();
                }

                changeBarrierColor();              //calls the function to change all barrier colors for each level
            }

            else if (score == 16)
            {
                levelNum.hideLevelCount();              //rehide the level count label

                if (levelNum.displayLevelTitle == false)
                {
                    LevelCount.Hide();
                }
            }

            else if (score == 25)
            {
                speed = 20;
                LevelCountLabel.Text = "3";
                //Level = 3;
                levelNum.Level  = 3;
                LevelCount.Text = "Level 3! Speed up!";

                levelNum.displayLevelCount();               //call the function to disply the next level title

                if (levelNum.displayLevelTitle == true)
                {
                    LevelCount.Show();
                }
            }

            else if (score == 26)
            {
                levelNum.hideLevelCount();              //rehide the level count label

                if (levelNum.displayLevelTitle == false)
                {
                    LevelCount.Hide();
                }
            }

            else if (score == 35)
            {
                speed = 25;
                LevelCountLabel.Text = "4";
                levelNum.Level       = 4;
                LevelCount.Text      = "Level 4! Keep it up!";

                levelNum.displayLevelCount();               //call the function to disply the next level title

                if (levelNum.displayLevelTitle == true)
                {
                    LevelCount.Show();
                }
            }

            else if (score == 36)
            {
                levelNum.hideLevelCount();              //rehide the level count label

                if (levelNum.displayLevelTitle == false)
                {
                    LevelCount.Hide();
                }
            }

            else if (score == 45)
            {
                speed = 30;
                LevelCountLabel.Text = "5";
                levelNum.Level       = 5;
                LevelCount.Text      = "Level 5! Good Luck!";

                levelNum.displayLevelCount();               //call the function to disply the next level title

                if (levelNum.displayLevelTitle == true)
                {
                    LevelCount.Show();
                }
            }

            else if (score == 46)
            {
                levelNum.hideLevelCount();              //rehide the level count label

                if (levelNum.displayLevelTitle == false)
                {
                    LevelCount.Hide();
                }
            }

            else if (score == 55)
            {
                speed = 40;
                LevelCountLabel.Text = "6";
                levelNum.Level       = 6;
                LevelCount.Text      = "Level 6! Almost to the end!";

                levelNum.displayLevelCount();               //call the function to disply the next level title

                if (levelNum.displayLevelTitle == true)
                {
                    LevelCount.Show();
                }
            }
            else if (score == 56)
            {
                levelNum.hideLevelCount();              //rehide the level count label

                if (levelNum.displayLevelTitle == false)
                {
                    LevelCount.Hide();
                }
            }

            else if (score == 65)
            {
                speed = 60;
                LevelCountLabel.Text = "Final Level!";
                levelNum.Level       = 7;
                LevelCount.Text      = "Final Level! Impossible...";

                levelNum.displayLevelCount();               //call the function to disply the next level title

                if (levelNum.displayLevelTitle == true)
                {
                    LevelCount.Show();
                }
            }

            else if (score == 66)
            {
                levelNum.hideLevelCount();              //rehide the level count label

                if (levelNum.displayLevelTitle == false)
                {
                    LevelCount.Hide();
                }
            }



            if (hitBarrier == false)            //checks to see if player hits barrier first
            {
                if (moveLeft)
                {
                    playerCube.Left -= playerSpeed;             //moves left by number that is set in player speed
                }
                else if (moveRight)
                {
                    playerCube.Left += playerSpeed;         //moves right by number that is set in player speed
                }

                foreach (Control x in this.Controls)         //loops through each barrier
                {
                    if (x is PictureBox && x.Tag == "barriers")
                    {
                        if (x.Bounds.IntersectsWith(playerCube.Bounds))
                        {
                            hitBarrier = true;                //change hitBarrier variable
                            this.Controls.Remove(playerCube); //removes the player from the screen
                            gameOver();                       //call the gameOver function
                                                              //System.Threading.Thread.Sleep(1000);
                            return;
                        }

                        x.Top += speed;

                        if (x.Top > 500)                        //resets the barriers back to the top
                        {
                            x.Top  = 0;
                            x.Left = randomNumber.Next(0, 1400);         //randomly position the blocks
                        }
                    }
                }
            }
        }