Esempio n. 1
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            boxTimer++;

            boxX = randGen.Next(1, 795);

            //update location of all boxes (drop down screen)
            foreach (Box b in boxes)
            {
                b.y++;
            }

            //TODO remove box if it has gone off screen

            /* if (y >= 300)
             *       {
             *           boxes.RemoveAt(0);
             *       }*/


            /*foreach (Box b in boxes)
             * if (b.y >= 300)
             * {
             *  boxes.Remove(b);
             * }*/

            //TODO add new box if it is time
            if (boxTimer == 10)
            {
                Box b = new Box(boxX, 225, 5);
                boxes.Add(b);

                boxTimer = 0;
            }



            //move hero
            if (leftArrowDown)
            {
                hero.Move("left");

                //adds to moveCount
            }
            if (rightArrowDown)
            {
                hero.Move("right");
            }
            if (upArrowDown)
            {
                hero.Move("up");
                moveCount++;
            }
            if (downArrowDown)
            {
                hero.Move("down");
                moveCount++;
            }
            Refresh();
        }
Esempio n. 2
0
        public void gameLoop_Tick(object sender, EventArgs e)
        {
            //update location of all boxes (drop down screen)
            foreach (Box b in leftBoxes)
            {
                b.Fall();
            }
            //remove box if it has gone of screen
            if (leftBoxes[0].y > this.Height)
            {
                leftBoxes.RemoveAt(0);
            }

            //add new box if it is time
            counter++;
            if (counter == 4)
            {
                Box box = new Box(4, 36, 10);
                leftBoxes.Add(box);
                counter = 0;
            }

            //move hero
            if (leftArrowDown)
            {
                hero.Move("left");
            }
            if (rightArrowDown)
            {
                hero.Move("right");
            }
            Refresh();
        }
Esempio n. 3
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            //update location of all boxes (drop down screen)
            foreach (Box b in boxesLeft)
            {
                b.Fall();
            }

            foreach (Box b in boxesRight)
            {
                b.Fall();
            }

            //remove box if it has gone of screen
            if (boxesLeft[0].y > 400)
            {
                boxesLeft.RemoveAt(0);
                boxesRight.RemoveAt(0);
            }

            //add new box if it is time
            counter++;
            if (counter == 9)
            {
                newBoxCounter++;

                boxLeftX += boxXOffset;

                Box b1 = new Box(boxLeftX, 0, boxSize);
                boxesLeft.Add(b1);

                Box b2 = new Box(boxLeftX + boxGap, 0, boxSize);
                boxesRight.Add(b2);

                counter = 0;

                if (newBoxCounter == patternAmount)
                {
                    boxXOffset    = -boxXOffset;
                    newBoxCounter = 0;

                    patternAmount = randGen.Next(1, 8);
                }
            }

            //move hero
            if (leftArrowDown)
            {
                hero.Move("left");
            }

            if (rightArrowDown)
            {
                hero.Move("right");
            }

            Refresh();
        }
Esempio n. 4
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            //update location of all boxes (drop down screen)
            foreach (Box b in left)
            {
                b.Move(5);
            }

            foreach (Box b in right)
            {
                b.Move(5);
            }

            //remove box if it has gone of screen
            if (left[0].y > 400)
            {
                left.RemoveAt(0);
                right.RemoveAt(0);
            }

            //add new box if it is time
            if (left[left.Count - 1].y > 21)
            {
                MakeBox();
            }

            // move hero
            if (leftArrowDown == true)
            {
                hero.Move(heroSpeed, "left");
            }
            else if (rightArrowDown == true)
            {
                hero.Move(heroSpeed, "right");
            }

            // check for collision
            Rectangle heroRec = new Rectangle(hero.x, hero.y, hero.size, hero.size);

            if (left.Count >= 4)
            {
                // check bottom 4 boxes
                for (int i = 0; i < 4; i++)
                {
                    Rectangle boxRec      = new Rectangle(left[i].x, left[i].y, left[i].size, left[i].size);
                    Rectangle rightBoxRec = new Rectangle(right[i].x, right[i].y, right[i].size, right[i].size);

                    if (boxRec.IntersectsWith(heroRec) || rightBoxRec.IntersectsWith(heroRec))
                    {
                        gameLoop.Enabled = false;
                    }
                }
            }

            Refresh();
        }
