Exemple #1
0
        /// <summary>
        /// Inicialización
        /// </summary>
        protected override void Initialize()
        {
            // Actualizar la proyección
            GlobalMatrices.UpdateProjection(this.GraphicsDevice);

            // Cámara
            CameraGameComponent camera = new CameraGameComponent(this);

            camera.Position            = new Vector3(50.0f, 80.0f, 50.0f);
            camera.KeyBoardSensibility = 50;
            this.Components.Add(camera);

            // Suelo
            float    size = _TerrainSize * 0.5f;
            Vector3  NO   = new Vector3(-size, 40, size);
            Vector3  NE   = new Vector3(size, 20, size);
            Vector3  SO   = new Vector3(-size, 20, -size);
            Vector3  SE   = new Vector3(size, 30, -size);
            Triangle tr1  = new Triangle(NO, SO, NE);
            Triangle tr2  = new Triangle(NE, SO, SE);

            this.Physics.RegisterTerrain(new CollisionTriangleSoup(new Triangle[] { tr1, tr2 }, float.PositiveInfinity));
            FloorGameComponent floor = new FloorGameComponent(this, new Vector3[] { NO, NE, SO, SE }, @"floor");

            floor.Position = new Vector3(0f, 0f, 0f);
            this.Components.Add(floor);

            // Inicializa las balas
            List <AmmoRound> roundList = new List <AmmoRound>();

            for (int i = 0; i < _AmmoRounds; i++)
            {
                AmmoRound round = new AmmoRound(ShotType.UnUsed, 0f, 0f);
                this.Physics.RegisterAmmoData(round);
                roundList.Add(round);
            }

            AmmoDrawer ammoDrawer = new AmmoDrawer(this);

            ammoDrawer.Rounds = roundList.ToArray();
            this.Components.Add(ammoDrawer);

            // Inicializa las cajas
            Random rnd = new Random(DateTime.Now.Millisecond);

            for (int i = 0; i < _Boxes; i++)
            {
                // Inicializa los componentes gráficos de las cajas
                float   hsX = 0.5f + ((float)rnd.NextDouble() * 1.5f);
                float   hsY = 0.5f + ((float)rnd.NextDouble() * 1.5f);
                float   hsZ = 0.5f + ((float)rnd.NextDouble() * 1.5f);
                Vector3 min = new Vector3(-hsX, -hsY, -hsZ);
                Vector3 max = new Vector3(hsX, hsY, hsZ);

                CubeGameComponent cube = new CubeGameComponent(this, min, max);
                cube.Register(this.Physics);
                this.m_Cubes.Add(cube);
                this.Components.Add(cube);
            }

            // El tanque del jugador 1
            m_Tank_1 = new Tank(this);
            this.Components.Add(m_Tank_1);

            // El tanque del jugador 2
            m_Tank_2 = new Tank(this);
            this.Components.Add(m_Tank_2);

            base.Initialize();

            m_Tank_1.Register(this.Physics);
            m_Tank_2.Register(this.Physics);

            this.Reset();
        }
