示例#1
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();
        }
示例#2
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            #region down
            int downSpeed = 5;

            // - update location of all boxes (drop down screen)
            foreach (box b in boxLeft)
            {
                b.boxMove(downSpeed);
            }

            foreach (box b in boxRight)
            {
                b.boxMove(downSpeed);
            }

            #endregion

            #region player movement
            if (leftArrowDown)
            {
                player.boxMove("left", 5);
            }

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

            foreach (box b in boxLeft.Union(boxRight))
            {
                if (player.Collision(b))
                {
                    gameLoop.Stop();
                }
            }
            #endregion

            #region remove
            // - remove box if it has gone of screen
            if (boxLeft[0].y > this.Height - 50)
            {
                boxLeft.RemoveAt(0);
                boxRight.RemoveAt(0);
            }


            #endregion

            #region addding
            // - add new box if it is time
            counter++;

            if (counter == 8)
            {
                Random randGen = new Random();
                int    r       = randGen.Next(0, 255);
                int    g       = randGen.Next(0, 255);
                int    blue    = randGen.Next(0, 255);

                moveSwitch = randGen.Next(0, 11);

                if (moveSide == false)
                {
                    box1X -= 10;
                    box2X -= 10;
                    if (box1X <= 25)
                    {
                        moveSide = true;
                    }
                    if (moveSwitch == counter)
                    {
                        moveSide = true;
                    }
                }
                if (moveSide == true)
                {
                    box1X += 10;
                    box2X += 10;
                    if (box2X >= 475)
                    {
                        moveSide = false;
                    }
                    if (moveSwitch == counter)
                    {
                        moveSide = false;
                    }
                }

                box anotherBox = new box(box1X, 25, 20, r, g, blue);
                boxLeft.Add(anotherBox);
                box fourthBox = new box(box2X, 25, 20, r, g, blue);
                boxRight.Add(fourthBox);

                counter = 0;
            }
            #endregion

            Refresh();
        }