Esempio n. 5
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            //update location of all boxes (drop down screen)
            foreach (Box b in leftBoxes)
            {
                b.Move(boxSpeed);
            }
            foreach (Box b in rightBoxes)
            {
                b.Move(boxSpeed);
            }

            if (leftArrowDown == true && player.x > 0)
            {
                player.Move(5, "left");
            }

            if (rightArrowDown == true && player.y <= this.Width - player.size)
            {
                player.Move(5, "right");
            }

            foreach (Box b in leftBoxes.Union(rightBoxes))
            {
                if (player.Collision(b))
                {
                    gameLoop.Stop();
                }
            }

            //remove box if it has gone of screen

            if (leftBoxes[0].y > this.Height - leftBoxes[0].size)
            {
                leftBoxes.RemoveAt(0);
                rightBoxes.RemoveAt(0);
            }

            //add new box if it is time
            boxCounter++;
            if (boxCounter % 5 == 0)
            {
                Color randomized = randomColour();

                Box b1 = new Box(25, 24, 20, randomized);
                leftBoxes.Add(b1);

                Box b2 = new Box(b1.x + this.Height / 3, 24, 20, randomized);
                rightBoxes.Add(b2);
                boxCounter = 0;
            }

            Refresh();
        }
Esempio n. 6
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            gameScore++;
            scoreLabel.Text = "" + gameScore;

            // check for collisions

            Rectangle heroRec = new Rectangle(hero.x, hero.y, hero.size, hero.size);

            if (boxes.Count >= 6)
            {
                // 0-3
                for (int i = 0; i < 6; i++)
                {
                    Rectangle boxRec = new Rectangle(boxes[i].x, boxes[i].y, boxes[i].size, boxes[i].size);

                    if (boxRec.IntersectsWith(heroRec))
                    {
                        gameLoop.Enabled = false;
                    }
                }
            }
            // move player

            if (leftArrowDown == true)
            {
                hero.Move(heroSpeed, false);
            }
            else if (rightArrowDown == true)
            {
                hero.Move(heroSpeed, true);
            }

            // update location of all boxes (drop down screen)

            foreach (Box b in boxes)
            {
                b.Move(5);
            }

            // remove box if it has gone of screen

            if (boxes[0].y > 400)
            {
                boxes.RemoveAt(0);
            }

            // add new box if it is time

            MakeBox();
            Refresh();
        }
Esempio n. 7
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            // update location of all boxes (drop down screen)
            foreach (Box b in boxesLeft.Union(boxesRight))
            {
                b.Move(boxSpeed);
            }
            if (leftArrowDown == true)
            {
                player.Move(boxSpeed, "left");
            }
            if (rightArrowDown == true)
            {
                player.Move(boxSpeed, "right");
            }

            foreach (Box b in boxesLeft.Union(boxesRight))
            {
                if (player.Collision(b))
                {
                    gameLoop.Stop();
                }
            }

            // remove box if it has gone of screen
            if (boxesLeft[0].y > this.Height)
            {
                boxesLeft.RemoveAt(0);
            }
            if (boxesRight[0].y > this.Height)
            {
                boxesRight.RemoveAt(0);
            }

            // add new box if it is time
            boxCounter++;
            if (boxCounter == 7)
            {
                Colourchooser();
                Box b1 = new Box(25, 24, 20, randomColourLeft);
                Box b2 = new Box(100, 24, 20, randomColourRight);
                boxesLeft.Add(b1);
                boxesRight.Add(b2);
                boxCounter = 0;
            }

            Refresh();
        }
