Example #1
0
        private void RenderWindow_KeyPressed(object sender, SFML.Window.KeyEventArgs e)
        {
            Vector2D copy = position;

            if (e.Code == Keyboard.Key.Left)
            {
                position.X -= speed.X;
                animation.SetCurrentAnimation("player_left");
            }
            if (e.Code == Keyboard.Key.Right)
            {
                position.X += speed.X;
                animation.SetCurrentAnimation("player_right");
            }
            if (e.Code == Keyboard.Key.Up)
            {
                position.Y -= speed.Y;
                animation.SetCurrentAnimation("player_up");
            }
            if (e.Code == Keyboard.Key.Down)
            {
                position.Y += speed.Y;
                animation.SetCurrentAnimation("player_down");
            }
            animation.Update(deltaTime);
        }
Example #2
0
        public Player()
        {
            this.speed    = new Vector2D(3, 3);
            this.position = new Vector2D(10, 10);

            animation = AnimationGroupManager.GetAnimationGroup("player_animation");
            animation.SetCurrentAnimation("player_up");

            Program.RenderWindow.KeyPressed  += RenderWindow_KeyPressed;
            Program.RenderWindow.KeyReleased += RenderWindow_KeyReleased;
        }
Example #3
0
        public void Move(Direction direction)
        {
            Vector2D movement = VectorHelper.GetDirectionVector(direction, speed);

            animation.SetCurrentAnimation(animationCouples[direction]);
            animation.Update(deltaTime);

            if (!Collides(direction))
            {
                position += movement;
                base.UpdateHitboxPosition();
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Collides");
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }