예제 #1
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();
        }
예제 #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();
        }
예제 #3
0
        /// <summary>
        /// Set initial game values here
        /// </summary>
        public void OnStart()
        {
            // - set game start values
            box newBox   = new box(25, 25, 20, 0, 0, 0);
            box thirdBox = new box(200, 25, 20, 0, 0, 0);

            boxLeft.Add(newBox);
            boxRight.Add(thirdBox);

            player = new box(120, this.Height - 75, 25, 255, 0, 0);
        }
예제 #4
0
파일: box.cs 프로젝트: Samunear779/BoxField
        public bool Collision(box b)
        {
            Rectangle rect1 = new Rectangle(b.x, b.y, b.size, b.size);
            Rectangle rect2 = new Rectangle(x, y, size, size);

            if (rect1.IntersectsWith(rect2))
            {
                return(true);
            }
            return(false);
        }
예제 #5
0
        /// <summary>
        /// Set initial game values here
        /// </summary>
        public void OnStart()
        {
            //TODO - set game start values

            box b1 = new box(50, 50, 20);

            boxesLeft.Add(b1);
            box b2 = new box(825, 50, 20);

            boxesRight.Add(b2);
            player = new box(400, this.Height - 50, 20);
        }
예제 #6
0
        /// <summary>
        /// Set initial game values here
        /// </summary>
        public void OnStart()
        {
            //set game start values
            box b1 = new box(boxLeftX, 0, boxSize);

            boxesLeft.Add(b1);

            box b2 = new box(boxLeftX + boxGap, 0, boxSize);

            boxesRight.Add(b2);

            newBoxCounter++;

            hero = new box(50, 300, 20);
        }
예제 #7
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();
        }