/// <summary>
        /// Añade un edificio del tipo especificado
        /// </summary>
        /// <param name="type">Tipo</param>
        /// <param name="where">Posición inicial</param>
        /// <returns>Devuelve el edificio añadido</returns>
        public Building AddBuilding(BuildingTypes type, Point where)
        {
            Building newBuilding = null;

            if (type == BuildingTypes.Type0)
            {
                newBuilding = new BuildingType0(this.Game, @"Content/Buildings/", @"WHBuilding01.xml");
            }

            if (newBuilding != null)
            {
                newBuilding.UpdateOrder = this.UpdateOrder;

                this.Game.Components.Add(newBuilding);

                updateList = true;

                newBuilding.Position = new Vector3(where.X, 0f, where.Y);
            }

            return(newBuilding);
        }
Пример #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();
        }