Exemple #2
0
        /// <summary>
        /// Inicialización
        /// </summary>
        protected override void Initialize()
        {
            // Inicializar el control de entrada de usuario
            InputHelper.Initialize(this.GraphicsDevice);

            // Actualizar la proyección
            GlobalMatrices.UpdateProjection(this.GraphicsDevice);
#if DEBUG
            // Debug
            GameComponents.Debug.DebugDrawer.Initialize(this.GraphicsDevice);
#endif

            // Suelo
            this.m_Scenery             = new DemoScenery(this, _TerrainSize, GlobalTraslation, @"Content/dharma");
            this.m_Scenery.UpdateOrder = 0;
            this.Components.Add(this.m_Scenery);
            this.Physics.RegisterScenery(this.m_Scenery);

            // Reflejo solar
            this.m_LensFlare           = new LensFlareComponent(this);
            this.m_LensFlare.DrawOrder = 98;
            this.Components.Add(this.m_LensFlare);

            // Texto
            this.m_Text           = new TextDrawerComponent(this);
            this.m_Text.DrawOrder = 99;
            this.Components.Add(this.m_Text);

            // Cámara
            this.m_Camera             = new CameraGameComponent(this);
            this.m_Camera.UseMouse    = true;
            this.m_Camera.Forward     = Keys.Up;
            this.m_Camera.Backward    = Keys.Down;
            this.m_Camera.Left        = Keys.Left;
            this.m_Camera.Right       = Keys.Right;
            this.m_Camera.Up          = Keys.Add;
            this.m_Camera.Down        = Keys.Subtract;
            this.m_Camera.Mode        = CameraGameComponent.CameraModes.Free;
            this.m_Camera.UpdateOrder = 99;
            this.Components.Add(this.m_Camera);

            // Un edificio
            this.m_Building_1             = new BuildingType0(this, @"Content/Buildings/", @"WHBuilding01.xml");
            this.m_Building_1.UpdateOrder = 3;
            this.Components.Add(this.m_Building_1);
            this.Physics.RegisterObject(this.m_Building_1);

            // Otro edificio
            this.m_Building_2             = new BuildingType0(this, @"Content/Buildings/", @"WHBuilding02.xml");
            this.m_Building_2.UpdateOrder = 3;
            this.Components.Add(this.m_Building_2);
            this.Physics.RegisterObject(this.m_Building_2);

            // Otro edificio
            this.m_Building_3             = new BuildingType0(this, @"Content/Buildings/", @"WHBuilding03.xml");
            this.m_Building_3.UpdateOrder = 3;
            this.Components.Add(this.m_Building_3);
            this.Physics.RegisterObject(this.m_Building_3);

            AmmoDrawer ammoDrawer = new AmmoDrawer(this, @"Content/dharma");
            ammoDrawer.Rounds      = this.Physics.Projectiles;
            ammoDrawer.UpdateOrder = 3;
            this.Components.Add(ammoDrawer);

            Random rnd = new Random(DateTime.Now.Millisecond);

            // Inicializa las cajas
            for (int i = 0; i < _Boxes; i++)
            {
                // Inicializa los componentes gráficos de las cajas
                float   hsX = 0.5f + ((float)rnd.NextDouble() * 1.5f);
                float   hsY = 0.5f + ((float)rnd.NextDouble() * 1.5f);
                float   hsZ = 0.5f + ((float)rnd.NextDouble() * 1.5f);
                Vector3 min = new Vector3(-hsX, -hsY, -hsZ);
                Vector3 max = new Vector3(hsX, hsY, hsZ);

                CubeGameComponent cube = new CubeGameComponent(this, min, max, (max - min).Length() * 20f);
                this.Physics.RegisterObject(cube);
                this.m_Cubes.Add(cube);
                cube.UpdateOrder = 4;
                this.Components.Add(cube);
            }

            // Inicializa las esferas
            for (int i = 0; i < _Balls; i++)
            {
                // Inicializa los componentes gráficos de las esferas
                float radius = 0.5f + ((float)rnd.NextDouble() * 1.5f);

                BallGameComponent ball = new BallGameComponent(this, radius, radius);
                this.Physics.RegisterObject(ball);
                this.m_Balls.Add(ball);
                ball.UpdateOrder = 4;
                this.Components.Add(ball);
            }

            // Land Raider
            this.m_LandRaider             = new LandRaider(this, "Content/Vehicles");
            this.m_LandRaider.UpdateOrder = 5;
            this.Components.Add(this.m_LandRaider);
            this.Physics.RegisterObject(m_LandRaider);

            // Leman Russ
            this.m_LemanRuss             = new LemanRuss(this, "Content/Vehicles");
            this.m_LemanRuss.UpdateOrder = 5;
            this.Components.Add(this.m_LemanRuss);
            this.Physics.RegisterObject(m_LemanRuss);

            // Land speeder 1
            this.m_LandSpeeder_1             = new LandSpeeder(this, "Content/Vehicles");
            this.m_LandSpeeder_1.UpdateOrder = 5;
            this.Components.Add(this.m_LandSpeeder_1);
            this.Physics.RegisterObject(m_LandSpeeder_1);

            // Land speeder 2
            this.m_LandSpeeder_2             = new LandSpeeder(this, "Content/Vehicles");
            this.m_LandSpeeder_2.UpdateOrder = 5;
            this.Components.Add(this.m_LandSpeeder_2);
            this.Physics.RegisterObject(m_LandSpeeder_2);

            // El tanque del jugador 1
            this.m_Rhino_1             = new Rhino(this, "Content/Vehicles");
            this.m_Rhino_1.UpdateOrder = 5;
            this.Components.Add(this.m_Rhino_1);
            this.Physics.RegisterObject(m_Rhino_1);

            // El tanque del jugador 2
            this.m_Rhino_2             = new Rhino(this, "Content/Vehicles");
            this.m_Rhino_2.UpdateOrder = 5;
            this.Components.Add(this.m_Rhino_2);
            this.Physics.RegisterObject(m_Rhino_2);

            // Prueba
            //this.ball1 = new BallGameComponent(this, 1f, 1f);
            //this.Components.Add(ball1);
            //this.Physics.RegisterVehicle(ball1);

            //this.ball2 = new BallGameComponent(this, 1.5f, 2f);
            //this.Components.Add(ball2);
            //this.Physics.RegisterVehicle(ball2);

            //this.ball3 = new BallGameComponent(this, 2f, 4f);
            //this.Components.Add(ball3);
            //this.Physics.RegisterVehicle(ball3);

            //RodComponent rod1 = new RodComponent(this, this.ball1, Vector3.Up * this.ball1.Radius, null, new Vector3(0, 40, 0), 10f);
            //this.Components.Add(rod1);
            //this.Physics.RegisterContactGenerator(rod1.Rod);

            //RodComponent rod2 = new RodComponent(this, this.ball2, Vector3.Up * this.ball2.Radius, null, new Vector3(0, 40, 0), 10f);
            //this.Components.Add(rod2);
            //this.Physics.RegisterContactGenerator(rod2.Rod);

            //JointComponent joint1 = new JointComponent(this, this.ball1, Vector3.Down * this.ball1.Radius, this.ball3, Vector3.Left * this.ball3.Radius, 5f);
            //this.Components.Add(joint1);
            //this.Physics.RegisterContactGenerator(joint1.Joint);

            //JointComponent joint2 = new JointComponent(this, this.ball2, Vector3.Down * this.ball2.Sphere.Radius, this.ball3, Vector3.Right * this.ball3.Sphere.Radius, 5f);
            //this.Components.Add(joint2);
            //this.Physics.RegisterContactGenerator(joint2.Joint);

            //Joint2Component rod24 = new Joint2Component(this, this.ball1, Vector3.Up * this.ball1.Radius, null, new Vector3(0, 40, 0), 10f);
            //this.Components.Add(rod24);
            //this.Physics.RegisterContactGenerator(rod24.Rod);

            // Establecer el foco en el vehículo
            this.SetFocus(this.m_Rhino_1);

            base.Initialize();

            this.Reset();
        }