Ejemplo n.º 1
0
        public void MoveASmoothStepTo(WorldPosition target, float factor)
        {
            factor = Math.Min(factor, 1.0f);
            factor = Math.Max(factor, 0.0f);

            X = (factor - X) / (target.X - X);
            Y = (factor - Y) / (target.Y - Y);
        }
Ejemplo n.º 2
0
 public override void Read(PacketReader reader)
 {
     EntityId = reader.ReadInt();
     Position = new WorldPosition
     {
         X = reader.ReadFloat(),
         Y = reader.ReadFloat()
     };
     Direction = reader.ReadFloat();
     Speed = reader.ReadFloat();
     #if DEBUG
     Console.WriteLine(ToString());
     #endif
 }
Ejemplo n.º 3
0
 protected virtual void SetPosition(WorldPosition position)
 {
     _position = position;
 }
Ejemplo n.º 4
0
 public MovePacket()
 {
     Position = new WorldPosition();
 }
Ejemplo n.º 5
0
        internal void SendPacketToNearbyPlayers(WorldPosition pos, Packet packet, Client excludedClient = null)
        {
            Client[] nearbyClients = GetNearbyPlayers(pos).ToArray();

            if (nearbyClients.Length == 0)
                return;

            packet.SetShared(nearbyClients.Length);

            Parallel.ForEach(nearbyClients, client =>
                {
                    if (excludedClient != client)
                    {
                        client.SendPacket(packet);
                    }
                    else
                    {
                        packet.Release();
                    }
                });
        }
Ejemplo n.º 6
0
 internal IEnumerable<Client> GetNearbyPlayers(WorldPosition pos)
 {
     int radius = SightRadius;
     foreach (Client c in GetClients())
     {
         int playerPatternX = (int) Math.Floor(c.Player.Position.X) >> 5;
         int playerPatternY = (int) Math.Floor(c.Player.Position.Y) >> 5;
         if (Math.Abs(pos.X - playerPatternX) <= radius && Math.Abs(pos.Y - playerPatternY) <= radius)
             yield return c;
     }
 }
Ejemplo n.º 7
0
 public WorldPosition SmoothStep(WorldPosition target, float factor)
 {
     WorldPosition step = new WorldPosition(this);
     step.MoveASmoothStepTo(target, factor);
     return step;
 }
Ejemplo n.º 8
0
 public WorldPosition(WorldPosition src)
 {
     X = src.X;
     Y = src.Y;
 }
Ejemplo n.º 9
0
 protected override void SetPosition(WorldPosition position)
 {
     if (_position == null)
     {
         _position = new WorldPosition();
     }
     _position.X = position.X;
     _position.Y = position.Y;
     if (VisualPosition == null)
     {
         VisualPosition = new WorldPosition(_position);
     }
 }
Ejemplo n.º 10
0
        public void Move(int entityId, WorldPosition position, float direction, float speed)
        {
            IEntity entity;
            if (!GameScene.Entities.TryGetValue(entityId, out entity))
            {
                Console.WriteLine("Couldn't find entity with id" + entityId);
                return;
            }

            entity.StopMoving(null);
            entity.Position = position;
            if (speed > 0)
            {
                entity.PrepareToMove(direction, speed);
            }
        }
Ejemplo n.º 11
0
 public void HandlePlayerPosition(PlayerPositionPacket ppp)
 {
     Console.WriteLine("Received Player Position Packet");
     if (GameScene.Player != null)
     {
         WorldPosition wp = new WorldPosition(ppp.X, ppp.Y);
         GameScene.Player.Position = wp;
     }
     else
     {
         Console.WriteLine("Error. Player should exist");
     }
 }