Пример #1
0
        private void tmrPlanet_Tick(object sender, EventArgs e)
        {
            score = 0;
            for (int i = 0; i < 7; i++)
            {
                planet[i].movePlanet();
                if (spaceship.spaceRec.IntersectsWith(planet[i].planetRec))
                {
                    //reset planet[i] back to top of panel
                    planet[i].y   = 30;               // set  y value of planetRec
                    lives        -= 1;                // lose a life
                    txtLives.Text = lives.ToString(); // display number of lives
                    checkLives();
                }

                score           += planet[i].score;     // get score from Planet class (in movePlanet method)
                lblScore.Text    = score.ToString();    // display score
                ScoreLvlLbl.Text = scorelvl.ToString(); // display score


                if (score > (scorelvl * scorelvl * 10))
                {
                    scorelvl += 1;
                    lives    += 1;
                }
            }
            PnlGame.Invalidate();//makes the paint event fire to redraw the panel
        }
Пример #2
0
        private void tmrSpaceship_Tick(object sender, EventArgs e)
        {
            if (turnRight)
            {
                spaceship.rotationAngle += 5;
            }
            if (turnLeft)
            {
                spaceship.rotationAngle -= 5;
            }

            if (moveRight) // if right arrow key pressed
            {
                move = "right";
                spaceship.MoveSpaceship(move);
            }
            if (moveLeft) // if left arrow key pressed
            {
                move = "left";
                spaceship.MoveSpaceship(move);
            }

            if (moveUp) // if right arrow key pressed
            {
                move = "up";
                spaceship.MoveSpaceship(move);
            }
            if (moveDown) // if left arrow key pressed
            {
                move = "down";
                spaceship.MoveSpaceship(move);
            }

            PnlGame.Invalidate();
        }
Пример #3
0
        private void TmrRestart_Tick(object sender, EventArgs e)
        {
            if (restart == true)
            {
                //If the player has lost and r is pressed, set everything back to its original place
                tmrGame.Enabled    = true;
                tmrRestart.Enabled = false;
                tmrScore.Enabled   = true;
                tmrAnim.Enabled    = true;
                MnuStart.Enabled   = true;
                BtnScore.Enabled   = false;
                LblRestart.Visible = false;
                player.x           = 20;
                player.y           = 220;

                jump  = false;
                shoot = true;
                string move = string.Empty;
                score         = 0;
                player.ySpeed = 18;

                crate.x = 1000;
                tree.x  = 1400;
                bush.x  = 600;
                bat1.x  = 700;

                bush.MoveBush();
                crate.MoveCrate();
                tree.MoveTree();
                player.MovePlayer(move);
                bat1.MoveEnemy();
            }

            PnlGame.Invalidate();
        }
Пример #4
0
        private void Tmrmeteor_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i <= 4; i++)
            {
                areamet[i].X += meteorspeed[i];

                if (areamet[i].IntersectsWith(areaAircraft))
                {                                       // If the surfer collides with any shark
                    areamet[i].X = 25;                  // Move the meteors back to the begining of the panel
                    livesnum    -= 1;                   // Reduce lives count by one
                    lives.Text   = livesnum.ToString(); // Display the score count on the Scorenum textbox
                    CheckLives();
                }



                if (areamet[i].X > PnlGame.Width)
                {                                       // If the Meteor reaches the end of the panel
                    scorenum    += 1;
                    score.Text   = scorenum.ToString(); // Display the score count on the Scorenum textbox
                    areamet[i].X = -35;                 // Move the meteor back to the begining of the panel
                    CheckScore();
                }
            }

            PnlGame.Invalidate();//meke the paint even fire to redraw the panel
        }
Пример #5
0
        private void TmrPlanet_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i < 9; i++)
            {
                planet[i].MovePlanet();
                if (spaceship.spaceRec.IntersectsWith(planet[i].planetRec))
                {
                    //reset planet[i] back to top of panel
                    // planet[i].y = 0; // set  y value of planetRec
                    lives        -= 1;                // lose a life
                    txtLives.Text = lives.ToString(); // display number of lives
                    CheckLives();
                }

                //if a planet reaches the bottom of the Game Area reposition it at the top
                if (planet[i].y >= PnlGame.Height)
                {
                    planet[i].y   = -20;
                    score        += 1;                //update the score
                    lblScore.Text = score.ToString(); // display scor
                    if (score == 20)
                    {
                        TmrPlanet.Enabled = false;
                        textBox2.Visible  = true;
                        timer1.Enabled    = true;
                        TmrShip.Enabled   = false;
                        TmrPlanet.Enabled = false;
                        startgame         = false;
                        timer5.Enabled    = true;
                    }
                }
            }

            PnlGame.Invalidate();//makes the paint event fire to redraw the panel
        }
Пример #6
0
        private void Tmrsat_Tick_1(object sender, EventArgs e)
        {
            for (int i = 0; i <= 4; i++)
            {
                areasat[i].Y += satspeed[i];

                if (areasat[i].IntersectsWith(areaAircraft))
                {                                       // If the Aircraft collides with any sattillites or Meteors
                    areasat[i].Y = 25;                  // Move the Sattllite back to the begining of the panel
                    livesnum    -= 1;                   // Reduce lives count by one
                    lives.Text   = livesnum.ToString(); // Display the score count on the Scorenum textbox
                    CheckLives();
                }

                if (areasat[i].Y > PnlGame.Height)
                {                                       // If the shark reaches the end of the panel
                    scorenum    += 1;
                    score.Text   = scorenum.ToString(); // Display the score count on the Scorenum textbox
                    areasat[i].Y = -35;                 // Move the sattelite back to the begining of the panel
                    CheckScore();
                }
            }

            PnlGame.Invalidate();//meke the paint even fire to redraw the panel
        }
