Exemple #1
0
        public void Pause()
        {
            if (gameTimer.Enabled == true)
            {
                gameTimer.Enabled = false;

                DialogResult dr = PauseForm.Show();

                if (dr == DialogResult.Cancel)
                {
                    gameTimer.Enabled = true;
                }
                else if (dr == DialogResult.Abort)
                {
                    Form       form = this.FindForm();
                    MainScreen ms   = new MainScreen();

                    form.Controls.Add(ms);
                    form.Controls.Remove(this);
                }
            }
        }
Exemple #2
0
        public void Pause()
        {
            if (gameTimer.Enabled == true)
            {
                gameTimer.Enabled = false;

                DialogResult dr = PauseForm.Show();

                if (dr == DialogResult.Cancel)
                {
                    gameTimer.Enabled = true;
                }
                else if (dr == DialogResult.Abort)
                {
                    Form       form = this.FindForm();
                    MainScreen ms   = new MainScreen();

                    form.Controls.Add(ms);
                    ms.Location = new Point((form.Width - ms.Width) / 2, (form.Height - ms.Height) / 2);
                    form.Controls.Remove(this);
                }
            }
        }
Exemple #3
0
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            #region direction
            //BlueRider
            if (leftArrowDown && (upArrowDown || downArrowDown))
            {
                leftArrowDown = upArrowDown = downArrowDown = false;
            }
            else if (rightArrowDown && (upArrowDown || downArrowDown))
            {
                rightArrowDown = upArrowDown = downArrowDown = false;
            }
            else if (downArrowDown && (rightArrowDown || leftArrowDown))
            {
                downArrowDown = rightArrowDown = leftArrowDown = false;
            }
            else if (upArrowDown && (rightArrowDown || leftArrowDown))
            {
                upArrowDown = rightArrowDown = leftArrowDown = false;
            }

            //OrangeRider
            if (aDown && (wDown || sDown))
            {
                aDown = wDown = sDown = false;
            }
            else if (dDown && (wDown || sDown))
            {
                dDown = wDown = sDown = false;
            }
            else if (sDown && (dDown || aDown))
            {
                sDown = dDown = aDown = false;
            }
            else if (wDown && (dDown || aDown))
            {
                wDown = dDown = aDown = false;
            }

            //BlueRider
            if (leftArrowDown && blueDirection == "Up")
            {
                blueDirection = "Left";
                BlueRider.X  -= 32;
                BlueRider.Y  += 32;
                leftArrowDown = false;
            }
            else if (leftArrowDown && blueDirection == "Down")
            {
                blueDirection = "Left";
                BlueRider.X  -= 32;
                BlueRider.Y  -= 6;
                leftArrowDown = false;
            }
            else if (rightArrowDown && blueDirection != "Right" && blueDirection == "Up")
            {
                blueDirection = "Right";
                BlueRider.X  += 6;
                BlueRider.Y  += 32;
            }
            else if (rightArrowDown && blueDirection != "Right" && blueDirection == "Down")
            {
                blueDirection = "Right";
                BlueRider.X  += 6;
                BlueRider.Y  -= 10;
            }
            else if (upArrowDown && blueDirection != "Up" && blueDirection == "Left")
            {
                blueDirection = "Up";
                BlueRider.X  += 32;
                BlueRider.Y  -= 32;
            }
            else if (upArrowDown && blueDirection != "Up" && blueDirection == "Right")
            {
                blueDirection = "Up";
                BlueRider.X  -= 6;
                BlueRider.Y  -= 32;
            }
            else if (downArrowDown && blueDirection != "Down" && blueDirection == "Left")
            {
                blueDirection = "Down";
                BlueRider.X  += 32;
                BlueRider.Y  += 6;
            }
            else if (downArrowDown && blueDirection != "Down" && blueDirection == "Right")
            {
                blueDirection = "Down";
                BlueRider.X  -= 6;
                BlueRider.Y  += 6;
            }

            //OrangeRider
            if (aDown && orangeDirection != "Left" && orangeDirection == "Up")
            {
                orangeDirection = "Left";
                OrangeRider.X  -= 23;
                OrangeRider.Y  += 32;
            }
            else if (aDown && orangeDirection != "Left" && orangeDirection == "Down")
            {
                orangeDirection = "Left";
                OrangeRider.X  -= 23;
                OrangeRider.Y  -= 6;
            }
            else if (dDown && orangeDirection != "Right" && orangeDirection == "Up")
            {
                orangeDirection = "Right";
                OrangeRider.X  += 6;
                OrangeRider.Y  += 32;
            }
            else if (dDown && orangeDirection != "Right" && orangeDirection == "Down")
            {
                orangeDirection = "Right";
                OrangeRider.X  += 6;
                OrangeRider.Y  -= 10;
            }
            else if (wDown && orangeDirection != "Up" && orangeDirection == "Left")
            {
                orangeDirection = "Up";
                OrangeRider.X  += 28;
                OrangeRider.Y  -= 32;
            }
            else if (wDown && orangeDirection != "Up" && orangeDirection == "Right")
            {
                orangeDirection = "Up";
                OrangeRider.X  -= 6;
                OrangeRider.Y  -= 32;
            }
            else if (sDown && orangeDirection != "Down" && orangeDirection == "Left")
            {
                orangeDirection = "Down";
                OrangeRider.X  += 28;
                OrangeRider.Y  += 6;
            }
            else if (sDown && orangeDirection != "Down" && orangeDirection == "Right")
            {
                orangeDirection = "Down";
                OrangeRider.X  -= 6;
                OrangeRider.Y  += 6;
            }
            #endregion

            #region Movement & Adding Trail
            if (blueDirection == "Up" && BlueRider.Y > 0)
            {
                BlueRider.PlayerMoveUpDown(blueDirection);
                Trail newtrail = new Trail(BlueRider.X + bufferDistanceX, BlueRider.Y + BlueRider.riderHeight + bufferDistanceY, blueBrush);
                playerTrailList.Add(newtrail);
            }
            else if (blueDirection == "Down" && BlueRider.Y + BlueRider.riderHeight < this.Height - 160)
            {
                BlueRider.PlayerMoveUpDown(blueDirection);
                Trail newtrail = new Trail(BlueRider.X + bufferDistanceX, BlueRider.Y - bufferDistanceY, blueBrush);
                playerTrailList.Add(newtrail);
            }
            else if (blueDirection == "Left" && BlueRider.X > 0)
            {
                BlueRider.PlayerMoveLeftRight(blueDirection);
                Trail newtrail = new Trail(BlueRider.X + BlueRider.riderWidth + bufferDistanceY, BlueRider.Y + bufferDistanceX, blueBrush);
                playerTrailList.Add(newtrail);
            }
            else if (blueDirection == "Right" && BlueRider.X + BlueRider.riderWidth < this.Width)
            {
                BlueRider.PlayerMoveLeftRight(blueDirection);
                Trail newtrail = new Trail(BlueRider.X - bufferDistanceY, BlueRider.Y + bufferDistanceX, blueBrush);
                playerTrailList.Add(newtrail);
            }

            if (orangeDirection == "Up" && OrangeRider.Y > 0)
            {
                OrangeRider.PlayerMoveUpDown(orangeDirection);
                Trail newtrail = new Trail(OrangeRider.X + bufferDistanceX, OrangeRider.Y + OrangeRider.riderHeight + bufferDistanceY, orangeBrush);
                playerTrailList.Add(newtrail);
            }
            else if (orangeDirection == "Down" && OrangeRider.Y + OrangeRider.riderHeight < this.Height - 160)
            {
                OrangeRider.PlayerMoveUpDown(orangeDirection);
                Trail newtrail = new Trail(OrangeRider.X + bufferDistanceX, OrangeRider.Y - bufferDistanceY, orangeBrush);
                playerTrailList.Add(newtrail);
            }
            else if (orangeDirection == "Left" && OrangeRider.X > 0)
            {
                OrangeRider.PlayerMoveLeftRight(orangeDirection);
                Trail newtrail = new Trail(OrangeRider.X + OrangeRider.riderWidth + bufferDistanceX, OrangeRider.Y + bufferDistanceX, orangeBrush);
                playerTrailList.Add(newtrail);
            }
            else if (orangeDirection == "Right" && OrangeRider.X + OrangeRider.riderWidth < this.Width)
            {
                OrangeRider.PlayerMoveLeftRight(orangeDirection);
                Trail newtrail = new Trail(OrangeRider.X - bufferDistanceY, OrangeRider.Y + bufferDistanceX, orangeBrush);
                playerTrailList.Add(newtrail);
            }
            #endregion

            if (reset == false)
            {
                HighScore();
            }

            #region Music
            musicCounter++;
            if (musicCounter == 616)
            {
                musicCounter = 0;
                musicPlayer.Open(new Uri(Application.StartupPath + "/Resources/gameBackgroundMusic.wav"));
                musicPlayer.Play();
            }
            #endregion

            #region Collision
            //Collision with walls
            if (BlueRider.Y <= 0 || BlueRider.Y + BlueRider.riderHeight >= this.Height - 160 || BlueRider.X <= 0 || BlueRider.X + BlueRider.riderWidth >= this.Width)
            {
                BlueRider.lives--;
                collisionReset();
            }
            if (OrangeRider.Y <= 0 || OrangeRider.Y + OrangeRider.riderHeight >= this.Height - 160 || OrangeRider.X <= 0 || OrangeRider.X + OrangeRider.riderWidth >= this.Width)
            {
                OrangeRider.lives--;
                collisionReset();
            }
            //Collision with other player
            if (BlueRider.PlayerCollision(OrangeRider))
            {
                collisionReset();
            }
            //Collision with trail
            foreach (Trail x in playerTrailList)
            {
                Trail tempTrail = new Trail(x.trailX, x.trailY, x.colour);
                if (BlueRider.Collision(tempTrail))
                {
                    collisionReset();
                    break;
                }
            }

            foreach (Rectangle x in obstaclesList)
            {
                Rectangle tempObstacle = new Rectangle(x.X, x.Y, x.Width, x.Height);
                if (BlueRider.BarrierCollision(tempObstacle) || OrangeRider.BarrierCollision(tempObstacle))
                {
                    collisionReset();
                    break;
                }
            }
            #endregion

            #region Life Check
            //Blue Life
            if (BlueRider.lives == 3)
            {
                blueLife1.BackgroundImage = Properties.Resources.bluelife_1_png;
                blueLife2.BackgroundImage = Properties.Resources.bluelife_1_png;
                blueLife3.BackgroundImage = Properties.Resources.bluelife_1_png;
            }
            else if (BlueRider.lives == 2)
            {
                blueLife1.BackgroundImage = Properties.Resources.bluelife_1_png;
                blueLife2.BackgroundImage = Properties.Resources.bluelife_1_png;
                blueLife3.BackgroundImage = null;
            }
            else if (BlueRider.lives == 1)
            {
                blueLife1.BackgroundImage = Properties.Resources.bluelife_1_png;
                blueLife2.BackgroundImage = null;
                blueLife3.BackgroundImage = null;
            }
            else if (BlueRider.lives == 0)
            {
                blueLife1.BackgroundImage = null;
                blueLife2.BackgroundImage = null;
                blueLife3.BackgroundImage = null;
            }
            //Orange Life
            if (OrangeRider.lives == 3)
            {
                orangeLife1.BackgroundImage = Properties.Resources.orangeLife_1_png;
                orangeLife2.BackgroundImage = Properties.Resources.orangeLife_1_png;
                orangeLife3.BackgroundImage = Properties.Resources.orangeLife_1_png;
            }
            else if (OrangeRider.lives == 2)
            {
                orangeLife1.BackgroundImage = Properties.Resources.orangeLife_1_png;
                orangeLife2.BackgroundImage = Properties.Resources.orangeLife_1_png;
                orangeLife3.BackgroundImage = null;
            }
            else if (OrangeRider.lives == 1)
            {
                orangeLife1.BackgroundImage = Properties.Resources.orangeLife_1_png;
                orangeLife2.BackgroundImage = null;
                orangeLife3.BackgroundImage = null;
            }
            else if (OrangeRider.lives == 0)
            {
                orangeLife1.BackgroundImage = null;
                orangeLife2.BackgroundImage = null;
                orangeLife3.BackgroundImage = null;
            }

            if (BlueRider.lives == 0 || OrangeRider.lives == 0)
            {
                gameTimer.Enabled    = false;
                countDownBox.Visible = false;
                winnerLabel.Visible  = true;
                if (BlueRider.lives == 0)
                {
                    winnerLabel.Text = InstructionScreen.orangePlayerName + " is the Winner!!!";
                }
                else
                {
                    winnerLabel.Text = InstructionScreen.bluePlayerName + " is the Winner!!!";
                }
                Refresh();
                Thread.Sleep(4000);
                winnerLabel.Visible = false;
                Refresh();
                // Goes to the main screen
                Form f = this.FindForm();
                f.Controls.Remove(this);
                MainScreen ms = new MainScreen();
                f.Controls.Add(ms);
                ms.Focus();
            }
            #endregion

            Refresh();
        }