Example #1
0
 public MovementItem(ScreenPoint destination, MovementType type, Directions direction, string animationname)
 {
     this.destination = destination;
     this.type = type;
     this.direction = direction;
     this.animationname = animationname;
 }
Example #2
0
        /// <summary>
        /// Tweens the camera to a destination starting at the cameras current location
        /// </summary>
        /// <param name="endPoint">The ending point that the camera should tween to.</param>
        /// <param name="time">How long in milliseconds it should take to tween.</param>
        public void Tween(ScreenPoint endpoint, int time)
        {
            TweenEffect effect = new TweenEffect(this, endpoint, time);

            lock(this.Effects)
            {
                this.Effects.Add(effect);
            }
        }
        public void BeginMoveDestination(IMovable movable, ScreenPoint destination, bool fireevent)
        {
            if(movable.IsMoving || this.MovableCache.ContainsKey (movable))
                this.EndMove (movable, fireevent, false);

            movable.IgnoreMoveInput = true;
            movable.IsMoving = true;

            this.AddToCache(movable, MovementType.Destination);

            this.InternalMove(movable, destination);

            movable.OnStartedMoving(this, EventArgs.Empty);
        }
        public ScreenPoint GetNextScreenPointTile(ScreenPoint point, Directions direction)
        {
            float x = point.X;
            float y = point.Y;

            if(direction == Directions.North)
                y = (point.Y / 32) * 32;
            else if(direction == Directions.South)
                y = ((point.Y + 32) / 32) * 32;

            if(direction == Directions.East)
                x = ((point.X + 32) / 32) * 32;
            else if(direction == Directions.West)
                x = (point.X / 32) * 32;

            return new ScreenPoint ((int) x, (int) y);
        }
        private bool CollideBeforeMove(BaseCharacter movable, Directions directon)
        {
            float x = movable.Location.X;
            float y = movable.Location.Y;

            #region Destination calculation
            if(directon == Directions.North)
            {
                y -= movable.Speed;
            }
            else if(directon == Directions.South)
            {
                y += movable.Speed;
            }
            else if(directon == Directions.East)
            {
                x += movable.Speed;
            }
            else if(directon == Directions.West)
            {
                x -= movable.Speed;
            }
            #endregion

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

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

            var collisionevent = this.context.EventProvider.GetMapsEvents(movable.WorldName, movable.CurrentMap, collision.ToMapPoint()).Where( p => p.Activation == ActivationTypes.Collision && p.Direction == movable.Direction).FirstOrDefault();
            if(collisionevent != null)
                return false;

            return !this.context.CollisionProvider.CheckCollision (movable, collision);
        }
        private bool MoveDestinationBased(Character movable, List<Character> collided, float speedmodifier)
        {
            bool movedok = true;

            float x = movable.Location.X;
            float y = movable.Location.Y;
            float speed = movable.Speed * speedmodifier;

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

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

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

            movable.Location = destination;

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

            return movedok;
        }
        private ScreenPoint GetDestinationFromDirection(ScreenPoint source, Directions Direction)
        {
            ScreenPoint newSource = new ScreenPoint (source.X, source.Y);

            if(Direction == Directions.North)
                newSource = new ScreenPoint (newSource.X, newSource.Y - 32);
            else if(Direction == Directions.South)
                newSource = new ScreenPoint (newSource.X, newSource.Y + 32);
            else if(Direction == Directions.East)
                newSource = new ScreenPoint (newSource.X + 32, newSource.Y);
            else if(Direction == Directions.West)
                newSource = new ScreenPoint (newSource.X - 32, newSource.Y);

            return newSource;
        }
 public MovementChangedEventArgs(Character character, MovementStage stage, ScreenPoint location)
 {
     this.Character = character;
     this.Stage = stage;
     this.location = location;
 }
Example #9
0
 public ScreenPoint(ScreenPoint point)
     : base(point.ToPoint())
 {
 }
 public void BeginMoveDestination(IMovable movable, ScreenPoint destination)
 {
     this.BeginMoveDestination(movable, destination, true);
 }
        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;
        }
        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);

            movable.Location = destination;

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

            return movedok;
        }
 private void InternalMove(IMovable movable, ScreenPoint destination)
 {
     movable.MovingDestination = destination;
 }
Example #14
0
 public static ScreenPoint ScreenSpaceToWorldSpace(this BaseCamera self, ScreenPoint point)
 {
     return (point / self.Zoom) + self.Origin;
 }
 public bool CheckCollision(IMovable Source, ScreenPoint Destination)
 {
     return this.CheckCollision(Source, Destination.ToMapPoint());
 }