public void Update(IList <Entity> entities)
        {
            Distance = MaxDistance * MaxDistance;
            Color    = Vector4.Zero;
            Vector2 startPos = Owner.Transform(ref Start);

            foreach (var e in entities)
            {
                if (e == Owner)
                {
                    continue;
                }

                var dx    = e.Position.X - startPos.X;
                var dy    = e.Position.Y - startPos.Y;
                var angle = MathUtil.Mod2PI((float)Math.Atan2(dy, dx));
                if (angle < 0)
                {
                    angle += MathUtil.TwoPi;
                }

                var minAngle = MathUtil.Mod2PI(MidAngle - WidthAngle / 2.0f + Owner.Rotation);
                if (minAngle < 0)
                {
                    minAngle += MathUtil.TwoPi;
                }
                var maxAngle = MathUtil.Mod2PI(MidAngle + WidthAngle / 2.0f + Owner.Rotation);
                if (maxAngle < 0)
                {
                    maxAngle += MathUtil.TwoPi;
                }

                if (maxAngle < minAngle)
                {
                    maxAngle += MathUtil.TwoPi;
                    angle    += MathUtil.TwoPi;
                }

                if (minAngle < maxAngle)
                {
                    if (angle < minAngle || angle > maxAngle)
                    {
                        continue;
                    }
                }

                var distSqr = dx * dx + dy * dy;
                if (distSqr < Distance)
                {
                    Distance = distSqr;
                    Color    = e.Color;
                }
            }

            Distance = (float)Math.Sqrt(Distance);
        }
Ejemplo n.º 2
0
 protected override void UpdateEntity(float dt, Entity entity)
 {
     var tc = entity.Get<TypeChanger>();
     if ((tc.TTL -= dt) <= 0)
     {
         for (int i = 0; i < entity.Count(); ++i)
         {
             entity.Transform(i, tc.Transformation);
         }
     }
 }
Ejemplo n.º 3
0
        protected override void UpdateEntity(float dt, Entity entity)
        {
            if (entity.Count() == 0)
            {
                return;
            }
            var direction = entity.Get<Direction>();
            var position = entity.Get<Position>();
            var input = entity.Get<InputComponent>();
            var hotspots = entity.Get<Hotspots>();

            float accel = dt * 0.8f;
            if (input.Right)
            {
                direction.X[0] = direction.X[0] + accel * (24.0f - direction.X[0]);
            }
            if (input.Left)
            {
                direction.X[0] = direction.X[0] + accel * (-24.0f - direction.X[0]);
            }
            if (!(input.Left || input.Right))
            {
                if (hotspots.BottomHit[0])
                {
                    direction.X[0] = direction.X[0] + dt * (0 - direction.X[0]);
                }
                else
                {
                    direction.X[0] = direction.X[0] + dt * .1f * (0 - direction.X[0]);
                }
            }
            if (input.Jump && hotspots.BottomHit[0])
            {
                if (input.Down)
                {
                    direction.Y[0] = 1.5f;
                    entity.Transform(0, input.DroppingPlayer);
                    input.DroppingPlayer.Get<TypeChanger>().Transformation = entity;
                    input.DroppingPlayer.Get<TypeChanger>().TTL = 0.8f;
                }
                else
                {
                    direction.Y[0] = -32.0f;
                }
            }
        }