Пример #7
0
        private void TmrPlanet_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i < 7; i++)
            {
                planet[i].MovePlanet();

                if (spaceship.spaceRec.IntersectsWith(planet[i].planetRec))
                {
                    //reset planet[i] back to top of panel
                    planet[i].y   = 30;               // set  y value of planetRec
                    lives        -= 1;                // lose a life
                    txtLives.Text = lives.ToString(); // display number of lives
                    CheckLives();
                }


                //if a planet reaches the bottom of the Game Area reposition it at the top
                if (planet[i].y >= PnlGame.Height)
                {
                    score        += 1;                //update the score
                    lblScore.Text = score.ToString(); // display score
                    planet[i].y   = 10;
                }
            }
            PnlGame.Invalidate();//makes the paint event fire to redraw the panel
        }
Пример #8
0
 private void tmrPlanet_Tick(object sender, EventArgs e)
 {
     for (int i = 0; i < 7; i++)
     {
         planet[i].movePlanet();
     }
     PnlGame.Invalidate();//makes the paint event fire to redraw the panel
 }
Пример #9
0
 private void TmrBalls_Tick(object sender, EventArgs e)
 {
     area1.X -= 5; // move the area(Red_Circle) across the panel
     area2.X -= 5; //  move the area(Blue_Circle) across the panel
     area3.X -= 5;
     area4.X -= 5;
     area5.X -= 5;
     area6.X -= 5;
     area7.X -= 5;
     PnlGame.Invalidate();//makes the paint event fire to redraw the panel
 }
Пример #10
0
        private void TmrPlanet_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i <= 6; i++)
            {
                area[i].Y += planetSpeed[i];
                if (area[i].IntersectsWith(areaSpaceship))
                {
                    area[i].Y     = 20;
                    lives        -= 1; // reduce lives by 1
                    LblLives.Text = lives.ToString();

                    CheckLives();
                }
                if (secretStuffz2 == true)
                {
                    planetSpeed[i] = speed.Next(5, 10);
                    secretStuffz2  = false;
                }

                if (score > 20)
                {
                    planetSpeed[i] = speed.Next(10, 20);
                    secretStuffz2  = false;
                }
                if (score > 50)
                {
                    planetSpeed[i] = speed.Next(20, 25);
                }
                if (score > 100)
                {
                    planetSpeed[i] = speed.Next(25, 40);
                }
                if (score > 200)
                {
                    planetSpeed[i] = speed.Next(40, 50);
                }
                if (score > 500)
                {
                    planetSpeed[i] = speed.Next(50, 80);
                }
                if (score > 1000)
                {
                    planetSpeed[i] = speed.Next(80, 100);
                }

                if (area[i].Y > PnlGame.Height)
                {
                    area[i].Y     = 20;
                    score        += 1;                // add 1 to score
                    LblScore.Text = score.ToString(); //display score on the form
                }
            }
            PnlGame.Invalidate();
        }
Пример #11
0
        // on robber movement
        private void TmrRobber_Tick(object sender, EventArgs e)
        {
            if (left)                  // if left key pressed - moves robber unless it would go off screen
            {
                if (areaRobber.X < 10) // if robber would go off screen move it, otherwise move to the left
                {
                    areaRobber.X = 10;
                }
                else
                {
                    areaRobber.X -= 7;
                }
                PnlGame.Invalidate(); // invalidate the panel
            }
            if (right)
            {
                if (areaRobber.X > PnlGame.Width - 80) // if robber would go off screen move it, otherwise move to the right
                {
                    areaRobber.X = PnlGame.Width - 80;
                }
                else
                {
                    areaRobber.X += 7;
                }
                PnlGame.Invalidate(); // invalidate the panel
            }

            if (up)
            {
                if (areaRobber.Y < PnlGame.Height - 430) // if robber would go off screen move it, otherwise move upwards
                {
                    areaRobber.Y = PnlGame.Height - 430;
                }
                else
                {
                    areaRobber.Y -= 7;
                }
                PnlGame.Invalidate(); // invalidate the panel
            }

            if (down)
            {
                if (areaRobber.Y > PnlGame.Height - 80) // if robber would go off screen move it, otherwise move downwards
                {
                    areaRobber.Y = PnlGame.Height - 80;
                }
                else
                {
                    areaRobber.Y += 7;
                }
                PnlGame.Invalidate(); // invalidate the panel
            }
        }
Пример #12
0
 private void TmrPlanet_Tick(object sender, EventArgs e)
 {
     for (int i = 0; i < 7; i++)
     {
         planet[i].MovePlanet();
         //if a planet reaches the bottom of the Game Area reposition it at the top
         if (planet[i].y >= PnlGame.Height)
         {
             score        += 1;                //update the score
             lblScore.Text = score.ToString(); // display score
             planet[i].y   = 30;
         }
     }
     PnlGame.Invalidate(); //makes the paint event fire to redraw the panel
 }
