Example #1
0
        public Animation AddFrame(string TexturePath, int?AnimationLength = null)
        {
            if (AnimationLength.HasValue)
            {
                defaultAnimationLength = AnimationLength.Value;
            }

            Texture2D texture  = SpriteLoader.LoadTexture(TexturePath);
            Frame     newFrame = new Frame(texture, defaultAnimationLength);

            frames.Add(newFrame);

            return(this);
        }
Example #2
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);
            });
        }