Esempio n. 8
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            foreach (Box b in boxList)
            {
                b.Move();
            }
            boxCountdown--;
            Form1.currentScore++;

            if (Form1.currentScore % 1000 == 0)
            {
                scoreSound.Play();
            }
            #region difficulty scaling
            if (Form1.currentScore % 1000 == 0 && Form1.currentScore <= 7000) //the speed will gradually increase to a point, at which point it becomes a test of endurance
            {
                foreach (Box b in boxList)
                {
                    b.speed++;
                }
                boxSpeed++;
                if (newBoxCounter > 0)
                {
                    newBoxCounter--;
                }
                rightColumnBoxLocation -= 5;
            }
            if (Form1.currentScore % 2500 == 0 && Form1.currentScore <= 5000) //the player will gradually get faster to a point
            {
                maxPlayerSpeed++;
            }
            #endregion

            scoreLabel.Text = "Score: " + (Form1.currentScore + 1); //adding 1 to sync up the displayed score with the actual score

            #region creates boxes in the "random" phase
            if (randomSectionTimer > 0)
            {
                randomSectionTimer--;

                if (randomSectionTimer < phaseBuffer) //waits for a few timer ticks as a buffer between phases
                {
                    colourCounterUp++;
                    colourCounterDown--;
                    //if (colourCounterDown == 0)
                    //{
                    //    colourCounterDown = 255;
                    //}
                    //if (colourCounterUp == 255)
                    //{
                    //    colourCounterUp = 0;
                    //}
                    if (boxCountdown <= 0)
                    {
                        Box b = new Box(randnum.Next(0, this.Width * Convert.ToInt16(0.75)), -boxSize, boxSize, boxSpeed, 255, 255, 255);
                        boxList.Add(b);
                        boxCountdown = newBoxCounter;
                    }
                    if (backColour == "red")
                    {
                        backColourRed   = colourCounterDown;
                        backColourGreen = colourCounterUp;
                        backColourBlue  = 0;
                        this.BackColor  = Color.FromArgb(backColourRed, backColourGreen, backColourBlue);
                        if (colourCounterDown <= 0)
                        {
                            backColour        = "green";
                            colourCounterDown = 255;
                            colourCounterUp   = 0;
                        }
                    }
                    if (backColour == "green")
                    {
                        backColourRed   = 0;
                        backColourGreen = colourCounterDown;
                        backColourBlue  = colourCounterUp;
                        this.BackColor  = Color.FromArgb(backColourRed, backColourGreen, backColourBlue);
                        if (colourCounterDown <= 0)
                        {
                            backColour        = "blue";
                            colourCounterDown = 255;
                            colourCounterUp   = 0;
                        }
                    }
                    if (backColour == "blue")
                    {
                        backColourRed   = colourCounterUp;
                        backColourGreen = 0;
                        backColourBlue  = colourCounterDown;
                        this.BackColor  = Color.FromArgb(backColourRed, backColourGreen, backColourBlue);
                        if (colourCounterDown <= 0)
                        {
                            backColour        = "red";
                            colourCounterDown = 255;
                            colourCounterUp   = 0;
                        }
                    }
                }

                if (randomSectionTimer <= 0)
                {
                    transitioning     = true;; //1875 ticks is equal to 15 seconds at 125 fps
                    columnBoxLocation = randnum.Next(5, this.Width - rightColumnBoxLocation - boxSize);
                }
            }
            #endregion

            #region transition to column phase
            else if (transitioning)
            {
                int leftDistanceRequired  = columnBoxLocation;
                int rightDistanceRequired = this.Width - columnBoxLocation - rightColumnBoxLocation - boxSize;
                int generalDistanceRequired;
                if (leftDistanceRequired > rightDistanceRequired)
                {
                    generalDistanceRequired = leftDistanceRequired;
                }
                else
                {
                    generalDistanceRequired = rightDistanceRequired;
                }

                if (boxCountdown <= 0)
                {
                    //Gets the inverse of the background colour, for guarenteed aesthetic pleasing-ness
                    int redValue   = 255 - backColourRed;
                    int greenValue = 255 - backColourGreen;
                    int blueValue  = 255 - backColourBlue;

                    Box b1 = new Box(columnBoxLocation - generalDistanceRequired + transitionCounterThing, -boxSize, boxSize, boxSpeed, redValue, greenValue, blueValue);
                    boxList.Add(b1);
                    Box b2 = new Box(columnBoxLocation + rightColumnBoxLocation + generalDistanceRequired - transitionCounterThing, -boxSize, boxSize, boxSpeed, redValue, greenValue, blueValue);
                    boxList.Add(b2);
                    transitionCounterThing += boxSize;
                    boxCountdown            = newBoxCounter;
                }
                if (transitionCounterThing >= generalDistanceRequired)
                {
                    transitioning          = false;
                    columnSectionTimer     = randnum.Next(500, 1251); //change back to 600 after
                    transitionCounterThing = 0;
                }
            }
            #endregion

            #region creates boxes in the "column" phase
            else if (columnSectionTimer > 0)
            {
                columnSectionTimer--;
                boxColourUp   += 5;
                boxColourDown -= 5;


                if (boxCountdown <= 0)
                {
                    //boxes in the column phase are the inverse of whatever colour the background was when the phase started
                    int redValue   = 255 - backColourRed;
                    int greenValue = 255 - backColourGreen;
                    int blueValue  = 255 - backColourBlue;

                    //if the boxes are supposed to be moving left, their x value will decrease
                    if (direction == "left")
                    {
                        columnBoxLocation -= 5;

                        if (columnBoxLocation <= 0)
                        {
                            counter = randomNumber; //changes the direction the column is shifting
                        }
                        counter++;
                    }

                    else if (direction == "right")
                    {
                        columnBoxLocation += 5;
                        if (columnBoxLocation + rightColumnBoxLocation >= this.Width - boxSize)
                        {
                            counter = randomNumber; //changes the direction the column is shifting
                        }
                        counter++;
                    }



                    boxCountdown = newBoxCounter;

                    if (columnBoxLocation < 0 || columnBoxLocation + rightColumnBoxLocation + boxSize > this.Width)
                    {
                        counter = randomNumber;
                    }
                    if (counter == randomNumber)
                    {
                        randomNumber = randnum.Next(10, 51);
                        counter      = 0;

                        if (direction == "left")
                        {
                            direction = "right";
                        }
                        else if (direction == "right")
                        {
                            direction = "left";
                        }
                    }


                    Box b1 = new Box(columnBoxLocation, -boxSize, boxSize, boxSpeed, redValue, greenValue, blueValue);
                    boxList.Add(b1);
                    Box b2 = new Box(columnBoxLocation + rightColumnBoxLocation, -boxSize, boxSize, boxSpeed, redValue, greenValue, blueValue);
                    boxList.Add(b2);
                }

                if (columnSectionTimer <= 0)
                {
                    randomSectionTimer = randnum.Next(500, 1501); //the timer is greater than the max timer for the randomsection so that there is a delay between the two phases
                    phaseBuffer        = randomSectionTimer - bufferTicks;
                }
            }
            #endregion

            //removes box after it has gone offscreen
            if (boxList.Count > 0)
            {
                if (boxList[0].y > this.Height && boxList.Count > 0)
                {
                    boxList.RemoveAt(0);
                }
            }
            #region player movement and collision
            //Move player
            if (leftArrowDown)
            {
                player.Move("left");
                if (currentPlayerSpeed < maxPlayerSpeed) //&& (Form1.currentScore / 2) % 2 == 0)
                {
                    currentPlayerSpeed = currentPlayerSpeed * 8 / 5;
                    if (currentPlayerSpeed > maxPlayerSpeed)
                    {
                        currentPlayerSpeed = maxPlayerSpeed;
                    }
                    player.speed = currentPlayerSpeed;

                    //player.speed = Convert.ToInt16(Math.Round(currentPlayerSpeed));
                }

                if (player.x < 0) //if the player is too far to the left
                {
                    player.x += player.speed;
                }
            }

            if (rightArrowDown)
            {
                player.Move("right");
                if (currentPlayerSpeed < maxPlayerSpeed) //&& (Form1.currentScore / 2) % 2 == 0)
                {
                    currentPlayerSpeed = currentPlayerSpeed * 8 / 5;
                    if (currentPlayerSpeed > maxPlayerSpeed)
                    {
                        currentPlayerSpeed = maxPlayerSpeed;
                    }
                    player.speed = currentPlayerSpeed;

                    //player.speed = Convert.ToInt16(Math.Round(currentPlayerSpeed));
                }

                if (player.x > this.Width - player.size) //if the player is too far to the right
                {
                    player.x -= player.speed;
                }
            }
            else if (rightArrowDown == false && leftArrowDown == false)
            {
                currentPlayerSpeed = 2;
            }

            //Check for collision between player and boxes
            foreach (Box b in boxList)
            {
                Boolean hasCollided = false;

                hasCollided = player.Collision(b);

                if (hasCollided)
                {
                    gameLoop.Stop();
                    Refresh();


                    //plays a sound effect once the player gets hit / loses
                    SoundPlayer soundplayer = new SoundPlayer(Properties.Resources.smb_mariodie);
                    soundplayer.Play();

                    //waits for the sound effect to finish before continuing on to the next screen
                    Thread.Sleep(500);

                    Form f = this.FindForm();
                    f.Controls.Remove(this);

                    LoseScreen ls = new LoseScreen();
                    ls.Location = new Point((f.Width - ls.Width) / 2, (f.Height - ls.Height) / 2);

                    f.Controls.Add(ls);
                }
            }
            #endregion
            Refresh();
        }