Пример #13
0
        // Timer for cops - movement

        private void TmrCop_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i <= 5; i++)
            {
                area[i].X += copSpeed[i];

                // collision between robber and cops

                if (area[i].IntersectsWith(areaRobber))
                {
                    area[i].X       = 20;
                    lives          -= 1; // reduce lives by 1
                    labelLives.Text = lives.ToString();
                    if (lives != 0)
                    {
                        splashText.Text = "You only just got away this time";
                    }

                    CheckLives(); //checks to see if the lives is 0
                }
                // makes game harder as you progress
                if (score > 10)
                {
                    copSpeed[i] = speed.Next(5, 20);
                }
                if (score > 25)
                {
                    copSpeed[i] = speed.Next(10, 35);
                }
                if (score > 50)
                {
                    copSpeed[i] = speed.Next(25, 40);
                }

                // if cops reach end of screen - 'you have escaped'

                if (area[i].X > PnlGame.Width)
                {
                    area[i].X = 20;
                    score    += 1; // add 1 to score
                    CheckScore();
                    splashText.Text = "Take that silly cop!";
                    labelScore.Text = score.ToString();//display score on the form
                }
            }
            PnlGame.Invalidate();
        }
Пример #14
0
        private void TmrPlanet_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i <= 6; i++)
            {
                area[i].Y += planetSpeed[i];
                //if spaceship collides with any planet lose a life and move planet to the top of the panel
                if (area[i].IntersectsWith(areaSpaceship))
                {
                    area[i].Y = -30;
                    lives    -= 1; // reduce lives by 1
                                   //display the number of lives on the form
                    TxtLives.Text = lives.ToString();

                    player      = Image.FromFile("collision.png");
                    heart.Image = Image.FromFile("heartdmg.png");



                    CheckLives();
                }

                if (area[i].Y > PnlGame.Height)
                {
                    area[i].Y           = 20;
                    score              += 1;                // add 1 to score
                    LblScore1.Text      = score.ToString(); //display score on the form
                    LblScore1.ForeColor = Color.Green;
                }

                if (areaSpaceship.IntersectsWith(areaOxygen))
                {
                    player = Image.FromFile("oxygeninc.png");

                    areaOxygen.X = rand.Next(450);
                    areaOxygen.Y = rand.Next(350);

                    int timeLeft = int.Parse(lblOx.Text); //getting the last value (the one from the label)
                    timeLeft  += 5;                       //adding 5
                    lblOx.Text = timeLeft.ToString();     //adding it back to the label.
                }
            }

            PnlGame.Invalidate();
            typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, PnlGame, new object[] { true });
        }
Пример #15
0
        private void TmrChips_Tick(object sender, EventArgs e)
        {                                               // On tick of the TmrChips timer
            if (showChips == true)
            {                                           // If showChips is enabled
                for (int i = 0; i < 8; i++)
                {                                       // Loop through each of the chips on tick of the timer
                    chip[i].moveChip();                 // Call the moveChip method in the Chip.cs class for the particular chip

                    chipSpeed[i] = random.Next(10, 23); // Select a random speed between 10 and 22
                    chip[i].x   += chipSpeed[i];        // Set each chip to the correct speed

                    if (chip[i].x > PnlGame.Width)
                    {                   // If the chip reaches the end of the panel (x value is greater than width of panel)
                        chip[i].x = 20; // Move the chip back to the begining of the panel (x = 20)
                    }
                }
            }

            PnlGame.Invalidate();
        }
Пример #16
0
        private void TmrPlanet_Tick(object sender, EventArgs e)
        {
            if (firemylaser == true)
            {
                laser.Enabled = true;
            }
            if (firemylaser == false)
            {
                laser.Enabled = false;
            }
            for (int i = 0; i <= 6; i++)
            {
                area[i].Y += planetSpeed[i];
                if (area[i].IntersectsWith(areaSpaceship))
                {
                    area[i].Y = 20;
                    lives    -= 1; // reduce lives by 1
                                   //display the number of lives on the form
                    LblLives.Text = lives.ToString();

                    CheckLives();
                }
                if (area[i].IntersectsWith(fireingmalaser))
                {
                    area[i].Y = -100;
                }


                if (area[i].Y > PnlGame.Height)
                {
                    score        += 1;                //add 1 to score
                    tillfire     += 1;
                    LblScore.Text = score.ToString(); //display score on form

                    area[i].Y = 20;
                }
            }
            PnlGame.Invalidate();
        }
Пример #17
0
 private void Tmrogre_Tick(object sender, EventArgs e)
 {
     if (right) // if right arrow key pressed
     {
         move = "right";
         player.moveogre(move);
     }
     if (left) // if left arrow key pressed
     {
         move = "left";
         player.moveogre(move);
     }
     if (up) // if left arrow key pressed
     {
         move = "up";
         player.moveogre(move);
     }
     if (down) // if left arrow key pressed
     {
         move = "down";
         player.moveogre(move);
     }
     PnlGame.Invalidate();
 }
Пример #18
0
        Rectangle[] area = new Rectangle[7];//area[0] to area[6]


        private void TmrPlanet_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i <= 6; i++)
            {
                area[i].Y -= piggySpeed[i];
                //if spaceship collides with any planet lose a life and move planet to the top of the panel
                if (area[i].IntersectsWith(areakermit))
                {
                    area[i].Y = 290;
                    lives    -= 1; // reduce lives by 1
                                   //display the number of lives on the form
                    LblLives.Text = lives.ToString();

                    CheckLives();
                }
                if (area[i].Y < 0)
                {
                    score        += 1;                // add 1 to score
                    LblScore.Text = score.ToString(); //display score on the form
                    area[i].Y     = 390;
                }
            }
            PnlGame.Invalidate();
        }
