コード例 #1
0
        private void Window_Initialized(object sender, EventArgs e)
        {
            MainPlayer.Initialize();
            float aspectRatio = (float)view1.Width / (float)view1.Height;

            Camera.CurrentBehavior = Behavior.Spectator;
            //Camera.Perspective((float)Math.PI / 4.0f, aspectRatio, 1.0f, 1000000.0f);
            Camera.Perspective((float)Math.PI / 4.0f, aspectRatio, 1.0f, 4000.0f);
            Camera.Position      = new Vector3(0, 0, 0);
            Camera.Velocity      = new Vector3(40.0f, 40.0f, 40.0f);
            Camera.RotationSpeed = 0.25f;
            WorldTime.Speed      = 0;

            //compile shaders
            List <BaseGameObject> shaders = WorldData.GetObjectsByType(typeof(Shader));

            foreach (Shader s in shaders)
            {
                s.Recompile();
            }



            SpriteDrawer.Initialize();
            DeferredRenderer.Initialize((int)view1.Width, (int)view1.Height);
            DeferredRenderer.RenderHeight = (int)view1.Height;
            DeferredRenderer.RenderWidth  = (int)view1.Width;
            SkyDome.Initialize();
            Rendering.Grid.Initialize();

            view1.OnRenderView += new EventHandler(view1_OnRender);
            view1.D3DScene      = new CellViewer((int)view1.Width, (int)view1.Height);
            view1.OnRenderView += new EventHandler(view1_OnRender);

            this.WindowState = System.Windows.WindowState.Maximized;


            GameData.LoadGameData();
            PhysicsEngine.Initialize();
            ScriptManager.Initialize();
        }
コード例 #2
0
        protected override void Initialize()
        {
            //GameWorld.Initialize(this.Window, GraphicsDeviceManager.ScreenWidth, GraphicsDeviceManager.ScreenHeight);
            //GameWorld.DeSerializeWorld(@"..\..\Content\export\World\physicsTest.world");

            PlayerInput.Initialize();
            float aspectRatio = (float)GraphicsDeviceManager.ScreenWidth / (float)GraphicsDeviceManager.ScreenHeight;

            Camera.CurrentBehavior = Behavior.Spectator;
            Camera.Perspective((float)Math.PI / 4.0f, aspectRatio, 1.0f, 1000000.0f);
            Camera.Position = new Vector3(0.0f, 10.0f, 0.0f);
            Camera.Velocity = new Vector3(40.0f, 40.0f, 40.0f);


            KeyboardInput.CreateDevice(this.Window);
            MouseInput.CreateDevice(this.Window);
            PrintText.Initialize();
            EffectManager.Initialize();
            SpriteDrawer.Initialize();
            DeferredRenderer.Initialize(GraphicsDeviceManager.ScreenWidth, GraphicsDeviceManager.ScreenHeight);

            SkyDome.Initialize();
            PhysicsEngine.Initialize();
        }
