示例#1
0
        private void EntityMovePlatformer(EntityPlayable entity)
        {
            int w = 0, h = 0;

            if (entity.Mask != null)
            {
                h = entity.Mask.Width;
                w = entity.Mask.Width;
            }

            //By using some logic we can reduce the amount of Collideable terrain to only the immediate surroundings and things that can collide.
            //This will allow for us to greatly reduce neccessary calculations for complex movement.
            float finalX = entity.Location.X;
            float finalY = entity.Location.Y;

            float gravX = (float)((entity.Gravity + entity.GravityMod) * Math.Cos(entity.GravityDirection.DegToRad()));
            float gravY = (float)((entity.Gravity + entity.GravityMod) * -Math.Sin(entity.GravityDirection.DegToRad()));

            //Add gravity
            entity.SpeedHorizontal += gravX;
            entity.SpeedVertical   += gravY;

            //Clamp
            entity.SpeedHorizontal.Clamp(-entity.SpeedHorizontalMax, entity.SpeedHorizontalMax);
            entity.SpeedVertical.Clamp(-entity.SpeedVerticalMax, entity.SpeedVerticalMax);

            if (CollisionSolid(entity, Map.CurrentMap.Solids, gravX * 2, gravY * 2))
            {
                entity.OnGround        = true;
                entity.SpeedHorizontal = 0;
                entity.SpeedVertical   = 0;
            }
            else
            {
                entity.OnGround = false;
            }

            if (CollisionSolid(entity, Map.CurrentMap.Solids))
            {
                entity.Location.X -= gravX;
                entity.Location.Y -= gravY;
            }


            finalX += entity.SpeedHorizontal;
            finalY += entity.SpeedVertical;

            entity.Location.X = finalX;
            entity.Location.Y = finalY;
        }
示例#2
0
 public void EntityMove(EntityPlayable entity)
 {
     if (MovementType == MOVEMENT_NONE)
     {
         return;
     }
     else if (MovementType == MOVEMENT_PLATFORM)
     {
         EntityMovePlatformer(entity);
     }
     else if (MovementType == MOVEMENT_FLOATING)
     {
         EntityMoveFloating(entity);
     }
 }
示例#3
0
 public NpcAI(EntityPlayable target, int ai)
 {
     Target = target;
     AI     = ai;
 }
示例#4
0
 private void EntityMoveFloating(EntityPlayable entity)
 {
 }