Пример #19
0
        private void TmrPlatform_Tick(object sender, EventArgs e) // controls the movement of the platforms, and if the player intersects with the platform, and rocket.
        {
            if (movingdown == false)                              // if the player intesects with the platform from the bottom repulse the character downwards.
            {
                for (int i = 0; i <= 2; i++)
                {
                    if (theperson.IntersectsWith(area[i]))
                    {
                        theperson.Y = theperson.Y + 10;
                        DelayJump();
                    }
                }
                for (int o = 0; o <= 2; o++)
                {
                    if (theperson.IntersectsWith(area2[o]))
                    {
                        theperson.Y = theperson.Y + 10;
                        DelayJump();
                    }
                }
                for (int p = 0; p <= 2; p++)
                {
                    if (theperson.IntersectsWith(area3[p]))
                    {
                        theperson.Y = theperson.Y + 10;
                        DelayJump();
                    }
                }
            }
            if (movingdown == true) // if the player intersects with the platfrom from the top repluse the character upwards
            {
                for (int i = 0; i <= 2; i++)
                {
                    if (theperson.IntersectsWith(area[i]))
                    {
                        theperson.Y = theperson.Y - 10;
                        jumpdelay   = false;
                    }
                }
                for (int o = 0; o <= 2; o++)
                {
                    if (theperson.IntersectsWith(area2[o]))
                    {
                        theperson.Y = theperson.Y - 10;
                        jumpdelay   = false;
                    }
                }
                for (int p = 0; p <= 2; p++)
                {
                    if (theperson.IntersectsWith(area3[p]))
                    {
                        theperson.Y = theperson.Y - 10;
                        jumpdelay   = false;
                    }
                }
            }
            if (right == true) // if the player intersects with the platform from the right, repluse the character left
            {
                for (int i = 0; i <= 2; i++)
                {
                    if (theperson.IntersectsWith(area[i]))
                    {
                        theperson.X = theperson.X - 40;
                    }
                }
                for (int o = 0; o <= 2; o++)
                {
                    if (theperson.IntersectsWith(area2[o]))
                    {
                        theperson.X = theperson.X - 40;
                    }
                }
                for (int p = 0; p <= 2; p++)
                {
                    if (theperson.IntersectsWith(area3[p]))
                    {
                        theperson.X = theperson.X - 40;
                    }
                }
            }
            if (left == true) // if the player intersects with the platform from the left, repulse the character right
            {
                for (int i = 0; i <= 2; i++)
                {
                    if (theperson.IntersectsWith(area[i]))
                    {
                        theperson.X = theperson.X + 40;
                    }
                }
                for (int o = 0; o <= 2; o++)
                {
                    if (theperson.IntersectsWith(area2[o]))
                    {
                        theperson.X = theperson.X + 40;
                    }
                }
                for (int p = 0; p <= 2; p++)
                {
                    if (theperson.IntersectsWith(area3[p]))
                    {
                        theperson.X = theperson.X + 40;
                    }
                }
            }
            // platform movement
            for (int i = 0; i <= 2; i++)
            {
                area[i].X -= platformSpeed[i];
            }
            for (int o = 0; o <= 2; o++)
            {
                area2[o].X -= platform2Speed[o];
            }
            for (int p = 0; p <= 2; p++)
            {
                area3[p].X -= platform3Speed[p];
            }
            PnlGame.Invalidate();

            for (int i = 0; i <= 2; i++)  // if the platform exits the screen give a point
            {
                if (area[i].X < -200)
                {
                    score        += 1;                //add 1 to score
                    LblScore.Text = score.ToString(); //display score on form

                    area[i].X = 800;
                }
            }
            for (int o = 0; o <= 2; o++) // if the platform exits the screen give a point
            {
                if (area2[o].X < -200)
                {
                    score        += 1;                //add 1 to score
                    LblScore.Text = score.ToString(); //display score on form

                    area2[o].X = 800;
                }
            }
            for (int p = 0; p <= 2; p++) // if the platform exits the screen give a point
            {
                if (area3[p].X < -200)
                {
                    score        += 1;                //add 1 to score
                    LblScore.Text = score.ToString(); //display score on form

                    area3[p].X = 800;
                }
            }
            therocket.X += 40;
            if (therocket.X > 800)                // if the rocket exits the screen
            {
                score        += 1;                //add 1 to score
                LblScore.Text = score.ToString(); //display score on form
                Random rocketlayer = new Random();
                int    rcktlayer   = rocketlayer.Next(25, 375);
                therocket.Y = rcktlayer;
                therocket.X = -100;
            }
            if (theperson.IntersectsWith(therocket))
            {
                Gameover();
            }
            if (ingame == true)        // is the person ingame
            {
                if (theperson.Y > 550) // is the person lower than 500, if so game over.
                {
                    Gameover();        // game over method
                }
            }
        }
