Пример #1
0
        protected override void OnKeyDown(KeyboardKeyEventArgs e)
        {
            if (e.Key == Key.Z)
            {
                _blockPosition.AddX(_block.Width);
                _block = new Texture2D(_block.Id, -_block.Width, _block.Height);
            }

            if (e.Key == Key.X)
            {
                Test();
            }

            if (e.Key == Key.C)
            {
                rotation = 0;
            }
            base.OnKeyDown(e);
        }
Пример #2
0
        public override void Act()
        {
            //Act
            Tracer1.TraceEvent($"Press to make {Name} act");
            ConsoleKey key = Console.ReadKey(true).Key;

            switch (key)
            {
            case ConsoleKey.A:
                Hit();
                break;

            case ConsoleKey.L:
                Loot();
                break;
            }

            //Move
            Tracer1.TraceEvent($"Press to move {Name}");
            ConsoleKey key2 = Console.ReadKey(true).Key;

            switch (key2)
            {
            case ConsoleKey.UpArrow:
                Move(Position.AddY(-1));
                break;

            case ConsoleKey.DownArrow:
                Move(Position.AddY(1));
                break;

            case ConsoleKey.LeftArrow:
                Move(Position.AddX(-1));
                break;

            case ConsoleKey.RightArrow:
                Move(Position.AddX(1));
                break;
            }
        }
Пример #3
0
        public Game(int width, int height, GraphicsMode mode, string title, long tickRateMillis, long serverTickRateMillis)
            : base(width, height, mode, title, tickRateMillis, serverTickRateMillis)
        {
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            _debugger = new GameDebugger(this);
            _debugger.Initialize();
            _block         = SpriteLoader.LoadTexture("slimeBlock.png");
            _blockPosition = new Position {
                Current = Vector2.Zero
            };
            _enemyPosition = new Position {
                Current = Vector2.One
            };
            _enemy  = SpriteLoader.LoadTexture("alienBlue_front.png");
            _camera = new TweenCamera
            {
                Zoom     = 1,
                Position = new Position {
                    Current = Vector2.One
                }
            };

            UpdateQueue.Instance.Enqueue(-1, () =>
            {
                if (Focused)
                {
                    var state = Keyboard.GetState(0);

                    if (state.IsKeyDown(Key.W))
                    {
                        _blockPosition.SubtractY(10);
                    }
                    if (state.IsKeyDown(Key.S))
                    {
                        _blockPosition.AddY(10);
                    }
                    if (state.IsKeyDown(Key.A))
                    {
                        _blockPosition.SubtractX(10);
                    }
                    if (state.IsKeyDown(Key.D))
                    {
                        _blockPosition.AddX(10);
                    }
                    if (state.IsKeyDown(Key.X))
                    {
                        rotation += 2;
                    }
                }

                _camera.SetPosition(_blockPosition.Current);
                _camera.Move();
            });

            _debugger.Run(() =>
                          "Player: " + _blockPosition.Current + " Rotation: " + rotation);


            RenderQueue.Instance.Enqueue(-1, () =>
            {
                Sprite.Sprite.Begin(this);
                _camera.Render(this);
            });

            RenderQueue.Instance.Enqueue(-1, () =>
            {
                Sprite.Sprite.DrawWithRotation(rotation, _block, _player);
                Sprite.Sprite.DrawWithRotation(rotation, _enemy, _enemyRec);
            });
        }