Esempio n. 9
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            //update location of all boxes (drop down screen)
            foreach (Box b in leftBoxes)
            {
                b.leftMove();
            }

            foreach (Box b in rightBoxes)
            {
                b.rightMove();
            }

            //add new box if it is time

            newBoxCounter++;

            if (newBoxCounter == 60)
            {
                //creating all of the boxes on the screen and adding them to lists.
                Box b1 = new Box(-40, 100, boxSize, boxSpeed3);
                Box b2 = new Box(-40, 130, boxSize, boxSpeed2);
                Box b3 = new Box(-40, 300, boxSize, boxSpeed1);
                Box b4 = new Box(1000, 200, boxSize, boxSpeed3);
                Box b5 = new Box(1000, 250, boxSize, boxSpeed2);
                Box b6 = new Box(1000, 350, boxSize, boxSpeed1);

                leftBoxes.Add(b1);
                leftBoxes.Add(b2);
                leftBoxes.Add(b3);
                rightBoxes.Add(b4);
                rightBoxes.Add(b5);
                rightBoxes.Add(b6);
                newBoxCounter = 0;
            }
            //Removing boxes after they leave the screen
            foreach (Box b in leftBoxes)
            {
                if (leftBoxes[0].x > this.Width - 20)
                {
                    leftBoxes.RemoveAt(0);
                    break;
                }
            }

            foreach (Box b in rightBoxes)
            {
                if (rightBoxes[0].x < -20)
                {
                    rightBoxes.RemoveAt(0);
                    break;
                }
            }

            //hero collison with the sides of the screen
            if (hero.x < -40)
            {
                hero.x = 900;
            }
            if (hero.x > 900)
            {
                hero.x = -40;
            }

            //move our hero
            if (leftArrowDown == true)
            {
                hero.Move("left");
                leftArrowDown = false;
            }

            if (leftArrowUp == true)
            {
                leftArrowDown = true;
            }

            if (rightArrowDown == true)
            {
                hero.Move("right");
                rightArrowDown = false;
            }

            if (rightArrowUp == true)
            {
                rightArrowDown = true;
            }

            if (upArrowDown == true)
            {
                hero.Move("up");
                upArrowDown = false;
                score1++;
            }

            if (upArrowUp == true)
            {
                upArrowUp = true;
            }

            if (downArrowDown == true)
            {
                hero.Move("down");
                downArrowDown = false;
                score1        = score1 - 2;
            }

            if (downArrowUp == true)
            {
                downArrowUp = true;
            }

            //Check for collision between hero and boxes
            foreach (Box b in leftBoxes)
            {
                if (hero.Collision(b))
                {
                    squashPlayer.Play();

                    gameLoop.Enabled = false;
                    Form f = this.FindForm();
                    f.Controls.Remove(this);

                    GameoverScreen gos = new GameoverScreen();
                    f.Controls.Add(gos);
                }
            }

            foreach (Box b in rightBoxes)
            {
                if (hero.Collision(b))
                {
                    squashPlayer.Play();

                    gameLoop.Enabled = false;
                    Form f = this.FindForm();
                    f.Controls.Remove(this);

                    GameoverScreen gos = new GameoverScreen();
                    f.Controls.Add(gos);
                }
            }

            //check top wall
            if (hero.wallCollision(topWall))
            {
                hero.Move("down");
            }
            //check bottom wall
            if (hero.wallCollision(bottomWall))
            {
                hero.Move("up");
            }
            //check victory wall
            if (hero.wallCollision(victoryWall))
            {
                Thread.Sleep(1500);

                gameLoop.Enabled = false;
                Form f = this.FindForm();
                f.Controls.Remove(this);

                victoryScreen vs = new victoryScreen();
                f.Controls.Add(vs);
            }

            Refresh();
        }