Пример #20
0
        private void TmrBall_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i <= 9; i++)
            {
                area[i].X += ballSpeed[i];
                //if ladybug collides with any ball lose a life and move ball to the top of the panel
                if (area[i].IntersectsWith(arealadybug))
                {
                    area[i].X = 20;
                    lives    -= 1; //reduce lives by 1
                    //display the number of lives on the form
                    Txtlives.Text = lives.ToString();
                    CheckLives();
                }
                if (area[i].X > PnlGame.Width)
                {
                    score        += 1;                // add 1 to score
                    LblScore.Text = score.ToString(); //display score on the form
                    area[i].X     = 20;
                }
            }

            if (score > 10)
            {
                TmrBall.Interval = 60;
            }

            if (score > 20)
            {
                TmrBall.Interval = 50;
            }

            if (score > 30)
            {
                TmrBall.Interval = 47;
            }

            if (score > 40)
            {
                TmrBall.Interval = 44;
            }

            if (score > 50)
            {
                TmrBall.Interval = 42;
            }

            if (score > 60)
            {
                TmrBall.Interval = 40;
            }

            if (score > 70)
            {
                TmrBall.Interval = 39;
            }

            if (score > 80)
            {
                TmrBall.Interval = 38;
            }

            if (score > 90)
            {
                TmrBall.Interval = 37;
            }

            if (score > 100)
            {
                TmrBall.Interval = 36;
            }

            if (score > 110)
            {
                TmrBall.Interval = 35;
            }

            if (score > 120)
            {
                TmrBall.Interval = 34;
            }

            if (score > 130)
            {
                TmrBall.Interval = 33;
            }

            if (score > 140)
            {
                TmrBall.Interval = 32;
            }

            if (score > 150)
            {
                TmrBall.Interval = 31;
            }

            if (score > 160)
            {
                TmrBall.Interval = 30;
            }

            if (score > 170)
            {
                TmrBall.Interval = 29;
            }

            if (score > 180)
            {
                TmrBall.Interval = 28;
            }

            if (score > 190)
            {
                TmrBall.Interval = 27;
            }

            if (score > 200)
            {
                TmrBall.Interval = 26;
            }

            if (score > 210)
            {
                TmrBall.Interval = 25;
            }

            if (score > 220)
            {
                TmrBall.Interval = 24;
            }

            if (score > 230)
            {
                TmrBall.Interval = 23;
            }

            if (score > 240)
            {
                TmrBall.Interval = 22;
            }

            if (score > 250)
            {
                TmrBall.Interval = 21;
            }

            if (score > 260)
            {
                TmrBall.Interval = 20;
            }

            if (score > 270)
            {
                TmrBall.Interval = 19;
            }

            if (score > 280)
            {
                TmrBall.Interval = 18;
            }

            if (score > 290)
            {
                TmrBall.Interval = 17;
            }

            if (score > 300)
            {
                TmrBall.Interval = 16;
            }

            if (score > 310)
            {
                TmrBall.Interval = 15;
            }

            if (score > 320)
            {
                TmrBall.Interval = 14;
            }

            if (score > 330)
            {
                TmrBall.Interval = 13;
            }

            if (score > 340)
            {
                TmrBall.Interval = 12;
            }

            if (score > 350)
            {
                TmrBall.Interval = 11;
            }

            if (score > 360)
            {
                TmrBall.Interval = 10;
            }

            if (score > 370)
            {
                TmrBall.Interval = 9;
            }

            if (score > 380)
            {
                TmrBall.Interval = 8;
            }

            if (score > 390)
            {
                TmrBall.Interval = 7;
            }

            if (score > 400)
            {
                TmrBall.Interval = 6;
            }

            if (score > 410)
            {
                TmrBall.Interval = 5;
            }

            if (score > 420)
            {
                TmrBall.Interval = 4;
            }

            if (score > 430)
            {
                TmrBall.Interval = 3;
            }

            if (score > 440)
            {
                TmrBall.Interval = 2;
            }

            if (score > 450)
            {
                TmrBall.Interval = 1;
            }

            PnlGame.Invalidate();//makes the paint event fire to redraw panel
        }