コード例 #3
0
ファイル: TheGame.cs プロジェクト: khlieng/ProjectHeis
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);
            font = Content.Load<SpriteFont>("Sprites/arial");
            bigFont = Content.Load<SpriteFont>("Sprites/big");

            box = Content.Load<Model>("Models/box");
            (box.Meshes[0].Effects[0] as BasicEffect).EnableDefaultLighting();
            treeModel = Content.Load<Model>("Models/tree");
            (treeModel.Meshes[0].MeshParts[0].Effect as BasicEffect).EnableDefaultLighting();

            textureBuilding = Content.Load<Texture2D>("Texture/Building_texture3");
               /*effect.TextureEnabled = true;
            effect.Texture = textureBuilding;*/

            ElevatortMusic = Content.Load<Song>("Audio\\elevatorMusic");
            ElevatorBell = Content.Load<Song>("Audio\\ElevatorBell");

            #region Player
            player = new Entity(this, box);
            player.Position = new Vector3(0, 120, 0);
            player.Controller = new KeyboardController(player);
            player.Scale = new Vector3(0.01f, 0.02f, 0.01f);
            player.Gravity = true;
            player.Color = Color.Purple;
            #endregion

            #region floor
            floor = new Entity(this, box);
            floor.Scale = new Vector3(0.99f, 0.5f, 0.99f);
            floor.Position = new Vector3(0, -50, 0);
            #endregion

            #region walls
            Entity wall = new Entity(this, box);
            wall.Position = new Vector3(100, 450, 0);
            wall.Scale = new Vector3(0.02f, 5, 1);
            wall.Texture = textureBuilding;
            Entity wall2 = new Entity(this, box);
            wall2.Position = new Vector3(0, 450, 100);
            wall2.Scale = new Vector3(1, 5, 0.02f);
            wall2.Texture = textureBuilding;
            Entity wall3 = new Entity(this, box);
            wall3.Position = new Vector3(0, 450, -100);
            wall3.Scale = new Vector3(1, 5, 0.02f);
            wall3.Texture = textureBuilding;
            Entity wall4 = new Entity(this, box);
            wall4.Position = new Vector3(-100, 500, 20);
            wall4.Scale = new Vector3(0.02f, 4.5f, 0.8f);
            wall4.Texture = textureBuilding;
            #endregion

            #region elevator
            elevator = new Entity(this, box);
            elevator.Color = Color.LimeGreen;
            elevator.Scale = new Vector3(0.2f, 0.02f, 0.2f);
            elevator.Position = new Vector3(-120, 0, -80);
            #endregion

            #region Tree model
            Entity tree = new Entity(this, treeModel);
            tree.Scale = new Vector3(0.15f);
            tree.Position = new Vector3(50, 10, 50);
            Entity tree2 = new Entity(this, treeModel);
            tree2.Scale = new Vector3(0.17f);
            tree2.Position = new Vector3(30, 5, 40);
            Entity tree3 = new Entity(this, treeModel);
            tree3.Scale = new Vector3(0.2f);
            tree3.Position = new Vector3(40, 5, 10);
            #endregion

            #region Skydome and Terrain
            Terrain terrain = new Terrain(this);
            terrain.Initialize();
            SkyDome skyDome = new SkyDome(this);
            skyDome.Initialize();
            #endregion

            #region ShaftWall(elevator shaft)
            Entity shaftWall1 = new Entity(this, box);
            shaftWall1.Position = new Vector3(-121, 450, -100);
            shaftWall1.Scale = new Vector3(0.21f, 5, 0.02f);
            //shaftWall1.Texture = Content.Load<Texture2D>("trans");
            Entity shaftWall2 = new Entity(this, box);
            shaftWall2.Position = new Vector3(-121, 450, -60);
            shaftWall2.Scale = new Vector3(0.21f, 5, 0.02f);
            //shaftWall2.Texture = Content.Load<Texture2D>("trans");
            shaftWall1.Alpha = 0.5f;
            shaftWall2.Alpha = 0.5f;
            #endregion
            staticEntities.Add(shaftWall1);
            staticEntities.Add(shaftWall2);

            floors = new Entity[20];
            doors = new ElevatorDoors[20];
            floorNumbers = new BoundingBox[20];
            elevatorFronts = new BoundingBox[20];
            for (int i = 0; i < floors.Length; i++)
            {
                floors[i] = new Entity(this, box);
                floors[i].Position = new Vector3(0, i * 50, 0);
                floors[i].Scale = new Vector3(0.99f, 0.02f, 0.99f);

                doors[i] = new ElevatorDoors(this, i, box);

                BoundingBox bb = floors[i].BB;
                bb.Min.X -= 45;
                bb.Max.Y += 40;
                floorNumbers[i] = bb;

                bb.Min.X += 45;
                bb.Max.X -= 175;
                bb.Max.Z -= 150;
                elevatorFronts[i] = bb;
            }

            #region add component
            staticEntities.Add(wall);
            staticEntities.Add(wall2);
            staticEntities.Add(wall3);
            staticEntities.Add(wall4);
            staticEntities.Add(elevator);
            movingEntities.Add(player);

            Components.Add(terrain);
            Components.Add(skyDome);
            #endregion

            #region elevatorButtons
            elevatorButtons = new TextButton[20];
            for (int i = 0; i < elevatorButtons.Length; i++)
            {
                elevatorButtons[i] = new TextButton(this, new Vector2(50 + i * 60, 650), (i+1)+"", bigFont);
                elevatorButtons[i].Click += (o, e) =>
                {
                    int targetFloor = int.Parse((o as TextButton).Text);
                    TrySelectFloor(targetFloor);
                };
                //elevatorButtons[i].Visible = true;
                elevatorButtons[i].Enabled = false;
                elevatorButtons[i].DrawOrder = 10;
            }
            #endregion

            #region AddDoors
            staticEntities.Add(floor);
            for (int i = 0; i < floors.Length; i++)
            {
                staticEntities.Add(floors[i]);
                staticEntities.Add(doors[i].LeftDoor);
                staticEntities.Add(doors[i].RightDoor);
                //staticEntities.Add(doors[i * 2]);
                //staticEntities.Add(doors[i * 2 + 1]);
            }
            #endregion

            Camera = new Camera(this, player);
            Camera.Initialize();

            ParticleEmitter emitter = new ParticleEmitter(this);
            emitter.Initialize();
            Components.Add(emitter);
        }