Esempio n. 10
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            //TODO - update location of all boxes (drop down screen)
            foreach (Box b in boxes)
            {
                b.Move();
                //check for collision between hero and boxes
            }
            Form1.currentScore = sideCounter;
            scoreLabel.Text    = "Levels Completed: " + Convert.ToString(sideCounter);

            //add new box if it is time
            newBoxCounter++;
            //Level 1
            if (sideCounter == 0)
            {
                level1();
            }
            //Level 2
            if (sideCounter == 1)
            {
                level2();
            }
            //level 3
            if (sideCounter == 2)
            {
                level3();
            }
            //level 4
            if (sideCounter == 3)
            {
                level4();
            }
            //level 5
            if (sideCounter == 4)
            {
                level5();
            }
            //level 6
            if (sideCounter == 5)
            {
                level6();
            }
            //level 7
            if (sideCounter == 6)
            {
                level7();
            }
            //level 8
            if (sideCounter == 7)
            {
                level8();
            }
            //level 9
            if (sideCounter == 8)
            {
                level9();
            }
            //level 10
            if (sideCounter == 9)
            {
                level10();
            }
            //level 11
            if (sideCounter == 10)
            {
                level11();
            }
            if (sideCounter == 11)
            {
                level12();
            }
            if (sideCounter == 12)
            {
                level13();
            }
            if (sideCounter == 13)
            {
                level14();
            }
            if (sideCounter == 14)
            {
                if (Form1.gamemode == 2)
                {
                    gameLoop.Stop();

                    Form form = this.FindForm();
                    Menu ms   = new Menu();
                    ms.Location = new Point((form.Width - ms.Width) / 2, (form.Height - ms.Height) / 2);

                    form.Controls.Add(ms);
                    form.Controls.Remove(this);
                }
                if (Form1.gamemode == 1)
                {
                    level15();
                }
            }
            if (sideCounter == 15)
            {
                gameLoop.Stop();


                LoseScreen ls   = new LoseScreen();
                Form       form = this.FindForm();
                ls.Location = new Point((form.Width - ls.Width) / 2, (form.Height - ls.Height) / 2);

                form.Controls.Add(ls);
                form.Controls.Remove(this);
            }
            //this is a placeholder for more levels
            //sideCounter = 0;

            List <int> boxesToRemove = new List <int>();

            //remove box if it has gone of screen vertical
            foreach (Box b in boxes)
            {
                if (b.yspeed < 0 && (b.y + b.size) < -100)
                {
                    boxesToRemove.Add(boxes.IndexOf(b));
                }
                if (b.yspeed > 0 && (b.y + b.size) > this.Height + 100)
                {
                    boxesToRemove.Add(boxes.IndexOf(b));
                }
            }
            boxesToRemove.Sort();
            boxesToRemove.Reverse();

            //remove boxes from its original list based on index values
            foreach (int i in boxesToRemove)
            {
                boxes.RemoveAt(i);
            }

            boxesToRemove.Clear();

            //remove box if it has gone of screen horizontal
            foreach (Box b in boxes)
            {
                if (b.xspeed < 0 && (b.x + b.size) < this.Width - 800)
                {
                    boxesToRemove.Add(boxes.IndexOf(b));
                }
                if (b.xspeed > 0 && (b.x + b.size) > this.Width - 100)
                {
                    boxesToRemove.Add(boxes.IndexOf(b));
                }
            }
            boxesToRemove.Sort();
            boxesToRemove.Reverse();

            //remove boxes from its original list based on index values
            foreach (int i in boxesToRemove)
            {
                boxes.RemoveAt(i);
            }

            if (hero.x > this.Width - 50)
            {
                //Random randonGen = new Random();
                //Color randomColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255),
                //randonGen.Next(255));
                sideCounter++;
                hero.Move("right");
                hero.Move("right");
            }

            //move hero
            if (leftArrowDown)
            {
                hero.Move("left");
            }
            if (rightArrowDown)
            {
                hero.Move("right");
            }
            if (upArrowDown)
            {
                hero.Move("up");
            }
            if (downArrowDown)
            {
                hero.Move("down");
            }

            foreach (Box b in boxes)
            {
                if (hero.Collision(b))
                {
                    if (Form1.gamemode == 1)
                    {
                        gameLoop.Stop();


                        LoseScreen ls   = new LoseScreen();
                        Form       form = this.FindForm();
                        ls.Location = new Point((form.Width - ls.Width) / 2, (form.Height - ls.Height) / 2);

                        form.Controls.Add(ls);
                        form.Controls.Remove(this);
                        break;
                    }
                    if (Form1.gamemode == 2)
                    {
                        hero = new Box(50, 250, 20, heroyspeed, 0);
                        break;
                    }
                }
            }
            Refresh();
        }
