Beispiel #1
0
        public void Update(MapEngine map)
        {
            switch (Movement)
            {
            case Movement.Walking:

                if (Pos == _destination || (_destination.X == 0 && _destination.Y == 0) || _step > 100)
                {
                    _destination = NextDestination();
                }

                var oldPos = Pos;

                // move towards destination
                if (Pos.X > _destination.X && Pos.X > 0 && !map.IsCollision(Pos, Direction.Left))
                {
                    Pos.X--;
                }
                else if (Pos.X < _destination.X && Pos.X < map.Width && !map.IsCollision(Pos, Direction.Right))
                {
                    Pos.X++;
                }

                if (Pos.Y > _destination.Y && Pos.Y > 0 && !map.IsCollision(Pos, Direction.Up))
                {
                    Pos.Y--;
                }
                else if (Pos.Y < _destination.Y && Pos.Y < map.Height && !map.IsCollision(Pos, Direction.Down))
                {
                    Pos.Y++;
                }

                _step++;

                Animation.Step();

                break;
            }
        }
        public void MoveRight(MapEngine map, float deltaTime)
        {
            direction = Direction.Right;

            var dest = Pos;

            dest.X += deltaTime * speedX;

            if (!map.IsCollision(dest.ToVector(), direction))
            {
                Pos.X += deltaTime * speedX;
            }

            if (Pos.X > map.Width)
            {
                Pos.X = map.Width;
            }
        }
        public void MoveLeft(MapEngine map, float deltaTime)
        {
            direction = Direction.Left;

            var dest = Pos;

            dest.X -= deltaTime * speedX;

            if (!map.IsCollision(dest.ToVector(), direction))
            {
                Pos.X -= deltaTime * speedX;
            }

            if (Pos.X < 0)
            {
                Pos.X = 0;
            }
        }
        public void MoveDown(MapEngine map, float deltaTime)
        {
            direction = Direction.Down;

            var dest = Pos;

            dest.Y += deltaTime * speedY;

            if (!map.IsCollision(dest.ToVector(), direction))
            {
                Pos.Y += deltaTime * speedY;
            }

            if (Pos.Y > map.Height)
            {
                Pos.Y = map.Height;
            }
        }
        public void MoveUp(MapEngine map, float deltaTime)
        {
            direction = Direction.Up;

            var dest = Pos;

            dest.Y -= deltaTime * speedY;

            if (!map.IsCollision(dest.ToVector(), direction))
            {
                Pos.Y -= deltaTime * speedY;
            }

            if (Pos.Y < 0)
            {
                Pos.Y = 0;
            }
        }