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();
        }
Exemple #2
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            boxCounter++;
            //TODO - update location of all boxes (drop down screen)
            foreach (box b1 in boxesLeft)
            {
                b1.Move(boxSpeed);
            }

            foreach (box b2 in boxesRight)
            {
                b2.Move(boxSpeed);
            }

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

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

            //check for collsioon between player and boxes
            foreach (box b in boxesLeft.Union(boxesRight))
            {
                if (player.Collision(b))
                {
                    gameLoop.Stop();
                }
            }

            //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
            if (boxCounter == 8)
            {
                box b1 = new box(50, 50, 20);
                boxesLeft.Add(b1);

                box b2 = new box(825, 50, 20);
                boxesRight.Add(b2);
                boxCounter = 0;
            }
            Refresh();
        }