Пример #21
0
        private void TmrGame_Tick(object sender, EventArgs e)
        {
            if (right) // if right arrow key pressed
            {
                move = "right";
                player.MovePlayer(move);
            }
            if (left) // if left arrow key pressed
            {
                move = "left";
                player.MovePlayer(move);
            }

            if (jump == true) //If space is pressed
            {
                move = "jump";
                player.MovePlayer(move);
            }

            if (player.y == 220) //Reset jump when the player hits the ground, so the player my jump again
            {
                jump          = false;
                player.ySpeed = 18;
            }

            bush.MoveBush();
            crate.MoveCrate();
            tree.MoveTree();

            //If the objects intersect with each other, move them
            if (tree.treeRec.IntersectsWith(crate.crateRec) || tree.treeRec.IntersectsWith(bush.bushRec))
            {
                tree.x += 20;
            }

            if (crate.crateRec.IntersectsWith(tree.treeRec) || crate.crateRec.IntersectsWith(bush.bushRec))
            {
                crate.x += 10;
            }

            if (score > 100) //Allow enemies to move only when score is > 100
            {
                bat1.MoveEnemy();
            }

            foreach (Bullet b in bullets) //If the bat intersects with the bullet reset the bat and remove the bullet, or the bullet reaches the right side of the panel, remove the bullet
            {
                if (bat1.enemyRec.IntersectsWith(b.bulletRec))
                {
                    bat1.x = -50;
                    bullets.Remove(b);
                    break;
                }

                if (b.bulletRec.X >= 700)
                {
                    bullets.Remove(b);
                    break;
                }
            }

            if (player.playerRec.IntersectsWith(crate.crateRec) || player.playerRec.IntersectsWith(tree.treeRec) || player.playerRec.IntersectsWith(bush.bushRec) || player.playerRec.IntersectsWith(bat1.enemyRec))
            {
                //If the player intersects with any bad objects, stop the game and show the restart label
                tmrGame.Enabled    = false;
                tmrRestart.Enabled = true;
                tmrScore.Enabled   = false;
                tmrAnim.Enabled    = false;
                BtnScore.Enabled   = true;
                LblRestart.Visible = true;
                MnuStart.Enabled   = false;
                shoot = false;
            }

            PnlGame.Invalidate(); //makes the paint event fire to redraw the panel
        }
        private void TmrShark_Tick(object sender, EventArgs e)
        {
            if (ButtonClicked == 1)
            {     // Only run the code if a difficulty button has been pressed
                for (int i = 0; i <= 4; i++)
                { // Run the code for each of the 5 sharks
                    if (level == 1)
                    {
                        sharkSpeed[i] = speed.Next(4, 15); // If the level is 1, then each shark has a random speed between 4 and 15
                    }

                    if (level == 2)
                    {
                        sharkSpeed[i] = speed.Next(10, 20); // If the level is 2, then each shark has a random speed between 10 and 20
                    }

                    if (level == 3)
                    {
                        sharkSpeed[i] = speed.Next(15, 20); // If the level is 3, then each shark has a random speed between 15 and 20
                    }

                    if (level == 4)
                    {
                        sharkSpeed[i] = speed.Next(20, 22); // If the level is 4, then each shark has a random speed between 20 and 22
                    }

                    if (level == 5)
                    {
                        sharkSpeed[i] = speed.Next(20, 22); // If the level is 5, then each shark has a random speed between 20 and 22
                    }

                    if (level == 6)
                    {
                        sharkSpeed[i] = speed.Next(21, 24); // If the level is 6, then each shark has a random speed between 21 and 24
                    }

                    if (level == 7)
                    {
                        sharkSpeed[i] = speed.Next(21, 24); // If the level is 7, then each shark has a random speed between 21 and 24
                    }

                    if (level == 8)
                    {
                        sharkSpeed[i] = speed.Next(21, 24); // If the level is 8, then each shark has a random speed between 21 and 24
                    }

                    if (level == 9)
                    {
                        sharkSpeed[i] = speed.Next(25, 30); // If the level is 9, then each shark has a random speed between 25 and 30
                    }

                    if (level > 9)
                    {
                        sharkSpeed[i] = speed.Next(25, 30); // If the level is greater than 9, then each shark has a random speed between 25 and 30
                    }

                    sharksRectangle[i].X += sharkSpeed[i]; // Set each shark to the correct speed

                    if (sharksRectangle[i].IntersectsWith(surferRectangle))
                    {                                   // If the surfer collides with any shark
                        sharksRectangle[i].X = 20;      // Move the shark back to the begining of the panel
                        lives      -= 1;                // Reduce lives count by one
                        LvsTxt.Text = lives.ToString(); // Display the number of lives remaining on the LvsTxt textbox
                        CheckLives();                   // Initiate the function that checks how many lives the user has

                        TmrPopUp.Start();
                        LblPopUp.Visible = true; // Display the popup text
                        LblPopUp.Text    = "You lost a life. You now have " + lives + " lives remaining";
                    }

                    if (sharksRectangle[i].X > PnlGame.Width)
                    {                                            // If the shark reaches the end of the panel
                        score += 1;                              // Add one point to score count
                        sharksRectangle[i].X = 25;               // Move the shark back to the begining of the panel
                        ScoreTxt.Text        = score.ToString(); // Display the score count on the ScoreTxt textbox

                        // Increase the value/ step the level progressbar by one
                        LevelProgress.Value += 1;
                        LevelProgress.Step  += 1;

                        CheckScore(); // Initiate the function that checks the score the user is on and if the level needs increasing
                    }

                    PnlGame.Invalidate();
                }
            }
        }
Пример #23
0
 private void TmrAlien_Tick(object sender, EventArgs e)
 {
     PnlGame.Invalidate();
 }
Пример #24
0
 private void TmrCar_Tick(object sender, EventArgs e)
 {
     if (level == 1)
     {
         area1.X -= 30; // move the area(car) across the panel
         area2.X += 22; // move the area(car) across the panel
         area3.X -= 23; // move the area(car) across the panel
         area4.X += 17; // move the area(car) across the panel
         area5.X -= 19; // move the area(car) across the panel
         area6.X += 16; // move the area(car) across the panel1
         area7.X += 57; // move the area(train) across the panel
         area8.X -= 57; // move the area(train) across the panel
     }
     if (level == 2)
     {
         area1.X -= 35; // move the area(car) across the panel
         area2.X += 27; // move the area(car) across the panel
         area3.X -= 28; // move the area(car) across the panel
         area4.X += 22; // move the area(car) across the panel
         area5.X -= 24; // move the area(car) across the panel
         area6.X += 21; // move the area(car) across the panel
         area7.X += 47; // move the area(train) across the panel
         area8.X -= 47; // move the area(train) across the panel
     }
     if (level == 3)
     {
         area1.X -= 40; // move the area(car) across the panel
         area2.X += 32; // move the area(car) across the panel
         area3.X -= 33; // move the area(car) across the panel
         area4.X += 27; // move the area(car) across the panel
         area5.X -= 29; // move the area(car) across the panel
         area6.X += 26; // move the area(car) across the panel
         area7.X += 52; // move the area(train) across the panel
         area8.X -= 52; // move the area(train) across the panel
     }
     if (level == 4)
     {
         area1.X -= 45;    // move the area(car) across the panel
         area2.X += 37;    // move the area(car) across the panel
         area3.X -= 38;    // move the area(car) across the panel
         area4.X += 32;    // move the area(car) across the panel
         area5.X -= 34;    // move the area(car) across the panel
         area6.X += 31;    // move the area(car) across the panel
         area7.X += 62;    // move the area(train) across the panel
         area8.X -= 62;    // move the area(train) across the panel
     }
     if (area1.X < -25)    //If Yellow car X < -25 from PnlGame
     {
         area1.X = 500;    //Respawn Yellow car at X = 500
     }
     if (area3.X < -25)    //If Police car X < -25 from PnlGame
     {
         area3.X = 500;    //Respawn Police car at X = 500
     }
     if (area5.X < -25)    //If Silver car X < -25 from PnlGame
     {
         area5.X = 500;    //Respawn Silver car at X = 500
     }
     if (area8.X < -300)   //If Bottom Train X < -300 from PnlGame
     {
         area8.X = 500;    //Respawn Bottom Train at X = 500
     }
     if (area2.X > 500)    //If Red car X > 500 from PnlGame
     {
         area2.X = -25;    //Respawn Red car at X = -25
     }
     if (area4.X > 500)    //If Blue car X > 500 from PnlGame
     {
         area4.X = -25;    //Respawn Blue car at X = -25
     }
     if (area6.X > 500)    //If White car X > 500 from PnlGame
     {
         area6.X = -25;    //Respawn White car at X = -25
     }
     if (area7.X > 500)    //If Top Train X > 500 from PnlGame
     {
         area7.X = -300;   //Respawn Top Train at X = -300
     }
     PnlGame.Invalidate(); //makes the paint event fire to redraw the panel
 }
