예제 #1
0
        public void Draw(RenderWindow window)
        {
            Map.Draw(window);
            List <PEntity> draw = new List <PEntity>(Pentities);

            while (draw.Count > 0)
            {
                PEntity minY = draw[0];
                foreach (var entity in draw)
                {
                    if (entity.Position.Y < minY.Position.Y)
                    {
                        minY = entity;
                    }
                }
                minY.Draw(window);
                draw.Remove(minY);
            }
        }
예제 #2
0
 public void Hit(PEntity target)
 {
     Experience += target.TakeDamage(this, Strength);
     Busy        = true;
 }
예제 #3
0
 public bool InReach(PEntity target, float scale = 1)
 {
     return((Position.X - target.Position.X) * (Position.X - target.Position.X) +
            (Position.Y - target.Position.Y) * (Position.Y - target.Position.Y) < (Reach * scale) * (Reach * scale));
 }
예제 #4
0
        public bool Move(Time elapsed)
        {
            Vector2f deltaFirst  = new Vector2f(0, 0);
            Vector2f deltaSecond = new Vector2f(0, 0);

            if (Velocity.X < 0)
            {
                deltaFirst.X  = -1;
                deltaSecond.X = -1;
            }
            else if ((Velocity * elapsed.AsSeconds()).X > 0)
            {
                deltaFirst.X  = 1;
                deltaSecond.X = 1;
            }
            if ((Velocity * elapsed.AsSeconds()).Y < 0)
            {
                deltaFirst.Y = -1;
            }
            else if ((Velocity * elapsed.AsSeconds()).Y > 0)
            {
                deltaFirst.Y = 1;
            }
            float longer  = MathF.Abs((Velocity * elapsed.AsSeconds()).X);
            float shorter = MathF.Abs((Velocity * elapsed.AsSeconds()).Y);

            if (!(longer > shorter))
            {
                longer  = shorter;
                shorter = MathF.Abs((Velocity * elapsed.AsSeconds()).X);
                if ((Velocity * elapsed.AsSeconds()).Y < 0)
                {
                    deltaSecond.Y = -1;
                }
                else if ((Velocity * elapsed.AsSeconds()).Y > 0)
                {
                    deltaSecond.Y = 1;
                }
                deltaSecond.X = 0;
            }

            float numerator = longer / 2;

            for (int i = 0; i <= longer; i++)
            {
                PEntity found = Game.EntityAt(Position);
                if (found != null && found != Owner && found.IsHittable() && found != this)
                {
                    Owner.Experience += found.TakeDamage(Owner, Owner.Agility);
                    return(true);
                }
                numerator += shorter;
                if (!(numerator < longer))
                {
                    numerator  -= longer;
                    Position.X += deltaFirst.X;
                    Position.Y += deltaFirst.Y;
                }
                else
                {
                    Position.X += deltaSecond.X;
                    Position.Y += deltaSecond.Y;
                }
            }

            return(false);
        }