示例#1
0
文件: Engine.cs 项目: ATholin/Bounce
        private void TimerEventHandler(Object obj, EventArgs args)
        {
            if (random.Next(100) < 25)
            {
                AddBall();
            }

            foreach (var ball in balls)
            {
                foreach (var c in collidables)
                {
                    if (c.Intersects(ball))
                    {
                        c.OnCollision(ball);
                    }
                }

                ball.Move();

                if (ball.Position.X > form.Width || ball.Position.X < -20 || ball.Position.Y > form.Height || ball.Position.Y < -20)
                {
                    BallsToRemove.Add(ball);
                }
            }

            RemoveBalls();
            BallsToRemove.Clear();

            form.Refresh();
        }
示例#2
0
        private void TimerEventHandler(Object obj, EventArgs args)
        {
            if (Random.Next(100) < 25)
            {
                var ball = new Ball(400, 300, 10);
                ball.Speed = new Vector(Random.Next(10) - 5, Random.Next(10) - 5);
                //if (Balls.Count < 3)
                Balls.Add(ball);
            }

            foreach (var obs in Obstacles)
            {
                foreach (var ball in Balls)
                {
                    obs.HandleCollision(ball);
                }
            }

            foreach (var ball in Balls)
            {
                ball.Move();
            }

            Form.Refresh();
        }
示例#3
0
        private void TimerEventHandler(Object obj, EventArgs args)
        {
            Shape shape = null;

            if (random.Next(100) < 25)
            {
                AddBall();
            }

            foreach (var ball in balls)
            {
                foreach (var s in shapes)
                {
                    shape = ball.CheckIntersect(s);
                    if (shape != null)
                    {
                        switch (shape.ShapeType)
                        {
                        case Shape.Type.speed:
                            ball.Speed.X *= (float)1.03;
                            ball.Speed.Y *= (float)1.03;
                            break;

                        case Shape.Type.slow:
                            ball.Speed.X *= (float)0.98;
                            ball.Speed.Y *= (float)0.98;
                            break;

                        case Shape.Type.vertical:
                            ball.Speed.X *= -1;

                            break;

                        case Shape.Type.horizontal:
                            ball.Speed.Y *= -1;
                            break;
                        }
                    }
                }

                ball.Move();

                var x = ball.position.X;
                var y = ball.position.Y;

                if (x > form.Width || x < -20 || y > form.Height || y < -20)
                {
                    BallsToRemove.Add(ball);
                }
            }

            RemoveBalls();
            BallsToRemove.Clear();

            form.Refresh();

            ballsLabel.Text = "Balls: " + balls.Count;
        }