Esempio n. 11
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            //Moves All Boxes Down Screen
            foreach (Box b in leftBoxes)
            {
                b.Move(boxSpeed);
            }
            foreach (Box b in rightBoxes)
            {
                b.Move(boxSpeed);
            }

            //Check and remove the bottom box if it has gone off screen
            if (leftBoxes[0].y >= this.Height)
            {
                leftBoxes.Remove(leftBoxes[0]);
            }
            if (rightBoxes[0].y >= this.Height)
            {
                rightBoxes.Remove(rightBoxes[0]);
            }

            //Randomly change direction, 1 in 50
            change = randGen.Next(1, 101);
            if (change <= 2)
            {
                moveRight = !moveRight;
            }

            //If the boxes collide with walls, change direction
            if (location >= this.Width - 300)
            {
                moveRight = false;
            }
            else if (location <= 0)
            {
                moveRight = true;
            }
            else
            {
            }

            //Detect Movement
            if (leftBoxes[2].x + (leftBoxes[2].size / 2) + 50 > p.x)
            {
                p.Move(5, "right");
            }
            else if (leftBoxes[2].x + (leftBoxes[2].size / 2) + 50 < p.x)
            {
                p.Move(5, "left");
            }

            //if (rightArrowDown) { p.Move(3, "right"); }
            //else if (leftArrowDown){p.Move(3, "left");}

            boxTimer++;
            if (boxTimer % 2 == 0)
            {
                if (moveRight == true)
                {
                    location = location + 10;
                }
                else
                {
                    location = location - 10;
                }
                c = randGen.Next(1, 6);
                Box b1 = new Box(location, 0, 25, c);
                leftBoxes.Add(b1);
                Box b2 = new Box(location + 125, 0, 25, c);
                rightBoxes.Add(b2);
                boxTimer = 0;
            }

            foreach (Box b in leftBoxes.Union(rightBoxes))
            {
                if (p.Collision(b))
                {
                    gameLoop.Stop();
                }
                else
                {
                }
            }
            Refresh();
        }
