示例#1
0
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            camera = new Camera(new Vector3(0.0f, 6.0f, 25.0f), new Vector3(0f, 6f, 0f), Vector3.Up);
            pos = camera.Position;
            rot = Vector3.Zero;

            this.CreateCamera();

            float width = 10f;
            float height = 3f;

            float interval = 0f;
            float startX = - (width / 2f);
            float rackY = 0;
            float startY = rackY + 9;

            grid = new Grid(new Vector2(width, height), new Vector3(startX, startY, 0.0f), new Vector3(1f, 1f, 1f), interval);
            rack = new Pong(new Vector3(0, rackY, 0), new Vector3(1f, 1f, 1f));
            ball = new Ball(new Vector3(0, 0, 0), new Vector3(0.60f, 0.60f, 0.60f), 0.07f);

            terrain = new Terrain(new Vector3(-0.5f, 6, 0), new Vector3(12f, 15f, 0f));

            Vector3 loc = rack.Location;
            loc.Y = rack.Location.Y + rack.Scale.Y / 8 + ball.Scale.Y / 2;
            ball.Location = loc;

            sky = new SkyBox();
            sky.Initialize(this.GraphicsDevice);

            textureList = new List<Texture2D>();
            modelList = new List<Model>();

            base.Initialize();
        }
示例#2
0
        public void Update(ref Ball ball)
        {
            bool collision = false;

            for (int i = 0; i < Height && !collision; i++)
            {
                for (int j = 0; j < Width && !collision; j++)
                {
                    Cube3D c = elements[i][j];
                        //*

                    if (c.Visible)
                    {
                        // collision par le bas
                        if (ball.Location.Y > c.Location.Y - (c.Scale.Y / 2f) - (ball.Scale.Y / 2f) && ball.Location.Y < c.Location.Y - (c.Scale.Y / 2f) &&
                            ball.Location.X > c.Location.X - (c.Scale.X / 2f) && ball.Location.X < c.Location.X + (c.Scale.X / 2f))
                        {
                            Vector3 direction = Vector3.Zero;

                            direction.X = ball.Direction.X;
                            direction.Y = -ball.Direction.Y;

                            ball.Direction = direction;
                            collision = true;

                            ball.Update();
                            c.Visible = false;
                        }
                        // collision par le haut
                        else if (ball.Location.Y < c.Location.Y + (c.Scale.Y / 2f) + (ball.Scale.Y / 2f) && ball.Location.Y > c.Location.Y + (c.Scale.Y / 2f) &&
                                ball.Location.X > c.Location.X - (c.Scale.X / 2f) && ball.Location.X < c.Location.X + (c.Scale.X / 2f))
                        {
                            Vector3 direction = Vector3.Zero;

                            direction.X = ball.Direction.X;
                            direction.Y = -ball.Direction.Y;

                            ball.Direction = direction;
                            collision = true;
                            ball.Update();
                            c.Visible = false;
                        }

                        // collision par la gauche
                        else if (ball.Location.X > c.Location.X - (c.Scale.X / 2f) - (ball.Scale.X / 2f) && ball.Location.X < c.Location.X - (c.Scale.X / 2f) &&
                                ball.Location.Y > c.Location.Y - (c.Scale.Y / 2f) && ball.Location.Y < c.Location.Y + (c.Scale.Y / 2f))
                        {
                            Vector3 direction = Vector3.Zero;

                            direction.X = -ball.Direction.X;
                            direction.Y = ball.Direction.Y;

                            ball.Direction = direction;
                            collision = true;
                            ball.Update();
                            c.Visible = false;
                        }
                        // collision par la droite
                        else if (ball.Location.X < c.Location.X + (c.Scale.X / 2f) + (ball.Scale.X / 2f) && ball.Location.X > c.Location.X + (c.Scale.X / 2f) &&
                                ball.Location.Y > c.Location.Y - (c.Scale.Y / 2f) && ball.Location.Y < c.Location.Y + (c.Scale.Y / 2f))
                        {
                            Vector3 direction = Vector3.Zero;

                            direction.X = -ball.Direction.X;
                            direction.Y = ball.Direction.Y;

                            ball.Direction = direction;
                            collision = true;
                            ball.Update();
                            c.Visible = false;
                        }

                    }

            //*/
                }
            }
        }