Пример #25
0
        private void TmrCharacter_Tick(object sender, EventArgs e)
        {
            //if Character collides with any Car or Train, Game Over!
            if (area1.IntersectsWith(character1))
            {
                lives -= 1; // reduce lives by 1
                            //display the number of lives on the form
                LblLives.Text = lives.ToString();

                CheckLives();
            }
            if (area2.IntersectsWith(character1))
            {
                lives -= 1; // reduce lives by 1
                            //display the number of lives on the form
                LblLives.Text = lives.ToString();

                CheckLives();
            }
            if (area3.IntersectsWith(character1))
            {
                lives -= 1; // reduce lives by 1
                            //display the number of lives on the form
                LblLives.Text = lives.ToString();

                CheckLives();
            }
            if (area4.IntersectsWith(character1))
            {
                lives -= 1; // reduce lives by 1
                            //display the number of lives on the form
                LblLives.Text = lives.ToString();

                CheckLives();
            }
            if (area5.IntersectsWith(character1))
            {
                lives -= 1; // reduce lives by 1
                            //display the number of lives on the form
                LblLives.Text = lives.ToString();

                CheckLives();
            }
            if (area6.IntersectsWith(character1))
            {
                lives -= 1; // reduce lives by 1
                            //display the number of lives on the form
                LblLives.Text = lives.ToString();

                CheckLives();
            }
            if (area7.IntersectsWith(character1))
            {
                lives -= 1; // reduce lives by 1
                            //display the number of lives on the form
                LblLives.Text = lives.ToString();

                CheckLives();
            }
            if (area8.IntersectsWith(character1))
            {
                lives -= 1; // reduce lives by 1
                            //display the number of lives on the form
                LblLives.Text = lives.ToString();

                CheckLives();
            }
            if (area9.IntersectsWith(character1))
            {
                character1.X = 190; //move character to 190 on X axis
                character1.Y = 480; //move character to 480 on Y axis
                level++;
                LblLevel.Text = level.ToString();
            }
            // CHARACTER MOVEMENTS

            if (left)                  // if left arrow pressed
            {
                if (character1.X < 10) //check to see if character within 10 of left side
                {
                    character1.X = 10; //if it is < 10 away "bounce" it (set position at 10)
                }
                else
                {
                    character1.X -= 5; //move character to the left
                }
            }
            //move character 5 to the left
            if (right)                                 // if right arrow key pressed
            {
                if (character1.X > PnlGame.Width - 40) // is character within 40 of right side
                {
                    character1.X = PnlGame.Width - 40; //if it is < 40 away "bounce" it (set position at 40)
                }
                else
                {
                    character1.X += 5; //move character 5 to the right
                }
            }
            if (up)                                      // if up arrow key pressed
            {
                if (character1.Y < PnlGame.Height - 510) // is character within 510 of Up side
                {
                    character1.Y = PnlGame.Height - 510; //if it is < 510 away "bounce" it (set position at 510)
                }
                else
                {
                    character1.Y -= 5; //move character 5 upwards
                }
            }
            if (down)                                   // if down arrow key pressed
            {
                if (character1.Y > PnlGame.Height - 40) // is character within 40 of Down side
                {
                    character1.Y = PnlGame.Height - 40; //if it is < 40 away "bounce" it (set position at 40)
                }
                else
                {
                    character1.Y += 5; //move chracter 5 downwards
                }
            }
            PnlGame.Invalidate();
        }