Esempio n. 12
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            #region create new box if it is time
            newBoxCounter--;

            if (newBoxCounter == 0)
            {
                if (patternLength == 0)
                {
                    patternLeft   = !patternLeft; //change direction
                    patternLength = rand.Next(5, 15);
                    xChange       = rand.Next(10, 25);

                    if (patternLeft)
                    {
                        xChange *= -1;
                    }                                   // xChange value made negative to move left
                }

                // create left and right cubes
                int   randValue = rand.Next(1, 4);
                Color c         = Color.White;

                if (randValue == 1)
                {
                    c = Color.Red;
                }
                else if (randValue == 2)
                {
                    c = Color.Yellow;
                }
                else if (randValue == 3)
                {
                    c = Color.Orange;
                }

                leftStartX = boxesLeft[boxesLeft.Count() - 1].rec.X + xChange; // set left position

                Box b1 = new Box(leftStartX, 0, boxSize, c);
                Box b2 = new Box(leftStartX + gap, 0, boxSize, c);
                boxesLeft.Add(b1);
                boxesRight.Add(b2);

                newBoxCounter = 5;
                patternLength--;
            }

            #endregion

            #region update position of each box

            foreach (Box b in boxesLeft)
            {
                b.Move(boxSpeed);
            }

            foreach (Box b in boxesRight)
            {
                b.Move(boxSpeed);
            }

            #endregion

            #region Remove boxes from list that have gone off the screen

            if (boxesLeft[0].rec.Y > this.Height)
            {
                boxesLeft.RemoveAt(0);
                boxesRight.RemoveAt(0);
            }

            #endregion

            #region move hero

            if (leftArrowDown)
            {
                hero.Move(heroSpeed, "left");
            }
            else if (rightArrowDown)
            {
                hero.Move(heroSpeed, "right");
            }

            #endregion

            #region check for a collision

            foreach (Box b in boxesLeft.Union(boxesRight))
            {
                if (hero.Collision(b))
                {
                    gameLoop.Stop();
                }
            }

            #endregion

            Refresh();
        }
Esempio n. 13
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            leftMoveCounter++;
            rightMoveCounter++;

            //update location of all boxes (drop down screen)
            foreach (Box b in left)
            {
                b.Move(10);
            }
            foreach (Box b in right)
            {
                b.Move(10);
            }
            //remove box if it has gone of screen
            if (left[0].y > this.Height)
            {
                left.RemoveAt(0);
            }
            if (right[0].y > this.Height)
            {
                right.RemoveAt(0);
            }
            //add new box if it is time
            if (leftMoveCounter > 2)
            {
                leftMoveCounter = 0;
                MakeBox();
            }
            if (rightMoveCounter > 2)
            {
                rightMoveCounter = 0;
                MakeBox();
            }

            //move character
            //if (leftArrowDown == true)
            //{
            //    hero.x -= heroSpeed;
            //}
            //if (rightArrowDown == true)
            //{
            //    hero.x += heroSpeed;
            //}
            //if (upArrowDown == true)
            //{
            //    hero.y -= heroSpeed;
            //}
            //if (downArrowDown == true)
            //{
            //    hero.y += heroSpeed;
            //}

            if (leftArrowDown == true)
            {
                hero.Move(heroSpeed, false);
            }
            else if (rightArrowDown == true)
            {
                hero.Move(heroSpeed, true);
            }
            if (upArrowDown == true)
            {
                hero.Move2(heroSpeed, false);
            }
            if (downArrowDown == true)
            {
                hero.Move2(heroSpeed, true);
            }

            Rectangle heroRec = new Rectangle(hero.x, hero.y, hero.size, hero.size);

            if (left.Count >= 15)
            {
                for (int i = 0; i < 15; i++)
                {
                    Rectangle boxRec      = new Rectangle(left[i].x, left[i].y, left[i].size, left[i].size);
                    Rectangle rightBoxRec = new Rectangle(right[i].x, right[i].y, right[i].size, right[i].size);

                    if (boxRec.IntersectsWith(heroRec) || rightBoxRec.IntersectsWith(heroRec))
                    {
                        gameLoop.Enabled = false;
                    }
                }
            }

            Refresh();
        }
