예제 #1
0
        public MainWindow()
        {
            _resource = new VanillaResource();
            _font     = new Font(_resource, "default");

            _chunk = new Chunk2D();
            _chunk.Fill(0, 0, 0, 256, 0, 0, "bedrock");
            _chunk.Fill(0, 1, 0, 256, 60, 0, "stone");
            _chunk.Fill(0, 61, 0, 256, 62, 0, "dirt");
            _chunk.Fill(0, 63, 0, 256, 63, 0, "grass_block_side");

            var rand = new Random();

            for (int i = 0; i < 800; i++)
            {
                switch (rand.Next(11))
                {
                case 0:
                    _chunk.SetBlock(rand.Next(256), rand.Next(13) + 1, "diamond_ore");
                    break;

                case 1:
                case 2:
                    _chunk.SetBlock(rand.Next(256), rand.Next(30) + 3, "gold_ore");
                    break;

                case 3:
                case 4:
                case 5:
                    _chunk.SetBlock(rand.Next(256), rand.Next(40) + 10, "iron_ore");
                    break;

                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                    _chunk.SetBlock(rand.Next(256), rand.Next(45) + 15, "coal_ore");
                    break;
                }
            }

            _hud = new HudRenderer(this, () => _atlases, _font);
            _hud.Add(new TextHudObject {
                Text = "Hello, World!"
            });

            _viewInput       = this.CreateKeyAxisInput(negativeXKey: Keys.A, positionXKey: Keys.D, negativeYKey: Keys.S, positionYKey: Keys.W, negativeZKey: Keys.Minus, positionZKey: Keys.Equal).CreateScaledAxisInput(4F).CreateSmoothAxisInput();
            _playerMoveInput = this.CreateKeyAxisInput(negativeXKey: Keys.Left, positionXKey: Keys.Right, negativeYKey: Keys.Down, positionYKey: Keys.Up);

            _player = new Player();
            _boxObj = new BoxObject();

            //KeyDown += (sender, e) => Console.WriteLine(e.Key);

            this.AddCompletedRenderer(_hud);
        }
예제 #2
0
        public MainWindow()
        {
            _resource = new VanillaResource();
            _eye      = new Eye
            {
                DepthFar = 1024F,
            };
            _viewTransformProvider       = _eye.GetViewTransformProvider();
            _projectionTransformProvider = _eye.GetPerspectiveTransformProvider();
            _eyeInput  = this.CreatePointerAxisInput(.5F, true).CreateSmoothAxisInput();
            _moveInput = this.CreateKeyAxisInput(Keys.D, Keys.Space, Keys.S, Keys.A, Keys.LeftShift, Keys.W, true).CreateScaledAxisInput(10F).CreateSmoothAxisInput();
            _world     = new EmptyWorld
            {
                ChunkProvider = (x, z) => new EmptyChunk {
                    X = x, Z = z, World = _world
                }
            };
            _world.FillFast(0, 0, 0, 256, 0, 256, "bedrock");
            _world.FillFast(0, 1, 0, 256, 10, 256, "iron_block");
            _world.FillFast(0, 11, 0, 256, 11, 256, "diamond_block");

            _world.Fill(15, 12, 14, 16, 13, 17, "gold_block");
            _world.Fill(3, 12, 3, 5, 13, 5, "gold_block");


            _playerObject = new() { OriginalAABB = new Box3d(-.5D, -.5D, -.5D, .5D, .5D, .5D), GravityScale = 1D, Position = (0D, 15D, 0) };
            _floorObject  = new BlockCollisionObject(_world);

            _boxRenderer = new(_viewTransformProvider, _projectionTransformProvider) { Color = Color4.Blue };

            /*_cameraMotivatorRenderer = new CameraMotivatorRenderer(_eye)
             * {
             *  RotationInput = _eyeInput,
             *  PositionInput = _moveInput,
             *  MovementSpeed = 1F,
             *  Type = CameraType.Fps,
             *  Controlable = true
             * };*/
            this.AddCompletedRenderer(new CloudRenderer(_eye, _viewTransformProvider, _projectionTransformProvider, _resource));
            this.AddCompletedRenderer(new WorldRenderer(_world, () => _atlases, _viewTransformProvider, _projectionTransformProvider)
            {
                Camera = _eye, AutoSetCenterChunk = true
            });
            this.AddRenderObject(_boxRenderer);
            PointerGrabbed = true;
        }