コード例 #1
0
        private bool MoveDestinationBased(IMovable movable, List<IMovable> collided)
        {
            bool movedok = true;

            float x = movable.Location.X;
            float y = movable.Location.Y;

            if(x < movable.MovingDestination.X)
            {
                if(x + movable.Speed > movable.MovingDestination.X)
                    x = movable.MovingDestination.X;
                else
                    x += movable.Speed;
            }
            else if(x > movable.MovingDestination.X)
            {
                if(x + movable.Speed < movable.MovingDestination.X)
                    x = movable.MovingDestination.X;
                else
                    x -= movable.Speed;
            }

            if(y > movable.MovingDestination.Y)
            {
                if(y - movable.Speed < movable.MovingDestination.Y)
                    y = movable.MovingDestination.Y;
                else
                    y -= movable.Speed;
            }
            else if(y < movable.MovingDestination.Y)
            {
                if(y + movable.Speed > movable.MovingDestination.Y)
                    y = movable.MovingDestination.Y;
                else
                    y += movable.Speed;
            }

            ScreenPoint destination = new ScreenPoint((int)x, (int)y);

            ScreenPoint collision = new ScreenPoint(destination.X, destination.Y);

            if(movable.Direction == Directions.South)
                collision = new ScreenPoint(destination.X, destination.Y + 32);
            else if(movable.Direction == Directions.East)
                collision = new ScreenPoint(destination.X + 32, destination.Y);

            MapPoint lastpoint = movable.GlobalTileLocation;

            movable.Location = destination;

            if(destination.ToMapPoint () != lastpoint)
                movable.OnTileLocationChanged (movable, EventArgs.Empty);

            if(destination == movable.MovingDestination)
                movedok = false;

            return movedok;
        }
コード例 #2
0
        private bool MoveTileBased(IMovable movable, List<IMovable> collided)
        {
            bool movedok = true;
            float x = movable.Location.X;
            float y = movable.Location.Y;

            #region Destination calculation
            if(movable.Direction == Directions.North)
            {
                y -= movable.Speed;

                if(y < movable.MovingDestination.Y)
                    y = movable.MovingDestination.Y;
            }
            else if(movable.Direction == Directions.South)
            {
                y += movable.Speed;

                if(y > movable.MovingDestination.Y)
                    y = movable.MovingDestination.Y;
            }
            else if(movable.Direction == Directions.East)
            {
                x += movable.Speed;

                if(x > movable.MovingDestination.X)
                    x = movable.MovingDestination.X;
            }
            else if(movable.Direction == Directions.West)
            {
                x -= movable.Speed;

                if(x < movable.MovingDestination.X)
                    x = movable.MovingDestination.X;
            }
            #endregion

            ScreenPoint destination = new ScreenPoint((int)x, (int)y);

            ScreenPoint collision = new ScreenPoint(destination.X, destination.Y);

            if(movable.Direction == Directions.South)
                collision = new ScreenPoint(destination.X, destination.Y + 32 - (int)movable.Speed);
            else if(movable.Direction == Directions.East)
                collision = new ScreenPoint(destination.X + 32 - (int)movable.Speed, destination.Y);

            if(!this.context.CollisionProvider.CheckCollision(movable, collision))
            {
                movable.IsMoving = false;
                movedok = false;

                collided.Add(movable);
            }
            else
            {
                if(destination.ToMapPoint () != movable.GlobalTileLocation)
                    movable.OnTileLocationChanged (this, EventArgs.Empty);

                movable.Location = destination;

                //if(movable.GlobalTileLocation != movable.LastMapLocation)
                //movable.OnTileLocationChanged(this, EventArgs.Empty);

                if(movable.Location == movable.MovingDestination)
                {
                    movable.MovingDestination = this.GetDestinationFromDirection(movable, movable.Direction);
                }
            }

            return movedok;
        }
コード例 #3
0
 public bool CheckCollision(IMovable Source, ScreenPoint Destination)
 {
     return this.CheckCollision(Source, Destination.ToMapPoint());
 }