Esempio n. 14
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            //TODO - update location of all boxes (drop down screen)

            //move the hero
            if (leftArrowDown)
            {
                hero.Move("left");
            }

            if (rightArrowDown)
            {
                hero.Move("right");
            }

            if (upArrowDown)
            {
                hero.Move("up");
            }

            if (downArrowDown)
            {
                hero.Move("down");
            }

            //
            double distance = Math.Sqrt(Math.Pow(hero.x - cow.x, 2) + Math.Pow(hero.y - cow.y, 2));

            //check for collsion between hero and cow
            if (hero.Collision(cow))
            {
                found = true;
            }
            else
            {
                found = false;
            }

            if (hero.Collision(cow) && spaceDown)
            {
                //pause game
                gameLoop.Enabled = false;

                //create an instance of the VictoryScreen
                VictoryScreen vs = new VictoryScreen();

                //find the form for current screen
                Form f = this.FindForm();

                //resize the screen
                f.Size = new Size(300, 300);

                //add the User Control to the Form
                f.Controls.Add(vs);

                //remove current screen from the form
                f.Controls.Remove(this);
            }

            //refresh
            Refresh();
        }
Esempio n. 15
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            // update location of all boxes (drop down screen)
            foreach (Box b in leftBoxes)
            {
                b.Move(boxSpeed);
            }

            foreach (Box b in rightBoxes)
            {
                b.Move(boxSpeed);
            }

            if (leftArrowDown)
            {
                player.Move(5, "left");
            }

            if (rightArrowDown)
            {
                player.Move(5, "right");
            }

            // check for collision between player and boxes (foreach loop with two lists)
            foreach (Box b in leftBoxes.Union(rightBoxes))
            {
                if (player.Collision(b))
                {
                    gameLoop.Stop();
                }
            }

            // remove box if it has gone of screen
            if (leftBoxes[0].y > this.Height - leftBoxes[0].size)
            {
                leftBoxes.RemoveAt(0);
            }
            if (rightBoxes[0].y > this.Height - rightBoxes[0].size)
            {
                rightBoxes.RemoveAt(0);
            }

            // add new box if it is time
            boxCounter++;

            // increment index to create pattern
            if (moveRight)
            {
                index++;
            }
            else if (!moveRight)
            {
                index--;
            }

            if (index >= 360)
            {
                // move left
                moveRight = false;
            }
            else if (index < 50)
            {
                moveRight = true;
            }

            if (boxCounter % 5 == 0)
            {
                Box b1 = new Box(25 + (xValue * index), 24, 20, MakeRandomColour());
                leftBoxes.Add(b1);

                Box b2 = new Box(125 + (xValue * index), 24, 20, b1.colour);
                rightBoxes.Add(b2);
            }

            Refresh();
        }
Esempio n. 16
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            //TODO - update location of all boxes (drop down screen)
            foreach (Box b in boxesLeft)
            {
                b.Fall();
            }

            foreach (Box a in boxesRight)
            {
                a.Fall();
            }

            //TODO - remove box if it has gone of screen
            if (boxesLeft[0].y > this.Height)
            {
                boxesLeft.RemoveAt(0);
            }

            if (boxesRight[0].y > this.Height)
            {
                boxesRight.RemoveAt(0);
            }
            //TODO - add new box if it is time
            counter++;
            if (counter == 5)
            {
                boxLeftX = boxLeftX + boxOffset;
                newBoxCounter++;

                alphaStart = randGen.Next(1, 256);
                redStart   = randGen.Next(1, 256);
                greenStart = randGen.Next(1, 256);
                blueStart  = randGen.Next(1, 256);
                randomX    = randGen.Next(1, this.Width);

                tempBrush = new SolidBrush(Color.FromArgb(alphaStart, redStart, greenStart, blueStart));


                Box box = new Box(tempBrush, boxLeftX, 0, 10);
                boxesLeft.Add(box);

                Box box2 = new Box(tempBrush, boxLeftX + boxGap, 0, 10);
                boxesRight.Add(box2);

                counter = 0;

                if (newBoxCounter == patternAmount)
                {
                    boxOffset     = -boxOffset;
                    newBoxCounter = 0;

                    patternAmount = randGen.Next(1, 50);
                }
            }

            //move hero
            if (leftArrowDown)
            {
                hero.Move("left");
            }

            if (rightArrowDown)
            {
                hero.Move("right");
            }

            //check for collision between hero and box
            foreach (Box b in boxesLeft.Union(boxesRight))
            {
                if (b.Collision(hero))
                {
                    gameLoop.Enabled = false;
                }
            }

            Refresh();
        }