Exemplo n.º 1
0
        public static void chargePosition(CodableEntity codeEntity, Vector2 position, float chargeSpeed)
        {
            float distanceX = position.X - codeEntity.Center.X;  //get distance from the target
            float distanceY = position.Y - codeEntity.Center.Y;

            float totalDistance = (float)Math.Sqrt(distanceX * distanceX + distanceY * distanceY); //get the total distance

            codeEntity.velocity.X = distanceX * 5f / totalDistance * chargeSpeed;
            codeEntity.velocity.Y = distanceY * 5f / totalDistance * chargeSpeed;
        }
Exemplo n.º 2
0
        /*
         * use this one instead
         */
        public static void chargeTarget(CodableEntity codeEntity, Player target, float chargeSpeed)
        {
            codeEntity.velocity *= 0.98f;                              //slow down

            float distanceX = target.position.X - codeEntity.Center.X; //get distance from the target
            float distanceY = target.position.Y - codeEntity.Center.Y;

            float totalDistance = (float)Math.Sqrt(distanceX * distanceX + distanceY * distanceY);  //get the total distance

            codeEntity.velocity.X = distanceX * 5f / totalDistance * chargeSpeed;
            codeEntity.velocity.Y = distanceY * 5f / totalDistance * chargeSpeed;
        }
Exemplo n.º 3
0
        public static void MoveToLocation(CodableEntity codeEntity, Vector2 location, float movement = 0.07f, float mult = 6f)  //copied mostly from terraria's source code, EoC
        {
            float distX     = location.X - codeEntity.Center.X;
            float distY     = location.Y - codeEntity.Center.Y;
            float distTotal = (float)System.Math.Sqrt((double)(distX * distX + distY * distY));

            distTotal = mult / distTotal;
            distX    *= distTotal;
            distY    *= distTotal;

            if (codeEntity.velocity.X < distX)
            {
                codeEntity.velocity.X += movement;
                if (codeEntity.velocity.X < 0f && distX > 0f)
                {
                    codeEntity.velocity.X += movement;
                }
            }
            else
            {
                if (codeEntity.velocity.X > distX)
                {
                    codeEntity.velocity.X -= movement;
                    if (codeEntity.velocity.X > 0f && distX < 0f)
                    {
                        codeEntity.velocity.X -= movement;
                    }
                }
            }
            if (codeEntity.velocity.Y < distY)
            {
                codeEntity.velocity.Y += movement;
                if (codeEntity.velocity.Y < 0f && distY > 0f)
                {
                    codeEntity.velocity.Y += movement;
                }
            }
            else
            {
                if (codeEntity.velocity.Y > distY)
                {
                    codeEntity.velocity.Y -= movement;
                    if (codeEntity.velocity.Y > 0f && distY < 0f)
                    {
                        codeEntity.velocity.Y -= movement;
                    }
                }
            }
        }
Exemplo n.º 4
0
        /*  Checks if an npc is in a certain range of the player.
         *  @Param target: The target of the npc
         *  @Param npc: the npc itsself.
         *  @Param range: the distance you want to check.
         *  @Param inout: whether or not to check if the target is inside the range our outside the range.
         */
        public static bool IsInRange(Player target, CodableEntity npc, int range, bool insideRange)
        {
            if (insideRange)
            {
                if ((npc.Center - target.Center).Length() < range)
                {
                    return(true);
                }
            }
            if (!insideRange)
            {
                if ((npc.Center - target.Center).Length() > range)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
 /*
  *  Slows down the npc.
  */
 public static void SlowDown(CodableEntity codeEnt, float speed = 0.98f)
 {
     codeEnt.velocity.X *= speed;
     codeEnt.velocity.Y *= speed;
 }