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; }
public void EntityMove(EntityPlayable entity) { if (MovementType == MOVEMENT_NONE) { return; } else if (MovementType == MOVEMENT_PLATFORM) { EntityMovePlatformer(entity); } else if (MovementType == MOVEMENT_FLOATING) { EntityMoveFloating(entity); } }
public NpcAI(EntityPlayable target, int ai) { Target = target; AI = ai; }
private void EntityMoveFloating(EntityPlayable entity) { }