Пример #26
0
        private void TmrTire_Tick(object sender, EventArgs e)
        {
            area1.Y += speed.Next(3, 9); //move tyre down screen at a random speed between 3 and 9
            area2.X += speed.Next(3, 9); //move tyre across screen at a speed between 3 aqnd 9
            area3.Y += speed.Next(3, 9);
            area4.X += speed.Next(3, 9);
            area5.Y += speed.Next(3, 9);
            area6.X += speed.Next(3, 9);
            area7.Y += speed.Next(3, 9);
            PnlGame.Invalidate();//Forces panel to redraw and update the images in their new position

            if (area1.Y > PnlGame.Height)
            {
                area1.Y = -30;//Place tyre back to original position
            }
            if (area2.X > PnlGame.Width)
            {
                area2.X = -30;
            }
            if (area3.Y > PnlGame.Height)
            {
                area3.Y = -30;
            }
            if (area4.X > PnlGame.Width)
            {
                area4.X = -30;
            }
            if (area5.Y > PnlGame.Height)
            {
                area5.Y = -30;
            }
            if (area6.X > PnlGame.Width)
            {
                area6.X = -30;
            }
            if (area7.Y > PnlGame.Height)
            {
                area7.Y = -30;
            }
            if (score >= 5)//If score more than 5 increase the timer speed
            {
                TmrTire.Interval = 70;
            }
            if (score >= 7)//If score more than 7 increase the timer speed
            {
                TmrTire.Interval = 65;
            }
            if (score >= 10)//etc
            {
                TmrTire.Interval = 60;
            }
            if (score >= 13)
            {
                TmrTire.Interval = 55;
            }
            if (score >= 15)
            {
                TmrTire.Interval = 50;
            }
            if (score >= 20)
            {
                TmrTire.Interval = 40;
            }
            if (score >= 30)
            {
                TmrTire.Interval = 30;
            }
        }
Пример #27
0
        private void TmrPlanet_Tick(object sender, EventArgs e)
        {//resets animation cycle to keep it on a loop//
            if (thump > 30)
            {
                thump = 0;
            }
            //grow flare when scre is 20//
            if (score > 19)
            {
                flare1 += 1;
            }
            //more animation cycles//
            stop  += 1;
            stop2 += 1;
            //health bar shrinks as lives are lost//
            healthbar.Width = lives * 10;

            thump += 1;


            for (int i = 0; i < 1; i++)
            {
                titan[i].MovePlanet();
                titan2[i].MoveTitan2();
                titan3[i].MoveTitan3();

                rock[i].MoveRock();
                beast[i].MoveBeast();
                int rndmloc = (xloc.Next(1000, 1500)) - score;
                //bring in boss when score equals 31//
                if (score == 30)
                {
                    beast[i].x = 0;
                }
                //add to score when titans pass game pannel width and bring them back after awhile//
                if (titan[i].x >= 2500)
                {
                    titan[i].x = -100;
                }

                if (titan3[i].x >= 2500)
                {
                    titan3[i].x = -100;
                }

                if (beast[i].x > 1000)
                {
                    if (beast[i].x < 1200)
                    {
                        score        += 10;               //update the score
                        lblScore.Text = score.ToString(); // display score
                        beast[i].x    = 1200;
                    }
                }

                if (titan[i].x > 1000)
                {
                    if (titan[i].x < 1200)
                    {
                        score        += 1;                //update the score
                        lblScore.Text = score.ToString(); // display score
                        titan[i].x    = 1200;
                    }
                }
                if (titan3[i].x > 1000)
                {
                    if (titan3[i].x < 1200)
                    {
                        score        += 1;                //update the score
                        lblScore.Text = score.ToString(); // display score
                        titan3[i].x   = 1200;
                    }
                }

                if (rock[i].y == 270)
                {
                    rock[i].SpriteChange();
                    rock[i].y = 270;
                }
                if (rock[i].y >= 1000)
                {
                    rock[i].SpriteChange2();

                    rock[i].y = 0;
                    rock[i].x = 100;
                }


                if (titan2[i].x >= 2500)
                {
                    titan2[i].x = 0;
                }


                if (titan2[i].x > 1000)
                {
                    if (titan2[i].x < 1200)
                    {
                        score        += 1;                //update the score
                        lblScore.Text = score.ToString(); // display score
                        titan2[i].x   = 1200;
                    }
                }

                if (background[i].x > 1000)
                {
                    background[i].x = -1000;
                }



                titan[i].MovePlanet();
                titan2[i].MoveTitan2();
                titan3[i].MoveTitan3();
                beast[i].MoveBeast();
                background[i].MoveBackground();
                background2[i].MoveBackground();
                background3[i].MoveBackground();

                //lower health when collide with titans//
                if (player.spaceRec.IntersectsWith(titan[i].titanrec))
                {
                    if (down == false)
                    {
                        if (up == false)
                        {
                            lives        -= 1;                // lose a life
                            txtLives.Text = lives.ToString(); // display number of lives
                            CheckLives();
                        }
                    }
                }

                if (player.spaceRec.IntersectsWith(beast[i].titanrec))
                {
                    if (score > 30)
                    {
                        if (down == false)
                        {
                            if (up == false)
                            {
                                lives        -= 3;                // lose a life
                                txtLives.Text = lives.ToString(); // display number of lives
                                CheckLives();
                            }
                        }
                    }
                }

                if (player.spaceRec.IntersectsWith(titan2[i].titanrec))
                {
                    if (down == false)
                    {
                        if (up == false)
                        {
                            lives        -= 1;                // lose a life
                            txtLives.Text = lives.ToString(); // display number of lives
                            CheckLives();
                        }
                    }
                }

                if (player.spaceRec.IntersectsWith(titan3[i].titanrec))
                {
                    if (down == false)
                    {
                        if (up == false)
                        {
                            lives        -= 1;                // lose a life
                            txtLives.Text = lives.ToString(); // display number of lives
                            CheckLives();
                        }
                    }
                }
                if (player.spaceRec.IntersectsWith(rock[i].titanrec))
                {
                    if (score > 20)
                    {
                        if (score < 30)
                        {
                            //reset planet[i] back to top of panel
                            lives        -= 1;                // lose a life
                            txtLives.Text = lives.ToString(); // display number of lives
                            CheckLives();
                        }
                    }
                }
            }
            PnlGame.Invalidate();//makes the paint event fire to redraw the panel
        }